:root {
  --cream: #fffaf5;
  --paper: #fffdf9;
  --ink: #342736;
  --muted: #8c7d87;
  --rose: #ec6f78;
  --rose-dark: #d95360;
  --plum: #6c426b;
  --lavender: #eee5f2;
  --lavender-shadow: #ddcfdf;
  --green: #3d9b73;
  --red: #dc5662;
  --empty: #e8dedf;
  --outline: #a997a2;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: "Nunito", ui-rounded, system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.app-shell {
  min-height: 100dvh;
  position: relative;
}

.screen {
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
  position: relative;
  z-index: 1;
}

[hidden] { display: none !important; }

.screen--active { animation: screen-in .48s cubic-bezier(.22, 1, .36, 1) both; }

#welcomeScreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(46px, 9vh, 88px);
  text-align: center;
}

.mini-grid,
.progress-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  width: fit-content;
  margin-inline: auto;
}

.mini-grid { margin-bottom: 28px; }

.progress-dot {
  width: clamp(27px, 7.5vw, 34px);
  aspect-ratio: 1;
  border-radius: 9px;
  background: var(--empty);
  box-shadow: inset 0 -2px 0 rgba(84, 55, 72, .05);
  transition: background .25s ease, transform .25s ease;
}

.mini-grid .progress-dot {
  width: clamp(29px, 8vw, 37px);
  background: linear-gradient(145deg, #f1e6e5, #dfd3da);
  animation: dot-arrive .5s cubic-bezier(.22, 1, .36, 1) both;
  animation-delay: calc(var(--i) * 22ms);
}

.progress-dot--correct { background: var(--green); }
.progress-dot--missed { background: var(--red); }
.progress-dot--pop { animation: dot-pop .38s cubic-bezier(.34, 1.56, .64, 1); }

.eyebrow {
  margin: 0 0 10px;
  color: var(--rose-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: "DM Serif Display", Georgia, serif;
  font-weight: 400;
  letter-spacing: -.02em;
}

h1 { font-size: clamp(54px, 16vw, 76px); line-height: .95; }
h2 { font-size: clamp(44px, 12vw, 62px); line-height: 1; }

.welcome-actions { width: 100%; }

.instructions {
  max-width: 340px;
  margin: 0 auto 24px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
}

.button {
  min-width: 178px;
  border: 0;
  border-radius: 999px;
  padding: 16px 32px;
  cursor: pointer;
  font-weight: 900;
  font-size: 18px;
  transition: transform .1s ease, box-shadow .2s ease, background .2s ease;
}

.button:active { transform: translateY(2px) scale(.98); }
.button:focus-visible,
.text-button:focus-visible,
.letter-tile:focus-visible,
.icon-button:focus-visible { outline: 3px solid rgba(108, 66, 107, .35); outline-offset: 3px; }

.button--primary {
  color: white;
  background: var(--rose);
  box-shadow: 0 10px 24px rgba(213, 83, 96, .26), inset 0 -3px 0 rgba(132, 45, 58, .14);
}

.button--primary:hover { background: var(--rose-dark); }

.game-screen {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.game-header { padding-top: 2px; }

.round-row {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-top: 18px;
}

.round-label {
  margin: 0;
  color: var(--plum);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.game-center {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.timer {
  margin-bottom: clamp(25px, 5vh, 44px);
  font-size: 58px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer small { margin-left: 2px; color: var(--muted); font-size: 23px; }
.timer--low { color: var(--red); animation: timer-pulse .7s ease-in-out infinite; }
.timer--low small { color: inherit; }

.answer-slots {
  width: 100%;
  min-height: 53px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.answer-slot {
  width: var(--slot-size, 42px);
  height: calc(var(--slot-size, 42px) * 1.08);
  display: grid;
  place-items: center;
  border: 2px solid var(--outline);
  border-radius: 11px;
  color: var(--plum);
  font-size: calc(var(--slot-size, 42px) * .54);
  font-weight: 900;
  text-transform: uppercase;
  transition: transform .15s ease, border-color .2s ease, color .2s ease, background .2s ease;
}

.answer-slot--filled { border-color: var(--plum); transform: translateY(-2px); }
.answer-slot--correct { border-color: var(--green); color: white; background: var(--green); }
.answer-slot--missed { border-color: var(--red); color: white; background: var(--red); }

.status-message {
  height: 24px;
  margin: 12px 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
}

.status-message--correct { color: var(--green); }
.status-message--missed { color: var(--red); }

.letter-grid {
  width: min(100%, 420px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.letter-tile {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--lavender);
  color: var(--ink);
  box-shadow: inset 0 -4px 0 var(--lavender-shadow), 0 3px 9px rgba(79, 53, 74, .06);
  cursor: pointer;
  font-size: 28px;
  font-weight: 900;
  text-transform: uppercase;
  transition: transform .12s ease, background .18s ease, color .18s ease, opacity .18s ease;
  animation: tile-enter .38s cubic-bezier(.34, 1.56, .64, 1) both;
  animation-delay: calc(var(--i) * 35ms);
}

.letter-tile:hover { transform: translateY(-2px); }
.letter-tile:active { transform: scale(.9); }
.letter-tile--selected { background: var(--plum); color: white; box-shadow: inset 0 -4px 0 #543252; }
.letter-tile--correct { background: var(--green); box-shadow: inset 0 -4px 0 #2e7d5c; }
.letter-tile--wrong { background: var(--red); box-shadow: inset 0 -4px 0 #b54550; }

.shake { animation: shake .34s ease; }
.fade-away { animation: fade-away .3s ease forwards; }

.result-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  overflow-y: auto;
}

.result-content { width: 100%; padding: 24px 0; position: relative; z-index: 2; }
.score-line { margin: 22px 0 18px; color: var(--muted); font-size: 18px; font-weight: 700; }
.score-line strong { color: var(--plum); font-size: 25px; }
.progress-grid--result { margin-bottom: 28px; }

.signoff { margin: 20px 0 0; color: var(--muted); font-size: 13px; font-weight: 800; }

#confettiCanvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }

@media (max-height: 680px) {
  .screen { padding-top: 14px; padding-bottom: 12px; }
  .game-screen { gap: 7px; }
  .game-header .progress-dot { width: 25px; border-radius: 7px; }
  .round-row { margin-top: 9px; }
  .timer { margin-bottom: 17px; font-size: 48px; }
  .status-message { margin: 7px 0 3px; }
  .letter-tile { width: 58px; height: 58px; font-size: 25px; }
}

@media (max-width: 370px) {
  .screen { padding-left: 14px; padding-right: 14px; }
  .letter-tile { width: 57px; height: 57px; }
}

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

@keyframes screen-in { from { opacity: 0; transform: translateY(14px); } }
@keyframes dot-arrive { from { opacity: 0; transform: scale(.6); } }
@keyframes dot-pop { 50% { transform: scale(1.28); } }
@keyframes tile-enter { from { opacity: 0; transform: translateY(12px) scale(.75); } }
@keyframes timer-pulse { 50% { transform: scale(1.07); } }
@keyframes shake { 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
@keyframes fade-away { to { opacity: 0; transform: scale(.86); } }
