/* ============================================================
   Scramblio — design tokens
   ============================================================ */
@font-face {
  font-family: 'Fraunces';
  src: url('/fonts/Fraunces-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Montserrat';
  src: url('/fonts/Montserrat-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #12213d;
  --ink-soft: #1b2c4d;
  --ink-softer: #24375f;
  --ink-line: rgba(255, 255, 255, 0.1);

  --paper: #fbf5e9;
  --paper-dim: #f0e7d4;
  --paper-line: rgba(18, 33, 61, 0.12);

  --marigold: #f5a524;
  --marigold-dark: #d98c0f;
  --coral: #ff6b5e;
  --mint: #2fbe8f;

  --text-ink: #f6efdf;
  --text-ink-dim: #aeb9d6;
  --text-paper: #1c2333;
  --text-paper-dim: #5b6b8c;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 26px;
  --radius-tile: 12px;

  --shadow-tile:
    0 3px 0 rgba(18, 33, 61, 0.35), 0 10px 18px -6px rgba(18, 33, 61, 0.45);
  --shadow-tile-press:
    0 1px 0 rgba(18, 33, 61, 0.35), 0 3px 6px -2px rgba(18, 33, 61, 0.4);
  --shadow-card: 0 24px 60px -20px rgba(8, 14, 28, 0.55);

  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ============================================================
   Reset & base
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
}

/* Text selection */
::selection {
  background: #f5a524;
  color: #12213d;
}

::-moz-selection {
  background: #f5a524;
  color: #12213d;
}

body {
  margin: 0;
  background: var(--ink);
  color: var(--text-ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1,
h2,
h3 {
  font-family: var(--font-display);
  margin: 0;
  line-height: 1.05;
}
p {
  margin: 0;
}
ul,
dl {
  margin: 0;
  padding: 0;
}
button {
  font-family: inherit;
  cursor: pointer;
}
img {
  max-width: 100%;
  display: block;
}
.wrap {
  width: min(1180px, 100% - 48px);
  margin-inline: auto;
}

a.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  background: var(--marigold);
  color: var(--ink);
  padding: 12px 18px;
  border-radius: 0 0 10px 0;
  font-weight: 600;
  text-decoration: none;
}
a.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 3px solid var(--marigold);
  outline-offset: 3px;
  border-radius: 4px;
}

/* faint paper grain overlay across whole page */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2000;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================================================
   Header
   ============================================================ */
.game-section,
.how-section,
.leaderboard-section {
  scroll-margin-top: 96px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 500;
  backdrop-filter: blur(10px);
  background: rgba(18, 33, 61, 0.72);
  border-bottom: 1px solid var(--ink-line);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 14px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-ink);
}
.brand-tile {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--marigold);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 17px;
  border-radius: 8px;
  box-shadow: var(--shadow-tile);
  transform: rotate(-6deg);
}
.brand-word {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.site-nav {
  display: flex;
  gap: 6px;
}
.nav-link {
  background: none;
  border: none;
  color: var(--text-ink-dim);
  font-size: 14.5px;
  font-weight: 500;
  padding: 9px 14px;
  border-radius: 20px;
  transition:
    color 0.2s var(--ease-out),
    background 0.2s var(--ease-out);
}
.nav-link:hover {
  color: var(--text-ink);
  background: var(--ink-soft);
}

.header-play-btn {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--marigold);
  color: var(--ink);
  font-weight: 700;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 100px;
  border: none;
  box-shadow: 0 2px 0 var(--marigold-dark);
  transition: transform 0.15s var(--ease-spring);
}
.header-play-btn:active {
  transform: scale(0.95);
}

.sound-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--ink-line);
  background: var(--ink-soft);
  color: var(--text-ink-dim);
  display: grid;
  place-items: center;
  transition:
    color 0.2s,
    border-color 0.2s;
}
.sound-toggle:hover {
  color: var(--marigold);
  border-color: var(--marigold);
}
.sound-toggle .icon-sound-off {
  display: none;
}
.sound-toggle[aria-pressed='true'] .icon-sound-on {
  display: none;
}
.sound-toggle[aria-pressed='true'] .icon-sound-off {
  display: block;
}

