:root {
  color-scheme: light;
  --bg: #f6f0e8;
  --ink: #1b1530;
  --muted: #655d73;
  --coral: #f27b62;
  --paper: #fffdf9;
  --peach: #fde4d4;
  --sky: #d7eefc;
  --butter: #fff3c4;
  --lilac: #e7e0f8;
  --mint: #dcf3df;
  font-family: Outfit, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(rgba(27, 21, 48, 0.16) 1.1px, transparent 1.2px),
    linear-gradient(115deg, rgba(246, 240, 232, 0.2), rgba(214, 228, 244, 0.85));
  background-size: 22px 22px, 100% 100%;
}

button, a { font: inherit; color: inherit; }

.nav, main {
  width: min(1080px, calc(100% - 32px));
  margin-inline: auto;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  padding: 22px 0 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  text-decoration: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand strong { font-size: 1.2rem; letter-spacing: -0.03em; }

.brand-text span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.mark {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 14px;
  background:
    linear-gradient(var(--mint), var(--mint)) 8px 8px / 11px 14px no-repeat,
    linear-gradient(var(--peach), var(--peach)) 22px 12px / 11px 14px no-repeat,
    var(--ink);
}

.hub-back {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.9rem;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--coral);
}

.exit-game {
  padding: 0.45rem 0.9rem;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--coral);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(27, 21, 48, 0.12);
}

.nav .exit-game.hidden { display: none; }

main { flex: 1; padding: 18px 0 36px; }

#landing { padding-top: 18px; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 6px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #3aaa5a;
}

h1 {
  margin: 0;
  max-width: 12ch;
  font-family: Fraunces, Georgia, serif;
  font-weight: 700;
  font-size: clamp(3.2rem, 7vw, 5.2rem);
  letter-spacing: -0.045em;
  line-height: 0.95;
}

h1 em {
  font-style: italic;
  font-weight: 620;
  color: var(--coral);
}

.lede {
  max-width: 36rem;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.5;
}

.landing-actions, .player-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.player-picks { margin-top: 14px; }

.player-picks[hidden] { display: none; }

.rules {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 28px;
}

.rule {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 160px;
  padding: 18px;
  border: 2.5px solid var(--ink);
  border-radius: 24px;
  box-shadow: 6px 6px 0 var(--ink);
}

.rule strong { font-size: 1.35rem; letter-spacing: -0.03em; }
.rule span:last-child { color: var(--muted); line-height: 1.4; }
.rule-index { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.04em; }

.tone-peach { background: var(--peach); }
.tone-mint { background: var(--mint); }
.tone-lilac { background: var(--lilac); }
.tone-sky { background: var(--sky); }
.tone-butter { background: var(--butter); }

.btn {
  padding: 12px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--coral);
}

.btn-lg { padding: 16px 28px; font-size: 1.15rem; }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn.btn-quiet, .btn.btn-exit {
  background: var(--paper);
  box-shadow: 3px 3px 0 rgba(27, 21, 48, 0.12);
}

.btn.btn-quiet { color: var(--ink); }
.btn.btn-exit { color: var(--coral); }

.btn.is-on {
  background: var(--coral);
  color: #fff;
}

.stage {
  width: min(100%, 520px);
  margin-inline: auto;
  text-align: center;
}

.stage h2 {
  margin: 8px 0 0;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  letter-spacing: -0.045em;
  line-height: 0.95;
}

.stage h2 em {
  font-style: italic;
  font-weight: 620;
  color: var(--coral);
}

.mode-label {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.online-forms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 22px;
  text-align: left;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border: 2.5px solid var(--ink);
  border-radius: 24px;
  box-shadow: 6px 6px 0 var(--ink);
}

.panel h3 { margin: 0; font-size: 1.35rem; }
.panel label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 700;
}

.panel input {
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  padding: 12px 14px;
  font: inherit;
}

.panel .btn { width: 100%; }

