/* Tes IQ: mobile-first, satu file untuk halaman guru dan admin. */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --ink: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --brand: #18181b;
  --brand-hover: #3f3f46;
  --brand-ink: #ffffff;
  --brand-soft: #f4f4f5;
  --ok: #3f3f46;
  --ok-soft: #f4f4f5;
  --warn: #52525b;
  --warn-soft: #f4f4f5;
  --bad: #b91c1c;
  --bad-soft: #fef2f2;
  --good: #15803d;
  --good-soft: #f0fdf4;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: none;
  color-scheme: light;
}

/* Tema gelap: mengikuti sistem, kecuali guru memilih sendiri lewat tombol (data-theme di <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090b;
    --surface: #111113;
    --surface-2: #1c1c1f;
    --ink: #f4f4f5;
    --muted: #a1a1aa;
    --line: #27272a;
    --brand: #f4f4f5;
    --brand-hover: #d4d4d8;
    --brand-ink: #09090b;
    --brand-soft: #1c1c1f;
    --ok: #d4d4d8;
    --ok-soft: #1c1c1f;
    --warn: #d4d4d8;
    --warn-soft: #1c1c1f;
    --bad: #f87171;
    --bad-soft: #2a1414;
    --good: #4ade80;
    --good-soft: #10261a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #09090b;
    --surface: #111113;
    --surface-2: #1c1c1f;
    --ink: #f4f4f5;
    --muted: #a1a1aa;
    --line: #27272a;
    --brand: #f4f4f5;
    --brand-hover: #d4d4d8;
    --brand-ink: #09090b;
    --brand-soft: #1c1c1f;
    --ok: #d4d4d8;
    --ok-soft: #1c1c1f;
    --warn: #d4d4d8;
    --warn-soft: #1c1c1f;
    --bad: #f87171;
    --bad-soft: #2a1414;
    --good: #4ade80;
    --good-soft: #10261a;
    --shadow: none;
    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", sans-serif;
}
.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 96px; }
.wrap.wide { max-width: 1080px; }
[hidden] { display: none !important; }

/* ---------- kepala ---------- */
.brand { display: flex; align-items: center; gap: 14px; margin: 8px 0 20px; }
.brand img { width: 56px; height: auto; flex: none; }
.brand h1 { margin: 0; font-size: 1.35rem; line-height: 1.2; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: .92rem; }
.brand .spacer { flex: 1; }

/* ---------- kartu & form ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 4px; font-size: 1.08rem; }
.card .hint { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
label.field { display: block; font-weight: 600; font-size: .92rem; margin: 14px 0 6px; }
select, input[type=text], input[type=password] {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-height: 48px;
}
select:focus, input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.pin-input { letter-spacing: .4em; font-size: 1.3rem; font-weight: 700; text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
a.btn { text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; min-height: 52px; font-size: 1.02rem; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }

.msg { border-radius: var(--radius-sm); padding: 10px 14px; font-size: .92rem; margin: 12px 0 0; }
.msg.error { background: var(--bad-soft); color: var(--bad); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.info { background: var(--surface-2); color: var(--ink); }

/* pilihan mapel */
.subjects { display: grid; gap: 8px; }
.group-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 0 2px; }
.subject {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; cursor: pointer; background: var(--surface);
}
.subject input { accent-color: var(--brand); width: 20px; height: 20px; flex: none; }
.subject .name { font-weight: 600; }
.subject .meta { color: var(--muted); font-size: .85rem; }
.subject:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

.resume { border: 1.5px solid var(--ink); }

.rules { margin: 0; padding-left: 18px; color: var(--muted); font-size: .9rem; }
.rules li { margin: 3px 0; }