/* ============================================================
   Hero
   ============================================================ */
.hero {
  padding-block: 76px 90px;
  position: relative;
  background:
    radial-gradient(
      ellipse 900px 500px at 85% -10%,
      rgba(245, 165, 36, 0.16),
      transparent 60%
    ),
    var(--ink);
}
.hero-inner {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 40px;
  align-items: center;
}
.eyebrow {
  font-family: var(--font-body);
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--marigold);
  font-weight: 600;
  margin-bottom: 16px;
  display: block;
}
.hero-title {
  font-size: clamp(2.4rem, 4.6vw, 4rem);
  font-weight: 700;
  color: var(--text-ink);
  letter-spacing: -0.01em;
}
.accent-text {
  font-style: italic;
  font-weight: 600;
  color: var(--marigold);
  position: relative;
}
.hero-sub {
  margin-top: 22px;
  max-width: 46ch;
  font-size: 17px;
  line-height: 1.65;
  color: var(--text-ink-dim);
}
.hero-cta {
  display: flex;
  gap: 14px;
  margin-top: 32px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 15px;
  padding: 14px 24px;
  border-radius: 100px;
  border: 1px solid transparent;
  transition:
    transform 0.18s var(--ease-spring),
    box-shadow 0.2s var(--ease-out),
    background 0.2s;
}
.btn:active {
  transform: translateY(1px) scale(0.98);
}
.btn-primary {
  background: var(--marigold);
  color: var(--ink);
  box-shadow:
    0 2px 0 var(--marigold-dark),
    0 12px 24px -10px rgba(245, 165, 36, 0.55);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow:
    0 4px 0 var(--marigold-dark),
    0 16px 30px -10px rgba(245, 165, 36, 0.6);
}
.btn-ghost {
  background: var(--ink);
  color: var(--text-ink);
  border-color: var(--ink-line);
}
.btn-ghost:hover {
  border-color: var(--marigold);
  color: var(--marigold);
}
.btn-small {
  padding: 10px 18px;
  font-size: 13.5px;
  margin-top: 22px;
}
.btn-danger-ghost {
  background: transparent;
  color: var(--coral);
  border-color: rgba(255, 107, 94, 0.4);
  box-shadow: none;
}
.btn-danger-ghost:hover {
  background: rgba(255, 107, 94, 0.1);
  border-color: var(--coral);
  transform: translateY(-1px);
}

.hero-facts {
  display: flex;
  gap: 34px;
  margin-top: 46px;
  flex-wrap: wrap;
}
.hero-facts > div {
  display: flex;
  flex-direction: column;
}
.hero-facts dt {
  font-family: var(--font-body);
  font-size: 26px;
  font-weight: 700;
  color: var(--text-ink);
}
.hero-facts dd {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-ink-dim);
}

/* hero floating tiles */
.hero-stage {
  position: relative;
  height: 360px;
}
.tile-orbit {
  position: absolute;
  inset: 0;
}
.float-tile {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: var(--radius-tile);
  background: var(--paper);
  color: var(--text-paper);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 24px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-tile);
  animation: drift 7s ease-in-out infinite;
}
.t1 {
  top: 6%;
  left: 12%;
  animation-delay: 0s;
  background: var(--paper);
}
.t2 {
  top: 20%;
  left: 55%;
  animation-delay: 0.9s;
  background: var(--marigold);
  box-shadow:
    0 3px 0 var(--marigold-dark),
    0 10px 18px -6px rgba(217, 140, 15, 0.5);
}
.t3 {
  top: 46%;
  left: 6%;
  animation-delay: 1.8s;
}
.t4 {
  top: 55%;
  left: 62%;
  animation-delay: 2.6s;
  background: var(--mint);
  color: var(--ink);
  box-shadow:
    0 3px 0 #1f8c69,
    0 10px 18px -6px rgba(47, 190, 143, 0.5);
}
.t5 {
  top: 74%;
  left: 30%;
  animation-delay: 3.4s;
}
.t6 {
  top: 8%;
  left: 80%;
  animation-delay: 1.3s;
  background: var(--coral);
  color: var(--ink);
  box-shadow:
    0 3px 0 #c94236,
    0 10px 18px -6px rgba(255, 107, 94, 0.5);
}

