/* ============================================================
   Grade School Genius  —  custom styles
   Chalkboard-green classroom theme. All fonts are bundled
   locally (www/fonts) so the app has no network dependencies.
   ============================================================ */

/* Bundled variable fonts (latin subset). */
@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}
@font-face {
  font-family: "Baloo 2";
  src: url("fonts/baloo2-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  --board-0: #0b1f16;   /* deep chalkboard green */
  --board-1: #0e2a1e;
  --board-2: #09190f;
  --panel:   rgba(255, 255, 255, 0.035);
  --panel-solid: #12271d;
  --border:  rgba(234, 243, 236, 0.16);
  --border-strong: rgba(234, 243, 236, 0.34);
  --chalk:   #f7fbf4;
  --accent:  #ffe066;   /* chalky yellow */
  --accent-deep: #f4c430;
  --wood:    #4b3621;
  --wood-dark: #2f2113;
  --good:    #37b26b;
  --good-deep: #1f7a45;
  --bad:     #d9484b;
  --bad-deep: #a02c2f;
  --text:    #f4f8f2;
  --text-dim: #fef3c7;   /* crisp cream for secondary text */
  --shadow:  0 26px 55px -14px rgba(0, 0, 0, 0.75);
  --radius:  16px;
  --tap:     48px;       /* minimum touch-target height */

  /* Geometric display face for headers + a rounded body face */
  --font-head: "Fredoka", "Baloo 2", ui-rounded, "Segoe UI", system-ui, sans-serif;
  --font-body: "Baloo 2", "Fredoka", ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 720px at 12% -5%, rgba(255, 255, 255, 0.06), transparent 60%),
    radial-gradient(1000px 680px at 105% 105%, rgba(255, 255, 255, 0.045), transparent 55%),
    linear-gradient(160deg, var(--board-1), var(--board-0) 55%, var(--board-2));
  background-attachment: fixed;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
}

/* Faint chalk-dust grain over the whole board */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.05;
  mix-blend-mode: soft-light;
  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");
}

/* ---------- App shell (framed chalkboard) ---------- */
.app {
  position: relative;
  z-index: 1;
  margin: auto;            /* centers vertically but still scrolls when tall */
  flex-shrink: 0;          /* never squash below content — the page scrolls instead */
  width: 100%;
  max-width: 560px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015));
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow:
    0 0 0 8px var(--wood),
    0 0 0 10px var(--wood-dark),
    var(--shadow);
  overflow: hidden;
}
.chalk-frame {
  position: absolute;
  inset: 10px;
  border: 2px dashed rgba(234, 243, 236, 0.22);
  border-radius: 12px;
  pointer-events: none;
}
.app-inner { position: relative; padding: 24px; }
@media (min-width: 480px) { .app-inner { padding: 30px; } }

.screen { animation: fade-in 0.35s ease both; }
.hidden { display: none !important; }

/* ---------- Splash screen (Optima Media) ---------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background-color: #f9f9f9;                 /* matches the logo artwork's ground */
  transition: opacity 0.55s ease, visibility 0.55s ease;
}
#splash.is-hiding {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.splash-inner {
  width: 100%;
  max-width: 520px;
  text-align: center;
  animation: splash-in 0.6s ease both;
}
.splash-logo {
  display: block;
  width: min(90vw, 520px);
  height: auto;
  margin: 0 auto;
}

@keyframes splash-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Floating sound toggle ---------- */
.mute-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 14px;
  z-index: 60;
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: transform 0.12s ease, filter 0.12s ease;
}
.mute-btn:hover { filter: brightness(1.2); }
.mute-btn:active { transform: translateY(2px) scale(0.92); }
/* Muted = clearly "off": dimmed and recessed, so the button reads as a state,
   not a "tap here to enable sound" call-to-action. */
.mute-btn.is-muted { opacity: 0.45; background: rgba(0, 0, 0, 0.25); }

/* ---------- Confetti canvas ---------- */
#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 55;
}

