:root {
  --bg-top: #eef6ff;
  --bg-bottom: #d7e8ff;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-border: rgba(18, 57, 99, 0.12);
  --ink: #15304d;
  --muted: #55708d;
  --accent: #0f766e;
  --accent-strong: #0d9488;
  --shadow: 0 24px 60px rgba(19, 48, 77, 0.18);
  --cro-bg: #0b1f35;
  --cro-grid: rgba(190, 220, 255, 0.12);
  --cro-grid-major: rgba(190, 220, 255, 0.22);
  --cro-trace: #4ade80;
  --cro-trace-dim: rgba(120, 160, 140, 0.55);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.85), transparent 30%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.page {
  width: min(1360px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 2rem;
}

.mono {
  font-family: "Courier New", monospace;
}

.muted { color: var(--muted); }

.hidden { display: none !important; }

/* ── Hero ──────────────────────────────────────────────── */
.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.hero-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(21,48,77,0.12);
}
.hero-link:hover { background: white; }

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 0.95;
}

.intro {
  max-width: 68ch;
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 1rem;
}

/* ── Phase bar ─────────────────────────────────────────── */
.phase-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(21,48,77,0.12);
  border-radius: 16px;
  padding: 0.6rem 0.9rem;
  flex-shrink: 0;
}

.phase-step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.7;
  cursor: pointer;
  transition: opacity 0.2s, color 0.2s;
}

.phase-step:hover { opacity: 1; color: var(--ink); }
.phase-step:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.phase-step.active {
  color: var(--ink);
  opacity: 1;
}

.phase-step.done { opacity: 1; }
.phase-step.done .phase-num {
  background: var(--accent);
  color: white;
}

.phase-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(21,48,77,0.1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
}

.phase-step.active .phase-num {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
}

.phase-sep {
  width: 28px;
  height: 1px;
  background: rgba(21,48,77,0.2);
}

/* ── Main layout ───────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 1rem;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.main-col { min-width: 0; }

.phase-content {
  padding: 1.25rem 1.5rem 1.4rem;
}

.phase-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
}

.phase-sub {
  margin: 0 0 1.2rem;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 68ch;
}

/* ── Top row: scintillator + status ────────────────────── */
.top-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.25rem;
  margin-bottom: 1rem;
  align-items: stretch;
}

.scintillator-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.scintillator-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.scintillator {
  width: 150px;
  height: 120px;
  border-radius: 14px;
  background: linear-gradient(160deg, #1f3352, #122238);
  border: 1.5px solid rgba(255,255,255,0.08);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.scint-inner {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 100%);
  transition: background 0.08s linear;
}

.scintillator.flash .scint-inner {
  background: radial-gradient(circle at center, rgba(180,255,220,0.95) 0%, rgba(90,220,170,0.55) 35%, rgba(40,120,90,0.1) 70%, rgba(0,0,0,0) 100%);
}

.collection-status {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  background: rgba(239,247,255,0.7);
  border: 1px solid rgba(21,48,77,0.08);
  border-radius: 14px;
  justify-content: center;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.92rem;
}

.status-label { color: var(--muted); }
.status-val { font-weight: 700; font-size: 1.05rem; }
.status-val.mono { font-size: 1.05rem; }

.stop-hint, .phase-nav-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.playback-progress {
  height: 6px;
  background: rgba(21,48,77,0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.2rem;
}

.playback-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.1s linear;
}

/* ── CRO section ───────────────────────────────────────── */
.cro-section {
  border-top: 1px solid rgba(21,48,77,0.08);
  padding-top: 1rem;
}

.cro-section-head h3 {
  margin: 0 0 0.15rem;
  font-size: 1.05rem;
}

.cro-hint {
  margin: 0 0 0.85rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.cro-active-wrap {
  min-height: 180px;
  margin-bottom: 1rem;
}

.cro-empty {
  margin: 0;
  padding: 3rem 0;
  text-align: center;
  color: var(--muted);
  font-style: italic;
  background: rgba(11,31,53,0.04);
  border-radius: 14px;
  border: 1px dashed rgba(21,48,77,0.15);
}

.cro-trace {
  background: var(--cro-bg);
  border-radius: 14px;
  padding: 0.85rem 1rem 0.9rem;
  border: 1px solid rgba(255,255,255,0.05);
  position: relative;
}

.cro-trace-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
}

.cro-trace.active {
  box-shadow: 0 0 0 2px var(--accent-strong), 0 8px 28px rgba(15,118,110,0.22);
}

.cro-trace.confirmed {
  opacity: 0.62;
  padding: 0.5rem 0.7rem 0.55rem;
}

.cro-trace-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  color: #cbd5e1;
  font-size: 0.82rem;
}

