/* =========================================================================
   Bilo — stylesheet
   Light + dark themes, large touch targets, reduced-motion aware.
   ========================================================================= */

:root {
  /* ---- Bilo brand tokens (source of truth: assets/brand/) ------------- */
  --brand:      #5B3FE8;
  --brand-2:    #7C6BFF;
  --brand-deep: #3A1FA6;
  --brand-soft: #EFECFF;

  --spark:      #FFAE18;
  --spark-deep: #D98A00;
  --spark-soft: #FFF1D2;

  --pink:       #FF7A8A;
  --pink-soft:  #FFECEF;

  --success:      #12A46A;
  --success-ink:  #0F7048;
  --success-soft: #E4F8EF;

  --danger:      #E0526A;
  --danger-soft: #FDECEF;

  /* ---- mapped onto the app's semantic names --------------------------- */
  --violet: var(--brand);
  --violet-dark: var(--brand-deep);
  --teal: #12A4A0;
  --blue: #4C7DF0;
  --amber: var(--spark);
  --green: var(--success);
  --red: var(--danger);

  --bg: #F4F2FF;
  --bg-tint: #E6E1FF;
  --surface: #FFFFFF;
  --surface-2: #F7F5FF;
  --text: #1B1538;
  --text-soft: #7C7699;
  --line: #E4E0F7;
  --primary: var(--brand);
  --primary-dark: var(--brand-deep);
  --on-primary: #FFFFFF;
  --shadow: 0 14px 34px rgba(43, 26, 122, .10);
  --shadow-sm: 0 6px 16px rgba(43, 26, 122, .08);

  /* second background wash: warm on light, deep violet on dark */
  --wash-2: var(--spark-soft);

  --radius: 24px;
  --radius-sm: 18px;
  --radius-btn: 14px;
  --tap: 48px;
}

[data-theme="dark"] {
  --bg: #100D24;
  --bg-tint: #1C1740;
  --surface: #191536;
  --surface-2: #221C4A;
  --text: #F3F1FF;
  --text-soft: #A9A3CE;
  --line: #2E2760;
  --primary: #9B8CFF;
  --primary-dark: #8878FF;
  --on-primary: #16112E;
  --brand-soft: #241E52;
  --wash-2: #1A1440;
  --shadow: 0 14px 40px rgba(0, 0, 0, .40);
  --shadow-sm: 0 6px 16px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #100D24;
    --bg-tint: #1C1740;
    --surface: #191536;
    --surface-2: #221C4A;
    --text: #F3F1FF;
    --text-soft: #A9A3CE;
    --line: #2E2760;
    --primary: #9B8CFF;
    --primary-dark: #8878FF;
    --on-primary: #16112E;
    --brand-soft: #241E52;
    --wash-2: #1A1440;
    --shadow: 0 14px 40px rgba(0, 0, 0, .40);
    --shadow-sm: 0 6px 16px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont,
               "Segoe UI Variable Display", "Segoe UI", Nunito, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 8% -8%, var(--bg-tint) 0%, transparent 62%),
    radial-gradient(700px 380px at 100% 0%, var(--wash-2) 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  padding-env: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1, h2, h3, h4 { line-height: 1.15; margin: 0 0 10px; }
h2 { font-size: clamp(1.7rem, 4.4vw, 2.5rem); letter-spacing: -.02em; }
h3 { font-size: 1.16rem; }
h4 { font-size: 1.08rem; }
p { margin: 0 0 12px; }
a { color: var(--primary); }

button { font: inherit; font-weight: 700; cursor: pointer; border: 0; }
:focus-visible {
  outline: 4px solid rgba(91, 63, 232, .35);
  outline-offset: 3px;
  border-radius: 8px;
}

/* Headings and <main> are focused programmatically after navigation so that
   screen readers announce the new page. That is not a keyboard focus, so it
   should not paint a focus ring. */
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible { outline: none; }

.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;
}

.skip {
  position: absolute; left: -9999px; top: 8px;
  background: var(--surface); padding: 12px 18px;
  border-radius: 12px; z-index: 50; box-shadow: var(--shadow);
}
.skip:focus { left: 12px; }

.app { width: min(1000px, 100% - 26px); margin: 0 auto; }

