/* ==========================================================================
   Saville Swift Comprehension - practice app styles
   Clean, fast, distraction-free. Mobile-first, big readable text.
   ========================================================================== */

:root {
  --bg:          #f4f6fb;
  --surface:     #ffffff;
  --ink:         #1a2233;
  --ink-soft:    #5a6478;
  --line:        #e2e7f0;
  --brand:       #2f5bea;
  --brand-ink:   #ffffff;
  --good:        #1f9d57;
  --good-bg:     #e6f6ec;
  --bad:         #d5392b;
  --bad-bg:      #fdecea;
  --warn:        #d98a00;
  --shadow:      0 4px 18px rgba(26, 34, 51, .08);
  --radius:      14px;
  color-scheme:  light;   /* make native form controls match the theme */

  /* Secondary surfaces (also re-themed in dark mode) */
  --chip:        #eef1f8;   /* default button / key / tag / timer bg */
  --alt-row:     #fafbfe;   /* zebra striping */
  --th-bg:       #f0f3fa;   /* table headers */
  --sel-bg:      #eef3ff;   /* selected option */
  --explain-bg:  #f7f9ff;   /* explanation panel */
  --note-bg:     #fff6e6;   /* calculator note / focus flag */
  --note-border: #ffe2a8;
  --track:       #cfd6e4;   /* toggle track (off) */
  --knob:        #ffffff;   /* toggle knob */
  --sig:         #0d9488;   /* signature / alien accent */
}

/* Dark theme - applied either when the user explicitly chooses it,
   or (via the media query below) when the OS prefers dark and the user
   hasn't made an explicit choice. */
:root[data-theme="dark"] {
  --bg:          #0f141c;
  --surface:     #18202c;
  --ink:         #e6ebf3;
  --ink-soft:    #9aa6b8;
  --line:        #2a3543;
  --brand:       #5b82ff;
  --brand-ink:   #ffffff;
  --good:        #43c47e;
  --good-bg:     #14301f;
  --bad:         #ff6a5c;
  --bad-bg:      #341714;
  --warn:        #e0a23a;
  --shadow:      0 4px 18px rgba(0, 0, 0, .45);

  --chip:        #222d3b;
  --alt-row:     #1d2632;
  --th-bg:       #212c3a;
  --sel-bg:      #1c2b50;
  --explain-bg:  #161f2e;
  --note-bg:     #2e2615;
  --note-border: #574a1f;
  --track:       #3a4759;
  --knob:        #cdd6e3;
  --sig:         #5eead4;
  color-scheme:  dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0f141c;
    --surface:     #18202c;
    --ink:         #e6ebf3;
    --ink-soft:    #9aa6b8;
    --line:        #2a3543;
    --brand:       #5b82ff;
    --brand-ink:   #ffffff;
    --good:        #43c47e;
    --good-bg:     #14301f;
    --bad:         #ff6a5c;
    --bad-bg:      #341714;
    --warn:        #e0a23a;
    --shadow:      0 4px 18px rgba(0, 0, 0, .45);

    --chip:        #222d3b;
    --alt-row:     #1d2632;
    --th-bg:       #212c3a;
    --sel-bg:      #1c2b50;
    --explain-bg:  #161f2e;
    --note-bg:     #2e2615;
    --note-border: #574a1f;
    --track:       #3a4759;
    --knob:        #cdd6e3;
    --sig:         #5eead4;
    color-scheme:  dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Subtle layered background for depth (sits behind everything) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(60% 50% at 12% -5%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 70%),
    radial-gradient(55% 45% at 100% 0%, color-mix(in srgb, var(--sig) 12%, transparent), transparent 70%);
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

/* ---- Top bar -------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-right: 56px; /* keep content clear of the fixed theme toggle (top-right) */
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* Home header: title (+ grade) on top, then the sub line and the action
   buttons share one row so the buttons sit level with the sub text. */
.topbar-home { flex-direction: column; align-items: stretch; gap: 6px; padding-right: 0; }
.topbar-subrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: -.01em;
}
.topbar .sub { color: var(--ink-soft); font-size: 13px; }

