/* pyCMR Lite -- Flat Minimal, same tokens as the desktop app's ui_kit.py */

:root {
  --bg-main: #1a1a1a;
  --bg-ctrl: #2a2a2a;
  --bg-btn: #333333;
  --bg-btn-hov: #3e3e3e;
  --bg-off: #555555;
  --bg-panel: #161616;
  --accent: #1e4d78;
  --accent-hov: #2a5f8f;
  --green: #2a6e2a;
  --red: #5a2020;
  --border: #3a3a3a;
  --text: #f0f0f0;
  --text-dim: #aaaaaa;
  --text-faint: #777777;
  --gold: #ffcc00;
  /* Compare Study identity colors -- distinct from --accent (reserved for
     "this is the active panel") so a panel can show both at once. */
  --study1: #cc8833;
  --study2: #33aacc;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-main);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, Arial, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

/* -- Top bar --------------------------------------------------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--bg-ctrl);
  border-bottom: 1px solid var(--border);
}
#topbar .brand { font-weight: 700; font-size: 14px; }
#topbar .subtitle { color: var(--text-faint); font-size: 11.5px; }
.spacer { flex: 1; } /* generic flex spacer, used in any flex toolbar/action row */
#topbar { flex-wrap: wrap; row-gap: 6px; }
/* Unscoped (not just #topbar) so every SAX screen's toolbar -- Build,
   Review, Quantify -- picks up the exact same grey/blue button chrome as
   the top line, instead of rendering as bare unstyled buttons. */
.tool-btn {
  background: var(--bg-btn);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 5px 10px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.tool-btn:hover { background: var(--bg-btn-hov); color: var(--text); }
.tool-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tool-btn:disabled:hover { background: var(--bg-btn); color: var(--text-dim); }
.tool-group { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }
.tool-group .tool-btn { border: none; border-radius: 0; border-right: 1px solid var(--border); }
.tool-group .tool-btn:last-child { border-right: none; }

/* -- Main layout ------------------------------------------------------- */

#content {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 0;
}

/* #viewport and #sax-workflow occupy the same area, as alternates toggled
   via the `hidden` attribute -- #thumbs (left sidebar) stays visible and
   usable in both modes, since the SAX Build screen assigns slots by
   clicking a thumbnail in it. */
#main-area {
  position: relative;
  min-height: 0;
}
#main-area #viewport,
#main-area #sax-workflow {
  position: absolute;
  inset: 0;
}

#thumbs {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 6px;
}
#thumbs .thumb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  margin-bottom: 4px;
  border-radius: 2px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
#thumbs .thumb-row:hover { background: var(--bg-ctrl); }
#thumbs .thumb-row.selected { background: var(--accent); border-left-color: var(--gold); }
#thumbs .thumb-row .t-thumb {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  background: #000;
  border-radius: 2px;
  border: 1px solid var(--border);
}
#thumbs .thumb-row .t-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 9px;
  text-align: center;
  padding: 2px;
}
#thumbs .thumb-row .t-info { min-width: 0; }
#thumbs .thumb-row .t-desc { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#thumbs .thumb-row .t-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
#thumbs .thumb-row.selected .t-meta { color: #dce6f7; }
#thumbs .empty-msg { color: var(--text-faint); font-size: 12px; padding: 12px; text-align: center; }

#viewport {
  position: relative;
  background: #000;
  overflow: hidden;
}

#panel-grid {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 2px;
  background: var(--border);
}
#panel-grid.layout-1x1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
/* Which ONE cell shows in 1x1 is decided in JS (the active/blue-outlined
   panel), not fixed to the first -- see updateActivePanelVisibility(). */
#panel-grid.layout-1x1 .panel-cell.panel-cell-hidden-1x1 { display: none; }

#panel-grid.layout-1x2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
#panel-grid.layout-1x2 .panel-cell:nth-child(n+3) { display: none; }

#panel-grid.layout-1x3 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr; }
#panel-grid.layout-1x3 .panel-cell:nth-child(n+4) { display: none; }