.online-error {
  min-height: 1.4em;
  margin: 14px 0 8px;
  color: var(--coral);
  font-weight: 700;
}

.share-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(100%, 420px);
  margin: 22px auto 0;
  padding: 22px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 28px;
  background: var(--peach);
  box-shadow: 6px 6px 0 var(--ink);
}

.share-card span {
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2rem, 5vw, 2.8rem);
  letter-spacing: 0.12em;
}

#copy-room {
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  padding: 8px 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(100%, 420px);
  margin: 18px auto 0;
  padding: 0;
  list-style: none;
}

.lobby-players li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
  font-weight: 700;
}

.lobby-players .tag {
  color: var(--coral);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.round-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

#landing[hidden],
#online[hidden],
#lobby[hidden],
#play[hidden] { display: none !important; }

#play.stage {
  width: min(100%, 980px);
  text-align: center;
}

#play .mode-label {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.play-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 28px;
  width: 100%;
  margin-top: 22px;
}

.board-wrap {
  min-width: 0;
  display: flex;
  justify-content: center;
}

.play-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 280px;
  flex: none;
  min-width: 0;
}

.score-card {
  margin: 0;
  padding: 14px 14px 12px;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 24px;
  box-shadow: 6px 6px 0 var(--ink);
  text-align: left;
}

.score-card-title {
  margin: 0 0 10px;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  text-align: center;
}


#play .board {
  --gap: 14px;
  --tile: 72px;
  position: relative;
  margin-top: 0;
  padding: 18px;
  gap: var(--gap);
  width: fit-content;
  max-width: 100%;
  box-shadow: 8px 8px 0 var(--ink);
  border-radius: 28px;
}

#play .board[data-layout="pairs-15"] {
  --tile: 62px;
  --gap: 12px;
}

#play .board-play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
  width: fit-content;
  max-width: 100%;
}

#play .board-row {
  display: flex;
  justify-content: center;
  gap: var(--gap);
}

#play .board .tile { width: var(--tile); }

#play .tile-face {
  border-width: 5px;
  border-radius: 10px;
}

.status {
  margin: 10px 0 0;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 0.95;
  text-align: center;
}

.status.is-result {
  font-style: italic;
  color: var(--coral);
}

.scoreboard {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  margin-top: 0;
  width: 100%;
}

#play .score-pill {
  justify-content: space-between;
  width: 100%;
  border-radius: 14px;
}

#play .hint,
#play .note {
  text-align: left;
  margin-top: 0;
}

#play .hint {
  margin-top: 12px;
  text-align: center;
}

#play .hint:empty,
#play .note:empty {
  display: none;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font-weight: 700;
  box-shadow: 3px 3px 0 rgba(27, 21, 48, 0.1);
}

.score-pill.is-turn {
  background: var(--butter);
  box-shadow: 3px 3px 0 var(--ink);
}

.game-stats {
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 2px solid rgba(27, 21, 48, 0.12);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
}

.board {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: fit-content;
  max-width: 100%;
  margin-top: 22px;
  margin-inline: auto;
  padding: 18px;
  border: 2.5px solid var(--ink);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--ink);
}

.board-play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: fit-content;
  max-width: 100%;
}

.board-row {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.board-end[hidden],
.game-stats[hidden] { display: none; }

.board.is-ended .board-play {
  visibility: hidden;
}

.board-end {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 18px;
  border-radius: inherit;
  background: rgba(255, 253, 249, 0.94);
  text-align: center;
}


.board .tile {
  width: var(--tile, 78px);
  flex: none;
}

.tile-gone {
  visibility: hidden;
  pointer-events: none;
}

.tile {
  position: relative;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  perspective: 1000px;
  -webkit-tap-highlight-color: transparent;
  /* Slot stays fixed; shuffle happens on the inner face only. */
  overflow: visible;
}

.tile:disabled { cursor: default; }

.tile-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.48s cubic-bezier(0.4, 0.15, 0.2, 1);
  transform:
    translate(var(--nudge-x, 0px), var(--nudge-y, 0px))
    rotate(var(--tilt, 0deg))
    rotateY(0deg);
}

