/* ============ Theme ============
   Palette and shapes follow the Spagad drug-interaction checker:
   warm "page" background, one white rounded app card, borderless tinted
   panels, coral primary actions, teal / turquoise accents, Plus Jakarta Sans. */
:root {
  /* Palette */
  --white: #ffffff;
  --turquoise: #8cbebf;
  --coral: #e5765c;
  --coral-btn: #d4603f;
  --coral-btn-hover: #c95637;
  --teal: #344c4b;
  --spring: #dfe0c3;

  /* Roles (light) */
  --page: #eeeee3;
  --surface: var(--white);
  --tint: #f6f6ef;
  --tint-strong: #ecede0;
  --ink: #1f2b2a;
  --ink-2: #4f5d5c;
  --muted: #8b9493;
  --line: #e9e9df;

  --primary: var(--coral-btn);
  --primary-hover: var(--coral-btn-hover);
  --primary-text: var(--white);
  --primary-shadow: 0 14px 34px rgba(212, 96, 63, .35);
  --link: #c4553c;            /* coral darkened for text on white */
  --chosen-bg: var(--teal);   /* the user's selection: filled teal like the active timeline card */
  --chosen-text: var(--white);
  --focus: var(--turquoise);

  --correct: var(--teal);
  --correct-soft: #dcecec;    /* turquoise tint */
  --correct-mark: #5e9a9b;
  --wrong: #c4553c;
  --wrong-soft: #fbe9e4;
  --warn: #8a8c55;
  --warn-soft: #f1f1dd;
  --flag: var(--coral);

  --shadow-pop: 0 20px 50px rgba(52, 76, 75, .16);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --max: 980px;
  color-scheme: light;
}

/* Dark variant built from the same palette (deep teal page, turquoise selection). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #121a19; --surface: #1a2423; --tint: #22302f; --tint-strong: #2a3a39;
    --ink: #eef0e6; --ink-2: #b9c3c1; --muted: #8b9493; --line: #2c3a39;
    --link: #f0937b; --chosen-bg: var(--turquoise); --chosen-text: #10201f; --focus: var(--turquoise);
    --correct: #9fd3d4; --correct-soft: #203d3d; --correct-mark: #8cbebf;
    --wrong: #f0937b; --wrong-soft: #3d2520; --warn: #cfd08f; --warn-soft: #33331f;
    --shadow-pop: 0 20px 50px rgba(0, 0, 0, .45); --primary-shadow: 0 10px 28px rgba(212, 96, 63, .28);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #121a19; --surface: #1a2423; --tint: #22302f; --tint-strong: #2a3a39;
  --ink: #eef0e6; --ink-2: #b9c3c1; --muted: #8b9493; --line: #2c3a39;
  --link: #f0937b; --chosen-bg: var(--turquoise); --chosen-text: #10201f; --focus: var(--turquoise);
  --correct: #9fd3d4; --correct-soft: #203d3d; --correct-mark: #8cbebf;
  --wrong: #f0937b; --wrong-soft: #3d2520; --warn: #cfd08f; --warn-soft: #33331f;
  --shadow-pop: 0 20px 50px rgba(0, 0, 0, .45); --primary-shadow: 0 10px 28px rgba(212, 96, 63, .28);
  color-scheme: dark;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--page); color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
main { flex: 1; outline: none; }
a { color: var(--link); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.8rem, 4.5vw, 2.6rem); font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 .75rem; }
code { font-size: .85em; background: var(--tint); padding: .1em .4em; border-radius: 6px; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus); }

.site-header {
  display: flex; align-items: center; justify-content: space-between;
  max-width: var(--max); width: calc(100% - 64px); margin: 0 auto; padding: 22px 8px 0;
}
.brand { font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; color: var(--ink); text-decoration: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 14px; border: 0;
  background: var(--surface); color: var(--ink); font-size: 1.05rem; cursor: pointer;
}
.icon-btn:hover { background: var(--tint-strong); }
.site-footer { text-align: center; padding: 0 1rem 2rem; font-size: .85rem; }
.site-footer a { color: var(--muted); }

/* The app card */
.page {
  max-width: var(--max); width: calc(100% - 64px);
  margin: 18px auto 32px; padding: 44px 52px 52px;
  background: var(--surface); border-radius: 40px;
}
.page-head { margin: .25rem 0 2rem; }
.page-head > .muted { margin-top: .6rem; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 1rem; }
.back { display: inline-block; margin-bottom: 1rem; text-decoration: none; font-weight: 600; font-size: .9rem; }
.back:hover { color: var(--coral); }
.loading, .empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.error { color: var(--wrong); }
.error-box { margin-top: 1rem; padding: 20px 24px; border-radius: 20px; background: var(--wrong-soft); color: var(--wrong); }
.error-box h2 { color: var(--wrong); }
.ok { color: var(--correct); font-weight: 600; }
.notice { background: var(--warn-soft); color: var(--ink-2); padding: 14px 18px; border-radius: 18px; }