@keyframes drift {
  0%,
  100% {
    transform: translateY(0) rotate(-4deg);
  }
  50% {
    transform: translateY(-22px) rotate(5deg);
  }
}

/* ============================================================
   Game section
   ============================================================ */
.game-section {
  padding-block: 20px 90px;
}
.game-card {
  background: var(--paper);
  color: var(--text-paper);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 4vw, 40px);
  box-shadow: var(--shadow-card);
  max-width: 760px;
  margin-inline: auto;
  position: relative;
  transform: translateY(-64px);
}
.game-toolbar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}
.category-select-wrap {
  position: relative;
}
.category-select {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--paper-line) transparent;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
.category-select::-webkit-scrollbar {
  height: 5px;
}
.category-select::-webkit-scrollbar-thumb {
  background: var(--paper-line);
  border-radius: 10px;
}
.cat-chip {
  flex: 0 0 auto;
  background: var(--paper-dim);
  border-radius: 100px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  scroll-snap-align: start;
}
.cat-chip.is-active {
  background: var(--ink);
  color: var(--text-ink);
}
.category-select.is-pulsing {
  animation: cat-pulse 1.1s ease-in-out 2;
}
@keyframes cat-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(245, 165, 36, 0);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(245, 165, 36, 0.25);
  }
}

.scroll-fade {
  position: absolute;
  top: 0;
  bottom: 4px;
  width: 34px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s var(--ease-out);
  display: flex;
  align-items: center;
}
.scroll-fade-left {
  left: 0;
  background: linear-gradient(
    to right,
    var(--paper) 30%,
    rgba(251, 245, 233, 0)
  );
}
.scroll-fade-right {
  right: 0;
  justify-content: flex-end;
  background: linear-gradient(
    to left,
    var(--paper) 30%,
    rgba(251, 245, 233, 0)
  );
  color: var(--text-paper-dim);
  animation: fade-nudge 1.6s ease-in-out infinite;
}
.category-select-wrap.can-scroll-left .scroll-fade-left {
  opacity: 1;
}
.category-select-wrap.can-scroll-right .scroll-fade-right {
  opacity: 1;
}
@keyframes fade-nudge {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(-3px);
  }
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.difficulty-select {
  display: flex;
  gap: 8px;
  background: var(--paper-dim);
  padding: 5px;
  border-radius: 100px;
}
.chip-btn {
  border: none;
  background: transparent;
  color: var(--text-paper-dim);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 100px;
  transition:
    background 0.2s,
    color 0.2s;
}
.chip-btn.is-active {
  background: var(--ink);
  color: var(--text-ink);
}
.chip-btn:not(.is-active):hover {
  color: var(--text-paper);
}

.category-select.is-locked .cat-chip:not(.is-active),
.difficulty-select.is-locked .chip-btn:not(.is-active) {
  display: none;
}
.category-select.is-locked .cat-chip.is-active,
.difficulty-select.is-locked .chip-btn.is-active {
  cursor: default;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.category-select.is-locked .cat-chip.is-active::after,
.difficulty-select.is-locked .chip-btn.is-active::after {
  content: '\1F512';
  font-size: 11px;
  opacity: 0.75;
}

.game-stats {
  display: flex;
  gap: 10px;
}
.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--paper-dim);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  min-width: 64px;
}
.stat-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-paper-dim);
  font-weight: 600;
}
.stat-value {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.session-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}
.session-progress-label {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-paper-dim);
  letter-spacing: 0.02em;
}
.session-dots {
  display: flex;
  gap: 5px;
}
.session-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--paper-line);
  transition:
    background 0.25s,
    transform 0.25s;
}
.session-dot.is-done {
  background: var(--mint);
}
.session-dot.is-current {
  background: var(--marigold);
  transform: scale(1.3);
}
.session-dot.is-failed {
  background: var(--coral);
}
.session-dot.is-skipped {
  background: var(--text-paper-dim);
}