.cro-trace.confirmed .cro-trace-head {
  margin-bottom: 0.25rem;
  font-size: 0.76rem;
}

.cro-trace-n { font-weight: 700; color: #e2e8f0; }
.cro-trace-confirmed-val {
  font-family: "Courier New", monospace;
  color: #86efac;
  font-weight: 700;
}

.cro-input-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: center;
}

.cro-input-row label {
  flex: 1;
  font-size: 0.88rem;
  color: #cbd5e1;
}

.cro-input {
  width: 5.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
  color: #f1f5f9;
  background: rgba(255,255,255,0.08);
  text-align: right;
}

.cro-input:focus {
  outline: 2px solid var(--accent-strong);
  border-color: transparent;
  background: rgba(255,255,255,0.12);
}

.cro-confirm-btn {
  padding: 0.45rem 0.9rem;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15,118,110,0.3);
}
.cro-confirm-btn:hover:not(:disabled) { opacity: 0.88; }
.cro-confirm-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.cro-confirmed-wrap {
  border-top: 1px solid rgba(21,48,77,0.08);
  padding-top: 0.85rem;
}

.cro-confirmed-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cro-confirmed-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-right: 0.25rem;
}

.cro-confirmed-list::-webkit-scrollbar { width: 8px; }
.cro-confirmed-list::-webkit-scrollbar-thumb {
  background: rgba(21,48,77,0.25);
  border-radius: 999px;
}

/* ── Phase nav ─────────────────────────────────────────── */
.phase-nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(21,48,77,0.08);
  flex-wrap: wrap;
}

/* ── Buttons ───────────────────────────────────────────── */
.action-btn {
  padding: 0.65rem 1.1rem;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(15,118,110,0.25);
  transition: opacity 0.15s;
}
.action-btn:hover:not(:disabled) { opacity: 0.88; }
.action-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.action-btn--secondary {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid rgba(21,48,77,0.2);
  box-shadow: none;
}
.action-btn--secondary:hover:not(:disabled) { background: rgba(255,255,255,0.7); }