/* ---- Buttons -------------------------------------------------------------- */
button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--chip);
  color: var(--ink);
  transition: transform .04s ease, background .15s ease, border-color .15s ease;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--brand); color: var(--brand-ink); }
button.ghost   { background: transparent; border: 1px solid var(--line); }
button.block   { display: block; width: 100%; }
button:disabled { opacity: .5; cursor: default; }

/* ---- Cards & panels ------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 16px;
}

.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.center { text-align: center; }

/* ---- Home: mode grid ------------------------------------------------------ */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 6px;
}
.mode-btn {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  text-align: left;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.mode-btn:hover {
  border-color: color-mix(in srgb, var(--ic, var(--brand)) 55%, var(--line));
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .18);
}
.mode-btn:active { transform: translateY(0); }
.mode-tx { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mode-btn .t { font-weight: 650; font-size: 16.5px; }
.mode-btn .d { color: var(--ink-soft); font-size: 13px; line-height: 1.45; }

/* Icon chips on the mode cards */
.mode-ic {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: var(--ic, var(--brand));
  background: color-mix(in srgb, var(--ic, var(--brand)) 15%, transparent);
}
.mode-ic svg { width: 22px; height: 22px; }
.ic-verbal    { --ic: #5b82ff; }
.ic-numerical { --ic: #43c47e; }
.ic-error     { --ic: #e0a23a; }
.ic-all       { --ic: #c879e6; }
.ic-abstract  { --ic: #ef6f6c; }
.ic-mock      { --ic: var(--brand); }
.ic-study     { --ic: #3fc1c9; }
.mode-btn.ic-verbal, .mode-btn[data-mode="verbal"] { --ic: #5b82ff; }
.mode-btn[data-mode="numerical"] { --ic: #43c47e; }
.mode-btn[data-mode="abstract"] { --ic: #ef6f6c; }
.mode-btn[data-mode="error"] { --ic: #e0a23a; }
.mode-btn[data-mode="all"] { --ic: #c879e6; }

/* Full-width secondary CTA (Full Deck) */
.wide-btn { width: 100%; margin-top: 12px; }

/* Difficulty selector (home) */
.diff-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin: 4px 0 8px; }
.diff-label { font-weight: 600; font-size: 14px; color: var(--ink-soft); }
.diff-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.diff-chip {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  background: var(--chip);
  border: 1px solid transparent;
}
.diff-chip:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.diff-chip.active { background: var(--brand); color: var(--brand-ink); }

/* Difficulty tag (quiz header + review) */
.difftag {
  display: inline-block;
  font-size: 11px; font-weight: 700;
  letter-spacing: .03em;
  padding: 1px 8px;
  border-radius: 999px;
  vertical-align: middle;
}
.difftag.easy   { color: var(--good); background: var(--good-bg); }
.difftag.medium { color: var(--warn); background: var(--note-bg); }
.difftag.hard   { color: var(--bad);  background: var(--bad-bg); }

/* Abstract reasoning figures */
.absfig { width: 100%; height: 100%; color: var(--ink); display: block; }
.abs-seq { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 6px 0 4px; }
.abs-tile {
  width: 64px; height: 64px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  flex: 0 0 auto;
}
.abs-tile.abs-q { font-size: 26px; font-weight: 800; color: var(--ink-soft); }
.abs-opts { grid-template-columns: repeat(4, 1fr); }
.opt.optfig { flex-direction: column; gap: 8px; padding: 12px; justify-items: center; text-align: center; }
.opt.optfig .key { align-self: flex-start; }
.opt.optfig .absfig { width: 60px; height: 60px; }
@media (max-width: 520px) { .abs-opts { grid-template-columns: repeat(2, 1fr); } }

/* Real Mock Test: full-width, accented call-to-action below the practice grid */
.mock-btn {
  width: 100%;
  margin-top: 12px;
  --ic: var(--brand);
  border: 1.5px solid color-mix(in srgb, var(--brand) 42%, transparent);
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 60%),
    var(--surface);
}
.mock-btn:hover { border-color: var(--brand); box-shadow: 0 12px 30px color-mix(in srgb, var(--brand) 28%, transparent); }
.mock-btn .t { color: var(--brand); font-size: 18px; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.settings-row:first-child { border-top: none; }
.timing-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }

/* Let wide tables scroll horizontally instead of overflowing on small screens */
.tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.settings-row input[type="number"] {
  width: 76px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  text-align: right;
  background: var(--surface);
  color: var(--ink);
}

/* Toggle switch */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { display: none; }
.toggle .track {
  flex: 0 0 auto; /* never shrink: a squeezed track lets the knob escape on mobile */
  width: 46px; height: 26px; border-radius: 999px;
  background: var(--track); position: relative; transition: background .15s;
}
.toggle .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--knob); box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: left .15s;
}
.toggle input:checked + .track { background: var(--brand); }
.toggle input:checked + .track::after { left: 23px; }

/* ---- Quiz header / timer -------------------------------------------------- */
.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-right: 56px; /* clear the fixed theme-toggle in the corner */
}
.quiz-head .head-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.quiz-head .progress { font-size: 14px; color: var(--ink-soft); }
.quiz-head .seclabel {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--brand);
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 22px;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--chip);
}
.timer.study { background: var(--good-bg); color: var(--good); font-size: 15px; }
.timer.warn  { background: var(--bad-bg);  color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* Two-pill timer: per-question + per-section */
.timers { display: flex; gap: 8px; }
.timer-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 76px;
  padding: 4px 12px;
  border-radius: 10px;
  background: var(--chip);
}
.timer-pill .tlabel {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
}
.timer-pill .tval { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; }
/* low time on the section total */
.timer-pill.warn { background: var(--bad-bg); animation: pulse 1s infinite; }
.timer-pill.warn .tval, .timer-pill.warn .tlabel { color: var(--bad); }
/* over the per-question budget */
.timer-pill.over { background: var(--note-bg); }
.timer-pill.over .tval, .timer-pill.over .tlabel { color: var(--warn); }

.progress-bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress-bar > i { display: block; height: 100%; background: var(--brand); transition: width .2s ease; }

/* ---- Stimulus ------------------------------------------------------------- */
.passage { font-size: 18px; line-height: 1.65; }
.calc-note {
  display: inline-block;
  font-size: 13px;
  color: var(--warn);
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 16px;
}
table.data caption { text-align: left; font-weight: 600; margin-bottom: 8px; }
table.data th, table.data td {
  border: 1px solid var(--line);
  padding: 9px 11px;
  text-align: right;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { background: var(--th-bg); }
table.data tbody tr:nth-child(even) { background: var(--alt-row); }

/* Pie chart */
.chart-wrap { text-align: center; margin: 8px 0; }
.chart-title { font-weight: 600; color: var(--ink); }
.chart-sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
.pie { width: 220px; max-width: 100%; height: auto; display: inline-block; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; margin-top: 10px; }
.legend .leg { font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }
.bar-chart { width: 100%; max-width: 440px; height: auto; display: inline-block; }
.bar-val { fill: var(--ink); font-size: 11px; font-weight: 600; }
.bar-lbl { fill: var(--ink-soft); font-size: 11px; }

/* Multi-select checking: original vs re-entered */
.check-original caption, .check-entry caption { color: var(--ink-soft); }
.check-entry { margin-top: 4px; }
.coding-key { margin: 6px 0 12px; font-weight: 600; }

/* Error-checking record */
table.record { width: 100%; border-collapse: collapse; font-size: 16px; }
table.record th, table.record td { border: 1px solid var(--line); padding: 10px 12px; text-align: left; }
table.record thead th { background: var(--th-bg); }
table.record td.label { font-weight: 600; width: 34%; }
.cell-diff { background: var(--bad-bg); color: var(--bad); font-weight: 700; border-radius: 4px; }
.cell-same { background: var(--good-bg); }

/* ---- Question + options --------------------------------------------------- */
.q-text { font-size: 20px; font-weight: 600; margin: 18px 0 14px; }

.options { display: grid; gap: 10px; }
.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  font-size: 17px;
}
.opt:hover { border-color: var(--brand); }
.opt .key {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--chip);
  font-size: 13px; font-weight: 700; color: var(--ink-soft);
}
.opt.selected { border-color: var(--brand); background: var(--sel-bg); }

/* Multi-select checkbox indicator */
.opt .checkbox {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border: 2px solid var(--ink-soft);
  border-radius: 6px;
  position: relative;
}
.opt.selected .checkbox, .opt.correct .checkbox, .opt.wrong .checkbox { border-color: currentColor; }
.opt.multi.selected .checkbox { background: var(--brand); border-color: var(--brand); }
.opt.multi.correct .checkbox { background: var(--good); border-color: var(--good); }
.opt.multi.wrong .checkbox  { background: var(--bad);  border-color: var(--bad); }
.opt.multi.selected .checkbox::after,
.opt.multi.correct .checkbox::after,
.opt.multi.wrong .checkbox::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.opt.correct  { border-color: var(--good); background: var(--good-bg); }
.opt.wrong    { border-color: var(--bad);  background: var(--bad-bg); }

/* ---- Inline explanation (study mode) ------------------------------------- */
.explain {
  margin-top: 16px;
  border-left: 4px solid var(--brand);
  background: var(--explain-bg);
  border-radius: 0 10px 10px 0;
  padding: 14px 16px;
}
.explain h4 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.explain pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;       /* preserve line breaks AND wrap on small screens */
  word-break: break-word;
}
.verdict { font-weight: 700; margin-bottom: 6px; }
.verdict.ok  { color: var(--good); }
.verdict.no  { color: var(--bad); }

.nav-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }

/* ---- Results -------------------------------------------------------------- */
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 6px 0 4px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: center; }
.metric .big { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.metric .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }

.bd-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.bd-row:first-child { border-top: none; }
.bd-name { font-weight: 600; }
.bar { flex: 1; height: 8px; margin: 0 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.flag { background: var(--note-bg); border: 1px solid var(--note-border); border-radius: 10px; padding: 12px 14px; margin-top: 8px; }
.flag b { color: var(--warn); }

/* ---- Review --------------------------------------------------------------- */
.review-item { border-top: 1px solid var(--line); padding: 18px 0; }
.review-item:first-child { border-top: none; }
.tag { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--ink-soft); margin-right: 6px; }
.ans-line { font-size: 15px; margin: 4px 0; }
.ans-line .you.ok { color: var(--good); font-weight: 700; }
.ans-line .you.no { color: var(--bad);  font-weight: 700; }
.ans-line .corr   { color: var(--good); font-weight: 700; }
/* Abstract answers shown as a small inline figure on review / verdict lines. */
.ans-fig { display: inline-flex; vertical-align: middle; width: 34px; height: 34px; }
.ans-fig .absfig { width: 34px; height: 34px; }
.verdict .ans-fig { width: 30px; height: 30px; }
.verdict .ans-fig .absfig { width: 30px; height: 30px; }

/* ---- History list --------------------------------------------------------- */
.hist { font-size: 14px; }
.hist .row { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.hist .row:first-child { border-top: none; }

/* ---- Landing page --------------------------------------------------------- */
.landing {
  min-height: calc(100vh - 80px);
  min-height: calc(100dvh - 80px); /* dvh excludes Safari's bottom bar so the signature isn't hidden behind it */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px 0 calc(24px + env(safe-area-inset-bottom));
}

/* ---- About page ----------------------------------------------------------- */
.about-wrap {
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 4px calc(24px + env(safe-area-inset-bottom));
}
.about-title { margin: 4px 0 14px; font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.about-text { margin: 0 0 16px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.6; max-width: 480px; }
.about-contact { margin: 6px 0 14px; }
.mail-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 13px 22px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  color: var(--brand-ink);
  background: var(--brand);
  box-shadow: 0 8px 22px color-mix(in srgb, var(--brand) 40%, transparent);
  text-decoration: none;
}
.mail-btn:hover { filter: brightness(1.05); }
.mail-btn svg { width: 22px; height: 22px; }
.about-num { margin-top: 10px; font-size: 14px; color: var(--ink-soft); letter-spacing: .03em; }
.about-official { margin-top: 30px; width: 100%; max-width: 460px; }
.about-official h2 { font-size: 16px; font-weight: 800; margin: 0 0 4px; }
.about-official .about-text { margin-bottom: 12px; }
.res-link {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; margin: 8px 0;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  font-size: 14.5px; font-weight: 600; text-decoration: none; text-align: left;
}
.res-link:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); color: var(--brand); }
.res-ext { color: var(--ink-soft); flex: 0 0 auto; }
.about-sig { margin-top: 28px; }
.hero {
  position: relative;
  overflow: hidden;
  width: 100%;
  text-align: center;
  padding: 48px 26px 44px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    radial-gradient(120% 80% at 50% -10%, color-mix(in srgb, var(--brand) 26%, transparent), transparent 60%),
    var(--surface);
  box-shadow: var(--shadow);
}
/* soft glow blobs */
.hero::before, .hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .35;
  pointer-events: none;
}
.hero::before { width: 240px; height: 240px; background: var(--brand); top: -90px; left: -60px; }
.hero::after  { width: 220px; height: 220px; background: var(--sig);   bottom: -100px; right: -50px; }

