:root {
  color-scheme: light dark;
  --bg: #f4f5ef;
  --bg-elevated: #ffffff;
  --bg-sunken: #f7f8f3;
  --border: #e3e6db;
  --text: #1e2a38;
  --text-muted: #5f6d7a;
  --accent: #29384b;
  --accent-hover: #1b2530;
  --on-accent: #ffffff;
  --accent-soft: rgba(41, 56, 75, 0.06);
  --gold: #d9a928;
  --gold-soft: rgba(217, 169, 40, 0.14);
  --gold-line: rgba(217, 169, 40, 0.45);
  --danger: #b3261e;
  --danger-soft: rgba(179, 38, 30, 0.08);
  --success: #2f6b3a;
  --success-soft: rgba(47, 107, 58, 0.1);
  --on-status: #ffffff;
  --radius: 24px;
  --radius-sm: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 2px 8px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 12px 32px rgba(16, 24, 40, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1217;
    --bg-elevated: #181e26;
    --bg-sunken: #12171d;
    --border: #2a323d;
    --text: #eceef2;
    --text-muted: #9aa4b1;
    --accent: #a9bbd0;
    --accent-hover: #c3d1e0;
    --on-accent: #0e1217;
    --accent-soft: rgba(169, 187, 208, 0.1);
    --gold: #e8c157;
    --gold-soft: rgba(232, 193, 87, 0.1);
    --gold-line: rgba(232, 193, 87, 0.35);
    --danger: #ff8a80;
    --danger-soft: rgba(255, 138, 128, 0.12);
    --success: #7dd88a;
    --success-soft: rgba(125, 216, 138, 0.12);
    --on-status: #0e1217;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: "DM Sans", "Noto Sans Devanagari", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3 {
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

h1 {
  font-size: 1.65rem;
}

p {
  margin: 0 0 1rem;
}

.muted {
  color: var(--text-muted);
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

/* --- Topbar --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-mark {
  width: 26px;
  height: 26px;
  object-fit: contain;
  border-radius: 7px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.lang-toggle {
  display: flex;
  padding: 3px;
  background: var(--accent-soft);
  border-radius: 999px;
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}

.lang-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* --- Layout --- */

.app {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.25rem 1rem 3rem;
}

.card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.75rem 1.5rem;
  margin: 0 auto;
  animation: card-in 0.25s ease-out;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.card.center {
  text-align: center;
}

/* --- Form fields --- */

.field {
  display: block;
  margin-bottom: 1.1rem;
  text-align: left;
}

.field span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.field input,
.text-input {
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  transition: border-color 0.15s;
}

select.text-input {
  font-size: 0.95rem;
}

.field input:focus,
.text-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Optional starting levels, collapsed by default */

.disclosure {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 0.25rem 0 1.25rem;
  text-align: left;
}

.disclosure summary {
  list-style: none;
  cursor: pointer;
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.disclosure summary::-webkit-details-marker {
  display: none;
}

.disclosure summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.2s;
}

.disclosure[open] summary::after {
  transform: rotate(-135deg) translate(-2px, -2px);
}

.disclosure > :not(summary) {
  margin-left: 1rem;
  margin-right: 1rem;
}

.disclosure .field:last-child {
  margin-bottom: 1rem;
}

.starting-levels-intro {
  font-size: 0.88rem;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.95rem 1.5rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  text-decoration: none !important;
  min-height: 52px;
  transition: background 0.15s, transform 0.1s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
  margin-top: 0.5rem;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-link {
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.6rem 0.5rem;
  min-height: auto;
  text-decoration: underline !important;
}

/* --- Child dashboard --- */

.dash {
  width: 100%;
  max-width: 560px;
  display: grid;
  gap: 1rem;
  margin: 0 auto;
}

.dash .card {
  max-width: none;
}

.dash-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 0.15rem;
}

.dash-child {
  margin: 0;
  overflow-wrap: anywhere;
}

.btn-link.small {
  font-size: 0.85rem;
  padding: 0.25rem 0;
  white-space: nowrap;
}

.section-title {
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

.plan-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: grid;
  gap: 0.5rem;
}

.plan-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  font-size: 0.92rem;
}

.plan-subject {
  font-weight: 700;
}

.plan-text {
  color: var(--text-muted);
}

.plan-skipped {
  background: var(--success-soft);
  border-color: transparent;
}

.plan-skipped .plan-text {
  color: var(--success);
  font-weight: 600;
}

.resume-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--gold-soft);
  border: 1px solid var(--gold-line);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  margin-bottom: 1rem;
}

