:root {
  color-scheme: dark;
  font-family: ui-rounded, "Avenir Next", Avenir, system-ui, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  --background: #211d23;
  --surface: #2b262d;
  --tile: #302b32;
  --line: #514952;
  --cream: #fff4d8;
  --muted: #c7bcb8;
  --gold: #f3cb72;
  --green: #6d9c79;
  --yellow: #c7a64e;
  --gray: #625b63;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(ellipse at 50% -18%, rgb(148 105 93 / 27%), transparent 58%),
    radial-gradient(ellipse at 50% 108%, rgb(134 94 52 / 9%), transparent 40%),
    var(--background);
  color: var(--cream);
  touch-action: manipulation;
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  position: relative;
}

.game-ui {
  display: grid;
  height: 100vh;
  height: 100dvh;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-width: 560px;
  margin: 0 auto;
  opacity: 1;
  padding: max(12px, env(safe-area-inset-top)) 18px max(12px, env(safe-area-inset-bottom));
  row-gap: clamp(4px, 1vh, 10px);
  transition: opacity 800ms ease;
}

.game-ui[hidden] {
  display: none;
}

.game-ui.is-ending {
  opacity: 0;
  pointer-events: none;
}

.top {
  min-width: 0;
  text-align: center;
}

.eyebrow,
.collection-label {
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.19em;
  margin: 0;
  text-transform: uppercase;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 6vw, 1.9rem);
  font-weight: 500;
  letter-spacing: 0.01em;
  margin: 4px 0 2px;
}

h1 span {
  color: var(--gold);
  font-size: 0.8em;
}

.subtitle {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}

.version {
  color: rgb(199 188 184 / 65%);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  margin: 4px 0 0;
}

.collection {
  margin: 7px auto 0;
  max-width: 390px;
  min-height: 48px;
  text-align: left;
}

.collection-label {
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  margin: 0 0 6px 2px;
}

.collected-words {
  align-items: center;
  display: flex;
  flex-wrap: nowrap;
  gap: 7px;
  height: 28px;
  overflow: hidden;
}

.word-chip {
  align-items: center;
  background: rgb(243 203 114 / 12%);
  border: 1px solid rgb(243 203 114 / 42%);
  border-radius: 999px;
  color: var(--gold);
  display: inline-flex;
  font-size: clamp(0.65rem, 3.2vw, 0.75rem);
  font-weight: 800;
  flex: 0 0 auto;
  justify-content: center;
  letter-spacing: 0.08em;
  min-height: 25px;
  padding: 3px 8px;
}

.word-chip.is-arriving {
  opacity: 0;
}

.flying-word {
  inset: 0 auto auto 0;
  pointer-events: none;
  position: fixed;
  will-change: transform, opacity;
  z-index: 5;
}

.play-area {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: 0;
}

.board {
  aspect-ratio: 5 / 6;
  display: grid;
  gap: clamp(5px, 1.7vw, 8px);
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(6, minmax(0, 1fr));
  height: min(100%, 390px);
  max-width: 390px;
  max-height: 100%;
  transition: opacity 220ms ease;
  width: auto;
}

.board.is-transitioning,
.keyboard.is-transitioning,
.board.is-entering,
.keyboard.is-entering {
  opacity: 0;
}

.board.is-transitioning,
.keyboard.is-transitioning,
.board.is-entering,
.keyboard.is-entering,
.game-ui.is-ending {
  will-change: opacity;
}

.tile {
  align-items: center;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--cream);
  display: flex;
  font-size: clamp(1.15rem, 6vw, 1.7rem);
  font-weight: 800;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  backface-visibility: hidden;
  text-transform: uppercase;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.tile.is-filled {
  animation: pop 100ms ease-out;
  border-color: #9c8b83;
  will-change: transform;
}

.tile.is-revealed {
  transition: none;
  animation: flip-in 440ms cubic-bezier(0.25, 0.75, 0.3, 1) both;
  animation-delay: var(--reveal-delay, 0ms);
  transform-style: preserve-3d;
  will-change: transform;
}

.tile[data-state="correct"] {
  background: var(--green);
  border-color: var(--green);
}

.tile[data-state="present"] {
  background: var(--yellow);
  border-color: var(--yellow);
}

.tile[data-state="absent"] {
  background: var(--gray);
  border-color: var(--gray);
}