/* ============ Buttons & form ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 10px 20px;
  border: 0; border-radius: 16px;
  background: var(--tint); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background .15s, transform .15s, box-shadow .15s;
}
.btn:hover { background: var(--tint-strong); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-text); box-shadow: var(--primary-shadow); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.btn.ghost { background: transparent; color: var(--link); }
.btn.ghost:hover { background: var(--tint); color: var(--coral); }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: .88rem; border-radius: 12px; }
.btn.big { min-height: 56px; padding: 16px 32px; font-size: 1rem; border-radius: 22px; font-weight: 700; }
.btn.primary.small { box-shadow: none; }
.btn.danger { background: var(--coral-btn); color: var(--white); }
.btn.danger:hover { background: var(--coral-btn-hover); }
.btn.on-correct { background: var(--correct-soft); color: var(--correct); }
.btn.on-wrong { background: var(--wrong-soft); color: var(--wrong); }

input[type=text], input[type=number], input[type=search], textarea {
  width: 100%; padding: 14px 18px;
  border: 0; border-radius: 16px;
  background: var(--tint); color: var(--ink); font: inherit;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus { outline: none; box-shadow: 0 0 0 2px var(--focus); background: var(--surface); }
input:disabled, textarea:disabled { color: var(--ink-2); }
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: .4rem; }
.field > span { font-weight: 600; font-size: .92rem; }
.field.inline { flex-direction: row; align-items: center; gap: .6rem; }
.field.inline input { width: 6.5rem; }
.check { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; font-weight: 500; }
.check input, .seg input { width: 1.1rem; height: 1.1rem; accent-color: var(--teal); }

/* ============ Home ============ */
.filters { display: grid; gap: 14px; margin-bottom: 2.25rem; }
.search { font-size: 1rem; padding: 18px 22px; border-radius: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 0; background: var(--tint); color: var(--ink-2);
  padding: 8px 16px; border-radius: 14px; font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.chip:hover { background: var(--tint-strong); color: var(--ink); }
.chip.on { background: var(--chosen-bg); color: var(--chosen-text); }
.subject { margin-bottom: 2.5rem; }
.subject > h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; margin-bottom: 1.1rem; }
.exam-group { margin-bottom: 1.4rem; }
.exam-group h3 { color: var(--muted); font-weight: 600; font-size: .95rem; margin-bottom: .7rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 20px 24px; border-radius: 22px;
  background: var(--tint); color: var(--ink); text-decoration: none;
  transition: background .15s, transform .15s, box-shadow .15s;
}
.card strong { font-size: 1.02rem; }
.card:hover { background: var(--teal); color: var(--white); transform: translateY(-2px); box-shadow: 0 16px 36px rgba(52, 76, 75, .25); }
.card:hover .muted, .card:hover .card-desc { color: rgba(255, 255, 255, .7); }
.card .muted, .card-desc { font-size: .88rem; color: var(--muted); }
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; margin-bottom: 1.75rem;
  background: var(--wrong-soft); color: var(--ink); border-radius: 20px;
}
.banner.subtle { background: var(--tint); }

