/* Fixed dark theme: consistent viewing conditions for all raters. */
:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --panel-2: #1f232a;
  --border: #2a2f37;
  --text: #e6e8eb;
  --muted: #8b929c;
  --accent: #4aa3ff;
  --accent-text: #06121f;
  --ok: #4cc38a;
  --err: #ff6b6b;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
kbd {
  font: 11px ui-monospace, monospace;
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-2);
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 15px; font-weight: 600; margin: 0; white-space: nowrap; }
.progress { display: flex; align-items: center; gap: 12px; flex: 1; max-width: 420px; }
.progress span { white-space: nowrap; font-variant-numeric: tabular-nums; }
.progress-track { flex: 1; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
#case-id { margin-left: auto; }

/* Two columns (surface plot, rating); three with the MRI in front */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 8px;
  padding: 8px;
}
.layout.with-mri { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 220px; }
.panel[hidden] { display: none; }
.home {
  flex: none;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.home:hover { border-color: var(--accent); }
.disclaimer {
  padding: 6px 16px 8px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}
.disclaimer strong { color: var(--text); font-weight: 600; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.panel-title { font-weight: 600; margin-right: auto; padding-left: 4px; }
.viewport { position: relative; flex: 1; min-height: 0; background: #000; }
#gl { width: 100%; height: 100%; display: block; }
#contours { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.hint { padding: 6px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }

/* Surface plot */
.surf-body { flex: 1; min-height: 0; display: flex; background: #fff; }
.surf-view { background: #fff; }
.surf-view canvas { display: block; }
.surf-label {
  position: absolute;
  padding-top: 4px;
  text-align: center;
  font-size: 11px;
  color: #333;
  pointer-events: none;
}
.colorbar {
  width: 64px;
  padding: 24px 0 24px 10px;
  display: flex;
  flex-direction: column;
  color: #333;
  font-size: 11px;
}
.colorbar .cb-title { margin-bottom: 8px; font-weight: 600; }
.colorbar .cb-scale { position: relative; flex: 1; display: flex; gap: 4px; }
.colorbar .cb-gradient { width: 14px; border: 1px solid #999; }
.colorbar .cb-ticks { position: relative; flex: 1; }
.colorbar .cb-ticks span { position: absolute; transform: translateY(50%); white-space: nowrap; font-variant-numeric: tabular-nums; }
.colorbar .cb-undef { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.colorbar .cb-undef i { width: 14px; height: 10px; background: #808080; border: 1px solid #999; }
/* Takes the free space left of the surface switch, so the switch never moves. */
#surf-info {
  flex: 1;
  min-width: 0;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
/* Color range row: number field · two-handle slider · number field */
.clim-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.clim-title { color: var(--muted); white-space: nowrap; }
.clim-row input[type=number] {
  width: 72px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.clim-row input[type=number]:focus { outline: none; border-color: var(--accent); }
.clim-row input.invalid { border-color: var(--err); }

.range2 { position: relative; flex: 1; min-width: 120px; height: 28px; }
.range2-track, .range2-fill {
  position: absolute;
  top: 50%;
  height: 10px;
  margin-top: -5px;
  border-radius: 5px;
}
.range2-track { left: 0; right: 0; background: var(--panel-2); border: 1px solid var(--border); }
.range2-fill { border: 1px solid rgba(255, 255, 255, .25); }
/* Two stacked native range inputs; only their thumbs take pointer events. */
.range2 input[type=range] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.range2 input[type=range]::-webkit-slider-runnable-track { background: none; height: 100%; }
.range2 input[type=range]::-moz-range-track { background: none; }
.range2 input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 20px;
  height: 20px;
  margin-top: 4px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
  cursor: grab;
}
.range2 input[type=range]::-moz-range-thumb {
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
  cursor: grab;
}
.range2 input[type=range]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.range2 input[type=range]:focus { outline: none; }
.link-button { border: 0; background: none; padding: 3px 4px; color: var(--accent); cursor: pointer; font-size: 12px; }
.link-button:hover { text-decoration: underline; }
.surf-hemis {
  position: absolute;
  top: 8px;
  right: 10px;
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #333;
  user-select: none;
}
.surf-hemis[hidden] { display: none; }
.surf-hemis label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.surf-tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  padding: 6px 10px 7px;
  border-radius: 6px;
  background: rgba(17, 19, 23, .92);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
  pointer-events: none;
  white-space: nowrap;
}
.surf-tip[hidden] { display: none; }
.tip-main { display: flex; align-items: center; gap: 8px; }
.tip-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255, 255, 255, .6); }
.tip-value { font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tip-label { font-size: 11px; color: #b8bec7; margin-top: 2px; }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .55);
  color: #fff;
}
.loading[hidden] { display: none; }

/* Controls */
.segmented { display: inline-flex; align-items: center; background: var(--panel-2); border-radius: 6px; padding: 2px; }
.segmented[hidden] { display: none; }
.segmented button {
  border: 0;
  background: none;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--border); color: var(--text); }
.segmented span { padding: 0 6px; font-variant-numeric: tabular-nums; }

.toggles { display: flex; gap: 12px; flex-wrap: wrap; }
.toggles label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.swatch { width: 12px; height: 3px; border-radius: 2px; }

/* Study panel */
#questions { padding: 12px; display: flex; flex-direction: column; gap: 20px; flex: 1; overflow: auto; }
.question h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; }
.options { display: flex; flex-direction: column; gap: 6px; }
.option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: left;
}
.option:hover { border-color: var(--muted); }
.option.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); }
.option kbd { margin-left: auto; }

.study-footer { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.primary {
  border: 0;
  border-radius: 6px;
  padding: 10px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
.primary:disabled { background: var(--panel-2); color: var(--muted); cursor: not-allowed; }

/* Full-screen messages */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .75); padding: 16px; }
.overlay[hidden] { display: none; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 28px; max-width: 440px; }
.card h2 { margin: 0 0 8px; font-size: 18px; }
.card p { margin: 0; color: var(--muted); }

/* Narrow screens: stack panels (rating is meant for desktop, but stay usable) */
@media (max-width: 1100px) {
  body { height: auto; }
  .layout { grid-template-columns: 1fr; }
  .layout.with-mri { grid-template-columns: 1fr; }
  #mri-panel .viewport { height: 70vh; flex: none; }
  #surf-panel .surf-body { height: 70vh; flex: none; }
  .topbar { flex-wrap: wrap; gap: 8px 16px; }
}

/* Landing page */
.landing-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 16px;
}
.landing-main h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 320px)); gap: 16px; }
.mode-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.mode-card:hover, .mode-card:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
  outline: none;
}
.mode-card.disabled { opacity: .5; pointer-events: none; }
.mode-name { font-size: 17px; font-weight: 600; }
.mode-text { color: var(--muted); }
.mode-meta { margin-top: auto; font-variant-numeric: tabular-nums; }
@media (max-width: 700px) {
  .modes { grid-template-columns: minmax(0, 1fr); width: 100%; }
}
