:root {
  --bg: #0f1114;
  --bg-elevated: #171a1f;
  --bg-hover: #1e2229;
  --border: #2a3038;
  --border-focus: #4a9eff;
  --text: #e8eaed;
  --text-muted: #8b939e;
  --accent: #3d8bfd;
  --accent-dim: rgba(61, 139, 253, 0.15);
  --success: #3dd68c;
  --success-dim: rgba(61, 214, 140, 0.12);
  --warning: #f0b429;
  --warning-dim: rgba(240, 180, 41, 0.12);
  --danger: #f07178;
  --onset: #f0b429;
  --radius: 10px;
  --radius-sm: 6px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sidebar-w: 240px;
  --guide-w: 280px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
}

.welcome-card {
  max-width: 520px;
  margin: 0 auto;
  padding: 4rem 1.5rem;
}

.eyebrow, .item-eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

.welcome-card h1 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
}

.lede {
  color: var(--text-muted);
  margin: 0 0 2rem;
}

#welcome-form label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

#annotator-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--mono);
  margin-bottom: 0.5rem;
}

#annotator-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

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

.rules {
  margin-top: 2rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.rules summary {
  cursor: pointer;
  font-weight: 600;
}

.rules ol {
  margin: 0.75rem 0 0;
  padding-left: 1.25rem;
  color: var(--text-muted);
}

.rules li { margin-bottom: 0.35rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.82rem; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand {
  font-weight: 700;
  font-size: 0.9rem;
}

.badge {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 999px;
}

.progress-wrap {
  flex: 1;
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-text {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.save-status {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--success);
  min-width: 5rem;
  text-align: right;
}

.save-status.pending { color: var(--warning); }
.save-status.error { color: var(--danger); }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--guide-w);
  min-height: calc(100vh - 49px);
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: var(--sidebar-w) 1fr; }
  .guide-panel { display: none; }
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-head h2 {
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.filter-row {
  display: flex;
  gap: 0.35rem;
}

.filter {
  flex: 1;
  padding: 0.3rem 0.4rem;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
}

.filter.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1;
}

.item-list li button {
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.item-list li button:hover { background: var(--bg-hover); color: var(--text); }

.item-list li button.active {
  background: var(--accent-dim);
  border-color: rgba(61, 139, 253, 0.35);
  color: var(--text);
}

.item-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.item-dot.done { background: var(--success); }
.item-dot.partial { background: var(--warning); }

.main {
  padding: 1.25rem 1.5rem 2rem;
  overflow-y: auto;
  max-width: 820px;
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.item-header h2 {
  font-family: var(--mono);
  font-size: 1.05rem;
  margin: 0;
  word-break: break-all;
}

.item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  margin: 0;
}

.audio-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.audio-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.audio-block.locked {
  opacity: 0.55;
  pointer-events: none;
}

.audio-block.unlocked {
  opacity: 1;
  pointer-events: auto;
}

.audio-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-bottom: 0.6rem;
}

.audio-head h3 {
  margin: 0;
  font-size: 0.9rem;
}

.audio-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.lock-msg {
  font-size: 0.75rem;
  color: var(--warning);
  margin-left: auto;
}

.audio-block.unlocked .lock-msg { display: none; }

.wave-wrap {
  position: relative;
  padding-top: 0.35rem;
}

.wave-wrap audio {
  width: 100%;
  height: 36px;
  border-radius: var(--radius-sm);
}

/* Waveform (wavesurfer) — replaces the bare native player on the 3 main clips */
.wave-stage {
  position: relative;
  background: #0b0d10;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0;
}
.wave {
  width: 100%;
}
.wave-ctl {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.wave-play {
  background: var(--accent);
  color: #04101f;
  border: 0;
  border-radius: var(--radius-sm);
  width: 2.1rem;
  height: 2.1rem;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
.wave-play:hover { filter: brightness(1.08); }
.wave-play:disabled { opacity: 0.4; cursor: not-allowed; }
.wave-time {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.onset-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--onset);
  box-shadow: 0 0 8px rgba(240, 180, 41, 0.55);
  pointer-events: none;
  z-index: 3;
  opacity: 0.9;
}

.onset-marker::after {
  content: "B starts";
  position: absolute;
  top: -1px;
  left: -6px;
  transform: translateX(-100%);
  padding: 1px 5px;
  background: var(--bg-elevated);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--onset);
  white-space: nowrap;
}

.ab-block summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  user-select: none;
}

.ab-block[open] summary { margin-bottom: 0.6rem; color: var(--text); }

.label-form fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0 0 1rem;
  background: var(--bg-elevated);
}

.label-form legend {
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0 0.35rem;
}

.step-group.locked {
  opacity: 0.45;
  pointer-events: none;
}

.step-group.unlocked {
  opacity: 1;
  pointer-events: auto;
}

.step {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.step:last-child { border-bottom: none; }

.step-q {
  margin: 0 0 0.65rem;
  font-weight: 600;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  margin-right: 0.4rem;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 50%;
  font-size: 0.75rem;
  font-family: var(--mono);
}

.step-note {
  margin: -0.35rem 0 0.65rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.choices label,
.rating label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  font-size: 0.85rem;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.choices label:hover,
.rating label:hover {
  border-color: var(--text-muted);
}

.choices label:has(:checked),
.rating label:has(:checked) {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text);
}

.choices input,
.rating input {
  accent-color: var(--accent);
}

.rating label {
  min-width: 2.5rem;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 600;
}

.notes-step label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

#notes {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  resize: vertical;
}

#notes:focus {
  outline: none;
  border-color: var(--border-focus);
}

.nav-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.5rem;
}

.item-status {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.item-status.complete {
  color: var(--success);
}

.guide-panel {
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  font-size: 0.82rem;
}

.guide-panel h2 {
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.guide-content h3 {
  font-size: 0.88rem;
  margin: 1rem 0 0.35rem;
  color: var(--accent);
}

.guide-content h3:first-child { margin-top: 0; }

.guide-content p, .guide-content li {
  color: var(--text-muted);
  margin: 0.25rem 0;
}

.guide-content ul {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.1rem;
}

.guide-content code {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

/* v3 additions: environment gate + headphone check */
.env-gate { margin: 14px 0; padding: 12px; border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; display: flex; flex-direction: column; gap: 8px; }
.gate-check { display: flex; gap: 8px; align-items: center; font-size: 0.92em; }
.hp-check { margin-top: 4px; }
.hp-check audio { width: 100%; margin: 6px 0; }