/* ============ Set page ============ */
.panel, .instructions { background: var(--tint); border-radius: 28px; padding: 26px 28px; }
.instructions { margin-bottom: 1.75rem; }
.instructions summary { cursor: pointer; font-weight: 700; }
.instructions[open] summary { margin-bottom: .6rem; }
.panel h2 { font-size: 1.3rem; font-weight: 800; }
.panel .btn:not(.primary):not(.ghost) { background: var(--surface); }
.panel .btn:not(.primary):not(.ghost):hover { background: var(--tint-strong); }
.mode-cards { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 820px) { .mode-cards { grid-template-columns: 1fr 1.5fr; align-items: start; } }
.setup { display: grid; gap: 18px; }
.setup input[type=number] { background: var(--surface); }
.seg { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.seg legend { font-weight: 600; font-size: .92rem; margin-bottom: .5rem; }
.seg label {
  display: flex; align-items: center; gap: .7rem; padding: 14px 18px;
  background: var(--surface); border-radius: 16px; cursor: pointer; font-weight: 500;
  transition: background .15s, color .15s;
}
.seg label:has(input:checked) { background: var(--chosen-bg); color: var(--chosen-text); }
.seg label:has(input:checked) input { accent-color: var(--turquoise); }
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid2 small, .perq small { font-size: .8rem; }
.perq { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.2rem; }
.perq.disabled { opacity: .45; }
.perq-note { flex-basis: 100%; }
.checks { display: flex; flex-wrap: wrap; gap: .6rem 1.6rem; }

/* ============ Questions ============ */
.question-list { display: grid; gap: 14px; }
.question { position: relative; background: var(--tint); border-radius: 28px; padding: 24px 26px 26px; scroll-margin-top: 7rem; }
.question[data-status]::before {
  content: ""; position: absolute; left: 0; top: 26px; width: 5px; height: 28px; border-radius: 0 6px 6px 0; background: var(--muted);
}
.question[data-status=correct]::before { background: var(--correct-mark); }
.question[data-status=wrong]::before { background: var(--coral); }
.question[data-status=partial]::before, .question[data-status=pending]::before { background: var(--warn); }
.question[data-status=ungraded]::before { display: none; }
.q-head { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .8rem; margin-bottom: .8rem; }
.q-num { font-weight: 800; font-size: 1.02rem; }
.q-meta { color: var(--muted); font-size: .85rem; }
.q-head-extra { margin-left: auto; }
.badge {
  display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 10px;
  background: var(--surface); color: var(--ink-2);
}
.badge.status-correct { background: var(--correct-soft); color: var(--correct); }
.badge.status-wrong { background: var(--wrong-soft); color: var(--wrong); }
.badge.status-partial, .badge.status-pending { background: var(--warn-soft); color: var(--warn); }
.section-heading { margin: 1.75rem 0 .4rem; font-size: 1.3rem; font-weight: 800; letter-spacing: -.01em; }
.section-heading .rich > :last-child { margin-bottom: 0; }

/* rich (trusted) HTML content */
.rich { overflow-wrap: anywhere; }
.rich > :last-child { margin-bottom: 0; }
.rich img, .rich video, .rich svg, .rich canvas { max-width: 100%; height: auto; border-radius: 14px; }
.rich iframe { display: block; width: 100%; max-width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 18px; }
.rich iframe[height] { aspect-ratio: auto; }
.rich figure { margin: .9rem 0; }
.rich figcaption { color: var(--muted); font-size: .85rem; text-align: center; margin-top: .3rem; }
.rich table { border-collapse: separate; border-spacing: 0; display: block; overflow-x: auto; max-width: 100%; margin: .6rem 0; background: var(--surface); border-radius: 14px; }
.rich th, .rich td { padding: .5rem .8rem; border-bottom: 1px solid var(--line); text-align: left; }
.rich tr:last-child > * { border-bottom: 0; }
.rich th { color: var(--ink-2); font-weight: 700; }
.rich pre { overflow-x: auto; background: var(--surface); padding: 14px 16px; border-radius: 14px; }
.rich ul, .rich ol { padding-left: 1.4rem; }
.rich .katex-display { overflow-x: auto; overflow-y: hidden; padding: .25rem 0; }
.q-text { margin-bottom: 1.1rem; font-size: 1.02rem; }

.options { display: grid; gap: 8px; }
.option {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; background: var(--surface); border-radius: 18px;
  cursor: pointer; transition: background .15s, color .15s, box-shadow .15s;
}
.option:hover:not(:has(input:disabled)):not(.is-chosen) { background: var(--tint-strong); }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option:has(input:focus-visible) { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--focus); }
.option:has(input:disabled) { cursor: default; }
.opt-letter {
  flex: none; display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--tint); color: var(--ink-2); font-weight: 700; font-size: .85rem;
}
.type-multiple .opt-letter { border-radius: 10px; }
.opt-text { flex: 1; }
.option.is-chosen { background: var(--chosen-bg); color: var(--chosen-text); box-shadow: 0 12px 28px rgba(52, 76, 75, .22); }
.option.is-chosen .opt-letter { background: rgba(255, 255, 255, .16); color: var(--chosen-text); }
.option.is-key { background: var(--correct-soft); color: var(--ink); box-shadow: none; }
.option.is-key .opt-letter { background: var(--correct-mark); color: var(--white); }
.option.is-wrong { background: var(--wrong-soft); color: var(--ink); box-shadow: none; }
.option.is-wrong .opt-letter { background: var(--coral); color: var(--white); }
.option.is-key::after, .option.is-wrong::after { margin-left: auto; font-weight: 800; padding-left: .5rem; white-space: nowrap; }
.option.is-key::after { content: "✓"; color: var(--correct); }
.option.is-wrong::after { content: "✗ Your answer"; color: var(--wrong); font-size: .82rem; }
.option.is-key.is-chosen::after { content: "✓ Your answer"; font-size: .82rem; }
.text-answer { background: var(--surface) !important; }
.text-answer.is-key { box-shadow: 0 0 0 2px var(--correct-mark); }
.text-answer.is-wrong { box-shadow: 0 0 0 2px var(--coral); }