.tile.is-up .tile-inner {
  transform:
    translate(var(--nudge-x, 0px), var(--nudge-y, 0px))
    rotate(var(--tilt, 0deg))
    rotateY(180deg);
}

.tile-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 5px solid #fff;
  border-radius: 10px;
  outline: 2px solid var(--ink);
  outline-offset: -1px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow:
    3px 5px 0 rgba(27, 21, 48, 0.28),
    inset 0 0 0 1px rgba(27, 21, 48, 0.08);
}

.tile-back {
  background: var(--ink);
  color: #fff;
  transform: rotateY(0deg);
}

.tile-front {
  background: var(--mint);
  color: var(--ink);
  transform: rotateY(180deg);
}

.tile.is-match {
  z-index: 6;
  pointer-events: none;
}

.tile.is-match .tile-inner {
  animation: match-pop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}

.tile.is-match.is-leaving .tile-inner {
  animation: match-out 0.32s ease forwards;
}

.tile-front svg {
  width: 88%;
  height: 88%;
}

@keyframes match-pop {
  0% {
    transform:
      translate(var(--nudge-x, 0px), var(--nudge-y, 0px))
      rotate(var(--tilt, 0deg))
      rotateY(180deg)
      scale(1);
  }
  40% {
    transform:
      translate(var(--nudge-x, 0px), var(--nudge-y, 0px))
      rotate(var(--tilt, 0deg))
      rotateY(180deg)
      scale(1.28);
  }
  70% {
    transform:
      translate(var(--nudge-x, 0px), var(--nudge-y, 0px))
      rotate(var(--tilt, 0deg))
      rotateY(180deg)
      scale(1.14);
  }
  100% {
    transform:
      translate(var(--nudge-x, 0px), var(--nudge-y, 0px))
      rotate(var(--tilt, 0deg))
      rotateY(180deg)
      scale(1.18);
  }
}

@keyframes match-out {
  0% {
    transform:
      translate(var(--nudge-x, 0px), var(--nudge-y, 0px))
      rotate(var(--tilt, 0deg))
      rotateY(180deg)
      scale(1.18);
    opacity: 1;
  }
  100% {
    transform:
      translate(var(--nudge-x, 0px), var(--nudge-y, 0px))
      rotate(var(--tilt, 0deg))
      rotateY(180deg)
      scale(0.2);
    opacity: 0;
  }
}

.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.note {
  min-height: 1.4em;
  margin: 10px 0 0;
  color: var(--coral);
  font-weight: 700;
}

.leave-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(27, 21, 48, 0.45);
}

.leave-modal.hidden { display: none; }

.leave-card {
  width: min(400px, 100%);
  padding: 22px 20px 18px;
  text-align: center;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 18px;
  box-shadow: 7px 7px 0 var(--ink);
}

.leave-card h3 {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.7rem;
}

.leave-card p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.leave-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 860px) {
  .rules, .online-forms { grid-template-columns: 1fr; }

  .play-row {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  .play-side,
  .score-card {
    width: min(100%, 320px);
  }

  #play .note {
    text-align: center;
  }

  #play .board,
  #play .board[data-layout="pairs-11"],
  #play .board[data-layout="pairs-15"] {
    --tile: 64px;
    --gap: 12px;
    padding: 14px;
  }
}

@media (max-width: 520px) {
  #play .board,
  #play .board[data-layout="pairs-11"],
  #play .board[data-layout="pairs-15"] {
    --tile: min(58px, calc((100vw - 40px - 3 * 10px) / 4));
    --gap: 10px;
    padding: 12px;
  }

  .tile-face {
    border-width: 4px;
    border-radius: 8px;
  }
}