#panel-grid.layout-2x2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.panel-cell {
  position: relative;
  background: #000;
  overflow: hidden;
  outline: 2px solid transparent;
  outline-offset: -2px;
}
/* Compare Study: an inner 1px ring showing which study a panel's series
   belongs to, independent of (and always inside) the active-panel outline
   below, so both stay visible at once. */
.panel-cell[data-study="1"] { box-shadow: inset 0 0 0 1px var(--study1); }
.panel-cell[data-study="2"] { box-shadow: inset 0 0 0 1px var(--study2); }
.panel-cell.active { outline-color: var(--accent-hov); }
.panel-cell canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }

.panel-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  padding: 20px;
  cursor: pointer;
}

.panel-cell .frame-overlay {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 11px;
  color: #cfe0ff;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
  line-height: 1.45;
}

.panel-cell .frame-bottom-info {
  position: absolute;
  bottom: 6px;
  left: 8px;
  right: 8px;
  font-size: 11px;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
  line-height: 1.5;
}

.panel-cell .expand-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  padding: 5px 8px;
  font-size: 10.5px;
  cursor: pointer;
  display: none;
}
.panel-cell .expand-btn:hover { background: var(--accent-hov); }

/* Self-contained mini-grid overlay for reviewing every slice position in a
   series at once -- confined to this one panel cell, independent of the
   other panels and the global layout. */
.expand-grid {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  gap: 2px;
  background: #000;
}
.expand-mini { display: block; width: 100%; height: 100%; cursor: crosshair; }
.expand-toolbar {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 4;
  display: flex;
  gap: 6px;
}
.expand-toolbar-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  padding: 5px 8px;
  font-size: 10.5px;
  cursor: pointer;
}
.expand-toolbar-btn:hover { background: var(--accent-hov); }

/* -- Bottom bar ------------------------------------------------------- */

#bottombar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 14px;
  background: var(--bg-ctrl);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
#bottombar label { display: flex; align-items: center; gap: 6px; }
#bottombar input[type="range"] { width: 120px; }
#bottombar .status { flex: 1; text-align: right; color: var(--text-faint); }

/* -- SAX workflow (Build / Review / Quantify) --------------------------- */

#sax-workflow { background: var(--bg-main); overflow: hidden; display: flex; height: 100%; }
/* Same fix as .sax-screen[hidden] below: an ID selector setting display:flex
   has higher specificity than the browser's built-in [hidden] rule, so
   without this override #sax-workflow stayed visible (SAX appearing on
   startup, and the "SAX" button doing nothing) even with hidden set. */
#sax-workflow[hidden] { display: none; }
.sax-screen { height: 100%; display: flex; flex-direction: column; }
#sax-screens-col { flex: 1; min-width: 0; position: relative; }
#sax-screens-col .sax-screen { position: absolute; inset: 0; }
/* `.sax-screen`'s own `display: flex` above has the same specificity as the
   browser's built-in `[hidden] { display: none; }` rule, and being author
   CSS it would otherwise win -- so all 3 screens (Build/Review/Quantify)
   would stay laid out simultaneously and stack below each other instead of
   actually hiding, pushing later screens far off-screen. This rule
   restores real hiding. */
.sax-screen[hidden] { display: none; }

.sax-build-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px 4px;
}
.sax-build-header h2 { margin: 0; font-size: 16px; }
.sax-build-hint { color: var(--text-faint); font-size: 12px; padding: 0 18px 12px; margin: 0; }

