:root {
  --rose: #cc6f92;
  --rose-dark: #93516e;
  --peach: #ffd5c7;
  --cream: #fff8fb;
  --lilac: #c5b4ff;
  --mint: #bbf4dd;
  --ink: #653d55;
  --glass: rgba(255, 255, 255, 0.28);
  --glass-strong: rgba(255, 255, 255, 0.48);
  --line: rgba(255, 255, 255, 0.72);
  --shadow: 0 22px 70px rgba(144, 68, 113, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: #f8c0dd;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.bg {
  position: fixed;
  inset: 0;
  background-image: url("assets/peach-dream-mochi.png");
  background-position: center;
  background-size: cover;
  z-index: -4;
}

.bg-clear::after,
.bg-blur::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 198, 223, 0.18);
}

.bg-blur {
  filter: blur(14px);
  transform: scale(1.05);
  opacity: 0;
  transition: opacity 400ms ease;
  z-index: -3;
}

.start-mode .bg-blur {
  opacity: 1;
}

.cloud-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: -1;
}

.cloud {
  position: absolute;
  width: 180px;
  height: 58px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow:
    42px -20px 0 8px rgba(255, 255, 255, 0.68),
    88px -9px 0 18px rgba(255, 255, 255, 0.6),
    126px 4px 0 6px rgba(255, 255, 255, 0.62);
  filter: drop-shadow(0 12px 18px rgba(255, 166, 202, 0.28));
  opacity: 0.74;
  animation: floatCloud linear infinite;
}

.cloud-a {
  top: 12vh;
  left: -240px;
  animation-duration: 44s;
}

.cloud-b {
  top: 34vh;
  left: -360px;
  transform: scale(0.72);
  animation-duration: 58s;
  animation-delay: -19s;
}

.cloud-c {
  top: 63vh;
  left: -290px;
  transform: scale(0.9);
  animation-duration: 52s;
  animation-delay: -35s;
}

.cloud-d {
  top: 78vh;
  left: -310px;
  transform: scale(0.58);
  animation-duration: 67s;
  animation-delay: -11s;
}

.cloud-e {
  top: 22vh;
  left: -330px;
  transform: scale(0.64);
  animation-duration: 61s;
  animation-delay: -42s;
}

@keyframes floatCloud {
  from {
    translate: -12vw 0;
  }
  to {
    translate: 125vw 0;
  }
}

.app-shell {
  min-height: 100vh;
  padding: 22px;
}

.settings-button {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 10;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--rose-dark);
  background: rgba(255, 255, 255, 0.54);
  box-shadow: 0 12px 28px rgba(165, 75, 126, 0.22);
  backdrop-filter: blur(13px);
}

.gear {
  width: 19px;
  height: 19px;
  border: 4px solid currentColor;
  border-radius: 50%;
  position: relative;
}

.gear::before,
.gear::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30px;
  height: 5px;
  border-radius: 999px;
  background: currentColor;
  translate: -50% -50%;
}

.gear::after {
  rotate: 90deg;
}

.screen {
  width: min(1120px, 100%);
  min-height: calc(100vh - 44px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

.title {
  margin: 0;
  color: #a65a7d;
  font-family: "Comic Sans MS", "Segoe Print", cursive;
  font-size: clamp(2.4rem, 8vw, 6.5rem);
  line-height: 0.98;
  text-align: center;
  text-shadow: 0 5px 0 rgba(255, 255, 255, 0.42), 0 18px 35px rgba(123, 63, 98, 0.24);
}

.subtitle {
  margin: 0 auto;
  width: min(680px, 100%);
  color: #834766;
  text-align: center;
  font-weight: 700;
}

.owners-banner {
  margin: 4px auto 0;
  width: min(920px, 100%);
  color: #9a416b;
  font-family: "Comic Sans MS", "Segoe Print", cursive;
  font-size: clamp(1.25rem, 3.4vw, 2.45rem);
  font-weight: 900;
  line-height: 1.08;
  text-align: center;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.55), 0 10px 24px rgba(123, 63, 98, 0.2);
}

.home-owner-banner {
  margin: 8px 0 0;
  text-align: left;
  font-size: clamp(1rem, 2.2vw, 1.7rem);
}

.panel,
.dialog-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.18);
}

.panel {
  padding: clamp(16px, 3vw, 26px);
}

.auth-layout,
.home-layout,
.learn-grid,
.online-grid,
.tutorial-grid {
  display: grid;
  gap: 16px;
}

.auth-layout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.home-layout {
  grid-template-columns: 330px 1fr;
}