.hero-badge {
  position: relative;
  display: inline-block;
  font-size: 12px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 34%, transparent);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 20px;
}
.hero-title {
  position: relative;
  margin: 0 0 12px;
  font-size: 46px;
  line-height: 1.05;
  letter-spacing: -.03em;
  font-weight: 800;
  background: linear-gradient(120deg, var(--ink), var(--brand) 70%, var(--sig));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  position: relative;
  max-width: 460px;
  margin: 0 auto 28px;
  color: var(--ink-soft);
  font-size: 17px;
}
.hero-feats {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 560px;
  margin: 0 auto 30px;
}
.hero-feat {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 10px;
}
.hero-feat .n { display: block; font-size: 22px; font-weight: 800; color: var(--ink); }
.hero-feat .l { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* ---- Landing feature tiles ------------------------------------------------ */
.land-feats {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 520px;
  margin: 4px auto 30px;
  text-align: left;
}
.land-feat {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  border-radius: 14px;
  padding: 14px;
}
.land-feat .lf-tx { display: flex; flex-direction: column; min-width: 0; }
.land-feat .lf-tx b { font-size: 17px; font-weight: 800; color: var(--ink); line-height: 1.1; }
.land-feat .lf-tx span { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }

/* ---- Assessment chooser page ---------------------------------------------- */
.choose-wrap { text-align: center; padding: 8px 0 24px; }
.choose-title {
  margin: 4px 0 8px;
  font-size: 28px;
  letter-spacing: -.02em;
  font-weight: 800;
}
.choose-sub {
  max-width: 480px;
  margin: 0 auto 24px;
  color: var(--ink-soft);
  font-size: 15px;
}

.enter-btn {
  position: relative;
  font-size: 18px;
  font-weight: 700;
  padding: 16px 34px;
  border-radius: 14px;
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--brand) 45%, transparent);
}
.enter-btn:hover { filter: brightness(1.06); }