.sax-slots {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 0 18px;
}
.sax-slot {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 10px 12px;
  min-height: 90px;
  cursor: pointer;
}
.sax-slot:hover { background: var(--bg-ctrl); }
.sax-slot.active { border-color: var(--accent-hov); box-shadow: inset 0 0 0 1px var(--accent-hov); }
.sax-slot.assigned { border-left: 3px solid var(--gold); }
.sax-slot-label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sax-slot-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); }
.sax-slot-clear {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 10.5px;
  cursor: pointer;
  padding: 1px 4px;
  visibility: hidden;
}
.sax-slot.assigned .sax-slot-clear { visibility: visible; }
.sax-slot-clear:hover { color: #ff8080; }
.sax-slot-body { font-size: 12.5px; color: var(--text-dim); line-height: 1.4; }
.sax-slot-positions {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.5;
}
.sax-slot-positions strong { color: var(--text-dim); }
.sax-slot-placeholder { color: var(--text-dim); }
.sax-slot-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: var(--bg-ctrl);
  border-radius: 3px;
  padding: 3px 6px;
  margin-bottom: 4px;
  color: var(--text);
  font-weight: 600;
  font-size: 12px;
}
.sax-slot-chip:last-child { margin-bottom: 0; }
.sax-chip-pos { color: var(--text-faint); font-weight: 400; font-size: 10.5px; }
.sax-slot-chip button {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
  flex-shrink: 0;
}
.sax-slot-chip button:hover { color: #ff8080; }

.sax-primary-btn { background: var(--accent); color: #fff; border-color: var(--accent); }
.sax-primary-btn:hover { background: var(--accent-hov); }
.sax-primary-btn:disabled { background: var(--bg-btn); color: var(--text-faint); border-color: var(--border); cursor: not-allowed; }

.sax-screen-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-ctrl);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  row-gap: 6px;
}

.phase-marker-group { display: flex; gap: 4px; }
.phase-marker-btn { position: relative; }
.phase-marker-btn.marked { background: var(--accent); border-color: var(--accent); color: #fff; }
.phase-marker-btn .pm-value {
  display: block;
  font-size: 9px;
  font-weight: 400;
  opacity: 0.85;
}

#sax-quantify-phase .tool-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* -- Shared LAX column: visible in both Review and Quantify, resizable -- */
#sax-lax-column {
  /* flex-basis: auto (not a fixed length) so the `width` property below is
     what actually controls size -- JS resizing sets .style.width, which a
     fixed flex-basis would otherwise silently override and ignore. */
  flex: 0 0 auto;
  width: 260px;
  min-width: 120px;
  max-width: 520px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
}
#sax-workflow[data-screen="build"] #sax-lax-column,
#sax-workflow[data-screen="build"] #sax-lax-resizer { display: none; }
#sax-lax-resizer {
  flex: 0 0 5px;
  width: 5px;
  cursor: col-resize;
  background: var(--border);
}
#sax-lax-resizer:hover, #sax-lax-resizer.dragging { background: var(--accent-hov); }
.sax-lax-panel { position: relative; background: #000; aspect-ratio: 1; flex-shrink: 0; }
.sax-lax-panel canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.sax-lax-label {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 11px;
  color: #cfe0ff;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
.sax-lax-overlay {
  position: absolute;
  bottom: 4px;
  left: 6px;
  right: 6px;
  font-size: 10px;
  line-height: 1.35;
  color: #cfe0ff;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sax-review-grid {
  flex: 1;
  position: relative;
  display: grid;
  gap: 2px;
  background: var(--border);
  overflow: hidden;
}
.sax-review-cell { position: relative; }
.sax-review-cell canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.sax-review-cell-overlay {
  position: absolute;
  top: 3px;
  left: 5px;
  right: 5px;
  font-size: 10px;
  line-height: 1.3;
  color: #cfe0ff;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sax-quantify-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 260px;
  min-height: 0;
}
#sax-quantify-main-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#sax-quantify-main-wrap { flex: 1; position: relative; background: #000; min-height: 0; overflow: hidden; }
#sax-quantify-main-canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
#sax-quantify-main-overlay {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 12px;
  color: #cfe0ff;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
  line-height: 1.5;
}

/* The navigation/marking table: rows = slice positions (smallest to
   largest), columns = cardiac phases. Each cell is a small clickable box
   (not a full image thumbnail -- there can be hundreds of cells), loading
   that slice+phase into the single main view above when clicked. Column
   headers carry the LVED/LVES/RVED/RVES marker toggles that drive the
   volumetry math. */
#sax-quantify-table-wrap {
  flex: 0 0 auto;
  max-height: 38vh;
  overflow: auto;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}
