/* ─── tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:        #f4f6f8;
  --surface:   #ffffff;
  --surface-2: #f0f3f6;
  --line:      #d9e0e7;
  --line-soft: #e8edf1;
  --text:      #16212b;
  --text-dim:  #5b6b7a;
  --text-faint:#8697a6;

  --accent:      #b32b23;   /* Fortinet red */
  --accent-dark: #8e211b;
  --accent-soft: #fdeceb;

  --ok:       #1a7f4b;
  --ok-soft:  #e6f5ec;
  --ok-line:  #a8d9bd;
  --bad:      #c02a2a;
  --bad-soft: #fdecec;
  --bad-line: #eeb4b4;
  --warn:     #9a6b00;
  --warn-soft:#fdf3dd;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,32,48,.06), 0 4px 16px rgba(16,32,48,.05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #12171c;
    --surface:   #1a2027;
    --surface-2: #222a32;
    --line:      #2f3a44;
    --line-soft: #262f38;
    --text:      #e4eaf0;
    --text-dim:  #a4b2bf;
    --text-faint:#7d8b98;

    --accent:      #e2544a;
    --accent-dark: #c33d34;
    --accent-soft: #35211f;

    --ok:       #4ec288;
    --ok-soft:  #17281f;
    --ok-line:  #2c5741;
    --bad:      #f0706a;
    --bad-soft: #2c1b1b;
    --bad-line: #5c3232;
    --warn:     #e0b352;
    --warn-soft:#2b2413;

    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.15rem; letter-spacing: -.01em; }
h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
p  { margin: 0; }

.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ─── top bar ────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 9px;
  background: var(--accent); color: #fff;
  font-weight: 800; font-size: .8rem; letter-spacing: .04em;
}
.topbar h1 { font-size: 1.02rem; }
.topbar p  { font-size: .78rem; color: var(--text-faint); }

.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 7px 14px; border-radius: 7px;
  font: inherit; font-size: .88rem; font-weight: 500;
  color: var(--text-dim);
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }

main { max-width: 1160px; margin: 0 auto; padding: 26px 24px 80px; }

.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* ─── panels ─────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

/* ─── stats strip ────────────────────────────────────────────────────── */
.stats-strip {
  display: grid; gap: 12px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; }
.stat span { font-size: .78rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }

/* ─── form controls ──────────────────────────────────────────────────── */
.field { margin-bottom: 20px; }
.field-label {
  display: block; margin-bottom: 8px;
  font-size: .78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-faint);
}
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented button {
  cursor: pointer; font: inherit; text-align: left;
  padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-dim);
}
.segmented button em {
  display: block; font-style: normal; font-size: .76rem;
  color: var(--text-faint); margin-top: 2px;
}
.segmented button:hover { border-color: var(--text-faint); }
.segmented button.on {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.segmented button.on em { color: rgba(255,255,255,.82); }
.segmented.small button { padding: 5px 12px; font-size: .84rem; }

.checks { display: flex; gap: 22px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: .92rem; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.hint { font-size: .82rem; color: var(--text-faint); margin-top: 8px; }

.search {
  flex: 1; min-width: 220px; max-width: 420px;
  padding: 8px 12px; font: inherit; font-size: .9rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
}

/* ─── buttons ────────────────────────────────────────────────────────── */
.btn {
  cursor: pointer; font: inherit; font-weight: 550;
  padding: 9px 18px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
}
.btn:hover { border-color: var(--text-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--bad-line); color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.big { padding: 12px 30px; font-size: 1rem; }
.btn.small { padding: 5px 12px; font-size: .84rem; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.danger-text { color: var(--bad); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions.center { justify-content: center; }

/* ─── exam header ────────────────────────────────────────────────────── */
.exam-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap; margin-bottom: 16px;
}
.progress-wrap { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 220px; }
.progress { flex: 1; height: 7px; border-radius: 99px; background: var(--line-soft); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
#progText { font-size: .82rem; color: var(--text-dim); white-space: nowrap; }
.exam-meta { display: flex; align-items: center; gap: 10px; }
.pill {
  font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 10px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-dim);
}
.timer { font-size: 1rem; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.timer.urgent { color: var(--bad); font-weight: 700; }

/* ─── exam layout ────────────────────────────────────────────────────── */
.exam-body { display: grid; grid-template-columns: minmax(0,1fr) 232px; gap: 18px; align-items: start; }
@media (max-width: 900px) { .exam-body { grid-template-columns: 1fr; } }

.qcard .qnum {
  font-size: .78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--accent); margin-bottom: 10px;
}
.qcard .qnum .multi-tag {
  margin-left: 8px; color: var(--warn);
  background: var(--warn-soft); padding: 2px 8px; border-radius: 99px;
}
.stem p { margin-bottom: 12px; }
.stem img, .exhibit, .otext img {
  display: block; max-width: 100%; height: auto; cursor: zoom-in;
  border: 1px solid var(--line); border-radius: 8px;
  margin: 12px 0; background: #fff;
}

/* ─── options ────────────────────────────────────────────────────────── */
.opts { display: flex; flex-direction: column; gap: 9px; margin-top: 18px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface);
  transition: border-color .12s, background .12s;
}
.opt:hover { border-color: var(--text-faint); background: var(--surface-2); }
.opt input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.opt .letter {
  flex: none; width: 24px; height: 24px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: .8rem; font-weight: 700; color: var(--text-dim);
}
.opt .otext { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.opt .otext img { margin: 2px 0 0; }
.opt.picked { border-color: var(--accent); background: var(--accent-soft); }
.opt.picked .letter { background: var(--accent); border-color: var(--accent); color: #fff; }
.opt.locked { cursor: default; }
.opt.locked:hover { border-color: var(--line); background: var(--surface); }

.opt.correct { border-color: var(--ok-line); background: var(--ok-soft); }
.opt.correct .letter { background: var(--ok); border-color: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad-line); background: var(--bad-soft); }
.opt.wrong .letter { background: var(--bad); border-color: var(--bad); color: #fff; }

.verdict {
  display: block; margin-top: 7px; padding-top: 7px;
  border-top: 1px dashed var(--line);
  font-size: .87rem; color: var(--text-dim);
}
.verdict b { color: var(--text); }
.verdict.t b { color: var(--ok); }
.verdict.f b { color: var(--bad); }

/* ─── explanation block ──────────────────────────────────────────────── */
.why {
  margin-top: 16px; padding: 14px 16px;
  border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface-2);
}
.why h4 {
  margin: 0 0 6px; font-size: .76rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-faint);
}
.why p { font-size: .92rem; }

.answerline { margin-top: 14px; font-size: .92rem; }
.answerline .k { color: var(--text-faint); }
.answerline .v { font-weight: 700; font-family: var(--mono); }
.answerline .v.ok  { color: var(--ok); }
.answerline .v.bad { color: var(--bad); }
.votes { margin-top: 4px; font-size: .8rem; color: var(--text-faint); }

/* ─── question nav grid ──────────────────────────────────────────────── */
.navpanel { position: sticky; top: 86px; padding: 16px; }
.qgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin: 12px 0; }
.qgrid button {
  aspect-ratio: 1; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface-2); color: var(--text-dim);
  font: inherit; font-size: .76rem; font-weight: 600;
}
.qgrid button:hover { border-color: var(--text-faint); }
.qgrid button.answered { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.qgrid button.flagged  { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.qgrid button.current  { outline: 2px solid var(--text); outline-offset: 1px; }
.qgrid button.gotright { background: var(--ok-soft);  border-color: var(--ok-line);  color: var(--ok); }
.qgrid button.gotwrong { background: var(--bad-soft);  border-color: var(--bad-line); color: var(--bad); }

.legend { display: flex; flex-direction: column; gap: 5px; font-size: .78rem; color: var(--text-faint); }
.legend span { display: flex; align-items: center; gap: 7px; }
.sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); }
.sw.answered { background: var(--accent-soft); border-color: var(--accent); }
.sw.flagged  { background: var(--warn-soft); border-color: var(--warn); }
.sw.current  { background: var(--surface-2); outline: 2px solid var(--text); outline-offset: -1px; }

.qnav-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.qnav-buttons .btn.danger { margin-left: auto; }

/* ─── results ────────────────────────────────────────────────────────── */
.result-head { display: flex; gap: 26px; align-items: center; flex-wrap: wrap; }
.scorering {
  --pct: 0;
  flex: none; width: 132px; height: 132px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--ring) calc(var(--pct) * 1%), var(--line-soft) 0);
}
.scorering > div {
  width: 106px; height: 106px; border-radius: 50%; background: var(--surface);
  display: grid; place-items: center; text-align: center;
}
.scorering b { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; }
.scorering span { font-size: .72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.result-summary { flex: 1; min-width: 240px; }
.result-summary h2 { margin-bottom: 6px; }
.verdict-badge {
  display: inline-block; padding: 4px 12px; border-radius: 99px;
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 10px;
}
.verdict-badge.pass { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok-line); }
.verdict-badge.fail { background: var(--bad-soft); color: var(--bad); border: 1px solid var(--bad-line); }
.result-facts { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 12px; }
.result-facts div b { display: block; font-size: 1.25rem; }
.result-facts div span { font-size: .76rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }

.review-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.review-list { display: flex; flex-direction: column; gap: 14px; }
.review-item { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.review-item > header {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 11px 14px; background: var(--surface-2);
}
.review-item > header:hover { background: var(--line-soft); }
.review-item > header .rq { font-size: .8rem; font-weight: 700; font-family: var(--mono); color: var(--text-faint); }
.review-item > header .rt { flex: 1; min-width: 0; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-item > header .chev { color: var(--text-faint); font-size: .8rem; }
.review-item .body { padding: 18px; border-top: 1px solid var(--line); }
.tag {
  flex: none; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 3px 9px; border-radius: 99px;
}
.tag.right   { background: var(--ok-soft);  color: var(--ok);   border: 1px solid var(--ok-line); }
.tag.wrong   { background: var(--bad-soft); color: var(--bad);  border: 1px solid var(--bad-line); }
.tag.skipped { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }

/* ─── history ────────────────────────────────────────────────────────── */
#historyChart { margin-bottom: 20px; }
.spark { display: flex; align-items: flex-end; justify-content: flex-start; gap: 4px; height: 110px; padding-top: 6px; }
.spark .bar { flex: 1; min-width: 6px; max-width: 54px; border-radius: 4px 4px 0 0; position: relative; background: var(--accent); opacity: .85; }
.spark .bar.pass { background: var(--ok); }
.spark .bar:hover { opacity: 1; }
.spark .bar span {
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  font-size: .68rem; color: var(--text-faint); white-space: nowrap;
}
.chart-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--text-faint); margin-top: 6px; }

.history-list { display: flex; flex-direction: column; gap: 8px; }
.hrow {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
}
.hrow .hscore { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 62px; }
.hrow .hscore.pass { color: var(--ok); }
.hrow .hscore.fail { color: var(--bad); }
.hrow .hmeta { flex: 1; min-width: 190px; font-size: .86rem; color: var(--text-dim); }
.hrow .hmeta b { color: var(--text); font-weight: 600; }
.hrow .hdate { font-size: .8rem; color: var(--text-faint); }
.empty { padding: 26px; text-align: center; color: var(--text-faint); font-size: .92rem; }

.pq-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.pq {
  cursor: pointer; padding: 7px 2px; text-align: center;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2);
  font-size: .74rem; font-weight: 600; color: var(--text-dim);
}
.pq:hover { border-color: var(--text-faint); }
.pq small { display: block; font-size: .64rem; font-weight: 500; color: var(--text-faint); }
.pq.good { background: var(--ok-soft);  border-color: var(--ok-line);  color: var(--ok); }
.pq.mid  { background: var(--warn-soft); border-color: var(--warn);     color: var(--warn); }
.pq.poor { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }

/* ─── lightbox ───────────────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; z-index: 100; cursor: zoom-out;
  display: grid; place-items: center; padding: 30px;
  background: rgba(8,12,16,.88); backdrop-filter: blur(2px);
}
.lightbox img {
  max-width: 100%; max-height: 100%;
  border-radius: 8px; background: #fff; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

@media (max-width: 620px) {
  main { padding: 18px 14px 60px; }
  .panel { padding: 16px; }
  .topbar { padding: 10px 14px; }
  .qnav-buttons .btn.danger { margin-left: 0; }
}

/* inline literals inside study notes */
.verdict code, .why code {
  font-family: var(--mono); font-size: .86em;
  padding: 1px 5px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--line);
}
.verdict em, .why em { font-style: italic; color: var(--text); }

.storage-warning {
  margin-bottom: 18px; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--warn); background: var(--warn-soft);
  color: var(--text); font-size: .9rem;
}
.storage-warning code {
  font-family: var(--mono); font-size: .86em; padding: 1px 5px;
  border-radius: 4px; background: var(--surface); border: 1px solid var(--line);
}