/* ---------- ujian ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar .inner { max-width: 760px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title strong { display: block; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title span { color: var(--muted); font-size: .8rem; }
.timer {
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.1rem;
  padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--ink);
}
.timer.low { background: var(--bad-soft); color: var(--bad); }
.save-state { font-size: .78rem; color: var(--muted); }
.save-state.err { color: var(--bad); }
.progress { height: 4px; background: var(--line); }
.progress i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .3s; }

.qhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.qno { font-weight: 800; font-size: 1.05rem; }
.badge { font-size: .74rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.qinstr { font-size: .85rem; color: var(--muted); margin: 0 0 10px; }
.stem { font-size: 1rem; overflow-wrap: anywhere; }
.stem img { max-width: 100%; }
/* SVG bawaan bank soal (struktur, grafik) berukuran tetap 400px: ikut lebar layar; label di tepi tidak terpotong */
.stem svg { max-width: 100%; height: auto; overflow: visible; }
.fig { margin: 12px 0; color: var(--ink); }
.fig svg { display: block; width: 100%; max-width: 480px; height: auto; }
.fig.foto img { display: block; width: 100%; max-width: 520px; height: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.fig figcaption { font-size: .72rem; color: var(--muted); margin-top: 4px; }
.stem table, .kat-table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: .92rem; }
.stem td, .stem th { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.stem th { background: var(--surface-2); }
.scroll-x { overflow-x: auto; }
.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

.options { display: grid; gap: 8px; margin-top: 14px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  width: 100%; font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); padding: 12px 14px; cursor: pointer;
}
.opt:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.opt .mark {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: .9rem;
  border: 1.5px solid var(--line); color: var(--muted);
}
.opt.multi .mark { border-radius: 8px; }
.opt .txt { padding-top: 3px; overflow-wrap: anywhere; min-width: 0; }
.opt[aria-checked=true] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.opt[aria-checked=true] .mark { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.kat-table th, .kat-table td { border: 1px solid var(--line); padding: 10px; vertical-align: middle; }
.kat-table th { background: var(--surface-2); font-size: .85rem; }
.kat-table td.c { text-align: center; width: 1%; white-space: nowrap; }
.kat-table input { width: 22px; height: 22px; accent-color: var(--brand); cursor: pointer; }
.kat-table tr:has(input:checked) td:first-child { color: var(--ink); }

.qnav { display: flex; gap: 8px; margin-top: 18px; }
.qnav .btn { flex: 1; }
.flag[aria-pressed=true] { border-style: dashed; border-color: var(--ink); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.grid button {
  font: inherit; font-weight: 700; font-size: .88rem; height: 42px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.grid button.done { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.grid button.flagged { border: 2px dashed var(--ink); }
.grid button.cur { outline: 2px solid var(--ink); outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 4px; border: 1px solid var(--line); }
.legend .d { background: var(--brand); border-color: var(--brand); }
.legend .f { border: 2px dashed var(--ink); }

/* ---------- hasil ---------- */
.result { text-align: center; }
.score { font-size: 4rem; font-weight: 800; line-height: 1; letter-spacing: -.03em; color: var(--ink); margin: 10px 0 4px; }
.score small { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.breakdown { display: grid; gap: 8px; margin: 18px 0 6px; text-align: left; }
.breakdown div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: .92rem; }

/* ---------- dialog ---------- */
dialog {
  border: 0; border-radius: var(--radius); padding: 22px; max-width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px -20px rgba(0, 0, 0, .45);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog h3 { margin: 0 0 8px; }
dialog p { margin: 0 0 14px; color: var(--muted); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 14px; margin-bottom: 16px; }
.tabs button {
  flex: 1; font: inherit; font-weight: 700; font-size: .92rem; border: 0; background: none; color: var(--muted);
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
}
.tabs button[aria-selected=true] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.stat b { display: block; font-size: 1.4rem; }
.stat span { color: var(--muted); font-size: .8rem; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 180px; }
.rows { display: grid; gap: 8px; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; text-align: left; font: inherit; color: inherit; width: 100%; cursor: pointer;
}
.row .nm { font-weight: 700; overflow-wrap: anywhere; }
.row .sub { color: var(--muted); font-size: .85rem; grid-column: 1; }
.row .sc { grid-row: 1 / span 2; grid-column: 2; font-weight: 800; font-size: 1.25rem; text-align: right; }
.row .sc small { display: block; font-size: .72rem; color: var(--muted); font-weight: 600; }
.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 24px; }
.pin-now { font-size: 2.4rem; font-weight: 800; letter-spacing: .25em; text-align: center; padding: 10px 0; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.hist { display: grid; gap: 8px; max-height: 60vh; overflow: auto; margin-bottom: 14px; }
.hist div { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: .9rem; display: flex; justify-content: space-between; gap: 10px; }

@media (min-width: 720px) {
  .wrap { padding-top: 32px; }
  /* kolom tetap agar semua baris sejajar, apa pun isi kolom skor */
  .row { grid-template-columns: minmax(0, 2fr) minmax(0, 2fr) minmax(0, 1.6fr) 150px; }
  .row .sub { grid-column: auto; }
  .row .sc { grid-row: auto; grid-column: auto; }
}

@media (max-width: 480px) {
  .card { padding: 16px; }
  .qnav { gap: 6px; }
  .qnav .btn { min-width: 0; padding: 10px 6px; font-size: .9rem; }
  .kat-table th, .kat-table td { padding: 8px 6px; }
  .kat-table th { font-size: .74rem; }
  .opt { padding: 10px 12px; }
}
.opt .katex { font-size: 1.15em; }

/* teks soal tidak bisa diblok/disalin selama asesmen */
#v-exam .stem, #v-exam .options, #v-exam .kat-table { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* saklar tema: label mode aktif + matahari (kiri) dan bulan (kanan) yang selalu tampil; kenop bergeser ke ikon aktif */
.theme-btn {
  flex: none; display: inline-flex; align-items: center; gap: 8px; padding: 0;
  border: 0; background: none; color: var(--muted); font: inherit; font-size: .88rem; cursor: pointer;
}
.theme-btn .t-dark { display: none; }
.theme-btn .track {
  flex: none; position: relative; width: 56px; height: 32px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2);
}
.theme-btn .knob {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  transition: transform .2s ease;
}
.theme-btn svg {
  position: absolute; top: 8px; width: 14px; height: 14px;
  color: var(--ink); transition: opacity .2s ease;
}
.theme-btn .sun { left: 8px; }
.theme-btn .moon { left: 32px; opacity: .35; }
:root[data-theme="dark"] .theme-btn .knob { transform: translateX(24px); }
:root[data-theme="dark"] .theme-btn .sun { opacity: .35; }
:root[data-theme="dark"] .theme-btn .moon { opacity: 1; }
:root[data-theme="dark"] .theme-btn .t-light { display: none; }
:root[data-theme="dark"] .theme-btn .t-dark { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .knob { transform: translateX(24px); }
  :root:not([data-theme="light"]) .theme-btn .sun { opacity: .35; }
  :root:not([data-theme="light"]) .theme-btn .moon { opacity: 1; }
  :root:not([data-theme="light"]) .theme-btn .t-light { display: none; }
  :root:not([data-theme="light"]) .theme-btn .t-dark { display: inline; }
}
/* di HP, bilah atas ujian sempit (ada timer): cukup saklarnya saja */
@media (max-width: 480px) { .topbar .theme-btn .theme-label { display: none; } }
@media (prefers-reduced-motion: reduce) { .theme-btn .knob, .theme-btn svg { transition: none; } }


/* ---------- lembar jawaban (admin) ---------- */
.rv-who { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.rv-who span { color: var(--muted); font-size: .92rem; }
.rv-score { font-size: 2.4rem; font-weight: 800; line-height: 1; text-align: right; }
.rv-score small { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; }
.rv-score.struck { text-decoration: line-through; }
.rv-meta { color: var(--muted); font-size: .85rem; margin: 12px 0 0; }
.rv-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .82rem; color: var(--muted); margin-top: 10px; }
.rv-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 5px; border: 2px solid; }
.rv-legend .k { border-color: var(--good); background: var(--good-soft); }
.rv-legend .w { border-color: var(--bad); background: var(--bad-soft); }
.rv-legend .m { border-color: var(--good); border-style: dashed; }
.rv-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.rv-actions .hint { color: var(--muted); font-size: .82rem; }
.opt.rv { cursor: default; flex-wrap: wrap; }
.opt.rv:hover { border-color: var(--line); }
.opt.rv .txt { flex: 1; }
.opt.rv .tag { font-size: .74rem; font-weight: 700; align-self: center; white-space: nowrap; }
.opt.rv.key { border-color: var(--good); background: var(--good-soft); box-shadow: inset 0 0 0 1px var(--good); }
.opt.rv.key .mark { background: var(--good); border-color: var(--good); color: var(--surface); }
.opt.rv.key .tag { color: var(--good); }
.opt.rv.missed { border: 2px dashed var(--good); }
.opt.rv.missed .mark { border-color: var(--good); color: var(--good); }
.opt.rv.missed .tag { color: var(--good); }
.opt.rv.wrong { border-color: var(--bad); background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
.opt.rv.wrong .mark { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.opt.rv.wrong .tag { color: var(--bad); }
.kat-table.rv td.key { background: var(--good-soft); color: var(--good); font-weight: 700; }
.kat-table.rv td.wrong { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
.vd { font-size: .78rem; font-weight: 800; margin-right: 4px; }
.vd.good { color: var(--good); }
.vd.part { color: var(--warn); }
.vd.bad { color: var(--bad); }
.rv-none { color: var(--bad); font-size: .85rem; margin: 8px 0 0; }
.rv-src { color: var(--muted); font-size: .7rem; margin: 10px 0 0; text-align: right; }

/* cetak / simpan PDF: selalu tema terang, tanpa tombol, soal tidak terpotong antarhalaman */
@media print {
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) {
    --bg: #fff; --surface: #fff; --surface-2: #f4f4f5; --ink: #18181b; --muted: #52525b; --line: #d4d4d8;
    --bad: #b91c1c; --bad-soft: #fef2f2; --good: #15803d; --good-soft: #f0fdf4; --warn: #52525b;
    color-scheme: light;
  }
  @page { margin: 14mm 12mm; }
  body { font-size: 12px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .wrap { max-width: none; padding: 0; }
  .no-print { display: none !important; }
  .brand { margin: 0 0 10px; }
  .brand img { width: 40px; }
  .card { padding: 12px 14px; margin-bottom: 10px; }
  /* soal pendek tidak terpotong; bacaan panjang boleh berlanjut ke halaman berikut agar tidak ada halaman kosong */
  .rv-head, .opt, .kat-table tr, .fig { break-inside: avoid; }
  .qhead { break-after: avoid; }
  .opt { padding: 6px 10px; }
  .opt .mark { width: 24px; height: 24px; }
  .options { gap: 5px; margin-top: 8px; }
  .scroll-x, .katex-display { overflow: visible; }
}

/* Menu utama admin: Lembar cetak | Drill mingguan (dua halaman, tampil sebagai tab) */
.admin-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; margin: 0 0 18px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px; }
.admin-nav a { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 14px; border-radius: 11px; color: var(--muted); text-decoration: none; font-weight: 700; font-size: 1rem; }
.admin-nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--surface) 60%, transparent); }
.admin-nav a[aria-current=page] { background: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow); }
.admin-nav small { font-weight: 600; opacity: .7; font-size: .78rem; }
@media print { .admin-nav { display: none !important; } }

/* toast: pesan singkat setelah aksi */
#toasts { position: fixed; left: 16px; bottom: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: toast-in .18s ease-out; transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); }
.toast.error { background: var(--bad); color: #fff; }
.toast.pergi { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; transition: none; } }
@media print { #toasts { display: none !important; } }