.timer-track {
  height: 8px;
  background: var(--paper-dim);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 18px;
}
.timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 100px;
  background: var(--mint);
  transition:
    width 1s linear,
    background 0.4s;
}
.timer-fill.is-warn {
  background: var(--marigold);
}
.timer-fill.is-danger {
  background: var(--coral);
}

.board-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  flex-wrap: wrap;
  gap: 10px;
}
.category-tag {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-paper-dim);
  background: var(--paper-dim);
  padding: 6px 12px;
  border-radius: 100px;
}
.lives {
  display: flex;
  gap: 5px;
}
.board-meta-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.end-session-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-paper-dim);
  background: transparent;
  border: 1px solid var(--paper-line);
  padding: 5px 10px 5px 9px;
  border-radius: 100px;
  transition:
    color 0.2s,
    border-color 0.2s,
    background 0.2s;
}
.end-session-btn:hover {
  color: var(--coral);
  border-color: var(--coral);
  background: rgba(255, 107, 94, 0.08);
}
.life-heart {
  font-size: 18px;
  filter: grayscale(0);
  transition:
    transform 0.3s var(--ease-spring),
    opacity 0.3s;
}
.life-heart.is-lost {
  opacity: 0.25;
  transform: scale(0.8);
  filter: grayscale(1);
}

.hint-line {
  min-height: 20px;
  font-size: 13.5px;
  color: var(--marigold-dark);
  font-weight: 600;
  margin: 10px 2px 0;
}

.board-loading[hidden] {
  display: none;
}
.board-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 30px 0 10px;
  color: var(--text-paper-dim);
  font-size: 13.5px;
  font-weight: 600;
}
.board-play[hidden] {
  display: none;
}

.board-start[hidden] {
  display: none;
}
.board-start {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 34px 10px 14px;
}
.start-tile-stack {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.start-tile {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-tile);
  background: var(--ink);
  color: var(--text-ink);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 19px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-tile);
  animation: start-tile-bob 2.4s ease-in-out infinite;
}
.start-tile.st1 {
  background: var(--marigold);
  color: var(--ink);
  box-shadow:
    0 3px 0 var(--marigold-dark),
    0 10px 18px -6px rgba(217, 140, 15, 0.5);
  animation-delay: 0s;
}
.start-tile.st2 {
  animation-delay: 0.15s;
}
.start-tile.st3 {
  background: var(--mint);
  color: var(--ink);
  box-shadow:
    0 3px 0 #1f8c69,
    0 10px 18px -6px rgba(47, 190, 143, 0.5);
  animation-delay: 0.3s;
}
.start-tile.st4 {
  background: var(--coral);
  color: var(--ink);
  box-shadow:
    0 3px 0 #c94236,
    0 10px 18px -6px rgba(255, 107, 94, 0.5);
  animation-delay: 0.45s;
}
@keyframes start-tile-bob {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-9px) rotate(-3deg);
  }
}
.board-start-title {
  font-size: 21px;
  font-weight: 700;
  color: var(--text-paper);
}
.board-start-sub {
  margin-top: 8px;
  max-width: 40ch;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-paper-dim);
}
.board-start .btn-primary {
  margin-top: 22px;
}

.loading-tile {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-tile);
  background: var(--ink);
  box-shadow: var(--shadow-tile);
  animation: loading-spin 1s ease-in-out infinite;
}
@keyframes loading-spin {
  0% {
    transform: rotate(0deg) scale(1);
  }
  50% {
    transform: rotate(180deg) scale(0.85);
  }
  100% {
    transform: rotate(360deg) scale(1);
  }
}

/* letter tiles */
.scramble-row,
.answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  min-height: 64px;
}
.answer-row {
  margin-top: 14px;
}

.letter-tile {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-tile);
  background: var(--ink);
  color: var(--text-ink);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 22px;
  border: none;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-tile);
  transition:
    transform 0.16s var(--ease-spring),
    box-shadow 0.16s var(--ease-out),
    background 0.2s,
    opacity 0.2s;
  animation: tile-in 0.4s var(--ease-spring) both;
}
.letter-tile:hover:not(:disabled) {
  transform: translateY(-4px);
}
.letter-tile:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: var(--shadow-tile-press);
}
.letter-tile:disabled {
  opacity: 0.25;
  cursor: default;
}

