/* =========================================================================
   Roadschool — Kid UI styles
   Aesthetic: warm "road-trip adventure". Sunny paper, chunky rounded cards,
   big tactile buttons, a sense of a journey down an open road. Built for
   8-10 year-olds on a phone: big tap targets, low text density, large type.

   Token discipline borrowed from the repo design-system skill:
   - type scale, 4/8/12/16/24/32 spacing rhythm
   - semantic color tokens, WCAG 2.2 AA contrast, always-visible focus rings
   ========================================================================= */

/* ---- Fonts (distinctive, not system defaults) ----
   Fredoka = friendly rounded display; Nunito = warm, highly legible body. */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Nunito:wght@600;700;800&display=swap');

:root {
  /* --- Color tokens (sunny road-trip palette; all text pairings >= AA) --- */
  --sky:        #fdf3e3;   /* warm paper background */
  --sky-2:      #ffe9c7;   /* lower-sky gradient stop */
  --road:       #3a3a52;   /* deep asphalt — primary text */
  --road-soft:  #5a5a78;   /* secondary text */
  --sun:        #ff9f1c;   /* primary accent (orange) */
  --sun-deep:   #e8590c;   /* pressed / strong accent — AA on white */
  --grass:      #2a9d56;   /* success green — AA on white */
  --grass-deep: #1d7a41;
  --sky-blue:   #2d7dd2;   /* links / info — AA on white */
  --berry:      #d6336c;   /* gentle "try again" (not harsh red) */
  --card:       #ffffff;
  --card-edge:  #f0d9b5;   /* warm card border */
  --focus:      #1b6fd6;   /* high-contrast focus ring */

  /* per-subject color chips */
  --c-math:    #ff9f1c;
  --c-ela:     #2d7dd2;
  --c-science: #2a9d56;
  --c-social:  #d6336c;

  /* --- Type scale: 12/14/16/20/24/32 + a couple kid-sized display steps --- */
  --t-xs: 0.75rem;  --t-sm: 0.875rem; --t-md: 1rem;
  --t-lg: 1.25rem;  --t-xl: 1.5rem;   --t-2xl: 2rem;
  --t-3xl: 2.75rem; --t-4xl: 3.5rem;

  /* --- Spacing rhythm: 4/8/12/16/24/32(/48/64) --- */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-6: 24px; --s-8: 32px; --s-12: 48px; --s-16: 64px;

  --radius:    20px;
  --radius-lg: 28px;
  --shadow:    0 6px 0 rgba(58,58,82,0.12), 0 12px 28px rgba(58,58,82,0.14);
  --shadow-sm: 0 4px 0 rgba(58,58,82,0.10), 0 8px 16px rgba(58,58,82,0.10);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 700;
  color: var(--road);
  background: linear-gradient(180deg, var(--sky) 0%, var(--sky-2) 100%);
  background-attachment: fixed;
  /* subtle dotted road-map texture */
  background-image:
    radial-gradient(circle at 1px 1px, rgba(58,58,82,0.05) 1px, transparent 0),
    linear-gradient(180deg, var(--sky) 0%, var(--sky-2) 100%);
  background-size: 24px 24px, 100% 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

/* The rolling "road" hill that anchors every screen */
body::after {
  content: "";
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 88px;
  background:
    repeating-linear-gradient(90deg, #ffd166 0 28px, transparent 28px 56px) center 0/auto 6px no-repeat,
    var(--road);
  border-top: 6px solid #2a2a3d;
  border-radius: 50% 50% 0 0 / 80px 80px 0 0;
  z-index: 0;
  pointer-events: none;
}

/* =========================== Layout shell =========================== */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  padding: var(--s-6) var(--s-4) 120px;
  min-height: 100dvh;
}

.screen { animation: rise .4s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

[hidden] { display: none !important; }

/* =========================== Brand header =========================== */
.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-8);
}
.brand .logo {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-size: 1.9rem;
  background: var(--sun);
  border: 4px solid #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  transform: rotate(-6deg);
}
.brand h1 {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: var(--t-xl);
  margin: 0;
  letter-spacing: -0.01em;
}
.brand .tag { display: block; font-size: var(--t-xs); color: var(--road-soft); font-weight: 700; }

/* =========================== Big headings =========================== */
.h-title {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: var(--t-3xl);
  line-height: 1.05;
  margin: 0 0 var(--s-2);
  letter-spacing: -0.02em;
}
.h-sub {
  font-size: var(--t-lg);
  color: var(--road-soft);
  margin: 0 0 var(--s-8);
}

/* =========================== Name cards =========================== */
.kid-grid { display: grid; gap: var(--s-4); }

