:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #dbe2ec;
  --text: #1c2433;
  --muted: #5d6b82;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eceafd;
  --accent: #f59e0b;
  --good: #15803d;
  --good-soft: #e3f6e9;
  --bad: #c2410c;
  --bad-soft: #fdece3;
  --warn-soft: #fff6db;
  --header-a: #312e81;
  --header-b: #4f46e5;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 6px 20px rgba(20, 30, 60, .07);
  --radius: 14px;
  --on-primary: #ffffff;
  --on-good: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151d;
    --surface: #1a202b;
    --surface-2: #212938;
    --border: #2e384a;
    --text: #e6ebf3;
    --muted: #9aa7bd;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: #262a4d;
    --good: #4ade80;
    --good-soft: #15301f;
    --bad: #fb923c;
    --bad-soft: #3a2116;
    --warn-soft: #3a3016;
    --header-a: #1e1b4b;
    --header-b: #3730a3;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --on-primary: #14163a;
    --on-good: #0b1f12;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11151d;
  --surface: #1a202b;
  --surface-2: #212938;
  --border: #2e384a;
  --text: #e6ebf3;
  --muted: #9aa7bd;
  --primary: #818cf8;
  --primary-hover: #a5b4fc;
  --primary-soft: #262a4d;
  --good: #4ade80;
  --good-soft: #15301f;
  --bad: #fb923c;
  --bad-soft: #3a2116;
  --warn-soft: #3a3016;
  --header-a: #1e1b4b;
  --header-b: #3730a3;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --on-primary: #14163a;
  --on-good: #0b1f12;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; color: inherit; }

.app-header {
  background: linear-gradient(120deg, var(--header-a), var(--header-b));
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; color: #fff; cursor: pointer; padding: 0;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: #1c1400;
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
}
.brand-text { font-weight: 700; font-size: 20px; letter-spacing: .2px; }
.tagline { opacity: .8; font-size: 14px; }

.container { max-width: 820px; margin: 0 auto; padding: 24px 16px 60px; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 28px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.step {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary); font-size: 12px; letter-spacing: 0;
}
.section-title:first-child { margin-top: 4px; }

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

/* ---------- Home ---------- */
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.topic-card {
  text-align: left; cursor: pointer; padding: 16px 16px 14px;
  border: 2px solid var(--border); position: relative; overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.topic-card::before {
  content: ""; position: absolute; left: 0; top: 0; right: 0; height: 5px; background: var(--topic, var(--primary));
}
.topic-card:hover { transform: translateY(-2px); }
.topic-card.selected { border-color: var(--topic, var(--primary)); }
.topic-card .check {
  position: absolute; right: 12px; top: 14px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--border); display: grid; place-items: center; font-size: 14px; color: #fff;
}
.topic-card.selected .check { background: var(--topic); border-color: var(--topic); }
.topic-icon { font-size: 30px; line-height: 1; }
.topic-card h3 { margin: 8px 0 4px; font-size: 18px; }
.topic-card p { margin: 0; color: var(--muted); font-size: 14px; }
.topic-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip {
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.chip.best { background: var(--warn-soft); border-color: transparent; color: var(--text); }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mode-card { text-align: left; cursor: pointer; padding: 14px 16px; border: 2px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.mode-card.selected { border-color: var(--primary); background: var(--primary-soft); }
.mode-card .mode-icon { font-size: 24px; line-height: 1.2; }
.mode-card strong { display: block; font-size: 16px; }
.mode-card strong { color: var(--text); }
.mode-card span span { color: var(--muted); font-size: 14px; }

.options { padding: 6px 16px; }
.option-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.option-row:last-child { border-bottom: 0; }
.option-row .label strong { display: block; font-size: 15px; }
.option-row .label span { color: var(--muted); font-size: 13px; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 14px; color: var(--muted);
}
.segmented button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch .slider::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 3px solid var(--primary-soft); }

.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }

.btn {
  border: 0; border-radius: 10px; padding: 11px 20px; font-weight: 600; cursor: pointer;
  background: var(--primary); color: var(--on-primary); font-size: 16px;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { padding: 14px 28px; font-size: 17px; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: none; color: var(--muted); padding: 8px 12px; }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.kbd {
  font-size: 11px; font-weight: 700; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 8px; opacity: .7;
}

/* ---------- Quiz ---------- */
.quiz-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.quiz-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.stat.good { color: var(--good); }
.stat.bad { color: var(--bad); }

.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
.progress > div { height: 100%; background: var(--topic, var(--primary)); border-radius: 999px; transition: width .3s; }

.question-card { padding: 28px 24px 24px; border-top: 5px solid var(--topic, var(--primary)); }
.q-count { color: var(--muted); font-size: 13px; font-weight: 600; }
.q-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--topic, var(--primary)); margin-top: 6px; }
.q-prompt { font-size: clamp(30px, 6vw, 44px); font-weight: 800; margin: 2px 0 4px; word-break: break-word; }
.q-question { color: var(--muted); font-size: 17px; margin-bottom: 20px; }

