:root, :root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #eef0f4;
  --border: #d6dae1;
  --text: #1b2130;
  --muted: #5d6879;
  --accent: #2563d9;
  --accent-soft: #e6eefc;
  --good: #1e8a53;
  --warn: #a8690c;
  --bad: #d23c3c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e4e7ec;
  --muted: #8b93a3;
  --accent: #4c8dff;
  --accent-soft: #14233d;
  --good: #3fb67b;
  --warn: #e0a83a;
  --bad: #ef5b5b;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, pre { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end, .end { justify-content: flex-end; text-align: right; }
.warn-text { color: var(--warn); }
.bad-text { color: var(--bad); }

button, .button, select, input {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; display: inline-block;
}
button:hover, .button:hover { border-color: var(--muted); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { background: none; border: none; color: var(--accent); padding: 0 4px; }
input { cursor: text; width: 100%; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: var(--muted); }
.topbar nav a.active { color: var(--text); }
.learner { color: var(--muted); }
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.page { max-width: 1200px; width: 100%; margin: 0 auto; padding: 24px 20px 60px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin: 12px 0; box-shadow: var(--shadow); }
.panel.error { border-color: var(--bad); }
.panel.good-border { border-color: var(--good); }
.table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.good { color: var(--good); border-color: var(--good); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad { color: var(--bad); border-color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 16px 0; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.tile-label { color: var(--muted); font-size: 12px; }
.tile-value { font-size: 26px; font-weight: 600; }
.tile-value.small-value { font-size: 16px; padding-top: 8px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }
.reports pre { white-space: pre-wrap; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0; font-size: 13px; }
.progress { height: 8px; background: var(--panel-2); border-radius: 4px; margin: 10px 0 6px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }

.discs { display: grid; gap: 10px; }
.disc { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--warn); border-radius: 8px; padding: 12px 14px; display: grid; gap: 8px; }
.disc.major { border-left-color: var(--bad); }
.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 700px) { .cmp { grid-template-columns: 1fr; } }
.cmp-side { background: var(--panel-2); border: 1px solid var(--border); border-top: 3px solid var(--border); border-radius: 6px; padding: 8px 12px 10px; }
.cmp-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.cmp-side.attending { border-top-color: var(--good); }
.cmp-side.attending .cmp-label { color: var(--good); }
.cmp-side.learner { border-top-color: var(--warn); }
.cmp-side.learner .cmp-label { color: var(--warn); }
.disc.major .cmp-side.learner { border-top-color: var(--bad); }
.disc.major .cmp-side.learner .cmp-label { color: var(--bad); }
.feedback summary { cursor: pointer; }
.feedback ol li { margin-bottom: 8px; }

.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -1px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 20px 24px; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin-top: 0; }