.resume-title {
  font-weight: 700;
  margin: 0;
}

.resume-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.1rem 0 0;
}

.small-btn {
  min-height: 40px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.progress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.progress-cell {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
}

.progress-level {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0 0 0.5rem;
}

.progress-cell .level-meter {
  margin-bottom: 0.5rem;
}

.trend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.trend.up {
  color: var(--success);
}

.trend.down {
  color: var(--danger);
}

.past-list {
  display: grid;
  gap: 0.5rem;
}

.past {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.past summary {
  list-style: none;
  cursor: pointer;
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.past summary::-webkit-details-marker {
  display: none;
}

.past[open] summary {
  border-bottom: 1px solid var(--border);
}

.past-when {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.past-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.level-chip {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--gold-soft);
}

.level-chip.top {
  background: var(--success-soft);
  color: var(--success);
}

.past-body {
  padding: 0.75rem 0.9rem;
}

.past-body p:last-child {
  margin-bottom: 0;
}

.past-track + .past-track {
  margin-top: 0.9rem;
}

.attempt-list {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  display: grid;
  gap: 0.4rem;
}

.attempt-row {
  display: grid;
  grid-template-columns: 1.25rem auto minmax(0, 1fr);
  gap: 0.2rem 0.6rem;
  align-items: baseline;
  font-size: 0.88rem;
}

.attempt-n {
  color: var(--text-muted);
  font-weight: 700;
}

.attempt-level {
  font-weight: 700;
  white-space: nowrap;
}

.attempt-answer {
  overflow-wrap: anywhere;
}

.verdict-chip {
  grid-column: 2 / -1;
  justify-self: start;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}

.verdict-chip.pass {
  background: var(--success-soft);
  color: var(--success);
}

.verdict-chip.fail {
  background: var(--danger-soft);
  color: var(--danger);
}

/* --- Progress stepper --- */

.progress-row {
  list-style: none;
  padding: 0;
  display: flex;
  justify-content: center;
  margin: 0 0 1.5rem;
}

.progress-dot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  /* Fixed equal width regardless of label length ("Hindi Reading" vs.
     "Math") — keeps the connector line and markers evenly spaced. */
  flex: 0 0 110px;
}

/* Connector line between consecutive steps */
.progress-dot + .progress-dot::before {
  content: "";
  position: absolute;
  top: 14px;
  right: calc(50% + 20px);
  width: calc(100% - 40px);
  height: 2px;
  background: var(--border);
}

.progress-dot.done + .progress-dot::before {
  background: var(--success);
}

.progress-dot .dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  background: var(--bg-sunken);
  border: 2px solid var(--border);
  color: var(--text-muted);
}

.progress-dot.active .dot {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.progress-dot.done .dot {
  background: var(--success);
  border-color: var(--success);
  color: var(--on-status);
}

.progress-dot .dot-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.progress-dot.active .dot-label {
  color: var(--text);
  font-weight: 700;
}

.progress-dot.done .dot-label {
  color: var(--success);
}

/* --- Item screen --- */

.item-instruction {
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  margin-bottom: 0.85rem;
}

.item-box {
  background: var(--gold-soft);
  border: 1.5px dashed var(--gold-line);
  border-radius: var(--radius-sm);
  padding: 1.75rem 1.25rem;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  margin-bottom: 1.5rem;
  word-break: break-word;
}

.item-box-reading {
  font-size: 1.85rem;
  line-height: 1.75;
}

/* Number identification: the child reads this off the screen */
.item-box-number {
  font-size: clamp(5rem, 32vw, 8rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.04em;
  padding: 2.25rem 1rem;
  font-variant-numeric: tabular-nums;
}

/* --- Recorder: one big round button at a time --- */

.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.mic-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  background: none;
  border: none;
  padding: 0.25rem;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.mic-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.recorder:not(.is-recording) .mic-stop,
.recorder.is-recording .mic-record {
  display: none;
}

.mic-circle {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--danger);
  color: var(--on-status);
  box-shadow: 0 8px 20px var(--danger-soft);
  transition: transform 0.1s;
}

.mic-btn:active:not(:disabled) .mic-circle {
  transform: scale(0.95);
}

.mic-stop .mic-circle {
  background: var(--accent);
  color: var(--on-accent);
}

/* Pulsing ring while recording */
.mic-stop .mic-circle::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 3px solid var(--danger);
  animation: pulse 1.4s ease-out infinite;
}

.mic-stop:disabled .mic-circle::before {
  animation: none;
  opacity: 0;
}

.stop-square {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: currentColor;
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.25);
    opacity: 0;
  }
}

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--danger);
  font-weight: 700;
  margin: 0.25rem 0 0;
  font-variant-numeric: tabular-nums;
}