/* ---- Section-start interstitial (mock) ------------------------------------ */
.intro-card { text-align: center; align-items: center; }
.intro-ic { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; }
.intro-ic svg { width: 30px; height: 30px; }
.intro-eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand); }
.intro-title { font-size: 28px; margin: 6px 0 10px; }
.intro-meta { font-size: 16px; font-weight: 600; color: var(--ink); }
.intro-note { color: var(--ink-soft); font-size: 14px; max-width: 420px; margin: 12px auto 22px; line-height: 1.5; }
.intro-card .enter-btn { width: 100%; }
.intro-quit { margin-top: 12px; opacity: .8; }

/* ---- Study guide --------------------------------------------------------- */
.study-area { padding: 0; overflow: hidden; }
.study-area > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; font-weight: 650;
}
.study-area > summary::-webkit-details-marker { display: none; }
.study-area .mode-ic { width: 38px; height: 38px; }
.study-area-title { flex: 1; font-size: 16px; }
.study-chev { color: var(--ink-soft); transition: transform .2s ease; }
.study-area[open] .study-chev { transform: rotate(180deg); }
.study-body { padding: 0 18px 6px; }
.study-group { padding: 12px 0; border-top: 1px solid var(--line); }
.study-group h4 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.study-item { margin-bottom: 16px; }
.study-term { font-weight: 700; color: var(--ink); margin-bottom: 6px; }
/* Bold, highlighted formula chip for visibility */
.study-formula {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700; font-size: 14.5px; color: var(--ink);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  border-left: 3px solid var(--brand);
  border-radius: 6px; padding: 8px 11px; margin: 0 0 6px;
  white-space: pre-wrap; word-break: break-word;
}
.study-text { margin: 0 0 6px; font-size: 14px; line-height: 1.55; color: var(--ink-soft); }
.study-example {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px; color: var(--ink-soft); line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; margin-bottom: 6px;
}
.study-example span { color: var(--brand); font-weight: 700; }
.study-trick {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--note-bg); border: 1px solid var(--note-border);
  border-radius: 8px; padding: 8px 11px; font-size: 13.5px; line-height: 1.5; color: var(--ink);
}
.study-trick-ic { flex: 0 0 auto; }
.study-trick b { color: var(--warn); }
/* Fraction <-> percentage quick-reference grid */
.frac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.frac-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--chip); border-radius: 10px; padding: 10px 6px;
}
.frac-f { font-weight: 700; font-size: 16px; color: var(--ink); }
.frac-p { font-size: 13px; color: var(--brand); font-weight: 600; }