#sax-quantify-table { border-collapse: collapse; font-size: 10px; }
#sax-quantify-table th, #sax-quantify-table td {
  border: 1px solid var(--border);
  padding: 0;
  text-align: center;
}
#sax-quantify-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-ctrl);
  z-index: 2;
  padding: 2px;
  min-width: 50px;
}
#sax-quantify-table .sqt-row-header {
  position: sticky;
  left: 0;
  background: var(--bg-ctrl);
  z-index: 1;
  color: var(--text-dim);
  font-size: 10px;
  white-space: nowrap;
  padding: 2px 5px;
  text-align: right;
}
#sax-quantify-table thead th.sqt-corner { position: sticky; left: 0; top: 0; z-index: 3; }
.sqt-phase-num { color: var(--text-dim); font-size: 9.5px; font-weight: 600; }
.sqt-marker-row { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; justify-content: center; margin-top: 3px; }
.sqt-marker-btn {
  width: 100%;
  height: 16px;
  font-size: 9px;
  font-weight: 600;
  line-height: 14px;
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  padding: 0 1px;
  white-space: nowrap;
}
/* Even when inactive, a tinted background/border already hints at LV (red
   family, top row) vs RV (blue family, bottom row) -- so the buttons read
   as "obvious" before being clicked, not just after. */