.q-reveal { display: grid; gap: 10px; margin-top: 1.1rem; }
.reveal-block { padding: 16px 18px; border-radius: 18px; background: var(--surface); }
.reveal-block h4 { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .35rem; }
.reveal-block.answer { background: var(--correct-soft); }
.reveal-block.answer h4 { color: var(--correct); }
.reveal-block.inline { display: flex; align-items: baseline; gap: .7rem; }
.reveal-block.inline h4 { margin: 0; }
.reveal-block.inline span { font-weight: 800; color: var(--correct); }
.q-foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 1.1rem; }
.q-foot .btn { background: var(--surface); }
.q-foot .btn:hover { background: var(--tint-strong); }
.q-foot .btn.ghost { background: transparent; }
.self-mark { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 600; }
.self-mark .btn.on-correct { background: var(--correct-soft); }
.self-mark .btn.on-wrong { background: var(--wrong-soft); }
.mark-field { display: inline-flex; align-items: center; gap: .4rem; }
.mark-input { width: 5.5rem !important; padding: 8px 12px !important; background: var(--surface) !important; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px;
  padding: 12px 14px 12px 20px; margin-bottom: 1.25rem;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-pop);
}
.toolbar .btn { margin-left: auto; }
.toolbar.sticky { position: sticky; top: 12px; z-index: 10; }

/* ============ Quiz ============ */
.quiz-bar {
  position: sticky; top: 12px; z-index: 10;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center;
  padding: 14px 16px 14px 22px; margin-bottom: 1.1rem;
  background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-pop);
}
.quiz-bar-title { grid-column: 1 / -1; display: flex; gap: .6rem; align-items: center; min-width: 0; }
.quiz-bar-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quiz-bar-title .badge { background: var(--tint); }
.quiz-bar-stats { display: flex; flex-wrap: wrap; gap: 2px 18px; align-items: center; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.quiz-bar-actions { display: flex; gap: 6px; }
@media (min-width: 760px) {
  .quiz-bar { grid-template-columns: 1fr auto auto; }
  .quiz-bar-title { grid-column: auto; }
}
.timer { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--ink); font-size: 1.15rem; }
.timer.warn { color: var(--warn); }
.timer.danger { color: var(--wrong); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .timer.danger { animation: none; } }