.answer-row .letter-tile {
  background: var(--marigold);
  color: var(--ink);
  box-shadow:
    0 3px 0 var(--marigold-dark),
    0 10px 18px -6px rgba(217, 140, 15, 0.45);
}
.answer-row .slot-empty {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-tile);
  border: 2px dashed var(--paper-line);
  background: transparent;
}

@keyframes tile-in {
  from {
    opacity: 0;
    transform: scale(0.5) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
@keyframes tile-pop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.18) rotate(-4deg);
  }
  100% {
    transform: scale(1);
  }
}
.letter-tile.is-popping {
  animation: tile-pop 0.35s var(--ease-spring);
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(7px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(4px);
  }
}
.answer-row.is-shaking {
  animation: shake 0.4s var(--ease-out);
}

@keyframes correct-bounce {
  0% {
    transform: translateY(0) scale(1);
  }
  30% {
    transform: translateY(-14px) scale(1.08);
  }
  55% {
    transform: translateY(0) scale(0.98);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}
.answer-row.is-correct .letter-tile {
  animation: correct-bounce 0.5s var(--ease-spring);
  background: var(--mint);
  color: var(--ink);
  box-shadow:
    0 3px 0 #1f8c69,
    0 10px 18px -6px rgba(47, 190, 143, 0.5);
}
.answer-row.is-correct .letter-tile:nth-child(2) {
  animation-delay: 0.05s;
}
.answer-row.is-correct .letter-tile:nth-child(3) {
  animation-delay: 0.1s;
}
.answer-row.is-correct .letter-tile:nth-child(4) {
  animation-delay: 0.15s;
}
.answer-row.is-correct .letter-tile:nth-child(5) {
  animation-delay: 0.2s;
}
.answer-row.is-correct .letter-tile:nth-child(6) {
  animation-delay: 0.25s;
}
.answer-row.is-correct .letter-tile:nth-child(7) {
  animation-delay: 0.3s;
}
.answer-row.is-correct .letter-tile:nth-child(8) {
  animation-delay: 0.35s;
}

.feedback {
  text-align: center;
  min-height: 24px;
  margin-top: 16px;
  font-weight: 600;
  font-size: 14.5px;
}
.feedback.is-good {
  color: #1f8c69;
}
.feedback.is-bad {
  color: var(--coral);
}

.explain-line {
  text-align: center;
  min-height: 18px;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-paper-dim);
  max-width: 52ch;
  margin-inline: auto;
}

.game-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}
.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--paper-dim);
  border: 1px solid var(--paper-line);
  color: var(--text-paper);
  font-weight: 600;
  font-size: 14px;
  padding: 12px 18px;
  border-radius: 100px;
  transition:
    transform 0.16s var(--ease-spring),
    background 0.2s,
    border-color 0.2s;
}
.ctrl-btn:hover {
  background: #e8ddc4;
}
.ctrl-btn:active {
  transform: scale(0.96);
}
.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.hint-cost {
  font-family: var(--font-body);
  font-size: 11.5px;
  color: var(--coral);
  font-weight: 700;
}
.ctrl-btn-primary {
  background: var(--ink);
  color: var(--text-ink);
  border-color: var(--ink);
}
.ctrl-btn-primary:hover {
  background: #1f335c;
}
.ctrl-btn-next {
  background: var(--mint);
  color: var(--ink);
  border-color: var(--mint);
  opacity: 0;
  transform: scale(0.9);
  width: 0;
  padding-inline: 0;
  overflow: hidden;
  transition:
    opacity 0.25s var(--ease-out),
    transform 0.25s var(--ease-spring),
    background 0.2s,
    width 0.25s var(--ease-out),
    padding 0.25s var(--ease-out),
    margin 0.25s;
}
.ctrl-btn-next:hover {
  background: #29a87c;
}
.ctrl-btn-next.is-visible {
  opacity: 1;
  transform: scale(1);
  width: auto;
  padding-inline: 18px;
}