/* ------------------------------------------------------------------ top */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 18px 0 14px;
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; min-width: 0; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.brand-logo {
  width: 46px; height: 46px; flex: 0 0 auto; display: block;
  border-radius: 14px; box-shadow: var(--shadow-sm);
}
.hero-mascot { width: clamp(120px, 20vw, 190px); height: auto; display: block; position: relative; z-index: 2; }
.welcome-mascot { width: clamp(92px, 20vw, 118px); height: auto; margin: 0 auto; display: block; border-radius: 26px; box-shadow: var(--shadow-sm); }
.cert-logo { width: 4.6cqw; height: 4.6cqw; border-radius: 1.1cqw; display: block; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 1.14rem; letter-spacing: -.01em; }
.brand-text small { color: var(--text-soft); font-size: .82rem; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.star-pill {
  display: flex; align-items: center; gap: 5px;
  background: var(--spark-soft); color: var(--spark-deep); border: 1px solid #FFDE9B;
  border-radius: 999px; padding: 8px 14px; font-weight: 800;
}
[data-theme="dark"] .star-pill { background: #3a2f10; color: #ffd97a; border-color: #574512; }
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .star-pill { background: #3a2f10; color: #ffd97a; border-color: #574512; }
}

.topnav { display: flex; gap: 4px; }
.nav-button {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center; font-size: 20px;
  background: transparent; border-radius: 14px; color: inherit;
}
.nav-button:hover { background: var(--surface-2); }
.nav-button.active { background: var(--surface); box-shadow: var(--shadow-sm); }

.offline-banner {
  background: var(--spark-soft); color: var(--spark-deep); border: 1px solid #FFDE9B;
  padding: 10px 14px; border-radius: 12px; margin: 0 0 14px; font-size: .92rem;
}

/* --------------------------------------------------------------- shared */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.eyebrow {
  display: inline-block; color: var(--primary);
  font-weight: 800; font-size: .74rem;
  letter-spacing: .09em; text-transform: uppercase; margin-bottom: 4px;
}

.primary, .ghost, .danger-button, .chip-button {
  border-radius: var(--radius-btn); min-height: var(--tap); padding: 12px 20px;
  transition: transform .12s ease, background .15s ease;
}
.primary {
  background: var(--primary); color: var(--on-primary);
  box-shadow: 0 8px 18px rgba(91, 63, 232, .24);
}
.primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.primary.big { font-size: 1.06rem; padding: 15px 26px; }
.primary.wide, .ghost.wide { width: 100%; margin-top: 16px; }

.ghost { background: transparent; color: var(--primary); }
.ghost:hover { background: var(--surface-2); }
.ghost.back { margin: 0 0 12px; padding-left: 12px; }

.danger-button { background: var(--red); color: #fff; }
.danger-text { color: var(--red); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px;
  font-size: .82rem; font-weight: 700; color: var(--text-soft);
}
.chip.done { background: var(--success-soft); color: var(--success-ink); border-color: #BCEBD6; }
[data-theme="dark"] .chip.done { background: #123227; color: #7fe0b6; border-color: #1d5540; }
.chip.subtle { font-weight: 600; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip-button {
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); padding: 10px 18px;
}
.chip-button.active { background: var(--primary); color: var(--on-primary); border-color: transparent; }

.muted-text { color: var(--text-soft); }
.center { text-align: center; }
.small { font-size: .86rem; }

.progress-track {
  height: 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  overflow: hidden; margin-top: 10px;
}
.progress-track.small { height: 7px; margin: 0; flex: 1; }
.progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--primary), var(--brand-2));
  transition: width .45s ease;
}
.progress-fill.amber { background: linear-gradient(90deg, var(--spark), #FFD25E); }

/* ----------------------------------------------------------------- home */

.hero {
  display: grid; grid-template-columns: 1.5fr .7fr;
  align-items: center; gap: 16px;
  padding: clamp(24px, 4.5vw, 40px);
  position: relative; overflow: hidden;
}
.hero-body { position: relative; z-index: 2; }
.hero p { color: var(--text-soft); font-size: 1.04rem; max-width: 52ch; }
.hero-next {
  display: block; width: fit-content; max-width: 100%;
  font-weight: 700; color: var(--text) !important;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 14px; margin: 0 0 16px;
}
.hero-art { position: relative; display: grid; place-items: center; min-height: 130px; }
.orb {
  position: absolute; width: 190px; height: 190px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--bg-tint), transparent 70%);
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.stat { padding: 18px; }
.stat-value { display: block; font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.stat-total { font-size: 1rem; color: var(--text-soft); font-weight: 700; }
.stat-label { color: var(--text-soft); font-size: .9rem; font-weight: 600; }
.stat-note { color: var(--text-soft); font-size: .82rem; margin: 8px 0 0; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 26px 0 12px;
}
.section-head h3 { margin: 0; }

.unit-list, .lesson-list { display: grid; gap: 12px; }

.unit-card, .lesson-row, .quiz-teaser {
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 16px; padding: 18px 20px;
}
.unit-card.locked { opacity: .58; }
.unit-card.has-badge { border-color: #bfe9d5; }
[data-theme="dark"] .unit-card.has-badge { border-color: #2b6b50; }
.unit-emoji {
  width: 54px; height: 54px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 27px;
  background: var(--surface-2); border-radius: 17px;
}
.unit-emoji.big { width: 66px; height: 66px; font-size: 33px; }
.unit-main h4 { margin: 0 0 4px; }
.unit-main p { color: var(--text-soft); margin: 0 0 8px; font-size: .93rem; }
.unit-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .84rem; color: var(--text-soft); font-weight: 600; }
.unit-meta .progress-track { max-width: 120px; }
.unit-action { display: flex; justify-content: flex-end; }
.locked-note { color: var(--text-soft); font-size: .85rem; font-weight: 600; text-align: right; max-width: 130px; }

.accent-violet .unit-emoji { background: var(--brand-soft); }
.accent-teal   .unit-emoji { background: #DFF5F3; }
.accent-blue   .unit-emoji { background: #E5EDFF; }
.accent-amber  .unit-emoji { background: var(--spark-soft); }
.accent-green  .unit-emoji { background: var(--success-soft); }
.accent-rose   .unit-emoji { background: var(--pink-soft); }
.accent-indigo .unit-emoji { background: #E8E5FF; }
.accent-orange .unit-emoji { background: #FFEBD8; }
.accent-cyan   .unit-emoji { background: #DFF3FA; }
.accent-lime   .unit-emoji { background: #EDF7DA; }
[data-theme="dark"] .unit-emoji { background: var(--surface-2); }

/* ---------------------------------------------------------------- levels */

.level { margin-bottom: 26px; }
.level-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; margin-bottom: 12px; flex-wrap: wrap;
}
.level-head h4 { margin: 0 0 3px; font-size: 1.12rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.level-head p { margin: 0; color: var(--text-soft); font-size: .92rem; }
.level-side { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.level.locked .unit-list { opacity: .72; }
.small-btn { padding: 9px 16px; min-height: 40px; font-size: .9rem; }
.level-done { margin: 10px 0 0; font-weight: 600; }
.cert-callout { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.cert-callout h3 { margin-bottom: 2px; }
.cert-callout p { margin: 0; }

.quiz-teaser.muted { opacity: .6; }
.parents-link { text-align: center; margin: 26px 0 8px; font-size: .9rem; }

/* --------------------------------------------------------------- lesson */

.unit-header { display: flex; align-items: center; gap: 16px; margin: 6px 0 18px; }
.unit-header p { color: var(--text-soft); margin: 0; }
.unit-header h2 { margin: 0 0 4px; }

.lesson-row { grid-template-columns: auto 1fr auto; }
.lesson-row.done { background: linear-gradient(180deg, var(--surface), var(--surface-2)); }
.lesson-index {
  width: 40px; height: 40px; border-radius: 13px;
  display: grid; place-items: center; font-weight: 800;
  background: var(--surface-2); color: var(--text-soft);
}
.lesson-row.done .lesson-index { background: #d9f5e8; color: #14724f; }
[data-theme="dark"] .lesson-row.done .lesson-index { background: #16412f; color: #7fe0b6; }
.lesson-main h4 { margin: 0 0 3px; }
.lesson-main p { color: var(--text-soft); font-size: .92rem; margin: 0 0 7px; }

.lesson { padding: clamp(22px, 4.5vw, 38px); }
.lesson-head { display: flex; align-items: center; justify-content: space-between; }
.lesson-emoji { font-size: 40px; }
.lead { color: var(--text-soft); font-size: 1.06rem; }

.blocks { display: grid; gap: 12px; margin: 22px 0; }
.block {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 18px 20px;
}
.block h3 { margin: 0 0 5px; font-size: 1.04rem; }
.block p { margin: 0; color: var(--text-soft); }

.callout {
  border-radius: var(--radius-sm); padding: 16px 18px; margin-bottom: 12px;
  border: 1px solid var(--line);
}
.callout strong { display: block; margin-bottom: 4px; }
.callout p { margin: 0; }
.callout.try { background: var(--brand-soft); border-color: #D9D2FF; }
.callout.tip { background: var(--spark-soft); border-color: #FFDE9B; }
[data-theme="dark"] .callout.try { background: #17233f; border-color: #27406e; }
[data-theme="dark"] .callout.tip { background: #33290d; border-color: #5c4a15; }
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .callout.try { background: #17233f; border-color: #27406e; }
  [data-theme="auto"] .callout.tip { background: #33290d; border-color: #5c4a15; }
}

/* ----------------------------------------------------------- checkpoint */

.checkpoint {
  margin-top: 26px; padding-top: 22px; border-top: 2px dashed var(--line);
}
.checkpoint h3 { font-size: 1.2rem; }
.options { display: grid; gap: 10px; margin: 14px 0; }
.option {
  display: flex; align-items: center; gap: 12px; text-align: start;
  background: var(--surface-2); border: 2px solid var(--line);
  border-radius: var(--radius-sm); padding: 15px 17px;
  color: var(--text); font-weight: 600; min-height: var(--tap);
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option .marker {
  width: 22px; height: 22px; flex: 0 0 auto;
  border: 2px solid var(--line); border-radius: 50%;
}
.option.correct { border-color: var(--success); background: var(--success-soft); }
.option.correct .marker { background: var(--green); border-color: var(--green); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); opacity: .82; }
.option:disabled { cursor: default; }
[data-theme="dark"] .option.correct { background: #123227; }
[data-theme="dark"] .option.wrong { background: #3a1c22; }

.feedback {
  border-radius: var(--radius-sm); padding: 15px 17px; margin-top: 12px;
  font-weight: 600; line-height: 1.5;
}
.feedback.good { background: var(--success-soft); color: var(--success-ink); border: 1px solid #BCEBD6; }
.feedback.bad  { background: var(--danger-soft); color: #A32F45; border: 1px solid #F7CBD4; }
.feedback.warn { background: var(--spark-soft); color: var(--spark-deep); border: 1px solid #FFDE9B; }
[data-theme="dark"] .feedback.good { background: #123227; color: #7fe0b6; border-color: #1d5540; }
[data-theme="dark"] .feedback.bad  { background: #3a1c22; color: #ffb3bf; border-color: #6b2f3a; }
[data-theme="dark"] .feedback.warn { background: #3a2c10; color: #ffd28a; border-color: #6b5218; }

.bonus {
  display: inline-block; margin-left: 6px; padding: 2px 9px;
  background: var(--spark-soft); color: var(--spark-deep); border-radius: 999px;
  font-size: .84rem; font-weight: 800;
}
.lesson-actions { margin-top: 20px; }

/* ----------------------------------------------------------------- quiz */

.quiz { padding: clamp(22px, 4.5vw, 38px); }
.question { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 20px 0 8px; }
.question:first-of-type { border-top: 0; }
.question legend { font-weight: 800; font-size: 1.05rem; padding: 0 0 10px; }
.answer {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 13px 15px; border-radius: var(--radius-sm);
  border: 2px solid transparent; cursor: pointer; min-height: var(--tap);
}
.answer:hover { background: var(--surface-2); }
.answer input { margin-top: 4px; width: 20px; height: 20px; accent-color: var(--primary); }
.answer.is-answer { border-color: var(--green); background: #e9f9f1; }
[data-theme="dark"] .answer.is-answer { background: #123227; }

.explain {
  margin: 8px 0 0; padding: 11px 15px;
  border-radius: 12px; font-size: .92rem; line-height: 1.5;
}
.explain.good { background: #e9f9f1; color: #14724f; }
.explain.bad { background: #fdecee; color: #97283a; }
[data-theme="dark"] .explain.good { background: #123227; color: #7fe0b6; }
[data-theme="dark"] .explain.bad { background: #3a1c22; color: #ffb3bf; }

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* --------------------------------------------------------------- badges */

.page-head { margin: 4px 0 18px; }
.page-head p { color: var(--text-soft); }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 12px; }
.badge { padding: 20px; text-align: center; }
.badge h4 { margin: 10px 0 5px; font-size: 1rem; }
.badge p { color: var(--text-soft); font-size: .87rem; min-height: 40px; }
.badge-icon {
  width: 72px; height: 72px; margin: 0 auto;
  display: grid; place-items: center; font-size: 36px;
  border-radius: 22px; background: var(--spark-soft);
}
.badge.locked .badge-icon { filter: grayscale(1); opacity: .35; background: var(--surface-2); }
.badge.earned { border-color: #FFD98A; }

/* ------------------------------------------------------------- settings */

.setting { padding: 20px 22px; margin-bottom: 12px; }
.setting h3 { margin-bottom: 8px; }
.setting p { margin-bottom: 10px; }
.setting.danger { border-color: #f6c7ce; }
[data-theme="dark"] .setting.danger { border-color: #6b2f3a; }

.curriculum { padding-left: 20px; }
.curriculum > li { margin-bottom: 12px; }
.curriculum ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-soft); }
.curriculum ul li { margin-bottom: 3px; }

/* ----------------------------------------------------------- onboarding */

.welcome {
  padding: clamp(28px, 6vw, 48px);
  text-align: center;
  max-width: 620px; margin: 12px auto 0;
}
.welcome h2 { margin: 10px 0 12px; }
.welcome .lead { max-width: 44ch; margin: 0 auto 8px; }
.welcome-dots { justify-content: center; margin-bottom: 18px; }
.welcome-emoji { font-size: clamp(64px, 14vw, 92px); line-height: 1; }

.welcome-langs { display: grid; gap: 12px; margin: 22px 0 6px; }
.lang-choice {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 20px; min-height: 72px;
  background: var(--surface-2); border: 2px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text);
  font-weight: 800; font-size: 1.1rem;
}
.lang-choice:hover { border-color: var(--primary); }
.lang-choice.active { border-color: var(--primary); background: var(--brand-soft); }
[data-theme="dark"] .lang-choice.active { background: #23214d; }
.lang-choice .flag { font-size: 30px; }

.welcome-points { list-style: none; padding: 0; margin: 22px 0 6px; display: grid; gap: 12px; text-align: start; }
.welcome-points li {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.welcome-points li > span { font-size: 28px; }
.welcome-points strong { display: block; }
.welcome-points small { color: var(--text-soft); }

.welcome-ready {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 16px; margin-top: 18px;
}
.welcome-ready p { margin: 4px 0 0; color: var(--text-soft); }
.welcome-actions { margin-top: 24px; display: grid; gap: 8px; justify-items: center; }
.welcome-actions .wide { margin-top: 0; }

/* ----------------------------------------------------------- read aloud */

.listen-bar { margin: 2px 0 14px; }
.listen-btn {
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 2px solid var(--line);
  border-radius: 999px; padding: 10px 20px; min-height: 46px;
  color: var(--primary); font-weight: 800;
}
.listen-btn:hover { border-color: var(--primary); }
.listen-btn.playing { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.listen-icon { font-size: 18px; }

/* Whatever is being read is gently highlighted so she can follow along. */
.speaking {
  background: var(--spark-soft) !important;
  box-shadow: 0 0 0 3px #FFDE9B;
  border-radius: 10px;
  transition: background .2s ease;
}
[data-theme="dark"] .speaking { background: #3a2f10 !important; box-shadow: 0 0 0 3px #574512; }

/* ------------------------------------------------------------ activities */

.activity {
  padding: 20px 22px; margin-bottom: 12px;
  border: 2px solid #D9D2FF; background: linear-gradient(180deg, var(--surface), var(--surface-2));
}
[data-theme="dark"] .activity { border-color: #27406e; background: linear-gradient(180deg, var(--surface), #17233f); }
.activity.done { border-color: #b7e8d4; }
.activity-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.activity h3 { margin: 2px 0 4px; font-size: 1.16rem; }
.activity-body { margin-top: 14px; }

.sort-progress { color: var(--text-soft); font-size: .84rem; font-weight: 700; margin-bottom: 8px; }
.sort-item {
  background: var(--surface); border: 2px solid var(--line);
  border-radius: var(--radius-sm); padding: 18px 20px;
  font-weight: 700; font-size: 1.04rem; text-align: center; margin-bottom: 12px;
}
.sort-buckets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bucket {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 12px; min-height: 88px;
  background: var(--surface); border: 2px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text); font-weight: 700;
}
.bucket:hover:not(:disabled) { border-color: var(--primary); }
.bucket-emoji { font-size: 26px; }
.bucket.correct { border-color: var(--green); background: #e9f9f1; }
.bucket.wrong { border-color: var(--red); background: #fdecee; }
[data-theme="dark"] .bucket.correct { background: #123227; }
[data-theme="dark"] .bucket.wrong { background: #3a1c22; }

.rank-list { display: grid; gap: 10px; }
.rank-item {
  display: flex; align-items: center; gap: 12px; text-align: start;
  background: var(--surface); border: 2px solid var(--line);
  border-radius: var(--radius-sm); padding: 15px 17px;
  color: var(--text); font-weight: 600; min-height: var(--tap);
}
.rank-item:hover:not(:disabled) { border-color: var(--primary); }
.rank-badge {
  width: 30px; height: 30px; flex: 0 0 auto;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-2); border: 2px solid var(--line);
  font-weight: 800; font-size: .9rem;
}
.rank-item.picked { border-color: var(--green); background: #e9f9f1; opacity: .85; }
.rank-item.picked .rank-badge { background: var(--green); color: #fff; border-color: var(--green); }
[data-theme="dark"] .rank-item.picked { background: #123227; }
.shake { animation: shake .35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.activity-score { font-size: 1.3rem; font-weight: 800; text-align: center; margin: 6px 0 12px; }

/* ------------------------------------------------------- daily challenge */

.daily-card {
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 18px;
  padding: 20px 24px; margin-bottom: 14px;
  border: 2px solid transparent;
}
.daily-card.live {
  background: linear-gradient(135deg, var(--brand-2), var(--primary) 55%, var(--brand-deep));
  color: #fff; box-shadow: 0 14px 34px rgba(58, 31, 166, .32);
}
.daily-card.live .eyebrow { color: #FFE68A; }
.daily-card.live .chip { background: rgba(255,255,255,.18); color: #fff; border-color: rgba(255,255,255,.28); }
.daily-card.live .primary { background: #fff; color: var(--primary); box-shadow: none; }
.daily-card.live .primary:hover { background: var(--brand-soft); }
.daily-card.done { border-color: #b7e8d4; background: linear-gradient(180deg, var(--surface), #f4fdf8); }
[data-theme="dark"] .daily-card.done { background: linear-gradient(180deg, var(--surface), #13291f); border-color: #2b6b50; }

.daily-icon {
  width: 62px; height: 62px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 30px;
  border-radius: 20px; background: rgba(255,255,255,.2);
}
.daily-card.done .daily-icon { background: #e2f7ee; }
[data-theme="dark"] .daily-card.done .daily-icon { background: #16412f; }
.daily-title { font-size: 1.32rem; margin: 2px 0 6px; line-height: 1.25; }
.daily-body p { margin: 0 0 8px; opacity: .92; font-size: .96rem; }
.daily-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.daily-action { display: flex; }

.pulse { animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.09); }
}

.daily-quiz { padding: clamp(22px, 4.5vw, 36px); }
.daily-progress { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.dots { display: flex; gap: 6px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--line); transition: background .2s ease, transform .2s ease;
}
.dot.past { background: var(--green); }
.dot.now { background: var(--primary); transform: scale(1.35); }

.big-emoji { font-size: 58px; line-height: 1; margin-bottom: 6px; }
.daily-result h2 { margin: 6px 0 10px; }
.center-actions { justify-content: center; }

/* ---------------------------------------------------------------- trivia */

.trivia-card {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px;
  padding: 16px 22px; margin-bottom: 14px;
}
.trivia-card .daily-icon { background: var(--spark-soft); }
.trivia-card .daily-title { font-size: 1.12rem; margin: 0 0 3px; }
.trivia-card p { margin: 0 0 6px; color: var(--text-soft); font-size: .92rem; }
.trivia-setup { padding: clamp(24px, 5vw, 40px); text-align: center; max-width: 620px; margin: 0 auto; }
.trivia-setup .lead { max-width: 46ch; margin: 0 auto 8px; }
.trivia-label { margin: 18px 0 8px; font-size: 1rem; color: var(--text-soft); }
.center-row { justify-content: center; }
.trivia-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 12px; }
.mode-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 16px 12px; background: var(--surface-2); border: 2px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text);
}
.mode-card.active { border-color: var(--primary); background: var(--brand-soft); }
.mode-card small { color: var(--text-soft); font-weight: 600; }
.mode-emoji { font-size: 26px; }
.trivia-top { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.chip.timer { font-variant-numeric: tabular-nums; }
.chip.timer.urgent { background: var(--danger-soft); color: #A32F45; border-color: #F7CBD4; }
.timer-track { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 0 0 14px; }
.timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--spark), var(--primary)); transition: width 1s linear; }

@media (max-width: 760px) {
  .trivia-card { grid-template-columns: auto 1fr; row-gap: 10px; }
  .trivia-card .daily-action { grid-column: 1 / -1; }
  .trivia-card .daily-action button { width: 100%; }
}

/* ------------------------------------------------------ glossary/search */

.search-box { position: relative; margin: 4px 0 18px; }
.search-icon {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  font-size: 18px; pointer-events: none; opacity: .65;
}
.search-box input {
  width: 100%; font: inherit; padding: 14px 16px 14px 48px; min-height: 52px;
  border: 2px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.search-box input:focus { border-color: var(--primary); outline: none; }
.search-box input::-webkit-search-cancel-button { cursor: pointer; }

.result-head { margin: 20px 0 10px; font-size: 1rem; color: var(--text-soft); }
.term-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.term { padding: 18px 20px; }
.term h4 { margin: 0 0 6px; color: var(--primary); }
.term p { color: var(--text-soft); font-size: .93rem; margin: 0 0 10px; }
.term .small-btn { padding: 7px 12px; min-height: 36px; font-size: .84rem; text-align: start; }

/* ------------------------------------------------------------------ pack */

.pack-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-top: 12px; }
.pack-item {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 16px;
}
.pack-item strong { font-size: 1.02rem; }
.pack-item small { color: var(--text-soft); flex: 1; }
.pack-item button { margin-top: 6px; }
.field.compact { margin: 4px 0 0; }
.field.compact select {
  width: 100%; font: inherit; padding: 10px 12px; min-height: 44px;
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
.field.compact select:focus { border-color: var(--primary); outline: none; }

/* ---------------------------------------------------------- certificate */

.field { display: block; margin: 14px 0 6px; }
.field span { display: block; font-weight: 700; margin-bottom: 6px; font-size: .95rem; }
.field input {
  width: 100%; font: inherit; padding: 13px 16px; min-height: var(--tap);
  border: 2px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
}
.field input:focus { border-color: var(--primary); outline: none; }
.next-level { border-color: #cdd6ff; }

.certificate-wrap { margin: 18px 0; }
.certificate {
  background: #fffdf7;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  color: #2b2a4a;
  /* A4 landscape proportions so the print preview matches the screen */
  aspect-ratio: 297 / 210;
  container-type: inline-size;
}
.cert-border {
  height: 100%;
  border: 3px double #c9a227;
  border-radius: 16px;
  padding: 4cqw 5cqw;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  background:
    radial-gradient(circle at 12% 12%, rgba(201,162,39,.09), transparent 34%),
    radial-gradient(circle at 88% 88%, rgba(108,99,255,.09), transparent 34%);
}
.cert-top { display: flex; align-items: center; gap: 2cqw; margin-bottom: 1.5cqw; }
.cert-logo { font-size: 4.4cqw; }
.cert-app { font-weight: 800; letter-spacing: .18em; text-transform: uppercase; font-size: 1.7cqw; color: #6c63ff; }
.cert-title { font-size: 5.6cqw; margin: 0 0 .4cqw; letter-spacing: -.01em; color: #2b2a4a; }
.cert-sub { font-size: 2.5cqw; color: #8a6d1f; font-weight: 700; margin: 0 0 2.6cqw; letter-spacing: .04em; }
.cert-awarded { font-size: 1.9cqw; color: #6a6a86; margin: 0; }
.cert-name {
  font-size: 6.2cqw; font-weight: 800; margin: .8cqw 0; line-height: 1.1;
  color: #4b41d8; border-bottom: 2px solid #e3ddb8; padding: 0 4cqw .8cqw;
  max-width: 92%; word-break: break-word;
}
.cert-body { font-size: 2.1cqw; color: #4a4a68; max-width: 74%; margin: 1.6cqw 0 0; line-height: 1.5; }
.cert-stats { display: flex; gap: 5cqw; margin: 2.8cqw 0 0; }
.cert-stats div { display: flex; flex-direction: column; }
.cert-stats strong { font-size: 3.2cqw; color: #6c63ff; line-height: 1; }
.cert-stats span { font-size: 1.6cqw; color: #6a6a86; text-transform: uppercase; letter-spacing: .06em; }
.cert-foot {
  display: flex; align-items: flex-end; justify-content: space-between;
  width: 100%; margin-top: auto; padding-top: 2.6cqw; gap: 3cqw;
}
.cert-foot div { display: flex; flex-direction: column; min-width: 22%; }
.cert-foot span { font-size: 1.5cqw; color: #8a8aa3; text-transform: uppercase; letter-spacing: .07em; }
.cert-foot strong { font-size: 1.9cqw; border-top: 1px solid #d8d3b4; padding-top: .7cqw; margin-top: .5cqw; }
.cert-foot div:last-child { text-align: right; }
.cert-seal { font-size: 5cqw; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px);
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow);
  padding: 14px 20px; z-index: 40; max-width: min(420px, calc(100% - 32px));
  opacity: 0; transition: opacity .3s ease, transform .3s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-emoji { font-size: 30px; }

.footer { text-align: center; color: var(--text-soft); font-size: .85rem; padding: 30px 0 34px; }
.footer a { color: var(--text-soft); }

/* --------------------------------------------------------------- mobile */

@media (max-width: 760px) {
  body { font-size: 16px; }
  .brand-text small { display: none; }

  /* Stack the daily card so the button gets a full-width row of its own
     instead of being squeezed into a third column. */
  .daily-card { grid-template-columns: auto 1fr; row-gap: 14px; padding: 18px 20px; }
  .daily-action { grid-column: 1 / -1; }
  .daily-action button { width: 100%; }
  .daily-icon { width: 52px; height: 52px; font-size: 26px; border-radius: 17px; }
  .daily-title { font-size: 1.16rem; }
  .hero { grid-template-columns: 1fr; }
  .hero-art { min-height: 0; order: -1; }
  .hero-mascot { width: 108px; }
  .orb { width: 130px; height: 130px; }
  .stats { grid-template-columns: 1fr; }
  .stat { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 14px; }
  .stat-value { font-size: 1.45rem; }
  .stat .progress-track { grid-column: 1 / -1; }
  .stat-note { grid-column: 1 / -1; }

  .unit-card, .lesson-row, .quiz-teaser {
    grid-template-columns: auto 1fr; row-gap: 12px;
  }
  .unit-action { grid-column: 1 / -1; justify-content: stretch; }
  .unit-action button { width: 100%; }
  .locked-note { max-width: none; text-align: center; width: 100%; }
  .badge-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .badge p { min-height: 0; }
}

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

/* ---------------------------------------------------------------- print */

@page { size: A4 landscape; margin: 6mm; }

@media print {
  .topbar, .footer, .toast, .nav-button, .skip,
  .offline-banner, .no-print, .back { display: none !important; }

  html, body {
    background: #fff !important;
    color: #000;
    font-size: 12pt;
  }
  .app { width: 100%; }
  .card { box-shadow: none; }

  /* The certificate is the only thing that should reach the paper.
     Height is pinned to the printable area (A4 landscape 210mm minus the 6mm
     margins) instead of an aspect-ratio, because a 297:210 box is slightly
     taller than the page once margins are subtracted and spills to page 2. */
  .certificate-wrap { margin: 0; }
  .certificate {
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    width: 100%;
    height: 197mm;
    aspect-ratio: auto;
    background: #fff;
    overflow: hidden;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .cert-border { padding: 3.2cqw 5cqw; }
  .cert-border { border-color: #b8912a; }
  .cert-name { color: #3c33c0; }

  /* Anything that is not the certificate is dropped from the printout. */
  main > *:not(.certificate-wrap) { display: none !important; }
}

/* ---- Golden rules ------------------------------------------------------ */
.golden-rules { padding: 14px 18px; }
.golden-rules summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; font-weight: 800; font-size: 1.05rem; list-style: none; }
.golden-rules summary::-webkit-details-marker { display: none; }
.golden-rules .chev { transition: transform .2s; }
.golden-rules[open] .chev { transform: rotate(180deg); }
.golden-rules > p { margin: 8px 0 4px; }
.rule-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; counter-reset: rule; }
.rule-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 12px; background: var(--wash-2, var(--surface-2)); }
.rule-list li::before { counter-increment: rule; content: counter(rule); font-weight: 900; color: var(--primary); min-width: 1.2em; }
.rule-list .rule-emoji { font-size: 1.15rem; }
.rule-list li div { display: grid; gap: 2px; }
.rule-list li strong { font-size: .98rem; }
.rule-list li span:not(.rule-emoji) { color: var(--text-soft); font-size: .9rem; }
.rule-list.compact li { padding: 6px 8px; }
.rule-chip { display: inline-block; margin-top: 8px; padding: 4px 10px; border-radius: 999px; background: #fff8; border: 1px solid #FFDE9B; font-size: .82rem; font-weight: 700; color: var(--text); }
[data-theme="dark"] .rule-chip, .dark .rule-chip { background: #0003; }
.level-goal { margin: 6px 0 0; font-size: .9rem; color: var(--text-soft); }
.level-goal strong { color: var(--text); }
@media print { .golden-rules { display: none; } }

/* ---- Profiles ---------------------------------------------------------- */
.profile-pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px 6px 8px; min-height: 44px; font: inherit; font-weight: 700; color: var(--text); cursor: pointer; max-width: 140px; }
.profile-pill .profile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.profile-pill:hover { border-color: var(--primary); }
@media (max-width: 420px) { .profile-pill .profile-name { display: none; } }
.profile-list { display: grid; gap: 12px; margin-bottom: 16px; }
.profile-card { display: flex; gap: 14px; align-items: flex-start; }
.profile-card.active { border: 2px solid var(--primary); }
.profile-avatar { font-size: 2rem; width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: var(--surface-2); flex: none; }
.profile-body { flex: 1; min-width: 0; }
.profile-body h3 { margin: 0 0 4px; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.rename-box:not([hidden]) { display: flex; gap: 8px; margin-top: 8px; }
.rename-box input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); font: inherit; }
.confirm-box { margin-top: 10px; padding: 10px; border-radius: 12px; background: var(--danger-soft); }
.confirm-box p { margin: 0 0 8px; }
.danger-text { color: var(--danger); }
.emoji-row .emoji-choice { font-size: 1.3rem; padding: 6px 10px; }

/* ---- Cloud: account / classes ---------------------------------------- */
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip.warn { background: var(--spark-soft); border-color: #FFDE9B; color: var(--text); }
.login-box .field input { width: 100%; }
.cloud-kids, .class-list { list-style: none; padding: 0; margin: 8px 0 12px; display: grid; gap: 8px; }
.cloud-kids li, .class-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); }
.cloud-kids li div, .class-list li div { display: grid; flex: 1; min-width: 0; }
.cloud-kids .avatar { font-size: 1.4rem; }
.join-form { display: grid; gap: 8px; }
.join-form input, .join-form select { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); font: inherit; background: var(--surface); color: var(--text); }
.code-input { text-transform: uppercase; letter-spacing: .2em; font-weight: 800; }
.code-card { text-align: center; }
.big-code { font-size: 2.4rem; font-weight: 900; letter-spacing: .25em; color: var(--primary); user-select: all; margin-top: 4px; }
.board, .mini-board { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.board li, .mini-board li { display: grid; grid-template-columns: 2em 1fr auto auto; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); }
.mini-board li { grid-template-columns: 2em 1fr auto; }
.board li.me, .mini-board li.me { outline: 2px solid var(--primary); }
.board .rank, .mini-board .rank { font-weight: 900; color: var(--primary); }
.board .who em { font-style: normal; color: var(--text-soft); font-size: .85rem; }
.class-card .class-card-head h3 { margin: 2px 0 6px; }
.table-wrap { overflow-x: auto; }
.roster { width: 100%; border-collapse: collapse; font-size: .9rem; }
.roster th, .roster td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.roster .lvls { display: flex; gap: 3px; }
.roster .lvl { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; font-size: .72rem; font-weight: 800; background: var(--surface-2); color: var(--text-soft); }
.roster .lvl.part { background: var(--brand-soft); color: var(--primary); }
.roster .lvl.full { background: var(--primary); color: #fff; }

.backup-code { width: 100%; box-sizing: border-box; margin: 10px 0 8px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; background: var(--surface-2); color: var(--text); resize: vertical; }
