/* RadMatrix by MyoMed Prep — reading-room dark theme. */
:root {
  --bg: #101418;
  --bg-2: #161c22;
  --bg-3: #1d252e;
  --line: #2b3642;
  --text: #dbe4ec;
  --text-dim: #8fa0b0;
  --accent: #4db6e8;
  --accent-2: #2a7fb0;
  --good: #4caf82;
  --bad: #e06c65;
  --warn: #e0b04a;
  --peds: #b58ae6;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; margin: 0.2em 0 0.3em; }
h2 { font-size: 1.15rem; margin: 0 0 0.6em; color: var(--accent); }
h3 { font-size: 1rem; }
p { margin: 0.5em 0; }
ul, ol { padding-left: 1.4em; }
li { margin: 0.3em 0; }
strong { color: #fff; }
code { background: var(--bg-3); padding: 1px 6px; border-radius: 5px; font-size: 0.86em; }
pre.report-tpl {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; font-size: 0.82rem; line-height: 1.5; white-space: pre-wrap;
}
.dim { color: var(--text-dim); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* ——— Layout ——— */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.brand a { display: flex; flex-direction: column; gap: 6px; align-items: center; line-height: 1.2; color: var(--text); }
.brand-logo { display: block; width: 100%; max-width: 190px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45); }
.brand a small { color: var(--text-dim); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.brand a:hover { text-decoration: none; }
.brand a:hover .brand-logo { box-shadow: 0 2px 14px rgba(56, 189, 248, 0.35); }
.nav { display: flex; flex-direction: column; padding: 8px; gap: 1px; overflow-y: auto; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--text);
  font-size: 0.92rem;
}
.nav a:hover { background: var(--bg-3); text-decoration: none; }
.nav a.active { background: var(--accent-2); color: #fff; }
.nav-group {
  margin: 10px 12px 2px; font-size: 0.68rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-dim);
}
.sidebar-foot { margin-top: auto; padding: 12px 16px; font-size: 0.72rem; color: var(--text-dim); border-top: 1px solid var(--line); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 20;
}
.burger { display: none; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 8px; font-size: 1.1rem; padding: 4px 10px; cursor: pointer; }
.topbar-search { flex: 1; max-width: 560px; }
.topbar-search input {
  width: 100%; padding: 8px 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.session-badge { font-size: 0.8rem; white-space: nowrap; }
.main { padding: 24px clamp(16px, 4vw, 40px) 40px; max-width: 1160px; width: 100%; margin: 0 auto; flex: 1; }

.site-footer {
  border-top: 1px solid var(--line); background: var(--bg-2);
  padding: 18px clamp(16px, 4vw, 40px); margin-top: 24px;
}
.foot-legal { max-width: 1160px; margin: 0 auto; }
.foot-legal p { font-size: 0.74rem; color: var(--text-dim); margin: 0.35em 0; }

.page-head { margin-bottom: 18px; }
.page-head p { color: var(--text-dim); max-width: 75ch; }
.crumb { display: inline-block; margin-bottom: 6px; font-size: 0.9rem; }

/* ——— Cards & panels ——— */
.panel {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 20px; margin: 14px 0;
}
.panel.warn { border-color: #5a4a25; }
.panel.warn h2 { color: var(--warn); }
.panel.keypoints h2 { color: var(--good); }
.peds-callout { border-color: #4a3a66; }
.peds-callout h2 { color: var(--peds); }
.panel.diagram { text-align: center; color: var(--text); }
.panel.diagram svg { color: var(--text); }
.panel.center { text-align: center; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin: 12px 0; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin: 18px 0; }
.card {
  display: block; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; color: var(--text);
  transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.card-title { font-weight: 700; margin-bottom: 4px; }
.card-sub { font-size: 0.85rem; color: var(--text-dim); }
.card-meta { margin: 4px 0; }
.card.big .card-title { font-size: 1.05rem; }
.done { color: var(--good); }

.chip {
  display: inline-block; font-size: 0.72rem; padding: 1px 9px; margin-right: 4px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; color: var(--text-dim);
}
.chip.peds { border-color: var(--peds); color: var(--peds); }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 16px 0; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--text); text-align: center; }
.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat-num { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.stat-lbl { font-size: 0.8rem; color: var(--text-dim); }

/* ——— Buttons & forms ——— */
.btn {
  display: inline-block; padding: 8px 16px; border-radius: 8px; cursor: pointer;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line); font-size: 0.9rem;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { border-color: #6b3733; color: var(--bad); }
.btn.small { padding: 5px 12px; font-size: 0.82rem; }
.btn.tiny { padding: 1px 8px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; align-items: end; }
.form-grid .span2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-dim); }
input, select, textarea {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .search-box:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }

.search-box { padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); min-width: 280px; }
.search-box.wide { width: 100%; max-width: 640px; }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-center { display: flex; justify-content: center; gap: 10px; margin: 18px 0; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; margin-top: 10px; }
.row-start { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ——— Checklist ——— */
.checklist { list-style: none; padding: 0; }
.checklist li { margin: 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: none; }
.checklist label { flex-direction: row; gap: 12px; padding: 12px 4px; cursor: pointer; color: var(--text); align-items: flex-start; }
.checklist input { margin-top: 4px; width: 17px; height: 17px; accent-color: var(--accent); flex: 0 0 auto; }
.checklist p { margin: 2px 0 0; font-size: 0.88rem; color: var(--text-dim); }
.checklist input:checked + div { opacity: 0.55; }
.checklist input:checked + div strong { text-decoration: line-through; }

/* ——— Tables ——— */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; color: var(--text-dim); font-weight: 600; border-bottom: 2px solid var(--line); padding: 8px 10px; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ——— Quiz ——— */
.quiz-q { font-size: 1.05rem; font-weight: 600; }
.quiz-opts { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.quiz-opt {
  text-align: left; padding: 11px 14px; border-radius: 8px; cursor: pointer;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line); font: inherit;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); }
.quiz-opt.correct { border-color: var(--good); background: rgba(76,175,130,0.12); }
.quiz-opt.wrong { border-color: var(--bad); background: rgba(224,108,101,0.12); }
.quiz-why { margin: 12px 0; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--bg-3); border-radius: 0 8px 8px 0; font-size: 0.92rem; }
.score-big { font-size: 3rem; font-weight: 800; color: var(--accent); }

/* ——— Flashcards / rapid-fire ——— */
.flashcard { text-align: center; padding: 26px 24px; }
.fc-front { font-size: 1.15rem; font-weight: 600; margin: 12px 0; }
.fc-back { font-size: 1.05rem; color: var(--accent); border-top: 1px solid var(--line); padding-top: 16px; margin: 14px 0; }
.grade-again { border-color: var(--bad); color: var(--bad); }
.grade-hard { border-color: var(--warn); color: var(--warn); }
.grade-good { border-color: var(--accent); color: var(--accent); }
.grade-easy { border-color: var(--good); color: var(--good); }

/* ——— Study library & viewer ——— */
.study-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.study-viewer-col, .study-report-col { min-width: 0; }
.img-list { list-style: none; padding: 0; margin: 8px 0 0; max-height: 220px; overflow-y: auto; }
.img-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 2px; border-bottom: 1px solid var(--line); font-size: 0.86rem; }

.viewer { background: #000; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.viewer-toolbar {
  display: flex; align-items: center; gap: 3px; flex-wrap: wrap;
  padding: 6px 8px; background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.viewer-toolbar button {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 0.82rem;
}
.viewer-toolbar button:hover { border-color: var(--accent); }
.viewer-toolbar button.tool-on { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.viewer-toolbar select {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 3px 6px; font-size: 0.8rem; max-width: 120px;
}
.viewer-sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }
.viewer-count { font-size: 0.82rem; color: var(--text-dim); min-width: 52px; text-align: center; }
.viewer-info { margin-left: auto; font-size: 0.72rem; color: var(--text-dim); }
.viewer-stage { position: relative; height: 480px; cursor: grab; touch-action: none; }
.viewer-stage:active { cursor: grabbing; }
.viewer-stage canvas { display: block; }
.viewer-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); text-align: center; padding: 20px; font-size: 0.9rem;
  pointer-events: none; /* overlay must never swallow canvas/toolbar clicks */
}
.viewer-msg[hidden] { display: none; } /* class display:flex otherwise overrides the hidden attribute */
.viewer-slider { width: 100%; margin: 0; accent-color: var(--accent); }