.keyboard-hint {
  text-align: center;
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-paper-dim);
}
kbd {
  font-family: var(--font-body);
  background: var(--paper-dim);
  border: 1px solid var(--paper-line);
  border-radius: 5px;
  padding: 1.5px 6px;
  font-size: 11px;
}

/* Session end overlay (game over / deck cleared) */
.session-end-overlay[hidden] {
  display: none;
}
.session-end-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(28, 35, 51, 0.72);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  animation: overlay-in 0.3s var(--ease-out) both;
}
@keyframes overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.session-end-card {
  background: var(--paper);
  border-radius: var(--radius-md);
  padding: 36px 32px;
  width: min(400px, 88%);
  text-align: center;
  box-shadow: var(--shadow-card);
  animation: overlay-card-in 0.4s var(--ease-spring) both;
}
@keyframes overlay-card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.session-end-icon {
  font-size: 44px;
  display: block;
  margin-bottom: 6px;
}
.session-end-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-paper);
}
.session-end-sub {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-paper-dim);
}
.session-end-stats {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 24px;
}
.session-end-stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.session-end-stats span {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 26px;
  color: var(--ink);
}
.session-end-stats label {
  font-size: 11px;
  color: var(--text-paper-dim);
  margin-top: 4px;
  font-weight: 600;
}
.session-end-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 26px;
}
.session-end-actions .btn {
  justify-content: center;
  width: 100%;
}

/* ============================================================
   How it works
   ============================================================ */
.how-section {
  padding-block: 40px 100px;
}
.section-head {
  text-align: center;
  max-width: 620px;
  margin-inline: auto 0;
  margin-bottom: 46px;
}
.how-section .section-head,
.stats-inner .section-head {
  margin-inline: auto;
}
.section-head h2 {
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  font-weight: 600;
  margin-top: 10px;
  color: var(--text-ink);
}
.section-sub {
  margin-top: 12px;
  color: var(--text-ink-dim);
  font-size: 15px;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}
.feature-card {
  background: var(--ink-soft);
  border: 1px solid var(--ink-line);
  border-radius: var(--radius-md);
  padding: 26px 22px;
  transition:
    transform 0.25s var(--ease-out),
    border-color 0.25s;
}
.feature-card:hover {
  transform: translateY(-6px);
  border-color: rgba(245, 165, 36, 0.4);
}
.feature-tile {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  background: var(--ink-softer);
  border-radius: 12px;
  font-size: 21px;
  margin-bottom: 16px;
}
.feature-card h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-ink);
  margin-bottom: 8px;
}
.feature-card p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-ink-dim);
}

/* ============================================================
   Stats section
   ============================================================ */
.leaderboard-section {
  padding-block: 20px 110px;
}
.stats-inner {
  text-align: center;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 40px;
}
.stats-card {
  background: var(--paper);
  color: var(--text-paper);
  border-radius: var(--radius-md);
  padding: 30px 20px;
  box-shadow: var(--shadow-card);
}
.stats-num {
  display: block;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 40px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stats-label {
  display: block;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-paper-dim);
  font-weight: 500;
}

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--ink-line);
  padding-block: 40px;
}
.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.footer-tag {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--text-ink-dim);
  font-size: 15px;
}
.footer-fine {
  font-size: 12.5px;
  color: var(--text-ink-dim);
}
.footer-credit {
  color: var(--marigold);
  font-weight: 600;
}