/* ---------- Typography ---------- */
.title {
  font-family: var(--font-head);
  font-weight: 600;
  letter-spacing: 0.005em;
  line-height: 1.06;
  font-size: clamp(2rem, 7.6vw, 2.8rem);
  text-align: center;
  text-wrap: balance;
  color: var(--chalk);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 0 22px rgba(238, 247, 240, 0.12);
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-top: 8px;
  font-size: 1rem;
  line-height: 1.5;
}

.section-label {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-dim);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 15px 18px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
  user-select: none;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px) scale(0.99); }

.btn-primary {
  color: #3b2f00;
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  box-shadow: 0 6px 0 #a8871f, 0 12px 24px -8px rgba(244, 196, 48, 0.5);
}
.btn-primary:active { box-shadow: 0 2px 0 #a8871f; }

.btn-ghost {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { filter: brightness(1.25); }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { font-size: 0.98rem; padding: 13px 14px; }

/* ---------- HUD (lives / score / grade) ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.hud .pill {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 13px;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.lives { display: flex; gap: 3px; font-size: 1.05rem; line-height: 1; }
.life.lost { filter: grayscale(1) opacity(0.5); }
.life.pop { animation: life-pop 0.45s ease; }

/* ---------- Category board ---------- */
.board-head { text-align: center; margin-bottom: 16px; }
.board-head h2 {
  font-family: var(--font-head);
  font-weight: 600;
  margin: 4px 0 2px;
  font-size: 1.85rem;
  letter-spacing: 0.01em;
  color: var(--chalk);
}
.board-head .section-label { display: inline-block; margin-bottom: 2px; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 460px) { .category-grid { grid-template-columns: repeat(3, 1fr); } }

.category-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 92px;
  padding: 12px 8px;
  border-radius: 14px;
  border: 2px dashed var(--border-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.category-card:hover { background: rgba(255, 255, 255, 0.07); transform: translateY(-2px); box-shadow: var(--shadow); }
.category-card:active { transform: translateY(2px) scale(0.99); }
.category-card .cat-name {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 1.08rem;
  line-height: 1.15;
  color: var(--chalk);
}
.category-card .cat-points {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--accent);
  line-height: 1;
}
.category-card.taken {
  opacity: 0.22;
  pointer-events: none;
  filter: grayscale(0.7);
}

/* ---------- Question screen ---------- */
.q-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-head);
  font-weight: 600;
  color: var(--accent);
  font-size: 1rem;
  margin-bottom: 8px;
}
.q-text {
  font-size: clamp(1.15rem, 4.6vw, 1.5rem);
  font-weight: 700;
  line-height: 1.32;
  text-wrap: balance;
  margin: 6px 0 16px;
  color: var(--chalk);
}

.timer-wrap {
  height: 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
  overflow: hidden;
  margin-bottom: 4px;
}
.timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--good), #a3e635);
  transition: width 0.1s linear, background 0.3s ease;
}
.timer-bar.danger { background: linear-gradient(90deg, var(--bad-deep), var(--bad)); }
.timer-label { text-align: right; font-weight: 700; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 14px; }

.choices { display: grid; gap: 10px; }

.choice-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--panel-solid);
  color: var(--text);
  font: inherit;
  font-size: 1.02rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}
.choice-btn:hover:not(:disabled) { border-color: var(--accent); transform: translateX(2px); }
.choice-btn:active:not(:disabled) { transform: translateY(2px); }
.choice-btn:disabled { cursor: default; }
.choice-letter {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 1rem;
}
.choice-btn.correct {
  background: linear-gradient(180deg, var(--good), var(--good-deep));
  border-color: #86efac;
  color: #fff;
  animation: pop 0.35s ease;
}
.choice-btn.wrong {
  background: linear-gradient(180deg, var(--bad), var(--bad-deep));
  border-color: #fca5a5;
  color: #fff;
  animation: shake 0.4s ease;
}
.choice-btn.correct .choice-letter,
.choice-btn.wrong .choice-letter { background: rgba(0, 0, 0, 0.25); }

