:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --ink: #1b1f33;
  --ink-2: #4a5068;
  --muted: #7a7f93;
  --line: #e3e0d8;
  --accent: #2f4bd6;
  --accent-ink: #ffffff;
  --accent-soft: #e6eaff;
  --good: #16884a;
  --good-soft: #e3f5ea;
  --bad: #cf3a3a;
  --bad-soft: #fde9e9;
  --warn: #c27a0e;
  --warn-soft: #fdf1dc;
  --hl: #ffd34d;
  --shadow: 0 1px 2px rgba(20, 24, 45, .05), 0 6px 24px rgba(20, 24, 45, .06);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11131c;
    --surface: #1a1d29;
    --surface-2: #232736;
    --ink: #eef0f7;
    --ink-2: #c3c7d6;
    --muted: #8d92a6;
    --line: #2e3344;
    --accent: #6f86ff;
    --accent-ink: #0d1020;
    --accent-soft: #252c52;
    --good: #43c47e;
    --good-soft: #17301f;
    --bad: #ff6b6b;
    --bad-soft: #3a1c1f;
    --warn: #f0b04a;
    --warn-soft: #3a2c14;
    --hl: #8a6d10;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { width: 100%; max-width: 760px; margin: 0 auto; padding: 8px 16px 40px; flex: 1; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