.answer-row { display: flex; gap: 10px; flex-wrap: wrap; }
.answer-input {
  flex: 1 1 260px; min-width: 0; padding: 13px 14px; font-size: 18px;
  border: 2px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.answer-input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
.sub-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.confirm-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  text-align: left; padding: 14px 16px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 12px;
}
.choice:hover:not(:disabled) { border-color: var(--primary); background: var(--surface); }
.choice .num {
  flex: none; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center;
  font-size: 13px; background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.choice:disabled { cursor: default; }
.choice.correct { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.dim { opacity: .55; }

.feedback { margin-top: 18px; border-radius: 12px; padding: 16px 18px; border: 1px solid transparent; animation: pop .2s ease-out; }
.feedback.good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.feedback.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.feedback h3 { font-size: 20px; display: flex; align-items: center; gap: 8px; }
.feedback.good h3 { color: var(--good); }
.feedback.bad h3 { color: var(--bad); }
.feedback p { margin: 6px 0 0; }
.feedback .small { font-size: 14px; color: var(--muted); }
.feedback .symbol-note { font-size: 18px; font-weight: 600; }
.answer-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.answer-pill { padding: 3px 11px; border-radius: 999px; font-weight: 600; font-size: 15px; background: var(--surface); border: 1px solid var(--border); }
.answer-pill.hit { background: var(--good); color: var(--on-good); border-color: var(--good); }
.your-list { margin: 8px 0 0; padding: 0; list-style: none; font-size: 15px; }
.your-list li { margin: 2px 0; }
.mark-good { color: var(--good); font-weight: 700; }
.mark-bad { color: var(--bad); font-weight: 700; }
.next-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.auto-bar { flex: 1 1 120px; height: 4px; background: color-mix(in srgb, var(--good) 20%, transparent); border-radius: 99px; overflow: hidden; }
.auto-bar > div { height: 100%; background: var(--good); width: 0; }

@keyframes pop { from { transform: scale(.98); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.shake { animation: shake .25s; }

/* ---------- Results ---------- */
.results { padding: 28px 24px; text-align: center; border-top: 5px solid var(--topic, var(--primary)); }
.score-ring {
  width: 150px; height: 150px; border-radius: 50%; margin: 6px auto 14px; display: grid; place-items: center;
  background: conic-gradient(var(--topic, var(--primary)) calc(var(--pct) * 1%), var(--border) 0);
}
.score-ring > div { width: 118px; height: 118px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; }
.score-ring strong { font-size: 34px; display: block; line-height: 1; }
.score-ring span { font-size: 13px; color: var(--muted); }
.results h2 { font-size: 26px; }
.results .actions { justify-content: center; }
.missed { text-align: left; margin-top: 24px; }
.missed h3 { font-size: 16px; margin-bottom: 8px; }
.missed-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.missed-row:last-child { border-bottom: 0; }
.missed-row .p { font-weight: 700; }
.missed-row .a { color: var(--muted); }

/* ---------- Study list ---------- */
.study-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.search { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-width: 0; flex: 1 1 220px; max-width: 320px; }
.study-table { width: 100%; border-collapse: collapse; }
.study-table th, .study-table td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.study-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--surface-2); }
.study-table tr:last-child td { border-bottom: 0; }
.study-table td:first-child { font-weight: 700; white-space: nowrap; }
.study-table .note { display: block; color: var(--muted); font-size: 13px; }

.group-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.gchip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.gchip span { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 2px; }
.gchip:hover { border-color: var(--primary); }
.gchip.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.gchip.on span { color: inherit; opacity: .8; }
.option-row.stack { flex-direction: column; align-items: flex-start; }
.study-groups { flex-basis: 100%; padding-top: 8px; border-top: 1px solid var(--border); }
.answer-pill small { font-size: 11px; opacity: .8; font-weight: 700; }

.study-nav { margin: 0 0 14px; }
.study-nav.bottom { margin: 18px 0 0; }
.study-tools {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 14px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
}
.tool-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.study-tools .btn { font-size: 14px; padding: 8px 12px; }
.sel-count { font-size: 14px; color: var(--muted); font-weight: 600; }
.inline-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; padding: 0 6px; }
.tool-help { flex-basis: 100%; font-size: 14px; color: var(--good); }
.tool-help:empty { display: none; }
.copy-box { display: block; width: 100%; height: 90px; margin-top: 6px; font: 13px/1.4 ui-monospace, Consolas, monospace; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); padding: 8px; }
.study-table .sel-col { width: 44px; padding-right: 0; }
.study-table input[type="checkbox"], .inline-toggle input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.study-table tr.picked td { background: var(--primary-soft); }
.study-table .blank { display: inline-block; width: 60%; min-width: 80px; border-bottom: 1px solid var(--muted); height: 1.1em; }