/* ── Data column ───────────────────────────────────────── */
.data-col {
  padding: 1rem 1.15rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.data-title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.data-section {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.data-subtitle {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.summary-table, .detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.summary-table th, .detail-table th {
  text-align: left;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid rgba(21,48,77,0.1);
}

.summary-table td, .detail-table td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid rgba(21,48,77,0.05);
}

.summary-table td.mono, .detail-table td.mono {
  font-size: 0.85rem;
}

.detail-table-wrap {
  max-height: 420px;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid rgba(21,48,77,0.08);
}

.detail-table-wrap::-webkit-scrollbar { width: 8px; }
.detail-table-wrap::-webkit-scrollbar-thumb {
  background: rgba(21,48,77,0.25);
  border-radius: 999px;
}

.detail-table thead th {
  position: sticky;
  top: 0;
  background: rgba(239,247,255,0.98);
  z-index: 1;
}

.detail-empty td {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 1.2rem 0.4rem;
}

tr.muted { opacity: 0.45; }

/* ── Phase 3 graph ─────────────────────────────────────── */
.graph-wrap {
  background: white;
  border-radius: 16px;
  padding: 0.75rem;
  border: 1px solid rgba(21,48,77,0.08);
  margin-bottom: 1rem;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.phase3-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

.tally-card {
  padding: 0.85rem 1rem;
  background: rgba(239,247,255,0.7);
  border: 1px solid rgba(21,48,77,0.08);
  border-radius: 14px;
}

.tally-title {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tally-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.3rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(21,48,77,0.05);
}
.tally-row:last-child { border-bottom: 0; }

.tally-label { color: var(--muted); }
.tally-val { font-weight: 700; font-family: "Courier New", monospace; }

.tally-row--student { padding-top: 0.55rem; }

.tally-input {
  width: 4.5rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid rgba(21,48,77,0.2);
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: right;
  color: var(--ink);
  background: white;
}
.tally-input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ── Phase 4 ───────────────────────────────────────────── */
.phase4-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.phase4-side {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  align-items: start;
}

.eff-slider-card {
  padding: 0.85rem 1rem;
  background: rgba(239,247,255,0.7);
  border: 1px solid rgba(21,48,77,0.08);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.eff-slider-card label {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
}

.eff-slider-card .slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0.1rem 0 0.3rem;
}

.eff-readout-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.88rem;
  padding: 0.1rem 0;
}

.eff-readout-label { color: var(--muted); }
.eff-readout-val { font-weight: 700; color: var(--ink); }

.num-input {
  width: 5.2rem;
  padding: 0.25rem 0.4rem;
  border: 1.5px solid rgba(21,48,77,0.14);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.num-input:focus { outline: 2px solid var(--accent-strong); outline-offset: 1px; }
.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num-input { -moz-appearance: textfield; }
.slider-unit { font-size: 0.85rem; color: var(--muted); margin-left: 0.25rem; }

.eff-snap-btn {
  margin-top: 0.4rem;
  font-size: 0.82rem;
  padding: 0.45rem 0.85rem;
}

.gamma-card {
  padding: 0.9rem 1rem;
  background: linear-gradient(135deg, rgba(15,118,110,0.09), rgba(13,148,136,0.15));
  border: 1px solid rgba(15,118,110,0.2);
  border-radius: 14px;
}

.gamma-title {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.gamma-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 1.05rem;
  margin-bottom: 0.4rem;
}

.gamma-label { color: var(--ink); font-weight: 700; }
.gamma-val { font-weight: 700; color: var(--accent-strong); font-size: 1.2rem; }

.gamma-hint {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Explain-details ───────────────────────────────────── */
.explain-details {
  border-radius: 14px;
  background: rgba(239,247,255,0.9);
  border-left: 3px solid var(--accent-strong);
  font-size: 0.88rem;
  line-height: 1.55;
  color: #334155;
  overflow: hidden;
}

.explain-details summary {
  padding: 0.6rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}
.explain-details summary::-webkit-details-marker { display: none; }
.explain-details summary::before {
  content: '▶';
  font-size: 0.65rem;
  color: var(--accent-strong);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.explain-details[open] summary::before { transform: rotate(90deg); }
.explain-details > :not(summary) { padding: 0 0.9rem 0.75rem; }
.explain-details p { margin: 0.5rem 0; }
.explain-details p:first-of-type { margin-top: 0; }
.explain-details .mono {
  display: block;
  background: rgba(21,48,77,0.06);
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.88rem;
}

/* ── Display equations (LaTeX-ish, without a library) ─── */
.eqn {
  display: block;
  text-align: center;
  font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", Cambria, Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  background: rgba(21,48,77,0.06);
  padding: 0.6rem 0.7rem;
  border-radius: 6px;
  margin: 0.6rem 0;
  line-height: 1.55;
}
.eqn var {
  font-style: italic;
  font-family: inherit;
}
.eqn sub, .eqn sup { font-size: 0.7em; }
.eqn .op { margin: 0 0.2em; }
.frac {
  display: inline-block;
  vertical-align: middle;
  text-align: center;
  margin: 0 0.2em;
  line-height: 1.1;
  font-size: 0.95em;
}
.frac .num {
  display: block;
  border-bottom: 1px solid currentColor;
  padding: 0 0.4em 0.1em;
}
.frac .den {
  display: block;
  padding: 0.1em 0.4em 0;
}

/* ── Modal ─────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(21,48,77,0.35);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  max-width: 720px;
  width: 100%;
  padding: 1.5rem 1.75rem;
  background: white;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.modal h2 {
  margin: 0 0 0.75rem;
  font-size: 1.4rem;
}

.modal p { margin: 0.5rem 0; color: var(--ink); line-height: 1.55; }

.modal ol, .modal ul { margin: 0.5rem 0 0.75rem 1.2rem; padding: 0; line-height: 1.6; }

#modal-continue { margin-top: 1rem; }

/* ── Intro schematic diagram ─────────────────────────────── */
.intro-diagram {
  display: block;
  width: 100%;
  height: auto;
  max-width: 640px;
  margin: 0.9rem auto;
  background: rgba(239,247,255,0.55);
  border: 1px solid rgba(21,48,77,0.08);
  border-radius: 12px;
  padding: 0.5rem;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .data-col { position: static; max-height: none; }
  .phase3-row { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .hero { flex-direction: column; align-items: flex-start; }
  .top-row { grid-template-columns: 1fr; }
  .scintillator { width: 100%; }
  .phase4-side { grid-template-columns: 1fr; }
}