.q-timer { position: relative; height: 34px; margin-bottom: 1rem; border-radius: 14px; background: var(--tint); overflow: hidden; }
.q-timer-fill { position: absolute; inset: 0 auto 0 0; background: var(--correct-soft); border-right: 3px solid var(--turquoise); transition: width .25s linear; }
.q-timer.danger .q-timer-fill { background: var(--wrong-soft); border-color: var(--coral); }
.q-timer-text { position: relative; display: block; text-align: center; font-size: .85rem; line-height: 34px; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink-2); }

.quiz-body { display: grid; gap: 14px; }
.quiz-root .question { scroll-margin-top: 9rem; }
.quiz-nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 1.25rem 0; }
.quiz-nav.end { justify-content: center; margin-top: 2rem; }
.flag { background: var(--surface); }
.quiz-nav .flag { background: var(--tint); }
.flag.on, .quiz-nav .flag.on { color: var(--white); background: var(--coral); }
.flag.on:hover { background: var(--coral-btn-hover); }

.palette-wrap { margin: .5rem 0 1.25rem; }
.palette-wrap summary { cursor: pointer; color: var(--muted); font-size: .92rem; font-weight: 600; margin-bottom: .7rem; }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.pal {
  position: relative; height: 44px; border-radius: 14px; border: 0;
  background: var(--tint); color: var(--ink-2);
  font: inherit; font-size: .9rem; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer;
}
.pal:hover:not(:disabled) { background: var(--tint-strong); }
.pal.answered { background: var(--correct-soft); color: var(--correct); }
.pal.current { background: var(--chosen-bg); color: var(--chosen-text); }
.pal.flagged::after { content: ""; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--coral); }
.pal:disabled { cursor: default; opacity: .5; }