.print-sheet { display: none; }

@media print {
  body { background: #fff; color: #000; }
  .app-header, #study-view > :not(.print-sheet) { display: none !important; }
  .container { max-width: none; padding: 0; }
  .print-sheet { display: block; font-size: 11pt; color: #000; }
  .print-sheet h1 { font-size: 18pt; margin: 0 0 2pt; }
  .print-sub { margin: 0 0 10pt; color: #444; font-size: 10pt; }
  .print-sheet table { width: 100%; border-collapse: collapse; }
  .print-sheet th, .print-sheet td { border: 1px solid #999; padding: 5pt 7pt; text-align: left; vertical-align: top; }
  .print-sheet th { background: #eee; font-size: 9pt; text-transform: uppercase; letter-spacing: .05em; }
  .print-sheet td:first-child { width: 35%; font-weight: 700; }
  .print-sheet tr { break-inside: avoid; }
  .print-sheet thead { display: table-header-group; }
}

.empty { color: var(--muted); padding: 20px; text-align: center; }

@media (max-width: 560px) {
  .mode-grid, .choices { grid-template-columns: 1fr; }
  .question-card, .results { padding: 22px 16px; }
  .tagline { display: none; }
  .study-table th, .study-table td { padding: 8px 10px; }
  .study-table td:first-child { white-space: normal; }
}
.segmented button:disabled { opacity: .45; cursor: not-allowed; }
.topic-note {
  font-size: 14px; color: var(--text); background: var(--warn-soft);
  border-radius: 10px; padding: 9px 12px; margin: -8px 0 18px;
}
.study-head + .topic-note { margin: 0 0 14px; }
.feedback .near-miss { display: block; font-size: 15px; color: var(--text); background: var(--warn-soft); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.mixed-topic { color: var(--topic, var(--primary)); font-weight: 700; }
.clue {
  font-size: 15px; color: var(--text); background: var(--primary-soft);
  border-left: 3px solid var(--topic, var(--primary)); border-radius: 8px;
  padding: 9px 12px; margin: -8px 0 18px;
}

/* Mixed: All Topics — a shorter, centered card that spans from the middle of the
   first column to the middle of the last one (full width on narrow screens). */
.topic-card.mixed-card {
  grid-column: 1 / -1; justify-self: center;
  width: calc((100% - 28px) / 3 * 2 + 28px);
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 48px 12px 16px;
}
.mixed-card .topic-icon { font-size: 26px; }
.mixed-card .mixed-text { flex: 1 1 200px; min-width: 0; }
.mixed-card h3 { margin: 0 0 2px; font-size: 17px; }
.mixed-card .topic-meta { margin-top: 0; }
.mixed-card .check { top: 50%; transform: translateY(-50%); }
@media (max-width: 760px) {
  .topic-card.mixed-card { width: 100%; }
}

/* Logo photo in place of the "?" mark */
img.brand-mark {
  width: 96px; height: 96px; border-radius: 14px; object-fit: cover;
  border: 3px solid var(--accent); box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  background: #fff; flex: none;
}
.brand { text-align: left; }
.brand-sub { font-weight: 500; opacity: .85; white-space: nowrap; }
@media (max-width: 560px) {
  img.brand-mark { width: 72px; height: 72px; }
  .brand-text { font-size: 17px; }
}
/* Hover the logo to see the full photo bigger */
img.brand-mark { position: relative; z-index: 5; transform-origin: top left; transition: transform .2s ease; }
.brand:hover img.brand-mark, .brand:focus-visible img.brand-mark { transform: scale(2.2); }
@media (prefers-reduced-motion: reduce) { img.brand-mark { transition: none; } }

/* Touch screens: bigger checkboxes, clickable rows, no keyboard-only hints */
.study-table tbody tr { cursor: pointer; }
@media (hover: none) and (pointer: coarse) {
  .kbd, .keys-only { display: none; }
  .study-table input[type="checkbox"], .inline-toggle input { width: 22px; height: 22px; }
  .inline-toggle { padding: 6px; }
}