.board.is-winning .tile[data-state="correct"] {
  box-shadow: 0 0 0 1px rgb(243 203 114 / 50%), 0 0 16px rgb(243 203 114 / 20%);
}

.board.is-winning {
  animation: winning-glow 480ms ease-in-out 2 alternate;
  will-change: opacity;
}

.board.is-shaking {
  animation: shake 350ms ease;
  will-change: transform;
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 auto;
  max-width: 500px;
  padding-bottom: 2px;
  transition: opacity 220ms ease;
  width: 100%;
}

.key-row {
  display: flex;
  gap: clamp(4px, 1.2vw, 7px);
  justify-content: center;
  width: 100%;
}

.key {
  align-items: center;
  background: linear-gradient(155deg, #908488, #756b71);
  border: 0;
  border-radius: 6px;
  display: flex;
  flex: 1 1 0;
  font-size: clamp(0.78rem, 3.8vw, 1rem);
  font-weight: 750;
  justify-content: center;
  min-height: clamp(43px, 6.5vh, 57px);
  padding: 0 3px;
  box-shadow: inset 0 1px rgb(255 255 255 / 9%), 0 2px 4px rgb(0 0 0 / 15%);
  transition: background-color 180ms ease, transform 130ms ease, box-shadow 180ms ease;
}

.key:active {
  box-shadow: inset 0 2px 5px rgb(0 0 0 / 18%);
  transform: scale(0.96);
}

.key[data-state="correct"] {
  background: var(--green);
}

.key[data-state="present"] {
  background: var(--yellow);
}

.key[data-state="absent"] {
  background: var(--gray);
}

.key-wide {
  flex: 1.5 1 0;
  font-size: clamp(0.59rem, 2.8vw, 0.78rem);
  letter-spacing: 0;
}

.finale {
  align-items: center;
  display: flex;
  flex-direction: column;
  inset: 0;
  justify-content: center;
  overflow: hidden;
  padding: 28px 22px max(28px, env(safe-area-inset-bottom));
  position: absolute;
  text-align: center;
  opacity: 0;
  transition: opacity 1100ms ease;
}

.finale.is-visible {
  will-change: opacity;
}

.finale[hidden] {
  display: none;
}

.finale.is-visible {
  opacity: 1;
}

.poem {
  color: var(--cream);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 4.4vw, 1.3rem);
  line-height: 1.65;
  max-width: 620px;
  position: relative;
  z-index: 1;
  width: 100%;
}

.poem-line {
  display: block;
  min-height: 1.7em;
  white-space: pre-wrap;
}

.poem-letter {
  opacity: 0;
}

.poem-line.is-revealing .poem-letter {
  animation: letter-reveal 1450ms ease-in-out both;
  animation-delay: var(--letter-delay, 0ms);
}

.birthday-message {
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 8vw, 3.4rem);
  font-weight: 700;
  margin: 22px 0 0;
  max-width: 12ch;
  position: relative;
  text-shadow: 0 0 24px rgb(243 203 114 / 45%);
  z-index: 1;
  text-wrap: balance;
}

.birthday-message.is-visible {
  animation: birthday-pop 1800ms ease-in-out both;
}

.confetti {
  display: block;
  height: 100%;
  inset: 0;
  pointer-events: none;
  position: absolute;
  width: 100%;
  z-index: 0;
}



.sr-only {
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

@keyframes pop {
  50% { transform: scale(1.1); }
}

@keyframes flip-in {
  0% { transform: perspective(500px) rotateX(0); }
  45% { transform: perspective(500px) rotateX(82deg); }
  100% { transform: perspective(500px) rotateX(0); }
}

@keyframes letter-reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes winning-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.82; }
}

@keyframes shake {
  25%, 75% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
}

@keyframes birthday-pop {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes sparkle {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

h1 span {
  animation: sparkle 2.4s ease-in-out infinite;
  display: inline-block;
}

@media (max-height: 700px) {
  .game-ui {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .collection {
    margin-top: 6px;
    min-height: 44px;
  }

  .keyboard {
    gap: 6px;
  }

  .key {
    min-height: clamp(37px, 6vh, 48px);
  }

  .board {
    height: min(100%, 350px);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .tile.is-revealed {
  transition: none;
    animation-duration: 300ms !important;
  }

  .poem-line.is-revealing .poem-letter {
    animation-duration: 600ms !important;
  }

  .game-ui,
  .board,
  .keyboard,
  .finale {
    transition-duration: 280ms;
  }
}
