:root {
  --bg: #0b0d11;
  --bg-raise: #12161d;
  --bg-card: #161b24;
  --bg-card-hi: #1d2430;
  --line: #242c39;
  --line-hi: #33405270;
  --text: #e7ecf3;
  --text-dim: #8b98ac;
  --text-faint: #5d6a7d;
  --accent: #5eead4;
  --accent-dim: #2dd4bf33;
  --ref: #a78bfa;
  --ref-dim: #a78bfa26;
  --warn: #fbbf24;
  --err: #fca5a5;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  --slider-h: 280px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
body {
  min-height: 100vh;
  background-image:
    radial-gradient(900px 420px at 15% -10%, #16303022, transparent 70%),
    radial-gradient(700px 400px at 90% 0%, #2a1f4022, transparent 70%);
}

main, .topbar { max-width: 1040px; margin: 0 auto; padding: 0 20px; }

/* ---------- header ---------- */

.topbar { padding-top: 26px; padding-bottom: 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 11px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim); }
h1 { font-size: 19px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 22px; font-weight: 600; margin: 0 0 12px; letter-spacing: -0.01em; }
h3 { font-size: 14px; font-weight: 600; margin: 22px 0 8px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 12px; color: var(--text-faint); }
.progress { font-size: 12px; }
.save-state { padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); font-size: 11px; }
.save-state.saved { color: var(--accent); border-color: #2dd4bf55; }
.save-state.saving { color: var(--text-dim); }
.save-state.pending { color: var(--warn); border-color: #fbbf2455; }

.eyebrow { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-faint); font-weight: 600; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.hint-text { font-size: 13px; color: var(--text-dim); line-height: 1.5; margin: 6px 0 0; }
.error { color: var(--err); font-size: 13px; }

/* ---------- intro / prose / form ---------- */

.view { padding-bottom: 60px; }
.prose { max-width: 70ch; font-size: 15px; line-height: 1.6; color: #cfd7e2; }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose h2 { margin-top: 8px; }

.notice {
  border: 1px solid var(--line); background: var(--bg-raise);
  border-radius: var(--radius); padding: 14px 18px; margin: 0 0 22px; max-width: 70ch;
  font-size: 14px; line-height: 1.5;
}
.notice p { margin: 0 0 10px; }
.notice.warn { border-color: #fbbf2455; background: #fbbf240d; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.form { max-width: 70ch; margin-top: 26px; padding-top: 6px; border-top: 1px solid var(--line); }
.form .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.form .opt { color: var(--text-faint); font-weight: 400; }
.form .req { color: var(--accent); }
.form input[type=text], .form select, .form textarea {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.form label.check { flex-direction: row; align-items: flex-start; gap: 10px; margin: 18px 0; color: #cfd7e2; line-height: 1.5; }
.form label.check input { margin-top: 3px; accent-color: var(--accent); }
.form textarea { resize: vertical; }

button.primary, button.ghost, .linkish {
  font: inherit; cursor: pointer; border-radius: 9px;
  transition: background .13s, color .13s, border-color .13s, opacity .13s;
}
button.primary {
  font-size: 14px; font-weight: 600; padding: 11px 18px;
  border: 1px solid var(--accent); background: var(--accent); color: #06231f;
}
button.primary:hover:not(:disabled) { background: #7ff0dd; }
button.primary:disabled { opacity: .35; cursor: default; }
button.ghost {
  font-size: 13px; padding: 9px 14px;
  border: 1px solid var(--line); background: transparent; color: var(--text-dim);
}
button.ghost:hover { background: var(--bg-card); color: var(--text); }
.linkish { border: none; background: none; color: var(--text-dim); text-decoration: underline; padding: 0; font-size: 11.5px; }
.linkish:hover { color: var(--text); }
.code { font-size: 18px; color: var(--accent); }

/* ---------- trial head ---------- */

.trial-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 4px 0 16px; flex-wrap: wrap; }
.trial-head h2 { margin: 2px 0 0; font-size: 20px; }
.trial-head .hint-text { max-width: 52ch; margin: 0; }

/* ---------- transport ---------- */

.transport {
  display: flex; align-items: center; gap: 18px;
  background: var(--bg-raise); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 18px;
}
.play {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: none;
  background: var(--accent); color: #06231f; cursor: pointer;
  display: grid; place-items: center;
  transition: transform .1s, box-shadow .18s, opacity .15s;
  box-shadow: 0 0 0 0 var(--accent-dim);
}
.play:hover:not(:disabled) { box-shadow: 0 0 0 7px var(--accent-dim); }
.play:active:not(:disabled) { transform: scale(.94); }
.play:disabled { opacity: .3; cursor: default; }
.play svg { width: 24px; height: 24px; fill: currentColor; }
.play .ico-pause { display: none; }
body.playing .play .ico-play { display: none; }
body.playing .play .ico-pause { display: block; }

.scrub { flex: 1 1 auto; min-width: 0; }
.track { position: relative; height: 8px; background: #222a37; border-radius: 999px; cursor: pointer; touch-action: none; }
.track::before { content: ""; position: absolute; inset: -10px 0; }
.track-region { position: absolute; top: -3px; bottom: -3px; background: #a78bfa33; border: 1px solid #a78bfa88; border-radius: 4px; pointer-events: none; }
.track-region.provisional { background: #a78bfa22; border-style: dashed; }
.track-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #2dd4bf, var(--accent)); border-radius: 999px; }
.track-head { position: absolute; top: 50%; left: 0; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: #fff; opacity: 0; transition: opacity .13s; pointer-events: none; }
.track:hover .track-head, .track:focus-visible .track-head, body.playing .track-head { opacity: 1; }
.track:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }
.scrub-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 9px; font-size: 11.5px; color: var(--text-faint); }
.region-badge { display: inline-flex; align-items: center; gap: 8px; color: #d9d2ff; }
.region-hint { color: var(--text-faint); }

.vol { flex: none; display: flex; align-items: center; gap: 9px; color: var(--text-faint); }
.vol svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.vol input { -webkit-appearance: none; appearance: none; width: 84px; height: 4px; border-radius: 999px; background: #222a37; cursor: pointer; }
.vol input::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: var(--text-dim); cursor: pointer; }
.vol input::-moz-range-thumb { width: 12px; height: 12px; border: none; border-radius: 50%; background: var(--text-dim); cursor: pointer; }
.vol.locked { opacity: .4; }
.vol.locked input { cursor: not-allowed; }

/* ---------- rating panel ---------- */

.panel { background: var(--bg-raise); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 14px; }
.panel-scroll { overflow-x: auto; overflow-y: hidden; }
.panel-grid {
  display: grid;
  grid-template-columns: 78px 96px repeat(var(--n, 8), minmax(64px, 1fr));
  gap: 0 8px;
  min-width: calc(78px + 96px + var(--n, 8) * 64px);
  align-items: start;
}
.stims { display: contents; }

.stim { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }
.stim-btn {
  width: 100%; font: inherit; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 6px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg-card); color: var(--text); cursor: pointer;
  transition: background .12s, border-color .12s;
}
.stim-btn:hover { background: var(--bg-card-hi); }
.stim-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.stim-btn[aria-pressed="true"] { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-dim), transparent 70%), var(--bg-card-hi); }
.stim.ref .stim-btn { font-size: 13.5px; border-color: #2e2a45; background: linear-gradient(180deg, var(--ref-dim), transparent 60%), var(--bg-card); color: #d9d2ff; }
.stim.ref .stim-btn[aria-pressed="true"] { border-color: var(--ref); background: linear-gradient(180deg, #a78bfa30, transparent 70%), var(--bg-card-hi); }
.stim .live { display: flex; align-items: flex-end; gap: 2px; height: 13px; width: 13px; opacity: 0; transition: opacity .15s; flex: none; }
.stim .live i { display: block; width: 3px; border-radius: 1px; background: currentColor; height: 4px; }
body.playing .stim-btn[aria-pressed="true"] .live { opacity: 1; color: var(--accent); }
.stim.ref .stim-btn[aria-pressed="true"] .live { color: var(--ref); }
body.playing .stim-btn[aria-pressed="true"] .live i { animation: bob .62s ease-in-out infinite alternate; }
.stim .live i:nth-child(2) { animation-delay: .2s !important; }
.stim .live i:nth-child(3) { animation-delay: .4s !important; }
@keyframes bob { from { height: 4px; } to { height: 13px; } }
@media (prefers-reduced-motion: reduce) { body.playing .stim-btn[aria-pressed="true"] .live i { animation: none; height: 9px; } }

.ref-note { height: var(--slider-h); display: grid; place-items: center; text-align: center; font-size: 12px; color: var(--text-faint); line-height: 1.5; }

.slider { height: var(--slider-h); width: 100%; display: flex; justify-content: center; cursor: pointer; touch-action: none; border-radius: 6px; }
.slider:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.slider-track { position: relative; width: 10px; height: 100%; background: #222a37; border-radius: 999px; }
.slider-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; border-radius: 999px; background: linear-gradient(0deg, #2dd4bf, var(--accent)); }
.slider-thumb { position: absolute; left: 50%; bottom: 0; width: 20px; height: 20px; margin: 0 0 -10px -10px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px #0008; }
.slider[data-unset="1"] .slider-thumb { display: none; }
.slider[data-unset="1"] .slider-track { background: repeating-linear-gradient(0deg, #222a37 0 6px, #1a2029 6px 12px); }
.stim .value { font-size: 15px; color: var(--text-dim); min-height: 20px; }
.stim.is-100 .value { color: var(--ref); }
.stim kbd { margin: 0; }

.scale-col { position: relative; height: var(--slider-h); margin-top: 52px; }
.scale-band { position: absolute; left: 0; right: 0; height: 20%; display: flex; align-items: center; border-top: 1px solid var(--line); font-size: 11px; color: var(--text-dim); }
.scale-band:nth-child(1) { top: 0; }
.scale-band:nth-child(2) { top: 20%; }
.scale-band:nth-child(3) { top: 40%; }
.scale-band:nth-child(4) { top: 60%; }
.scale-band:nth-child(5) { top: 80%; border-bottom: 1px solid var(--line); }
.scale-num { position: absolute; right: 0; top: calc((100 - var(--v)) * 1%); transform: translateY(-50%); font-family: var(--mono); font-size: 10px; color: var(--text-faint); }
.stim { position: relative; }
/* faint grid lines across the stimulus columns at 20/40/60/80: a background
   on the grid container, offset past the scale and reference columns
   (78px + 96px + two 8px gaps) and down past the buttons (52px). */
.panel-grid {
  background-image: repeating-linear-gradient(0deg, transparent 0 calc(20% - 1px), var(--line) calc(20% - 1px) 20%);
  background-repeat: no-repeat;
  background-position: 190px 52px;
  background-size: calc(100% - 190px) var(--slider-h);
}

/* ---------- trial foot ---------- */

.trial-foot { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 18px 0 10px; flex-wrap: wrap; }
.reqs { margin: 0; padding: 0 0 0 18px; font-size: 13px; color: var(--warn); line-height: 1.6; }
.reqs li::marker { color: var(--warn); }
.keys { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 11.5px; color: var(--text-faint); margin-top: 10px; }
kbd { font-family: var(--mono); font-size: 10.5px; padding: 2px 5px; margin-right: 3px; border-radius: 4px; border: 1px solid var(--line); background: var(--bg-raise); color: var(--text-dim); }

/* ---------- splash / loading ---------- */

.splash { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--bg); transition: opacity .3s; }
.splash.fading { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; width: min(360px, 78vw); }
.splash-inner p { color: var(--text-dim); font-size: 13.5px; margin: 18px 0 14px; line-height: 1.5; }
.splash-inner p.error { color: var(--err); }
.spinner { width: 26px; height: 26px; margin: 0 auto; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.splash.errored .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 3px; background: #1c2430; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.splash.errored .bar { display: none; }

@media (max-width: 720px) {
  .form .grid { grid-template-columns: 1fr; }
  .transport { flex-wrap: wrap; }
  .vol { order: 3; width: 100%; }
  .vol input { flex: 1; width: auto; }
  :root { --slider-h: 220px; }
}