.sqt-marker-btn.lved, .sqt-marker-btn.lves { background: rgba(255, 68, 68, 0.14); border-color: rgba(255, 68, 68, 0.5); color: #ff9d9d; }
.sqt-marker-btn.rved, .sqt-marker-btn.rves { background: rgba(68, 102, 255, 0.14); border-color: rgba(68, 102, 255, 0.5); color: #9db0ff; }
.sqt-marker-btn:hover { filter: brightness(1.3); }
.sqt-marker-btn.lved.active { background: #ff4444; border-color: #ff4444; color: #fff; }
.sqt-marker-btn.lves.active { background: #aa2222; border-color: #aa2222; color: #fff; }
.sqt-marker-btn.rved.active { background: #4466ff; border-color: #4466ff; color: #fff; }
.sqt-marker-btn.rves.active { background: #2233aa; border-color: #2233aa; color: #fff; }
.sqt-cell {
  width: 20px;
  height: 18px;
  cursor: pointer;
  position: relative;
}
.sqt-cell:hover { background: var(--bg-ctrl); }
.sqt-cell.active { background: var(--accent); outline: 2px solid var(--accent-hov); outline-offset: -2px; }
.sqt-cell .sqt-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffcc00;
  margin: 0 auto;
}
#sax-quantify-results {
  border-left: 1px solid var(--border);
  background: var(--bg-panel);
  overflow-y: auto;
  padding: 14px;
  font-size: 12.5px;
}
#sax-quantify-results h3 { margin: 0 0 10px; font-size: 13.5px; }
#sax-quantify-results .sv-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
#sax-quantify-results .sv-stat { background: var(--bg-ctrl); border-radius: 4px; padding: 8px 10px; }
#sax-quantify-results .sv-stat .sv-label { color: var(--text-faint); font-size: 10px; text-transform: uppercase; letter-spacing: 0.03em; }
#sax-quantify-results .sv-stat .sv-value { font-size: 16px; font-weight: 700; margin-top: 2px; }
#sax-quantify-results table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
#sax-quantify-results th, #sax-quantify-results td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border); }
#sax-quantify-results th { color: var(--text-dim); font-weight: 600; font-size: 10px; text-transform: uppercase; }
#sax-quantify-results .sv-empty { color: var(--text-faint); }

/* -- Compare Study picker ------------------------------------------------- */

/* -- Generic confirm dialog (e.g. "importing a new study wipes...") ------ */

#confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
}
#confirm-overlay[hidden] { display: none; }
#confirm-modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 18px 20px;
  width: 420px;
  max-width: 90vw;
}
#confirm-modal h3 { margin: 0 0 10px; font-size: 15px; }
#confirm-modal p { color: var(--text-dim); font-size: 13px; line-height: 1.5; margin: 0 0 16px; }

#compare-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
}
#compare-overlay[hidden] { display: none; }
#compare-modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 18px 20px;
  width: 460px;
  max-width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
}
#compare-modal h3 { margin: 0 0 4px; font-size: 15px; }
#compare-modal .cmp-sub { color: var(--text-faint); font-size: 11.5px; margin: 0 0 14px; }
#compare-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.cmp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-ctrl);
  border-radius: 4px;
  padding: 8px 10px;
  cursor: pointer;
}
.cmp-row.checked { outline: 1px solid var(--accent-hov); background: var(--accent); }
.cmp-row .cmp-info { font-size: 12.5px; flex: 1; }
.cmp-row .cmp-meta { color: var(--text-dim); font-size: 11px; margin-top: 2px; }
.cmp-row.checked .cmp-meta { color: #dce6f7; }
.cmp-clear-btn {
  flex-shrink: 0;
  background: var(--bg-btn);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
}
.cmp-clear-btn:hover { background: var(--red); color: #fff; border-color: var(--red); }
#compare-modal .cmp-empty { color: var(--text-faint); font-size: 12.5px; padding: 10px 0; }
.cmp-error { color: #ff8080; font-size: 12px; margin: 4px 0 10px; }
.cmp-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* -- Split thumbnails (Compare mode) --------------------------------------- */

.thumb-compare-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  margin-bottom: 6px;
  background: var(--bg-ctrl);
  border-radius: 3px;
  font-size: 11px;
  color: var(--text-faint);
}
.thumb-section-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding: 8px 4px 4px 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.thumb-section-header:first-of-type { border-top: none; margin-top: 0; }
.thumb-section-header[data-study="1"] { border-left: 3px solid var(--study1); }
.thumb-section-header[data-study="2"] { border-left: 3px solid var(--study2); }

/* -- Disclaimer gate ----------------------------------------------------- */

/* -- Help modal ------------------------------------------------------------ */

#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
#help-overlay[hidden] { display: none; }
#help-modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 640px;
  max-width: 92vw;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}
.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.help-header h2 { margin: 0; font-size: 16px; }
.help-body { overflow-y: auto; padding: 4px 20px 20px; }
.help-section { padding-top: 16px; }
.help-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.help-section p { margin: 0 0 8px; font-size: 12.5px; line-height: 1.6; color: var(--text); }
.help-section p:last-child { margin-bottom: 0; }
.help-note { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; margin: 10px 0 4px !important; }
.help-note:first-of-type { margin-top: 0 !important; }
.help-subtext { color: var(--text-faint); font-size: 11.5px; font-style: italic; margin: 0 0 10px !important; }
.help-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: 12.5px; }
.help-table td { padding: 4px 8px 4px 0; vertical-align: top; border-bottom: 1px solid var(--border); }
.help-table tr:last-child td { border-bottom: none; }
.help-table td:first-child {
  white-space: nowrap;
  color: var(--gold);
  font-family: "Segoe UI", monospace;
  width: 1%;
  padding-right: 16px;
}
.help-table td:last-child { color: var(--text-dim); }

#disclaimer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
#disclaimer-overlay[hidden] { display: none; }
#disclaimer-modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 26px 28px;
  width: 460px;
  max-width: 90vw;
  text-align: center;
}
#disclaimer-modal h2 { margin: 0 0 14px; font-size: 18px; }
#disclaimer-modal p { color: var(--text-dim); font-size: 13px; line-height: 1.6; margin: 0 0 14px; }
#disclaimer-modal strong { color: var(--text); }
#disclaimer-modal .tool-btn {
  margin-top: 6px;
  padding: 8px 20px;
  font-size: 13px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
#disclaimer-modal .tool-btn:hover { background: var(--accent-hov); }