.kid-card {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  width: 100%;
  text-align: left;
  padding: var(--s-4) var(--s-6);
  font-family: 'Fredoka', sans-serif;
  font-size: var(--t-2xl);
  color: var(--road);
  background: var(--card);
  border: 4px solid var(--card-edge);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.kid-card:hover { transform: translateY(-3px) rotate(-0.5deg); border-color: var(--sun); }
.kid-card:active { transform: translateY(2px); box-shadow: var(--shadow-sm); }

.kid-avatar {
  width: 64px; height: 64px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  font-size: 2rem;
  border-radius: 50%;
  background: var(--sun);
  color: #fff;
  border: 4px solid #fff;
  box-shadow: var(--shadow-sm);
}
.kid-card:nth-child(2n) .kid-avatar { background: var(--sky-blue); }
.kid-card:nth-child(3n) .kid-avatar { background: var(--grass); }
.kid-name { line-height: 1; }
.kid-grade { display: block; font-family: 'Nunito'; font-size: var(--t-sm); color: var(--road-soft); font-weight: 700; margin-top: var(--s-1); }

/* =========================== PIN pad =========================== */
.pin-head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-6); }
.pin-head .kid-avatar { width: 56px; height: 56px; font-size: 1.7rem; }
.pin-head .pin-who { font-family: 'Fredoka'; font-size: var(--t-xl); }

.pin-dots { display: flex; gap: var(--s-4); justify-content: center; margin: var(--s-6) 0; }
.pin-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 4px solid var(--road-soft);
  background: transparent;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.pin-dot.filled { background: var(--sun); border-color: var(--sun-deep); transform: scale(1.12); }

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-3);
  max-width: 22rem;
  margin: 0 auto;
}
.key {
  font-family: 'Fredoka', sans-serif;
  font-size: var(--t-2xl);
  color: var(--road);
  background: var(--card);
  border: 4px solid var(--card-edge);
  border-radius: var(--radius);
  min-height: 72px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .1s ease, background .1s ease;
}
.key:hover { background: #fff7ea; }
.key:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(58,58,82,0.1); }
.key.key-back { font-size: var(--t-xl); }
.key.key-go { background: var(--grass); color: #fff; border-color: var(--grass-deep); }
.key.key-go:hover { background: var(--grass-deep); }

/* shake animation for a wrong PIN */
.shake { animation: shake .5s; }
@keyframes shake {
  10%,90% { transform: translateX(-2px); } 20%,80% { transform: translateX(4px); }
  30%,50%,70% { transform: translateX(-8px); } 40%,60% { transform: translateX(8px); }
}

/* =========================== Test picker =========================== */
.test-grid { display: grid; gap: var(--s-4); }
.test-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--s-6);
  background: var(--card);
  border: 4px solid var(--card-edge);
  border-left-width: 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease;
}
.test-card:hover { transform: translateY(-3px); }
.test-card:active { transform: translateY(2px); box-shadow: var(--shadow-sm); }
.test-card .t-title { font-family: 'Fredoka'; font-size: var(--t-xl); margin: 0 0 var(--s-2); }
.test-card .t-meta { display: flex; flex-wrap: wrap; gap: var(--s-2); }

.chip {
  display: inline-block;
  font-size: var(--t-sm);
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 999px;
  background: #fff3df;
  color: var(--sun-deep);
}
.chip.q { background: #eaf4ff; color: var(--sky-blue); }

/* =========================== Question screen =========================== */
.progress-wrap { margin-bottom: var(--s-6); }
.progress-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s-2); font-size: var(--t-sm); color: var(--road-soft); }
.progress-bar {
  position: relative;
  height: 16px;
  background: #fff;
  border: 3px solid var(--card-edge);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  position: absolute; inset: 0 100% 0 0;
  background: linear-gradient(90deg, var(--sun), var(--sun-deep));
  border-radius: 999px;
  transition: right .4s cubic-bezier(.2,.9,.3,1.2);
}
/* little car that rides the progress bar */
.progress-car {
  position: absolute; top: -10px;
  transform: translateX(-50%);
  font-size: 1.4rem;
  transition: left .4s cubic-bezier(.2,.9,.3,1.2);
}

.subject-tag {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--t-sm); font-weight: 800;
  padding: 4px 14px; border-radius: 999px;
  background: #fff; border: 3px solid var(--card-edge);
  margin-bottom: var(--s-4);
}
.subject-tag .dot { width: 12px; height: 12px; border-radius: 50%; }

.q-prompt {
  font-size: var(--t-2xl);
  font-family: 'Fredoka';
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 var(--s-8);
}