/* ---- reading room ---- */
.reading { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.study-header { display: flex; gap: 24px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.study-header .exam { font-weight: 600; }
.study-header .history { flex: 1; }
.timer-box { font-family: var(--mono); font-size: 18px; }
.blurred { filter: blur(6px); }
.reading-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(360px, 1fr); }
@media (max-width: 900px) { .reading-body { grid-template-columns: 1fr; grid-auto-rows: 60vh auto; } }
.report-pane { display: flex; flex-direction: column; padding: 10px 16px 12px; border-left: 1px solid var(--border); min-height: 0; }
.report-pane h2 { margin: 0; }
#report { flex: 1; min-height: 300px; margin: 10px 0 6px; resize: none; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font: 13px/1.55 var(--mono); }
#report:focus { outline: 1px solid var(--accent); }

.viewer { display: flex; flex-direction: column; min-height: 0; height: 100%; background: #000; }
.viewer-tools { display: flex; gap: 8px; align-items: center; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.viewer-tools button { padding: 3px 10px; font-size: 13px; }
.viewer-help { font-size: 12px; margin-left: auto; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.viewer-body { flex: 1; min-height: 0; display: flex; }
.series-strip { width: 110px; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--border); padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.thumb { padding: 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; }
.thumb img { width: 90px; height: 90px; object-fit: contain; background: #000; }
.thumb.active { border-color: var(--accent); }
.viewport { flex: 1; position: relative; min-width: 0; overflow: hidden; cursor: crosshair; touch-action: none; outline: none; }
.viewport:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
.viewport canvas { position: absolute; inset: 0; }
.overlay { position: absolute; color: #d8e0ea; font: 12px/1.4 var(--mono); white-space: pre; pointer-events: none; text-shadow: 0 0 3px #000; }
.overlay.tl { top: 8px; left: 10px; }
.overlay.tr { top: 8px; right: 10px; text-align: right; }
.overlay.bl { bottom: 8px; left: 10px; }
.slice-slider { position: absolute; right: 6px; top: 40px; bottom: 40px; width: 18px; writing-mode: vertical-lr; padding: 0; background: transparent; border: none; cursor: pointer; }

/* ---- sessions ---- */
.session-panel { border-color: var(--accent); }
.session-panel form { margin: 0; }
.session-bar { display: flex; gap: 16px; align-items: center; padding: 6px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--accent); }
.session-bar .link { margin-left: auto; }
.session-dots { display: flex; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--muted); }
.dot.done { background: var(--accent); border-color: var(--accent); }
.dot.current { border: 2px solid var(--text); }

/* Image viewer stays dark in both themes: reading images on a white surround hurts contrast perception. */
.viewer .viewer-tools { background: #171a21; border-bottom-color: #2a2f3a; color: #e4e7ec; }
.viewer .viewer-tools button { background: #1e222b; border-color: #2a2f3a; color: #e4e7ec; }
.viewer .viewer-tools .seg button.active { background: #4c8dff; border-color: #4c8dff; color: #fff; }
.viewer .viewer-help { color: #8b93a3; }
.viewer .series-strip { background: #171a21; border-right-color: #2a2f3a; }
.viewer .thumb { background: #1e222b; border-color: #2a2f3a; color: #e4e7ec; }
.viewer .thumb.active { border-color: #4c8dff; }

.theme-toggle { font-size: 13px; padding: 3px 10px; }
.offline-toggle.on { background: #f59e0b; border-color: #d97706; color: #1f1300; }
.hidden { visibility: hidden; }

/* ---- session results: case list + one case at a time ---- */
.results-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.case-list { background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; }
.case-list-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.case-list-title { font-weight: 700; font-size: 15px; }
.case-item { display: block; padding: 10px 16px; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; color: var(--text); }
.case-item:hover { background: var(--panel-2); text-decoration: none; }
.case-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.case-item.disabled { opacity: .55; }
.ci-top { display: flex; gap: 8px; align-items: baseline; }
.ci-num { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--border); font-size: 12px; display: inline-grid; place-items: center; }
.case-item.active .ci-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.ci-title { flex: 1; font-weight: 600; line-height: 1.3; }
.ci-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.ci-meta { font-size: 12px; color: var(--muted); margin: 3px 0 0 30px; }
.case-list-foot { margin-top: auto; padding: 14px 16px; }
.results-main { overflow-y: auto; min-width: 0; }
.results-inner { max-width: 1400px; padding: 20px 24px 60px; }
.rc-head { margin-bottom: 12px; align-items: flex-start; }
.rc-top { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 16px; height: min(68vh, 680px); min-height: 420px; }
.rc-viewer { min-height: 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.rc-grade { min-height: 0; overflow-y: auto; padding-right: 4px; display: flex; flex-direction: column; gap: 10px; }
.rc-grade h3 { margin: 6px 0 0; }
.rc-grade p { margin: 0; }
.mini-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-tiles .tile { padding: 8px 12px; }
.mini-tiles .tile-value { font-size: 22px; }
.reports h3.lbl-attending { color: var(--good); }
.reports h3.lbl-learner { color: var(--warn); }
@media (max-width: 1000px) {
  .rc-top { grid-template-columns: 1fr; height: auto; }
  .rc-viewer { height: 60vh; }
}
@media (max-width: 760px) {
  .results-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .case-list { max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
}
.rc-grade .cmp { grid-template-columns: 1fr; }
.rc-viewer .viewer-help { display: none; }
.ci-meta .muted { white-space: nowrap; }

/* ---- sign in (hosted version) ---- */
.page.narrow { max-width: 440px; }
.page.start { max-width: 760px; }
.page.start .session-panel form { margin: 10px 0 6px; }
.login { margin-top: 48px; padding: 22px 24px; }
.login h1 { margin-bottom: 6px; }
.field { display: grid; gap: 4px; margin: 12px 0; color: var(--muted); font-size: 13px; }
.field input { color: var(--text); }
.ci-num { width: auto; min-width: 22px; padding: 0 5px; border-radius: 11px; font-size: 11px; }
.offline-toggle[hidden] { display: none; }
.session-table tbody tr { cursor: pointer; }
.session-table tbody tr:hover { background: var(--accent-soft); }
.topbar .spacer { flex: 1; }