/* ============================================================
   Confetti + toast
   ============================================================ */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 900;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0.9;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--text-ink);
  border: 1px solid var(--ink-line);
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.3s var(--ease-out),
    transform 0.3s var(--ease-out);
  z-index: 1000;
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 980px) {
  .hero-inner {
    grid-template-columns: 1fr;
  }
  .hero-stage {
    height: 220px;
    order: -1;
  }
  .hero-content {
    text-align: left;
  }
  .feature-grid {
    grid-template-columns: 1fr 1fr;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  /* ---- Header: keep it slim so it never eats scroll budget ---- */
  .site-nav {
    display: none;
  }
  .header-play-btn {
    display: inline-flex;
  }
  .header-inner {
    padding-block: 10px;
  }

  /* ---- Hero: compressed hard so the game is reachable fast ---- */
  .hero {
    padding-block: 14px 22px;
  }
  .hero-inner {
    gap: 4px;
  }
  .hero-stage {
    display: none;
  }
  .eyebrow {
    margin-bottom: 8px;
    font-size: 11px;
  }
  .hero-title {
    font-size: clamp(1.5rem, 7vw, 1.9rem);
  }
  .hero-sub {
    font-size: 13.5px;
    line-height: 1.5;
    margin-top: 8px;
    margin-bottom: 20px;
  }
  .hero-cta,
  .hero-facts {
    display: none;
  }

  /* ---- Game card: pulled up close to the fold, tightened hard ---- */
  .game-section {
    padding-block: 0 40px;
  }
  .game-card {
    transform: translateY(-14px);
    border-radius: var(--radius-md);
    padding: 14px 14px 12px;
  }
  .game-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 10px;
  }
  .toolbar-row {
    gap: 8px;
  }
  .category-select {
    gap: 6px;
  }
  .cat-chip,
  .difficulty-select .chip-btn {
    padding: 6px 12px;
    font-size: 12.5px;
  }
  .difficulty-select {
    order: 2;
    padding: 4px;
  }
  .game-stats {
    order: 1;
    justify-content: space-between;
    gap: 8px;
  }
  .stat-chip {
    flex: 1;
    padding: 5px 8px;
  }
  .stat-label {
    font-size: 9.5px;
  }
  .stat-value {
    font-size: 16px;
  }
  .session-progress {
    margin-bottom: 8px;
  }
  .board-meta {
    margin-bottom: 4px;
  }
  .timer-track {
    height: 6px;
    margin-bottom: 8px;
  }
  .hint-line {
    margin: 4px 2px 0;
    min-height: 14px;
    font-size: 12.5px;
  }
  .scramble-row,
  .answer-row {
    gap: 7px;
    margin-top: 10px;
  }
  .answer-row {
    margin-top: 8px;
  }
  .letter-tile,
  .answer-row .slot-empty {
    width: 40px;
    height: 40px;
    font-size: 17px;
  }
  .feedback {
    margin-top: 6px;
    min-height: 20px;
  }
  .explain-line {
    margin-top: 4px;
  }
  .feature-grid {
    grid-template-columns: 1fr;
  }

  /* ---- Action row: docked visually right under the board — nothing
     to scroll past to reach Shuffle / Skip / Hint / Submit / Next ---- */
  .game-controls {
    margin: 12px -14px -12px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    gap: 6px;
    background: var(--paper-dim);
    border-top: 1px solid var(--paper-line);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
  }
  .ctrl-btn {
    padding: 9px 10px;
    font-size: 12.5px;
    gap: 4px;
    flex: 1 1 auto;
    justify-content: center;
  }
  .ctrl-btn-primary,
  .ctrl-btn-next {
    flex: 1 1 40%;
  }
  .keyboard-hint {
    display: none;
  }

  /* ---- Below-the-fold sections: no need to linger here ---- */
  .how-section {
    padding-block: 4px 56px;
  }
  .section-head {
    margin-bottom: 26px;
  }
  .leaderboard-section {
    padding-block: 0 60px;
  }
  .stats-grid {
    margin-top: 24px;
  }
}

@media (max-width: 480px) {
  /* Icon + cost badge is enough for the secondary actions here; keeps
     the action row compact and every control within easy thumb reach. */
  .ctrl-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .ctrl-btn {
    padding: 9px;
  }
  .ctrl-btn-primary,
  .ctrl-btn-next {
    flex: 1 1 30%;
  }
}

@media (max-width: 380px) {
  .letter-tile,
  .answer-row .slot-empty {
    width: 36px;
    height: 36px;
    font-size: 16px;
    border-radius: 9px;
  }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .float-tile {
    animation: none;
  }
}