/* Numbered step-by-step list */
.study-steps { margin: 0 0 8px; padding-inline-start: 22px; }
.study-steps li { font-size: 14px; line-height: 1.55; color: var(--ink); margin-bottom: 4px; }
.study-steps li::marker { color: var(--brand); font-weight: 700; }

/* Study-guide language toggle */
.study-lang { display: flex; gap: 8px; margin: 0 0 14px; }
.study-lang-opt {
  padding: 7px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--chip); border: 1px solid transparent;
}
.study-lang-opt:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.study-lang-opt.active { background: var(--brand); color: var(--brand-ink); }

/* RTL for the study screen (scoped — rest of app stays LTR) */
.study-screen[dir="rtl"] .study-formula { border-left: none; border-right: 3px solid var(--brand); }
.study-screen[dir="rtl"] .study-steps { padding-inline-start: 22px; }
.study-screen[dir="rtl"] .study-trick { flex-direction: row; }
.study-screen[dir="rtl"] .study-area > summary { text-align: right; }
.study-screen[dir="rtl"] .study-example,
.study-screen[dir="rtl"] .study-formula { direction: rtl; }
.study-screen[dir="rtl"] { font-family: "Segoe UI", Tahoma, "Geeza Pro", "Noto Naskh Arabic", -apple-system, sans-serif; }