.feedback {
  min-height: 24px;
  text-align: center;
  font-weight: 700;
  margin-top: 14px;
  font-size: 1rem;
}
.feedback.good { color: #b6f5cd; }
.feedback.bad { color: #ffc2c2; }

/* ---------- Grade transition screen ---------- */
.transition-inner { text-align: center; padding: 34px 8px 24px; }
.transition-star {
  font-size: 4rem;
  line-height: 1;
  animation: star-pop 0.65s ease both;
}
.transition-text {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: clamp(1.9rem, 8vw, 2.7rem);
  color: var(--chalk);
  margin: 12px 0 6px;
  text-shadow: 0 0 22px rgba(238, 247, 240, 0.16);
  animation: rise 0.5s 0.12s ease both;
}
#screen-transition .section-label { animation: rise 0.5s 0.06s ease both; }
#screen-transition .subtitle { animation: rise 0.5s 0.2s ease both; }

/* ---------- Lightning round ---------- */
.lightning-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font-head);
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fde047, #f4c430);
  color: #422006;
  animation: glow 1.4s ease-in-out infinite;
}
.lr-score-big {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 2.6rem;
  color: var(--accent);
  text-align: center;
  line-height: 1;
}

/* ---------- Game over / results ---------- */
.result-hero { text-align: center; margin-bottom: 18px; }
.result-emoji { font-size: 3rem; line-height: 1; }
.result-score {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 3rem;
  color: var(--accent);
  line-height: 1;
  margin: 6px 0;
}
.stat-row { display: flex; gap: 10px; margin: 16px 0; }
.stat {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  text-align: center;
}
.stat .v { font-size: 1.2rem; font-weight: 800; font-family: var(--font-head); }
.stat .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim); }

.name-input {
  width: 100%;
  min-height: var(--tap);
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  margin: 6px 0 12px;
}
.name-input::placeholder { color: rgba(254, 243, 199, 0.55); }
.name-input:focus { outline: 2px solid var(--accent); }
select.name-input { appearance: none; -webkit-appearance: none; cursor: pointer; }

/* ---------- Handle / identity ---------- */
.handle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0 4px;
}
.handle-chip {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--chalk);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 8px 16px;
}
.btn.handle-reroll { width: auto; flex: none; min-height: 40px; padding: 8px 14px; font-size: 0.9rem; }
.go-submit-note {
  margin: 10px 0 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-dim);
  min-height: 1.2em;
}

/* ---------- Leaderboard ---------- */
.lb-tabs {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.lb-tab {
  flex: 1;
  min-height: 40px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  touch-action: manipulation;
}
.lb-tab.is-active {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #3b2f00;
}
.lb-status {
  margin: 12px 0 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.lb-you {
  margin: 12px 0 0;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--chalk);
  min-height: 1.2em;
}

.lb-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.lb-table th, .lb-table td { padding: 10px 8px; text-align: left; }
.lb-table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.lb-table tbody tr:nth-child(odd) { background: rgba(255, 255, 255, 0.04); }
.lb-table td:nth-child(4) { font-weight: 800; color: var(--accent); }
.lb-table tr.lb-me { background: rgba(255, 224, 102, 0.16) !important; }
.lb-table tr.lb-me td { color: var(--chalk); }
.lb-rank { width: 34px; text-align: center; font-weight: 800; }
.lb-empty { text-align: center; color: var(--text-dim); padding: 24px 8px; }

.stack > * + * { margin-top: 12px; }
.mt-lg { margin-top: 22px; }
.center { text-align: center; }
.error-box {
  background: rgba(217, 72, 75, 0.16);
  border: 1px solid #fca5a5;
  color: #ffd7d7;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.9rem;
  margin-top: 14px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  min-height: var(--tap);
  padding: 8px 12px;
}

/* ---------- Animations ---------- */
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(0.9); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
@keyframes life-pop { 0% { transform: scale(1); } 50% { transform: scale(1.5); } 100% { transform: scale(1); } }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 196, 48, 0.55); }
  50% { box-shadow: 0 0 22px 4px rgba(244, 196, 48, 0.7); }
}
@keyframes star-pop {
  0% { transform: scale(0) rotate(-45deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(12deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

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