/* ——— MPR ——— */
.mpr-controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.mpr-controls label { flex-direction: row; align-items: center; gap: 6px; }
.mpr-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.mpr-pane { background: #000; border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; }
.mpr-pane h3 { margin: 0 0 6px; color: var(--text-dim); font-size: 0.85rem; }
.mpr-pane canvas { max-width: 100%; }
.mpr-pane input { width: 100%; accent-color: var(--accent); }

/* ——— Compare ——— */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.compare-grid .viewer-stage { height: 420px; }

/* ——— DDx ——— */
.ddx-features { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.ddx-feature { flex-direction: row; gap: 8px; align-items: center; color: var(--text); cursor: pointer; }
.ddx-feature input { accent-color: var(--accent); width: 16px; height: 16px; }
.ddx-row { margin-bottom: 12px; }
.ddx-bar { height: 7px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin: 4px 0; }
.ddx-bar div { height: 100%; background: var(--accent-2); border-radius: 4px; }

/* ——— Search results ——— */
.result-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.result {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
}
.result:hover { border-color: var(--accent); text-decoration: none; }
.result > span { font-size: 1.3rem; }

/* ——— Toast ——— */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--accent-2); color: #fff; padding: 10px 20px; border-radius: 8px;
  opacity: 0; transition: opacity 0.3s, transform 0.3s; z-index: 100; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ——— Responsive ——— */
@media (max-width: 980px) {
  .study-layout, .two-col, .compare-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.2s; height: 100vh;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.5); }
  .burger { display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
  .viewer-stage, .compare-grid .viewer-stage { height: 340px; }
  .session-badge { display: none; }
}