/* ---- Assessment selector (main page) -------------------------------------- */
.main-hero { padding-bottom: 36px; }
.assess-grid { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 640px; margin: 8px auto 0; }
.assess-card {
  display: flex; flex-direction: column; gap: 8px; text-align: left;
  padding: 20px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--surface);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.assess-card:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: 0 14px 30px rgba(0,0,0,.2); }
.assess-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.assess-name { font-size: 18px; font-weight: 700; color: var(--ink); }
.assess-grade { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-top: 2px; }
.assess-count { font-size: 12px; font-weight: 700; color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, transparent); padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.assess-sub { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.assess-blurb { font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; }
.assess-go { margin-top: 4px; font-weight: 700; color: var(--brand); }
@media (max-width: 520px) { .assess-grid { grid-template-columns: 1fr; } }

/* ---- Lock / access gate --------------------------------------------------- */
.lock-wrap {
  min-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px 0 8px;
}
.lock-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 440px;
  text-align: center;
  padding: 44px 28px 36px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    radial-gradient(120% 80% at 50% -10%, color-mix(in srgb, var(--brand) 26%, transparent), transparent 60%),
    var(--surface);
  box-shadow: var(--shadow);
}
.lock-card::before, .lock-card::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .35;
  pointer-events: none;
}
.lock-card::before { width: 200px; height: 200px; background: var(--brand); top: -80px; left: -50px; }
.lock-card::after  { width: 200px; height: 200px; background: var(--sig); bottom: -90px; right: -50px; }