.recording-indicator[hidden] {
  display: none;
}

.rec-limit {
  color: var(--text-muted);
  font-weight: 600;
}

/* Last 15 seconds before the auto-stop */
.recording-indicator.near-limit #rec-timer {
  background: var(--danger);
  color: var(--on-status);
  border-radius: 6px;
  padding: 0 0.3rem;
}

.rec-auto-note {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.rec-auto-note[hidden] {
  display: none;
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

/* --- Math: multiple choice --- */

.mc-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.mc-option-btn {
  font: inherit;
  font-size: 1.5rem;
  font-weight: 800;
  min-height: 72px;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, transform 0.1s;
}

.mc-option-btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.mc-option-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.mc-option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.mc-option-btn.selected.correct {
  background: var(--success);
  border-color: var(--success);
  color: var(--on-status);
  opacity: 1;
}

.mc-option-btn.selected.incorrect {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-status);
  opacity: 1;
}

/* --- Math: evaluator yes/no for number identification --- */

.judge-question {
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.judge-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.judge-btn {
  font: inherit;
  font-size: 1.2rem;
  font-weight: 800;
  min-height: 64px;
  border-radius: var(--radius-sm);
  border: 2px solid;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}

.judge-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.judge-yes {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.judge-no {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.judge-btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.judge-yes.selected {
  background: var(--success);
  color: var(--on-status);
  opacity: 1;
}

.judge-no.selected {
  background: var(--danger);
  color: var(--on-status);
  opacity: 1;
}

/* --- Status / errors --- */

.status-text {
  min-height: 1.3rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
}

.error-text {
  color: var(--danger) !important;
}

.insecure-banner {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 1rem;
  text-align: center;
}

/* --- Result screen --- */

.result-badge {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--success-soft);
  color: var(--success);
  font-size: 1.6rem;
  font-weight: 800;
}

.result-grid {
  display: grid;
  gap: 0.85rem;
  margin: 0.5rem 0 1.5rem;
  text-align: left;
}

.result-card {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.1rem 1.25rem;
}

.result-subject {
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.result-level {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.6rem;
}

.level-meter {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 0.7rem;
}

.level-meter span {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
}

.level-meter span.on {
  background: var(--gold);
}

/* Top rung reached */
.level-meter.top span.on {
  background: var(--success);
}

.result-label {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0;
}

/* --- Help modal --- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

/* An author `display` rule always beats the UA default [hidden] { display:
   none }, regardless of specificity — without this, the overlay stays
   visible (and blocks every click on the page under it) even with the
   `hidden` attribute set. */
.overlay[hidden] {
  display: none;
}

.help-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-md);
  animation: card-in 0.2s ease-out;
}

.help-card p {
  color: var(--text-muted);
}

.help-card .btn {
  width: 100%;
}

@media (min-width: 540px) {
  .overlay {
    align-items: center;
  }

  .result-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

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