button { font: inherit; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 18px; }
.brand b { color: var(--accent); font-weight: 800; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 20px; height: 20px; fill: none; stroke: var(--accent-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; font-size: 14px; }

/* hero */
.hero { padding: 28px 0 20px; }
.eyebrow { text-transform: uppercase; letter-spacing: .1em; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.hero h1 { font-size: clamp(28px, 6vw, 42px); font-weight: 800; }
.hl { background: linear-gradient(transparent 62%, var(--hl) 62%, var(--hl) 92%, transparent 92%); }
.lead { margin-top: 14px; color: var(--ink-2); font-size: 17px; max-width: 600px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.upload-card { display: grid; gap: 18px; }

.dropzone {
  position: relative; display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: 30px 16px; border: 2px dashed var(--line); border-radius: 14px; cursor: pointer;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dz-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--accent); display: grid; place-items: center; margin-bottom: 6px; }
.dz-icon svg { width: 26px; height: 26px; fill: none; stroke: var(--accent-ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.dz-title { font-weight: 700; font-size: 17px; }
.dz-sub { color: var(--muted); font-size: 13px; }

.btn-camera { position: relative; background: var(--surface); border: 1.5px solid var(--accent); color: var(--accent); padding: 13px 18px; font-size: 16px; }
.btn-camera:hover { background: var(--accent-soft); }
.btn-camera svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.camera-tip { color: var(--muted); font-size: 13px; text-align: center; margin-top: -8px; }
.file-thumb { flex: none; width: 40px; height: 40px; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.file-list:empty { display: none; }
.file-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.file-badge { flex: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 11px; font-weight: 800; letter-spacing: .03em; background: var(--accent-soft); color: var(--accent); }
.file-meta { flex: 1; min-width: 0; }
.file-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.file-size { color: var(--muted); font-size: 13px; }
.icon-btn { flex: none; width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1; }
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); }

.options { display: grid; gap: 14px; }
.field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.select {
  width: 100%; appearance: none; -webkit-appearance: none; font: inherit; font-weight: 600; font-size: 15px; color: var(--ink);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a7f93' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 18px;
  border: 0; border-radius: 12px; padding: 12px 40px 12px 14px; cursor: pointer;
}
.select:focus-visible { outline: 2px solid var(--accent); }
.fineprint { color: var(--muted); font-size: 13px; text-align: center; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px; border: 1px solid transparent; padding: 11px 18px; font-weight: 700; font-size: 15px;
  cursor: pointer; transition: transform .05s, background .15s, opacity .15s; text-decoration: none; color: var(--ink);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-outline { background: var(--surface); border-color: var(--line); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-lg { padding: 15px 20px; font-size: 17px; }
.btn-sm { padding: 7px 12px; font-size: 14px; }
.btn-block { width: 100%; }

/* banner */
.banner { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; background: var(--accent-soft); border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; }
.banner strong { display: block; }
.banner span { color: var(--ink-2); font-size: 14px; }
.banner-actions { display: flex; gap: 8px; }

/* how it works */
.how { list-style: none; padding: 0; margin: 28px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.how li { display: flex; gap: 12px; align-items: flex-start; }
.how li > span { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 800; font-size: 13px; color: var(--accent); }
.how p { color: var(--muted); font-size: 14px; }
@media (max-width: 600px) { .how { grid-template-columns: 1fr; } }

/* loading */
.loading-card { text-align: center; padding: 36px 22px; margin-top: 28px; display: grid; gap: 12px; justify-items: center; }
.spinner { width: 48px; height: 48px; border-radius: 50%; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.steps { list-style: none; padding: 0; margin: 8px 0; text-align: left; display: grid; gap: 8px; }
.steps li { color: var(--muted); padding-left: 28px; position: relative; font-weight: 500; }
.steps li::before { content: ""; position: absolute; left: 0; top: 4px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); }
.steps li.active { color: var(--ink); font-weight: 700; }
.steps li.active::before { border-color: var(--accent); border-top-color: transparent; animation: spin .9s linear infinite; }
.steps li.done { color: var(--ink-2); }
.steps li.done::before { background: var(--good); border-color: var(--good); }

.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; width: 100%; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .35s ease; }

/* exam */
.exam-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 22px 0 10px; }
.exam-head h2 { font-size: 22px; }
.progress-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress-row .muted { white-space: nowrap; }

.qmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 14px; }
.qmap button { aspect-ratio: 1; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-weight: 600; font-size: 13px; cursor: pointer; padding: 0; }
.qmap button.right { background: var(--good-soft); border-color: transparent; color: var(--good); }
.qmap button.missed { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.qmap button.current { outline: 2px solid var(--accent); outline-offset: 1px; }

.question-card { padding: 24px 20px; }
.q-counter { color: var(--accent); font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.q-text { font-size: 19px; font-weight: 700; line-height: 1.45; margin-bottom: 18px; white-space: pre-line; }
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  padding: 13px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; font-size: 16px; line-height: 1.45; transition: border-color .12s, background .12s;
}
.choice:hover { border-color: var(--accent); }
.choice .letter { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 14px; background: var(--surface-2); color: var(--ink-2); }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice.selected .letter { background: var(--accent); color: var(--accent-ink); }
.exam-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.exam-nav .btn { flex: 1; max-width: 220px; }
.submit-row { margin-top: 22px; }

/* results */
.score-card { display: flex; gap: 22px; align-items: center; margin-top: 22px; padding: 24px; }
.ring { position: relative; width: 130px; height: 130px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset 1s ease; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label strong { font-size: 30px; font-weight: 800; line-height: 1; }
.ring-label span { color: var(--muted); font-size: 13px; margin-top: 4px; }
.score-text { display: grid; gap: 6px; }
.score-text h2 { font-size: 24px; }
@media (max-width: 560px) { .score-card { flex-direction: column; text-align: center; } }

.section-title { font-size: 19px; margin-top: 30px; }
.section-sub { font-size: 14px; margin-top: 4px; }

.topics { display: grid; gap: 10px; margin-top: 14px; }
.topic { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.topic-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 8px; }
.topic-name { font-weight: 700; }
.topic-score { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.topic .bar-fill.good { background: var(--good); }
.topic .bar-fill.mid { background: var(--warn); }
.topic .bar-fill.bad { background: var(--bad); }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.mid { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.focus { display: grid; gap: 12px; margin-top: 14px; }
.focus-item { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--bad); border-radius: 14px; padding: 16px; }
.focus-item.mid { border-left-color: var(--warn); }
.focus-item h4 { margin: 0 0 4px; font-size: 16px; }
.focus-item p { color: var(--ink-2); font-size: 15px; }
.focus-item ul { margin: 10px 0 0; padding-left: 20px; color: var(--ink-2); font-size: 14px; display: grid; gap: 6px; }

.review-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.tabs { display: inline-flex; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.review { display: grid; gap: 12px; margin-top: 14px; }
.rq { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.rq-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.rq-num { font-weight: 800; }
.rq-status { font-weight: 700; }
.rq-status.good { color: var(--good); }
.rq-status.bad { color: var(--bad); }
.chip { background: var(--surface-2); color: var(--ink-2); border-radius: 999px; padding: 2px 9px; font-weight: 600; }
.rq-q { font-weight: 700; margin-bottom: 10px; white-space: pre-line; }
.rq-choices { display: grid; gap: 6px; }
.rq-choice { display: flex; gap: 10px; padding: 8px 10px; border-radius: 10px; font-size: 15px; color: var(--ink-2); }
.rq-choice b { flex: none; width: 18px; }
.rq-choice.correct { background: var(--good-soft); color: var(--ink); }
.rq-choice.correct b { color: var(--good); }
.rq-choice.wrong { background: var(--bad-soft); color: var(--ink); }
.rq-choice.wrong b { color: var(--bad); }
.rq-tag { margin-left: auto; font-size: 12px; font-weight: 700; white-space: nowrap; }
.rq-choice.correct .rq-tag { color: var(--good); }
.rq-choice.wrong .rq-tag { color: var(--bad); }
.rq-exp { margin-top: 10px; padding: 12px; background: var(--surface-2); border-radius: 10px; font-size: 15px; }
.rq-exp strong { display: block; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.empty { text-align: center; color: var(--muted); padding: 24px; background: var(--surface); border-radius: 14px; border: 1px dashed var(--line); }

.result-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
@media (max-width: 560px) { .result-actions .btn { flex: 1 1 100%; } }

/* footer, dialog, toast */
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 16px 30px; }
dialog { border: 0; border-radius: var(--radius); padding: 22px; max-width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(10, 12, 25, .45); }
dialog h3 { margin-bottom: 8px; }
dialog p { color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); z-index: 50; box-shadow: var(--shadow); }
.error-box { background: var(--bad-soft); color: var(--ink); border-radius: 12px; padding: 14px; text-align: left; font-size: 15px; }

@media print {
  .topbar, .foot, .result-actions, .tabs, #screen-upload, #screen-exam, #screen-loading { display: none !important; }
  body { background: #fff; }
  .card, .topic, .rq, .focus-item { box-shadow: none; break-inside: avoid; }
}

/* in-page camera */
.cam-dialog { padding: 0; width: min(720px, calc(100vw - 24px)); max-width: none; background: #0b0d14; color: #fff; overflow: hidden; }
.cam-wrap { position: relative; background: #000; aspect-ratio: 4 / 3; max-height: 70vh; width: 100%; }
.cam-wrap video { width: 100%; height: 100%; object-fit: contain; display: block; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
.cam-flash.on { opacity: .8; transition: none; }
.cam-count { position: absolute; top: 12px; left: 12px; background: rgba(0,0,0,.6); padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.cam-count:empty { display: none; }
.cam-msg { color: #c9ccd8 !important; font-size: 14px; text-align: center; padding: 12px 16px 0; }
.cam-actions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 14px 16px 18px; }
.cam-actions .cam-side:first-child { justify-self: start; color: #c9ccd8; }
.cam-actions .cam-side:last-child { justify-self: end; }
.shutter { width: 68px; height: 68px; border-radius: 50%; border: 4px solid rgba(255,255,255,.35); background: #fff; background-clip: padding-box; cursor: pointer; }
.shutter:active { transform: scale(.94); }
.shutter:disabled { opacity: .4; }

/* instant feedback */
.choice:disabled { cursor: default; }
.choice:disabled:hover { border-color: var(--line); }
.choice.correct, .choice.correct:disabled:hover { border-color: var(--good); background: var(--good-soft); }
.choice.correct .letter { background: var(--good); color: #fff; }
.choice.wrong, .choice.wrong:disabled:hover { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .letter { background: var(--bad); color: #fff; }
.choice.dim { opacity: .55; }
.feedback { margin-top: 14px; padding: 14px 16px; border-radius: 12px; animation: pop .2s ease-out; }
.feedback strong { display: block; font-size: 17px; }
.feedback p { margin-top: 6px; color: var(--ink-2); font-size: 15px; }
.feedback .fb-answer { color: var(--ink); }
.feedback.good { background: var(--good-soft); border: 1px solid color-mix(in srgb, var(--good) 35%, transparent); }
.feedback.good strong { color: var(--good); }
.feedback.bad { background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.feedback.bad strong { color: var(--bad); }
@keyframes pop { from { transform: translateY(4px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .feedback { animation: none; } }

/* study review */
.study-overall { background: var(--accent-soft); border-radius: 14px; padding: 14px 16px; font-weight: 500; }
.study-card { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--bad); border-radius: 14px; padding: 18px; display: grid; gap: 14px; }
.study-card.mid { border-top-color: var(--warn); }
.study-card.good { border-top-color: var(--good); }
.study-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.study-head h4 { margin: 0; font-size: 18px; }
.study-head .pill { margin: 0; }
.study-lesson { display: grid; gap: 10px; font-size: 16px; line-height: 1.65; }
.study-block h5 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.study-block ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.study-tip { display: flex; gap: 10px; align-items: flex-start; background: var(--warn-soft); border-radius: 12px; padding: 12px 14px; }
.study-tip span { font-size: 20px; line-height: 1.3; }
.qc { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
.qc summary { cursor: pointer; font-weight: 600; }
.qc p { margin-top: 8px; color: var(--good); font-weight: 600; }
.study-mistakes summary { cursor: pointer; font-weight: 700; color: var(--accent); font-size: 15px; }
.sm-item { border-top: 1px solid var(--line); padding: 10px 0; font-size: 15px; }
.sm-q { font-weight: 600; }
.sm-wrong { color: var(--bad); margin-top: 4px; }
.sm-right { color: var(--good); margin-top: 2px; }
.sm-exp { color: var(--ink-2); margin-top: 4px; }
.study-loading { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.mini-spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@media print { .study-card, .study-overall { break-inside: avoid; } }