.stack {
  display: grid;
  gap: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.spread {
  justify-content: space-between;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.soft-button,
.plain-button,
.select-like,
select,
input[type="text"],
input[type="password"],
.password-wrap input {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.64);
  box-shadow: 0 10px 22px rgba(154, 82, 123, 0.14);
}

.soft-button {
  padding: 11px 16px;
  font-weight: 900;
  color: #82415f;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(255, 221, 235, 0.74));
}

.soft-button.primary {
  color: white;
  border-color: rgba(255, 255, 255, 0.88);
  background: linear-gradient(135deg, #f7bcd8, #c8b6f3 55%, #b9efdb);
}

.soft-button:disabled,
.plain-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  color: rgba(101, 61, 85, 0.66);
  background: rgba(255, 255, 255, 0.38);
  box-shadow: none;
}

.plain-button {
  padding: 9px 12px;
  color: #8b4668;
  font-weight: 800;
}

input,
select {
  width: 100%;
  padding: 0 12px;
}

.password-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.password-wrap input {
  min-width: 0;
}

.show-password {
  width: auto;
  padding: 0 12px;
}

.name-builder {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.name-part {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.name-part span {
  color: #874562;
  font-weight: 900;
  font-size: 0.86rem;
}

.current-name {
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  color: #81415f;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.48);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.avatar-option,
.avatar {
  aspect-ratio: 1;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
  text-shadow: 0 2px 8px rgba(88, 35, 70, 0.34);
  background: var(--avatar-bg, linear-gradient(135deg, #f2a1c0, #b8a8ff));
  overflow: hidden;
}

.avatar-option {
  border: 2px solid rgba(255, 255, 255, 0.58);
}

.avatar-option.selected {
  border-color: #ffffff;
  outline: 3px solid rgba(199, 97, 147, 0.45);
}

.avatar img,
.avatar-option img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 14px;
  align-items: center;
}

.owner-tag,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #7c3c5d;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.6);
}

.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.player-list {
  display: grid;
  gap: 10px;
  max-height: 430px;
  overflow: auto;
  padding-right: 4px;
}

.player-card {
  display: grid;
  grid-template-columns: 52px 1fr minmax(120px, auto);
  align-items: center;
  gap: 10px;
  padding: 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.player-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(66px, 1fr));
  gap: 7px;
}

.soft-button.danger {
  color: #8c3151;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.84), rgba(255, 175, 199, 0.8));
}

.game-screen {
  width: min(1180px, 100%);
  min-height: calc(100vh - 44px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 690px);
  gap: 16px;
  align-items: center;
}

.game-hud {
  display: grid;
  gap: 12px;
}

.game-title {
  margin: 0;
  color: #8f4869;
  font-family: "Comic Sans MS", "Segoe Print", cursive;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
}

.board-wrap {
  position: relative;
  width: min(690px, 96vw);
  aspect-ratio: 1;
}

.ultimate-board {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(6px, 1.1vw, 10px);
  padding: clamp(7px, 1.2vw, 12px);
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.win-line {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 82%;
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.92), #ff79b7 45%, #ffd3e7);
  box-shadow: 0 0 12px rgba(255, 117, 183, 0.72), 0 0 24px rgba(255, 255, 255, 0.58);
  pointer-events: none;
  z-index: 6;
  transform-origin: center;
}

.mini-win-line {
  height: 5px;
  width: 86%;
}

.big-win-line {
  height: clamp(8px, 1.4vw, 14px);
  width: 86%;
  z-index: 8;
}

.line-0 {
  top: 16.666%;
  transform: translate(-50%, -50%);
}

.line-1 {
  transform: translate(-50%, -50%);
}

.line-2 {
  top: 83.333%;
  transform: translate(-50%, -50%);
}

.line-3 {
  left: 16.666%;
  transform: translate(-50%, -50%) rotate(90deg);
}

.line-4 {
  transform: translate(-50%, -50%) rotate(90deg);
}

.line-5 {
  left: 83.333%;
  transform: translate(-50%, -50%) rotate(90deg);
}

.line-6 {
  width: 112%;
  transform: translate(-50%, -50%) rotate(45deg);
}

.line-7 {
  width: 112%;
  transform: translate(-50%, -50%) rotate(-45deg);
}

.mini-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 1px 15px rgba(255, 255, 255, 0.24), 0 10px 20px rgba(108, 55, 92, 0.13);
}

.mini-board.active {
  outline: 3px solid rgba(255, 255, 255, 0.9);
  background: rgba(255, 247, 251, 0.38);
}

.mini-board.finished::after {
  content: attr(data-winner);
  position: absolute;
  inset: 7px;
  display: grid;
  place-items: center;
  padding: 6px;
  border-radius: 8px;
  color: rgba(125, 57, 91, 0.9);
  font-size: clamp(0.68rem, 1.65vw, 1.15rem);
  font-weight: 900;
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-align: center;
  background: rgba(255, 255, 255, 0.48);
  backdrop-filter: blur(2px);
  pointer-events: none;
  z-index: 4;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.28);
  transition: transform 160ms ease, background 160ms ease;
}

.cell:not(:disabled):hover {
  transform: translateY(-1px) scale(1.02);
  background: rgba(255, 255, 255, 0.5);
}

.cell:disabled {
  cursor: default;
}

.piece {
  width: 76%;
  aspect-ratio: 1;
  position: relative;
  animation: popIn 240ms ease both;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.42) rotate(-8deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.emoji-piece {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #fff;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: clamp(1.05rem, 4.3vw, 2.65rem);
  line-height: 1;
  text-shadow: 0 3px 7px rgba(103, 57, 91, 0.3);
  filter: brightness(0) invert(1) drop-shadow(0 5px 6px rgba(103, 57, 91, 0.24));
}

.cat-emoji {
  font-size: clamp(1.05rem, 4vw, 2.55rem);
  transform: translateY(1px) scaleX(1.08);
}

.paw-emoji {
  font-size: clamp(1.12rem, 4.5vw, 2.8rem);
}

.soft-dialog {
  width: min(430px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
}

.soft-dialog::backdrop {
  background: rgba(88, 38, 70, 0.26);
  backdrop-filter: blur(4px);
}

.dialog-card {
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.slider-row,
.check-row {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  font-weight: 900;
}

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.notice {
  min-height: 28px;
  color: #7f3e5d;
  font-weight: 900;
}

.confetti-burst {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 100;
}

.confetti-piece {
  position: absolute;
  left: var(--x);
  top: -18px;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  background: var(--color);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.58);
  animation: confettiFall var(--duration) ease-in var(--delay) forwards;
}

.confetti-piece:nth-child(3n) {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.confetti-piece:nth-child(4n) {
  width: 16px;
  height: 8px;
}

@keyframes confettiFall {
  0% {
    opacity: 0;
    transform: translate3d(0, -20px, 0) rotate(0deg);
  }
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift), 105vh, 0) rotate(var(--spin));
  }
}

.learn-grid,
.online-grid,
.tutorial-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.lesson-card {
  min-height: 150px;
}

.tiny {
  font-size: 0.86rem;
}

@media (max-width: 900px) {
  .auth-layout,
  .home-layout,
  .game-screen,
  .learn-grid,
  .online-grid,
  .tutorial-grid {
    grid-template-columns: 1fr;
  }

  .game-screen {
    align-items: start;
  }

  .board-wrap {
    margin: 0 auto;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 14px;
  }

  .menu-grid,
  .name-builder {
    grid-template-columns: 1fr;
  }

  .player-card {
    grid-template-columns: 42px 1fr;
  }

  .player-card .soft-button,
  .player-actions {
    grid-column: 1 / -1;
  }

  .settings-button {
    top: 10px;
    right: 10px;
  }
}

/* In-game chat box (replaces the title in the HUD during a game) */
.chat-title { font-size: 15px; font-weight: 600; color: var(--rose-dark); margin: 0; }
.chat-box { display: flex; flex-direction: column; gap: 8px; }
.chat-log {
  height: 190px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
}
.chat-msg { font-size: 13px; color: var(--rose-dark); line-height: 1.4; word-break: break-word; }
.chat-msg.mine { text-align: right; }
.chat-msg strong { font-weight: 600; }
.chat-empty { margin: auto; font-size: 12px; color: var(--rose-dark); opacity: 0.6; }
.chat-input { display: flex; gap: 8px; }
.chat-input input {
  flex: 1;
  min-width: 0;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--rose-dark);
  font: inherit;
}
.chat-input .soft-button { padding: 8px 15px; }

/* Keep primary-button text readable when tinted with the user's avatar color */
.soft-button.primary { text-shadow: 0 1px 4px rgba(110, 60, 95, 0.5); }

/* SVG game pieces - identical on every device (replaces OS emoji) */
.piece-svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 4px 5px rgba(103, 57, 91, 0.22)); }
.piece-cat .piece-svg { fill: #b0477e; }
.piece-paw .piece-svg { fill: #5b7fd6; }
.piece-cat .eye { fill: #fff; }
.piece-mini { display: inline-grid; place-items: center; width: 1.05em; height: 1.05em; vertical-align: -0.18em; }
.piece-mini .piece-svg { filter: none; }