.lock-badge {
  position: relative;
  width: 64px; height: 64px;
  margin: 0 auto 20px;
  display: grid; place-items: center;
  border-radius: 18px;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
}
.lock-badge svg { width: 30px; height: 30px; }
.lock-title {
  position: relative;
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: -.02em;
  font-weight: 800;
}
.lock-sub {
  position: relative;
  margin: 0 auto 24px;
  max-width: 340px;
  color: var(--ink-soft);
  font-size: 15px;
}
.lock-form {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lock-input {
  font: inherit;
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: center;
  letter-spacing: .02em;
}
.lock-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 20%, transparent);
}
.lock-error { position: relative; margin: 14px 0 0; color: var(--bad); font-size: 14px; font-weight: 600; }
.lock-card.shake { animation: shake .4s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}
@media (prefers-reduced-motion: reduce) { .lock-card.shake { animation: none; } }

/* ---- Typewriter signature ------------------------------------------------- */
.sig {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding: 10px 16px;
  font-family: ui-monospace, "Cascadia Code", "Fira Code", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  letter-spacing: .04em;
  color: var(--sig);
  user-select: none;
}
.sig-alien { display: none; align-items: center; }
.sig-alien.show { display: inline-flex; }
.sig .alien { width: 22px; height: 22px; flex: 0 0 auto; color: var(--sig); filter: drop-shadow(0 0 6px color-mix(in srgb, var(--sig) 55%, transparent)); }
.sig .alien-head { fill: currentColor; }
.sig .alien-eye  { fill: var(--bg); }
.sig-text { white-space: pre; }
.sig-cursor {
  display: inline-block;
  margin-left: 1px;
  font-weight: 700;
  animation: sig-blink 1.05s steps(1) infinite;
}
@keyframes sig-blink { 50% { opacity: 0; } }

/* ---- Floating dark-mode toggle ------------------------------------------- */
#theme-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 50;
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
#theme-toggle:hover { border-color: var(--brand); }
@supports (top: env(safe-area-inset-top)) {
  #theme-toggle { top: calc(14px + env(safe-area-inset-top)); }
}

/* Smooth the colour change when switching themes */
body, .card, button, .opt, table.data th, table.data td,
table.record th, table.record td, .timer, .explain, .metric, .flag {
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

/* ==========================================================================
   VISUAL POLISH
   ========================================================================== */

/* Cards: soft entrance + a hairline top highlight for depth */
.app .card { animation: cardIn .26s ease both; position: relative; }
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Buttons: consistent hover/active feel */
button.primary {
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 32%, transparent);
}
button.primary:hover { filter: brightness(1.06); }
button.ghost:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); color: var(--ink); }