/* multiple choice */
.choices { display: grid; gap: var(--s-3); }
.choice {
  display: flex; align-items: center; gap: var(--s-4);
  width: 100%; text-align: left;
  padding: var(--s-4) var(--s-6);
  font-size: var(--t-xl);
  background: var(--card);
  border: 4px solid var(--card-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .1s ease, border-color .1s ease, background .1s ease;
}
.choice:hover { border-color: var(--sun); }
.choice:active { transform: translateY(2px); }
.choice .bullet {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #fff3df; color: var(--sun-deep);
  font-family: 'Fredoka'; font-size: var(--t-lg);
}
.choice.selected { border-color: var(--sun); background: #fff7ea; }
.choice.correct { border-color: var(--grass); background: #e9f9ef; }
.choice.correct .bullet { background: var(--grass); color: #fff; }
.choice.wrong { border-color: var(--berry); background: #fdeef3; }
.choice.wrong .bullet { background: var(--berry); color: #fff; }
.choice[aria-disabled="true"] { cursor: default; }

/* numeric + short answer inputs */
.field { margin-bottom: var(--s-6); }
.field label { display: block; font-size: var(--t-md); color: var(--road-soft); margin-bottom: var(--s-2); }
.text-in, .num-in {
  width: 100%;
  font-family: 'Fredoka', sans-serif;
  font-size: var(--t-2xl);
  color: var(--road);
  padding: var(--s-4) var(--s-6);
  background: #fff;
  border: 4px solid var(--card-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.text-in { font-size: var(--t-lg); }
textarea.text-in { resize: vertical; min-height: 96px; line-height: 1.4; }
.text-in:hover, .num-in:hover { border-color: var(--sun); }

/* feedback banner */
.feedback {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-6);
  border-radius: var(--radius);
  font-size: var(--t-lg);
  margin: var(--s-6) 0 0;
  animation: rise .35s ease both;
}
.feedback .emoji { font-size: 1.6rem; }
.feedback.good { background: #e9f9ef; color: var(--grass-deep); border: 3px solid var(--grass); }
.feedback.tryagain { background: #fdeef3; color: #a01a4a; border: 3px solid var(--berry); }
.feedback.neutral { background: #eaf4ff; color: #1b5a96; border: 3px solid var(--sky-blue); }

/* =========================== Buttons =========================== */
.btn {
  font-family: 'Fredoka', sans-serif;
  font-size: var(--t-xl);
  font-weight: 600;
  padding: var(--s-4) var(--s-8);
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease, background .1s ease;
}
.btn-primary { background: var(--sun); color: #fff; box-shadow: 0 5px 0 var(--sun-deep); }
.btn-primary:hover { background: #ffab3a; }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--sun-deep); }
.btn-go { background: var(--grass); color: #fff; box-shadow: 0 5px 0 var(--grass-deep); }
.btn-go:hover { background: #2bae5f; }
.btn-go:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--grass-deep); }
.btn-ghost {
  background: #fff; color: var(--road);
  border: 4px solid var(--card-edge);
  box-shadow: var(--shadow-sm);
}
.btn-ghost:hover { border-color: var(--sun); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.q-nav { display: flex; gap: var(--s-3); margin-top: var(--s-8); }
.q-nav .btn { flex: 1; }
.q-nav .btn-back { flex: 0 0 auto; }

/* =========================== Results screen =========================== */
.results { text-align: center; padding-top: var(--s-8); }
.results .trophy { font-size: 5rem; animation: pop .6s cubic-bezier(.2,.9,.3,1.4) both; }
@keyframes pop { 0% { transform: scale(0) rotate(-20deg); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.score-ring {
  width: 200px; height: 200px;
  margin: var(--s-6) auto;
  border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--sun) var(--ring, 0%), #ffe9c7 0);
  border: 8px solid #fff;
  box-shadow: var(--shadow);
}
.score-inner {
  width: 150px; height: 150px;
  border-radius: 50%;
  background: #fff;
  display: grid; place-items: center; align-content: center;
}
.score-inner .big { font-family: 'Fredoka'; font-size: var(--t-4xl); line-height: 1; color: var(--sun-deep); }
.score-inner .of { font-size: var(--t-md); color: var(--road-soft); }
.results .praise { font-family: 'Fredoka'; font-size: var(--t-2xl); margin: var(--s-4) 0; }
.results .praise-sub { font-size: var(--t-lg); color: var(--road-soft); margin: 0 0 var(--s-8); }

/* confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px;
  width: 12px; height: 12px; border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: .9; }
}

/* =========================== States =========================== */
.center-state { text-align: center; padding: var(--s-16) var(--s-4); }
.spinner {
  width: 56px; height: 56px; margin: 0 auto var(--s-4);
  border: 6px solid var(--card-edge);
  border-top-color: var(--sun);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-state .msg { font-family: 'Fredoka'; font-size: var(--t-xl); }
.center-state .emoji { font-size: 3rem; display: block; margin-bottom: var(--s-3); }

/* =========================== Accessibility =========================== */
/* Always-visible, high-contrast focus ring on every interactive element */
:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
  border-radius: 8px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

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

/* MathJax: keep inline math from blowing up line-height on small screens */
mjx-container { font-size: 100% !important; }
