@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url("/fonts/fredoka.woff2") format("woff2");
}
@font-face {
  font-family: "Luckiest Guy";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/luckiest-guy.woff2") format("woff2");
}

:root {
  --ink: #2b124c;
  --ink-soft: #5b3a82;
  --paper: #fff8ef;
  --card: #ffffff;
  --accent: #ff2d55;
  --gold: #ffd60a;
  --teal: #00c2a8;
  --violet: #6c2bd9;
  --violet-deep: #3b1578;
  --shadow: 0 10px 28px rgb(43 18 76 / 0.22);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: Fredoka, "Trebuchet MS", "Segoe UI", sans-serif;
  font-weight: 600;
  color: var(--ink);
  background:
    radial-gradient(1200px 800px at 10% -10%, #ff4d8d 0%, transparent 55%),
    radial-gradient(900px 700px at 110% 10%, #ffd60a 0%, transparent 45%),
    radial-gradient(800px 600px at 50% 120%, #00c2a8 0%, transparent 50%),
    linear-gradient(160deg, #5b21c9 0%, #6c2bd9 40%, #c1226e 100%);
  background-attachment: fixed;
  overflow: hidden;
}

img, svg { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }

.blobs { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.blob {
  position: absolute;
  width: 42vw;
  height: 42vw;
  border-radius: 50%;
  filter: blur(8px);
  opacity: 0.35;
  animation: floaty 9s ease-in-out infinite;
}
.b1 { background: #ff9f1c; top: 8%; left: -8%; }
.b2 { background: #7b4dff; right: -10%; top: 30%; animation-delay: -3s; width: 50vw; height: 50vw; }
.b3 { background: #1b9fff; bottom: -12%; left: 20%; animation-delay: -5s; }

@keyframes floaty {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(12px, -18px) scale(1.08); }
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(56px + var(--safe-bot));
}

.screen {
  display: none;
  width: min(520px, 100%);
  margin: 0 auto;
  animation: screen-in 0.45s cubic-bezier(0.2, 1.4, 0.3, 1) both;
}
.screen.active {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100dvh - 16px - var(--safe-top) - 48px - var(--safe-bot));
}
.screen.play.active {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 10px;
  width: min(560px, 100%);
  height: calc(100dvh - 16px - var(--safe-top) - 48px - var(--safe-bot));
  min-height: 0;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 20px 24px;
  box-shadow: var(--shadow), 0 0 0 4px rgb(255 255 255 / 0.12);
}
.enter { animation: pop-card 0.5s cubic-bezier(0.2, 1.6, 0.3, 1) both; }
@keyframes pop-card {
  0% { transform: scale(0.86) rotate(-1.5deg); opacity: 0; }
  70% { transform: scale(1.03) rotate(0.4deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.title, h1 {
  font-family: "Luckiest Guy", Fredoka, sans-serif;
  font-weight: 400;
  letter-spacing: 0.02em;
  font-size: clamp(2rem, 8vw, 2.8rem);
  margin: 0 0 8px;
  text-wrap: balance;
  line-height: 1.05;
  color: var(--violet-deep);
}

.tagline, .lede, .hint, .waiting, .eyebrow {
  text-wrap: pretty;
  text-wrap: balance;
}

.tagline, .lede {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1.35;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-align: center;
}

.logo {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin: 2px 0 16px;
  flex-wrap: nowrap;
}
.logo span {
  font-family: "Luckiest Guy", sans-serif;
  font-size: clamp(1.85rem, 8.6vw, 3.05rem);
  width: 11.4%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #fff;
  color: var(--violet-deep);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--ink) 18%, white), 0 8px 16px rgb(43 18 76 / 0.16);
  transform-origin: 50% 80%;
  animation:
    logo-pop 0.5s cubic-bezier(0.2, 1.7, 0.3, 1) calc(var(--i) * 0.05s) both,
    tile-idle 1.15s ease-in-out calc(0.5s + var(--i) * 0.06s) infinite;
}
.logo span.boop {
  animation:
    logo-pop 0.5s cubic-bezier(0.2, 1.7, 0.3, 1) calc(var(--i) * 0.05s) both,
    tile-boop 0.9s cubic-bezier(0.2, 1.6, 0.3, 1) calc(0.5s + var(--i) * 0.06s) infinite;
}
.logo span:nth-child(1) { color: #ff2d55; }
.logo span:nth-child(2) { color: #ff9f1c; }
.logo span:nth-child(3) { color: #e0a800; }
.logo span:nth-child(4) { color: #00a892; }
.logo span:nth-child(5) { color: #1b9fff; }
.logo span:nth-child(6) { color: #7b4dff; }
.logo span:nth-child(7) { color: #ff5a1f; }
.logo span:nth-child(8) { color: #ff2d55; }

@keyframes logo-pop {
  0% { transform: scale(0) rotate(-18deg); opacity: 0; }
  70% { transform: scale(1.16) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes tile-idle {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  40% { transform: translateY(-8px) rotate(-3deg) scale(1.06); }
  70% { transform: translateY(-2px) rotate(2deg) scale(1); }
}
@keyframes tile-boop {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  35% { transform: translateY(-14px) rotate(-8deg) scale(1.12); }
  55% { transform: translateY(2px) rotate(5deg) scale(0.96); }
  75% { transform: translateY(-6px) rotate(-2deg) scale(1.06); }
}

.stack { display: flex; flex-direction: column; gap: 10px; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  min-height: 56px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  box-shadow: 0 5px 0 rgb(43 18 76 / 0.18);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  text-wrap: balance;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(4px) scale(0.98); box-shadow: 0 1px 0 rgb(43 18 76 / 0.18); }
.btn.primary {
  background: linear-gradient(180deg, #ff6b8a 0%, #ff2d55 100%);
  color: #fff;
  text-shadow: 0 1px 0 rgb(0 0 0 / 0.15);
}
.btn.ghost {
  background: #f3eaff;
  color: var(--violet-deep);
}
.btn.icon {
  min-width: 56px;
  padding: 0;
  font-size: 1.4rem;
  background: #fff3c4;
  flex: 0 0 56px;
}
.btn[hidden] { display: none !important; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.code-input, .name-input {
  width: 100%;
  border: 3px solid #ead9ff;
  border-radius: 16px;
  min-height: 64px;
  padding: 0 14px;
  background: #faf6ff;
  margin: 0 0 12px;
  outline: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.code-input:focus, .name-input:focus { border-color: var(--violet); transform: scale(1.01); }

.code-input {
  text-align: center;
  font-family: "Luckiest Guy", sans-serif;
  font-size: clamp(2.2rem, 12vw, 3rem);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--violet-deep);
}

.name-row { display: flex; gap: 8px; align-items: stretch; margin-bottom: 12px; }
.name-row .name-input { margin: 0; flex: 1; font-size: 1.1rem; min-height: 56px; }

.hint { color: #c0124a; margin: 8px 0 0; min-height: 1.2em; }
.waiting { text-align: center; color: var(--ink-soft); margin: 0; font-size: 1.05rem; }

.code-hero {
  font-family: "Luckiest Guy", sans-serif;
  font-size: clamp(3.2rem, 18vw, 5rem);
  letter-spacing: 0.18em;
  text-align: center;
  color: var(--violet-deep);
  line-height: 1;
  margin: 4px 0 10px;
  animation: code-bounce 1.6s ease-in-out infinite;
}
@keyframes code-bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.player-list, .scores, .word-bank, .leaderboard { list-style: none; margin: 0; padding: 0; }

.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 18px;
}
.player-pill, .score-pill, .word-pill, .rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 14px;
  background: #f6f0ff;
  font-weight: 700;
}
.swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px currentColor;
  flex: 0 0 20px;
}
.host-flag {
  margin-left: auto;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.play-top { display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; }
.theme-chip {
  align-self: flex-start;
  background: rgb(255 255 255 / 0.92);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  box-shadow: 0 3px 0 rgb(43 18 76 / 0.15);
}
.timer {
  align-self: center;
  font-family: "Luckiest Guy", sans-serif;
  font-size: clamp(2rem, 8vw, 2.8rem);
  color: #fff;
  text-shadow: 0 3px 0 rgb(43 18 76 / 0.35);
  letter-spacing: 0.06em;
  line-height: 1;
  padding: 2px 16px;
  border-radius: 16px;
}
.timer.low {
  color: #ffe066;
  animation: timer-shake 0.45s ease-in-out infinite;
  background: rgb(255 45 85 / 0.28);
}
@keyframes timer-shake {
  0%, 100% { transform: rotate(0) scale(1); }
  30% { transform: rotate(-4deg) scale(1.06); }
  60% { transform: rotate(4deg) scale(1.04); }
}

.scores {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.score-pill {
  background: rgb(255 255 255 / 0.95);
  min-height: 40px;
  padding: 4px 10px;
  flex: 0 0 auto;
  font-size: 0.92rem;
  box-shadow: 0 3px 0 rgb(43 18 76 / 0.12);
}
.score-pill .pts {
  font-family: "Luckiest Guy", sans-serif;
  font-size: 1.1rem;
  margin-left: 2px;
}
.score-pill.pop { animation: score-pop 0.5s cubic-bezier(0.2, 1.6, 0.3, 1); }
@keyframes score-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18) rotate(-3deg); }
  100% { transform: scale(1); }
}

.grid-wrap {
  position: relative;
  /* Square board: phone width with side margin to spare; never stretch tall. */
  width: min(92vw, 100%, calc(100dvh - 290px));
  max-width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  flex: 0 0 auto;
  margin: 4px auto 0;
  align-self: center;
}
.grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 6px;
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  width: 100%;
  height: auto;
  min-width: 0;
  min-height: 0;
  border-radius: 12px;
  background: #fff;
  color: var(--violet-deep);
  font-family: "Luckiest Guy", sans-serif;
  font-size: clamp(1.05rem, 5.4vw, 1.85rem);
  line-height: 1;
  box-shadow: 0 3px 0 #d9c6ff;
  cursor: pointer;
  overflow: hidden;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.cell.sel {
  background: #fff3c4;
  color: var(--violet-deep);
  animation: tile-bounce 0.28s cubic-bezier(0.2, 1.6, 0.3, 1);
  z-index: 2;
  box-shadow: 0 0 0 3px #ff9f1c, 0 4px 0 #e08900;
}
.cell.found {
  color: #fff;
  -webkit-text-stroke: 2px #2b124c;
  paint-order: stroke fill;
  text-shadow:
    0 0 1px #2b124c,
    1px 0 0 #2b124c,
    -1px 0 0 #2b124c,
    0 1px 0 #2b124c,
    0 -1px 0 #2b124c,
    1px 1px 0 #2b124c,
    -1px 1px 0 #2b124c,
    1px -1px 0 #2b124c,
    -1px -1px 0 #2b124c,
    0 2px 0 rgb(0 0 0 / 0.28);
  animation: found-pop 0.32s cubic-bezier(0.2, 1.4, 0.3, 1);
  transform: none;
  z-index: 2;
  box-shadow: 0 3px 0 rgb(0 0 0 / 0.2);
}
.cell.found.found-light {
  color: #2b124c;
  -webkit-text-stroke: 2px #fff8ef;
  text-shadow:
    0 0 1px #fff8ef,
    1px 0 0 #fff8ef,
    -1px 0 0 #fff8ef,
    0 1px 0 #fff8ef,
    0 -1px 0 #fff8ef,
    1px 1px 0 #fff8ef,
    -1px 1px 0 #fff8ef,
    1px -1px 0 #fff8ef,
    -1px -1px 0 #fff8ef,
    0 2px 0 rgb(43 18 76 / 0.25);
}
.word-pill.claimed.found-light {
  color: #2b124c;
  text-decoration-color: #2b124c;
}
.cell.miss {
  animation: miss-shake 0.35s ease;
  background: #ffe0e8;
}

@keyframes tile-bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes found-pop {
  0% { transform: scale(0.94); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
.cell.scramble {
  animation: scramble-boop 0.45s cubic-bezier(0.2, 1.6, 0.3, 1) both;
  z-index: 2;
}
@keyframes scramble-boop {
  0% { transform: scale(1) rotate(0); }
  35% { transform: scale(1.22) rotate(-10deg); }
  70% { transform: scale(0.92) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes miss-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-4deg); }
  75% { transform: translateX(5px) rotate(4deg); }
}

.swoosh {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 1; /* behind tile letters */
}
.swoosh path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3.5;
  opacity: 0.9;
}


.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  flex: 0 0 auto;
}
.word-pill {
  min-height: 36px;
  padding: 4px 10px;
  background: rgb(255 255 255 / 0.94);
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 2px 0 rgb(43 18 76 / 0.12);
}
.word-pill.claimed {
  color: #fff;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  animation: pill-flash 0.4s ease;
}
@keyframes pill-flash {
  0% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.leaderboard { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 18px; }
.rank-row {
  background: #f6f0ff;
  animation: rank-in 0.45s cubic-bezier(0.2, 1.5, 0.3, 1) both;
  animation-delay: calc(var(--i, 0) * 0.08s);
}
.rank-row.winner {
  background: #fff3c4;
  box-shadow: 0 0 0 3px #ffd60a;
}
.rank-num {
  font-family: "Luckiest Guy", sans-serif;
  width: 1.6rem;
  font-size: 1.3rem;
}
.rank-row .pts { margin-left: auto; font-family: "Luckiest Guy", sans-serif; font-size: 1.3rem; }
@keyframes rank-in {
  from { opacity: 0; transform: translateX(-16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.fx { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.confetti, .burst {
  position: absolute;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-burst 0.85s ease-out forwards;
}
@keyframes confetti-burst {
  0% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.6); opacity: 0; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + var(--safe-bot));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 30;
  max-width: min(90vw, 360px);
  text-align: center;
  text-wrap: balance;
  box-shadow: var(--shadow);
  animation: screen-in 0.25s ease;
}

footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 6px 12px calc(8px + var(--safe-bot));
  text-align: center;
  pointer-events: none;
}
footer p {
  margin: 0;
  color: rgb(255 255 255 / 0.85);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-wrap: balance;
  text-shadow: 0 1px 2px rgb(43 18 76 / 0.4);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