/* Options: smoother hover and a clearer selected/correct/wrong pop */
.opt {
  transition: transform .12s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.opt:hover { transform: translateX(3px); box-shadow: 0 4px 14px rgba(0, 0, 0, .12); }
.opt.selected { box-shadow: 0 4px 16px color-mix(in srgb, var(--brand) 26%, transparent); }
.opt.correct, .opt.wrong { animation: optPop .22s ease; }
@keyframes optPop { 0% { transform: scale(.99); } 60% { transform: scale(1.012); } 100% { transform: scale(1); } }
.opt .key, .opt .checkbox { transition: background .15s ease, border-color .15s ease, color .15s ease; }

/* Progress bar: gradient fill with a soft glow */
.progress-bar { height: 7px; }
.progress-bar > i {
  background: linear-gradient(90deg, var(--brand), var(--sig));
  box-shadow: 0 0 10px color-mix(in srgb, var(--brand) 55%, transparent);
}

/* Timer pill: a touch more presence */
.timer-pill { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 6%, transparent); }
.timer-pill.warn { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bad) 35%, transparent); }

/* Results metric cards: accent stripe + lift */
.metric {
  position: relative;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.metric::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--sig));
}
.metric:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, .16); }
.metric .big { background: linear-gradient(120deg, var(--ink), var(--brand)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Section breakdown bars: gradient fill */
.bar > i { background: linear-gradient(90deg, var(--brand), var(--sig)); }

/* Review tags: subtle accent */
.tag { border: 1px solid color-mix(in srgb, var(--ink) 8%, transparent); }

/* Quit button stays calm; primary actions lead the eye */
#quit-btn { opacity: .85; }
#quit-btn:hover { opacity: 1; }

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  .app .card, .opt.correct, .opt.wrong, .mode-btn, .metric { animation: none !important; transition: none !important; }
  .mode-btn:hover, .metric:hover, .opt:hover { transform: none; }
}

/* Keep formula lines in explanations from being reordered. */
.explain pre { unicode-bidi: plaintext; }

/* ---- Responsive ----------------------------------------------------------- */
@media (max-width: 520px) {
  body { font-size: 17px; }
  .app { padding: 14px 12px calc(56px + env(safe-area-inset-bottom)); }
  .card { padding: 16px; }
  .mode-grid { grid-template-columns: 1fr; }

  .hero-title { font-size: 32px; }
  .hero { padding: 36px 16px 32px; }
  .hero-sub { font-size: 16px; }
  .hero-feats { gap: 8px; }
  .hero-feat { padding: 12px 6px; }
  .hero-feat .n { font-size: 20px; }
  .enter-btn { width: 100%; }
  .land-feats { grid-template-columns: 1fr; gap: 10px; }
  .land-feat { padding: 13px 14px; }
  .choose-title { font-size: 24px; }

  /* Quiz header: let the timers wrap below the progress label if space is tight */
  .quiz-head { flex-wrap: wrap; padding-right: 52px; }
  /* Topbar: stack title and the back/Assessments button so the title isn't squeezed */
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; padding-right: 52px; }
  .topbar h1 { font-size: 19px; }
  /* Home: sub line and actions can't share a row on narrow screens, so stack
     them; actions span full width with Back left / About right. */
  .topbar-home { padding-right: 0; align-items: stretch; }
  .topbar-subrow { flex-direction: column; align-items: stretch; gap: 8px; }
  .topbar-subrow .topbar-actions { justify-content: space-between; }
  .quiz-head .progress { font-size: 13px; }
  .timer-pill { min-width: 66px; padding: 3px 10px; }
  .timer-pill .tval { font-size: 18px; }

  .q-text { font-size: 18px; }
  .opt { padding: 13px 13px; font-size: 16px; }

  table.data, table.record { font-size: 14px; }
  table.data th, table.data td,
  table.record th, table.record td { padding: 7px 9px; white-space: nowrap; }

  .metric .big { font-size: 26px; }
  .nav-row { gap: 8px; }
  .nav-row button { padding: 12px 14px; }

  /* Keep results metrics readable: 3 across is too tight, stack them */
  .metrics { grid-template-columns: 1fr; }
}

/* Very narrow phones */
@media (max-width: 360px) {
  .hero-feats { grid-template-columns: 1fr 1fr; }
  .hero-title { font-size: 28px; }
}