/* ============ Results ============ */
.score-card { display: grid; gap: 20px; margin-bottom: 2.25rem; }
.score-main { display: flex; flex-wrap: wrap; gap: 28px; align-items: center; }
.score-main h1 { margin-bottom: .4rem; }
.score-line { font-size: 1.25rem; font-weight: 700; margin-bottom: .3rem; }
.score-ring {
  --p: 0;
  flex: none; width: 128px; height: 128px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--coral) calc(var(--p) * 1%), var(--tint-strong) 0);
}
.score-ring span {
  display: grid; place-items: center; width: 100px; height: 100px; border-radius: 50%;
  background: var(--surface); font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em;
}
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat { display: flex; align-items: baseline; gap: 6px; padding: 10px 16px; border-radius: 16px; background: var(--tint); color: var(--ink-2); font-size: .92rem; }
.stat strong { font-size: 1.15rem; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat.status-correct { background: var(--correct-soft); }
.stat.status-correct strong { color: var(--correct); }
.stat.status-wrong { background: var(--wrong-soft); }
.stat.status-wrong strong { color: var(--wrong); }
.stat.status-partial, .stat.status-pending { background: var(--warn-soft); }
.stat.status-partial strong, .stat.status-pending strong { color: var(--warn); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.review-title { margin-top: .5rem; font-size: 1.5rem; font-weight: 800; }
#main .chips + .question-list { margin-top: 1.1rem; }

/* ============ Validator ============ */
.validate { display: grid; gap: 12px; }
.validate h3 { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.validate code { background: var(--surface); }
.warnings { margin: 0; padding-left: 1.2rem; color: var(--warn); }

/* ============ Dialog ============ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 1rem;
  background: rgba(31, 43, 42, .45);
  animation: fade-in .12s ease-out;
}
.modal {
  width: min(100%, 28rem);
  background: var(--surface); color: var(--ink);
  border-radius: 28px; padding: 28px 28px 22px; box-shadow: var(--shadow-pop);
}
.modal h2 { font-size: 1.35rem; font-weight: 800; }
.modal p { color: var(--ink-2); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 1.25rem; }
.modal .btn.primary { box-shadow: none; }
@keyframes fade-in { from { opacity: 0; } }

/* ============ Illustrations & logo ============ */
:root { --ill-dark: var(--teal); --ill-bg: var(--tint); --ill-paper: var(--white); --ill-line: #e3e4d6; }
:root[data-theme="dark"] { --ill-dark: #4d7472; --ill-bg: #22302f; --ill-paper: #2f3f3e; --ill-line: #435756; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ill-dark: #4d7472; --ill-bg: #22302f; --ill-paper: #2f3f3e; --ill-line: #435756; } }
.ill svg { display: block; width: 100%; height: auto; overflow: visible; }
.ill .i-bg { fill: var(--ill-bg); }
.ill .i-paper { fill: var(--ill-paper); stroke: var(--ill-line); stroke-width: 2; }
.ill .i-dash { stroke-dasharray: 6 5; fill: none; stroke: var(--turquoise); stroke-width: 2.5; opacity: .8; }
.ill .i-line { fill: var(--ill-line); }
.ill .i-dark { fill: var(--ill-dark); }
.ill .i-turq { fill: var(--turquoise); }
.ill .i-coral { fill: var(--coral); }
.ill .i-coral-dark { fill: #c95637; }
.ill .i-spring { fill: var(--spring); }
.ill .i-white { fill: #fff; }
.ill .i-white-soft { fill: rgba(255, 255, 255, .45); }
.ill .i-ring { fill: none; stroke: var(--turquoise); stroke-width: 3; }
.ill .i-ring-sq { fill: none; stroke: var(--turquoise); stroke-width: 2.5; }
.ill .i-check, .ill .i-tick { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ill .i-tick { stroke-width: 6; }
.ill .i-clock { fill: var(--ill-paper); stroke: var(--ill-dark); stroke-width: 6; }
.ill .i-hand { fill: none; stroke: var(--ill-dark); stroke-width: 4; stroke-linecap: round; }
.ill .i-lens { fill: rgba(140, 190, 191, .22); stroke: var(--ill-dark); stroke-width: 9; }
.ill .i-handle { stroke: var(--coral); stroke-width: 13; stroke-linecap: round; }
.ill .i-q { fill: var(--ill-dark); font: 800 34px var(--font); }
.ill .i-fold { fill: var(--ill-bg); stroke: var(--ill-line); stroke-width: 2; }
.ill .i-bang { stroke: #fff; stroke-width: 6; stroke-linecap: round; }
.ill .i-cup-handle { fill: none; stroke: var(--coral); stroke-width: 7; stroke-linecap: round; }
.ill .i-shine { fill: none; stroke: rgba(255, 255, 255, .45); stroke-width: 5; stroke-linecap: round; }
.ill .i-stem { stroke: var(--ill-dark); stroke-width: 3; stroke-linecap: round; }
.ill .i-icon-bg { fill: var(--teal); }
.ill .i-icon-bg-coral { fill: var(--coral-btn); }
.ill .i-icon-line { fill: none; stroke: var(--turquoise); stroke-width: 2.2; stroke-linecap: round; }
.ill .i-icon-hand { fill: none; stroke: var(--coral-btn); stroke-width: 3.5; stroke-linecap: round; }
.ill.ill-icon svg, .ill .ill-icon { width: 52px; height: 52px; }
.ill-icon-wrap { margin-bottom: 14px; }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 28px 16px 12px; color: var(--muted); }
.empty-state .ill { width: min(240px, 70%); margin-bottom: 18px; }
.empty-state h2 { color: var(--ink); font-size: 1.35rem; font-weight: 800; }
.empty-state p { max-width: 44ch; margin: 4px 0 18px; line-height: 1.65; }

.home-head { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.home-head .ill { flex: none; width: 230px; margin: -18px -8px -10px 0; }
.score-main { flex-wrap: nowrap; }
.score-text { flex: 1 1 auto; min-width: 0; }
.score-main .ill { flex: none; width: 150px; }
@media (max-width: 760px) { .score-main { flex-wrap: wrap; } .score-text { flex-basis: 100%; order: 3; } }
.validate-head { display: flex; align-items: center; gap: 18px; }
.validate-head .ill { width: 96px; flex: none; }

.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-logo { width: 34px; height: 34px; flex: none; }

/* ============ Charts ============
   Categorical palette validated with the dataviz checker (lightness band,
   chroma floor, colour-blind separation, contrast) for both surfaces. */
:root {
  --series-1: #009098; --series-2: #d9653f; --series-3: #7466d0;
  --series-4: #ad8700; --series-5: #3a7fd0; --series-6: #c4508a;
  --chart-surface: var(--surface); --chart-grid: #ecede3; --chart-axis: #b9bdb0;
}
:root[data-theme="dark"] {
  --series-1: #14a3aa; --series-2: #dc6a4c; --series-3: #8c80e6;
  --series-4: #b08a08; --series-5: #5895e6; --series-6: #d8679b;
  --chart-grid: #2a3837; --chart-axis: #4a5c5b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --series-1: #14a3aa; --series-2: #dc6a4c; --series-3: #8c80e6;
    --series-4: #b08a08; --series-5: #5895e6; --series-6: #d8679b;
    --chart-grid: #2a3837; --chart-axis: #4a5c5b;
  }
}
.chart { margin: .9rem 0; padding: 18px 18px 14px; background: var(--chart-surface); border-radius: 18px; max-width: 640px; }
.options .chart { margin: .25rem 0; padding: 10px; max-width: 360px; }
.chart-title { font-weight: 700; font-size: .95rem; margin-bottom: 8px; color: var(--ink); }
.chart-plot { position: relative; width: 100%; }
.chart-svg { display: block; overflow: visible; font-family: var(--font); }
.chart-svg text { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-svg .c-cat { fill: var(--ink-2); }
.chart-svg .c-title { fill: var(--ink-2); font-weight: 600; }
.chart-svg .c-value { fill: var(--ink); font-weight: 600; }
.chart-svg .c-pie-label { fill: var(--ink-2); font-weight: 500; }
.c-grid line { stroke: var(--chart-grid); stroke-width: 1; }
.c-baseline { stroke: var(--chart-axis); stroke-width: 1.5; }
.c-bar { transition: opacity .12s; }
.c-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { stroke: var(--chart-surface); stroke-width: 2; }
.c-trend { stroke-width: 1.5; opacity: .55; }
.c-slice { stroke: var(--chart-surface); stroke-width: 2; stroke-linejoin: round; transition: opacity .12s; }
.c-leader { fill: none; stroke: var(--chart-axis); stroke-width: 1; }
.c-cross { stroke: var(--chart-axis); stroke-width: 1; }
.c-hit rect { fill: transparent; outline: none; }
.c-hit rect:focus-visible { fill: rgba(140, 190, 191, .12); }
.c-overlay { fill: transparent; }
.c-dim .c-bar:not(.c-on), .c-dim .c-slice:not(.c-on) { opacity: .4; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 120px; max-width: 240px;
  background: var(--surface); color: var(--ink); border-radius: 14px; padding: 10px 12px;
  box-shadow: var(--shadow-pop); font-size: .85rem;
}
.tip-title { font-weight: 700; margin-bottom: 4px; color: var(--ink-2); }
.tip-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-row span:last-child:not(.tip-key) { color: var(--muted); }
.tip-key { width: 12px; height: 3px; border-radius: 2px; background: var(--c); flex: none; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font-size: .85rem; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.key { display: inline-block; background: var(--c); flex: none; }
.key-rect { width: 12px; height: 12px; border-radius: 4px; }
.key-line { width: 16px; height: 3px; border-radius: 2px; }
.key-dot { width: 10px; height: 10px; border-radius: 50%; }
.chart figcaption, .chart > figcaption { color: var(--muted); font-size: .82rem; margin-top: 8px; text-align: left; }
.chart-error { margin: .6rem 0; padding: 10px 14px; border-radius: 12px; background: var(--wrong-soft); color: var(--wrong); font-size: .88rem; }
.chart-table-toggle { margin-top: 10px; background: none; border: 0; padding: 2px 0; color: var(--link); font-weight: 600; font-size: .85rem; cursor: pointer; }
.chart-table { margin-top: 8px; overflow-x: auto; }
.chart-table table { border-collapse: collapse; font-size: .85rem; min-width: 60%; }
.chart-table th, .chart-table td { text-align: left; padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.chart-table th { color: var(--muted); font-weight: 600; }

.perf { margin-bottom: 2.25rem; }
.perf h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: .3rem; }
.perf > p { color: var(--muted); margin-bottom: 1rem; }
.perf-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.perf-grid .chart { --chart-surface: var(--tint); margin: 0; max-width: none; }
.perf-wide { grid-column: 1 / -1; }

/* ============ Smaller screens ============ */
@media (max-width: 640px) {
  .site-header { width: 100%; padding: 16px 20px 0; }
  .page { width: auto; margin: 14px 0 24px; padding: 28px 18px 36px; border-radius: 28px; }
  .panel, .instructions { padding: 22px 20px; border-radius: 24px; }
  .question { padding: 20px 16px 20px; border-radius: 24px; }
  .option { padding: 12px 14px; gap: 12px; }
  .quiz-bar { padding: 12px 12px 12px 16px; top: 8px; }
  .quiz-bar-actions { justify-self: end; }
  .quiz-bar-actions .btn { min-height: 38px; padding: 6px 14px; }
  .quiz-nav .btn { flex: 1; }
  .toolbar { top: 8px; }
  .toolbar .btn { margin-left: 0; }
  .score-ring { width: 104px; height: 104px; }
  .score-ring span { width: 80px; height: 80px; font-size: 1.35rem; }
  .modal-actions .btn { flex: 1; }
  .home-head .ill { display: none; }
  .score-main .ill { width: 104px; margin-left: auto; }
}

/* ============ Print ============ */
@media print {
  :root { --page: #fff; --surface: #fff; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .site-header, .site-footer, .no-print, .actions, .q-foot .btn, .back, .banner, .modal-overlay { display: none !important; }
  .page { max-width: none; width: auto; margin: 0; padding: 0; border-radius: 0; }
  .question { break-inside: avoid; border: 1px solid #ddd; }
  .question[hidden] { display: block !important; }
  .rich iframe { display: none; }
  .chart-tip, .chart-table-toggle { display: none !important; }
  .chart-svg text { fill: #333 !important; }
  .option input { display: none; }
  .mark-input { border: 0; }
}
.score-msg { margin: 0; font-weight: 600; color: var(--ink-2); }

/* ============ Share ============ */
.share-btn { margin-top: .9rem; gap: .45rem; }
.actions .share-btn { margin-top: 0; min-height: 44px; padding: 10px 20px; font-size: 1rem; border-radius: 16px; }
.share-btn .share-icon, .share-copy .share-icon { width: 18px; height: 18px; display: inline-flex; }
.share-icon svg { width: 100%; height: 100%; }
.share-modal { width: min(100%, 30rem); }
.share-preview { background: var(--tint); border-radius: 14px; padding: 12px 14px; font-size: .92rem; color: var(--ink-2); }
.share-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin: 14px 0; }
.share-target {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px 12px;
  border: 0; border-radius: 18px; background: var(--tint); color: var(--ink); text-decoration: none;
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; transition: background .15s, transform .15s;
}
.share-target:hover { background: var(--tint-strong); transform: translateY(-1px); }
.share-target .share-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; color: #fff; background: var(--teal); padding: 10px; }
.si-whatsapp { background: #25d366 !important; }
.si-telegram { background: #2aa3df !important; }
.si-facebook { background: #1877f2 !important; }
.si-x { background: #111 !important; }
.share-copy { display: flex; align-items: center; gap: 8px; background: var(--tint); border-radius: 16px; padding: 6px 6px 6px 14px; }
.share-copy .share-icon { color: var(--muted); flex: none; }
.share-url { background: transparent !important; box-shadow: none !important; padding: 8px 4px !important; font-size: .88rem; color: var(--ink-2); min-width: 0; }
.share-copy .btn { flex: none; }
main:focus, main:focus-visible { box-shadow: none; outline: none; }
@media (max-width: 520px) {
  .share-grid { grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 6px; }
  .share-target { padding: 12px 4px 10px; font-size: .78rem; }
  .share-target .share-icon { width: 40px; height: 40px; }
}
