/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --serif: 'Fraunces', 'Times New Roman', serif;
  --sans:  'Inter', system-ui, -apple-system, sans-serif;
  --mono:  'JetBrains Mono', ui-monospace, monospace;

  /* Light theme */
  --paper:   #faf7f1;
  --paper-2: #f3efe6;
  --paper-3: #ebe6d9;
  --ink:     #181613;
  --ink-2:   #4a463f;
  --ink-3:   #8a8378;
  --rule:    rgba(20, 18, 15, 0.10);
  --rule-2:  rgba(20, 18, 15, 0.18);
  --accent:  #c0392b;
  --good:    #2d6a4f;
  --warn:    #c97f2b;
  --bad:     #a8201a;

  --rail-w: 84px;
  --app-max: 1400px;
}

[data-theme="dark"] {
  --paper:   #131210;
  --paper-2: #1c1a17;
  --paper-3: #25221d;
  --ink:     #f3efe6;
  --ink-2:   #b3ada0;
  --ink-3:   #6f6a5f;
  --rule:    rgba(243, 239, 230, 0.12);
  --rule-2:  rgba(243, 239, 230, 0.22);
  --accent:  #ff7a5c;
  --good:    #6cc28d;
  --warn:    #e6a85c;
  --bad:     #ff6e63;
}

/* ── Reset & base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  transition: background .3s, color .3s;
}

h1, h2, h3, p { margin-top: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }

/* ── Brand title ────────────────────────────────────────────── */
.brand-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  font-size: clamp(1.9rem, 2.45vw, 2.55rem);
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}

.brand-mark {
  width: clamp(48px, 4.2vw, 58px);
  height: clamp(48px, 4.2vw, 58px);
  flex: 0 0 auto;
  display: block;
}

.brand-dot { color: var(--accent); }

/* ── Header ─────────────────────────────────────────────────── */
.app-header {
  width: min(100%, var(--app-max));
  flex-shrink: 0;
  background: var(--paper);
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "brand utils"
    "controls controls";
}

.header-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-brand-row {
  grid-area: brand;
  min-height: 88px;
  padding: 0 28px;
  border-bottom: 1px solid var(--rule);
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.header-controls-row {
  grid-area: controls;
  min-height: 64px;
  padding: 8px 28px 10px;
  flex-wrap: wrap;
}

.toolbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--rule-2);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.toolbar-drawer {
  display: contents;
}

.toolbar-drawer-head,
.toolbar-drawer-backdrop {
  display: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--rule-2);
  border-radius: 50%;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.header-utils {
  grid-area: utils;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  min-height: 66px;
  padding: 0 20px;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}

/* Language picker */
.language-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  min-width: 0;
  color: var(--ink-3);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.language-picker select {
  width: auto;
  max-width: 220px;
  min-width: 0;
  height: 34px;
  min-height: 34px;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  --select-bg: var(--paper-2);
  color: var(--ink);
  padding: 0 30px 0 8px;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

/* Theme toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--rule-2);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  transition: background .15s;
}
.theme-toggle:hover { background: var(--paper-3); }

/* Header settings button */
.header-settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  background: var(--paper-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  transition: background .15s;
}
.header-settings-btn:hover { background: var(--paper-3); }

/* Current study */
.current-study {
  min-width: 0;
}

.current-study-meta {
  margin: 0 0 5px;
  color: var(--ink-3);
  font-family: var(--serif);
  font-size: clamp(0.78rem, 0.9vw, 0.9rem);
  font-style: italic;
  font-weight: 700;
  line-height: 1.1;
}

.current-study-row {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  flex-wrap: wrap;
}

.current-study-title {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.2rem, 1.55vw, 1.55rem);
  font-style: italic;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}

.change-study-btn {
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 8px;
  font-family: var(--serif);
  font-size: 0.92rem;
  font-style: italic;
  font-weight: 700;
}

.header-select {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  height: 36px;
  padding: 0 30px 0 12px;
  background: var(--paper);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: var(--ink);
  font: 500 13px var(--sans);
  min-height: 0;
  transition: border-color .15s, box-shadow .15s;
}

.header-select::-ms-expand {
  display: none;
}
.header-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 15%, transparent);
}

/* Loop toggle pill */
.loop-toggle-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  gap: 8px;
  height: 36px;
  margin: 0;
  padding: 0 16px;
  border: 1px solid var(--rule-2);
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--paper-2);
  white-space: nowrap;
  user-select: none;
  transition: all .15s;
}
.loop-toggle-pill:has(input:checked) {
  border-color: var(--good);
  color: var(--good);
  background: color-mix(in oklab, var(--good) 12%, var(--paper-2));
}
.loop-toggle-pill input {
  appearance: none;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
  border: 0;
  border-radius: 3px;
  background: var(--good);
  box-shadow: none;
  accent-color: var(--good);
}
.loop-toggle-pill input::before {
  content: "";
  width: 9px;
  height: 6px;
  border-left: 3px solid #fff;
  border-bottom: 3px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}
.loop-toggle-pill input:not(:checked) {
  background: var(--paper);
  border: 2px solid var(--ink-3);
}
.loop-toggle-pill input:not(:checked)::before {
  display: none;
}
.loop-toggle-pill span {
  line-height: 1;
}

/* Ghost button */
.ghost-btn {
  background: transparent;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
  transition: background .12s;
}
.ghost-btn:hover { background: var(--paper-2); }

/* Import file name */
.import-name {
  font-size: 11px;
  color: var(--ink-3);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-flex-spacer { flex: 1; min-width: 8px; }

/* Phase display */
.phase-display {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 220px;
}
.phase-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
  transition: color .2s;
}
.phase-hint {
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.2;
}
.phase-display[data-phase="response"]     .phase-label { color: var(--good); }
.phase-display[data-phase="response"]     .phase-hint  { color: var(--good); opacity: .7; }
.phase-display[data-phase="demo"]         .phase-label { color: var(--accent); }
.phase-display[data-phase="count-in"]     .phase-label,
.phase-display[data-phase="count-response"] .phase-label { color: var(--warn); }

/* Count badge */
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--paper-2);
  border: 1px solid var(--rule-2);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 17px;
  color: var(--ink-2);
  transition: border-color .2s, color .2s, background .2s;
}

.phase-display,
.count-badge {
  display: none;
}

/* Animate count badge during count-in / count-response */
#stage[data-phase="count-in"]       ~ * .count-badge,
#stage[data-phase="count-response"] ~ * .count-badge { /* can't target ancestor */ }

/* Transport */
.transport {
  display: flex;
  align-items: center;
  gap: 8px;
}

.play-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 10px color-mix(in oklab, var(--accent) 35%, transparent);
  outline: none;
  transition: filter .15s, background .15s;
}
.play-btn:hover { filter: brightness(1.08); }
.play-btn:focus,
.play-btn:focus-visible {
  outline: none;
}

.stop-btn {
  background: var(--ink-2);
  box-shadow: none;
}
.stop-btn:hover { filter: brightness(1.15); }

.play-btn.is-stopping {
  background: var(--ink-2);
  box-shadow: none;
}

.restart-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  color: var(--ink-2);
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.06);
  transition: border-color .15s, color .15s, transform .15s, filter .15s;
}

.restart-btn[hidden] {
  display: none;
}

.restart-btn:hover {
  border-color: color-mix(in oklab, var(--accent) 45%, var(--border));
  color: var(--accent);
  filter: brightness(1.02);
}

.restart-btn:active {
  transform: scale(0.96);
}

/* ── Top training toast ─────────────────────────────────────── */
.training-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(520px, calc(100vw - 32px));
  min-height: 24px;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 14px 32px rgba(12, 11, 10, 0.22);
  transform: translate(-50%, -10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.training-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.training-toast[hidden] {
  display: none;
}

.toast-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-family: var(--mono);
}

.toast-count:empty {
  width: 9px;
  height: 9px;
  background: var(--good);
}

.toast-message {
  min-width: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.25;
  white-space: normal;
  overflow: hidden;
}

.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: color-mix(in oklab, var(--paper) 78%, transparent);
  font-size: 16px;
  line-height: 1;
}

/* ── Body layout ─────────────────────────────────────────────── */
.body-layout {
  width: min(100%, var(--app-max));
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
}

/* ── Left rail ───────────────────────────────────────────────── */
.left-rail {
  flex: 0 0 var(--rail-w);
  border-right: 1px solid var(--rule);
  background: var(--paper-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px 0 10px;
  gap: 13px;
  overflow-y: hidden;
}

.rail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.rail-label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1;
}

.rail-value-btn {
  width: 60px;
  height: 60px;
  min-height: 60px;
  aspect-ratio: 1;
  border-radius: 14px;
  border: 1px solid var(--rule-2);
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  gap: 2px;
  transition: background .12s;
}
.rail-value-btn:hover { background: var(--paper-3); }

.rail-number {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 19px;
  line-height: 1.1;
  text-align: center;
}

.rail-small {
  font-size: 13px;
  word-break: normal;
  text-align: center;
}

#railInputDisplay,
.rail-import-btn .rail-number {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
  overflow-wrap: normal;
  word-break: normal;
}

.rail-unit {
  font-size: 10px;
  color: var(--ink-3);
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: .06em;
}

.rail-import-btn {
  gap: 5px;
  text-transform: uppercase;
}

.rail-spacer {
  flex: 1 1 auto;
  min-height: 18px;
}

/* ── Stage ───────────────────────────────────────────────────── */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
  scroll-padding-bottom: 140px;
}

/* Score wrap */
.score-wrap {
  position: relative;
  padding: 20px 28px 24px;
  background: var(--paper);
  transition: background .25s;
}

.score-actions {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.score-shortcut-hint {
  margin: 0;
  margin-right: auto;
  color: var(--ink-3);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
}

.score-actions .loop-toggle-pill {
  align-self: center;
}

.import-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: min(320px, 48vw);
  min-height: 34px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--rule-2);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-2);
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
}

.import-chip[hidden] {
  display: none;
}

.import-name {
  min-width: 0;
  max-width: 18ch;
  color: inherit;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  font-size: 18px;
  line-height: 1;
}

.chip-close:hover {
  color: var(--accent);
  background: color-mix(in oklab, var(--accent) 10%, transparent);
}

.listen-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--rule-2);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  transition: background .15s, color .15s, border-color .15s;
}

.listen-btn:hover {
  background: var(--paper-3);
}

.listen-btn.is-listening {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#stage[data-phase="demo"]           .score-wrap { background: color-mix(in oklab, var(--accent) 5%, var(--paper)); }
#stage[data-phase="count-in"]       .score-wrap,
#stage[data-phase="count-response"] .score-wrap { background: color-mix(in oklab, var(--warn) 5%, var(--paper)); }
#stage[data-phase="response"]       .score-wrap { background: color-mix(in oklab, var(--good) 5%, var(--paper)); }

#abcContainer {
  width: 100%;
  overflow: visible;
  padding-bottom: 8px;
}

#abcContainer[aria-busy="true"] {
  min-height: var(--score-pending-height, 160px);
}

.score-loading {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
}

.score-loading-label {
  justify-self: center;
}

.score-loading-bar {
  position: relative;
  display: block;
  width: min(360px, calc(100vw - 48px));
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--rule);
}

.score-loading-bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 42%;
  border-radius: inherit;
  background: var(--accent);
  animation: score-loading-bar 1.15s ease-in-out infinite;
}

@keyframes score-loading-bar {
  0% {
    transform: translateX(-105%);
  }
  100% {
    transform: translateX(245%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .score-loading-bar span {
    animation: none;
    transform: none;
    width: 100%;
  }
}

.click-hit-btn {
  position: fixed;
  left: 50%;
  bottom: 48px;
  z-index: 20;
  width: min(448px, calc(100vw - 32px));
  min-width: min(448px, calc(100vw - 32px));
  height: 65px;
  padding: 0 22px;
  transform: translateX(-50%);
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-family: var(--sans);
  font-style: normal;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(12, 11, 10, 0.14);
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow .05s ease;
}

.click-hit-btn[hidden] {
  display: none;
}

.click-hit-btn:active,
.click-hit-btn.is-pressed {
  border-color: color-mix(in oklab, var(--accent) 72%, #000);
  background: color-mix(in oklab, var(--accent) 72%, #000);
  color: #fff;
  box-shadow: 0 10px 24px rgba(12, 11, 10, 0.14);
}

#abcContainer svg {
  width: 100% !important;
  height: auto !important;
  overflow: visible;
  margin-bottom: 14px;
}

#abcContainer .abcjs-note,
#abcContainer .abcjs-rest,
#abcContainer .abcjs-bar {
  pointer-events: none;
}

.abc-cursor,
.abc-cursor-response {
  fill: #00ff00 !important;
  opacity: 1;
}

/* Event log */
.event-log {
  padding: 0 28px 120px;
  flex: 0 0 auto;
  overflow: visible;
  min-height: 80px;
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-bottom: 10px;
}

.log-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink-2);
}

.performance-panel {
  margin-bottom: 14px;
}

.performance-panel[hidden] {
  display: none;
}

.performance-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.performance-title {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-3);
}

.performance-title strong {
  color: var(--ink);
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.88rem;
  font-weight: 700;
}

.compact-report-btn {
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.performance-chart {
  position: relative;
  height: 76px;
  --chart-pad-x: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--rule-2);
  border-radius: 8px;
  background:
    linear-gradient(to bottom, transparent calc(50% - 1px), var(--rule-2) calc(50% - 1px), var(--rule-2) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--paper-2);
  overflow: hidden;
}

.performance-tolerance-band {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--tol-top);
  height: var(--tol-height);
  background: color-mix(in oklab, var(--good) 16%, transparent);
  border-top: 1px solid color-mix(in oklab, var(--good) 28%, transparent);
  border-bottom: 1px solid color-mix(in oklab, var(--good) 28%, transparent);
  pointer-events: none;
}

.performance-marker {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: calc(var(--chart-pad-x) + (100% - (var(--chart-pad-x) * 2)) * var(--x-ratio));
  width: 1px;
  background: var(--rule-2);
}

.performance-dot {
  position: absolute;
  left: calc(var(--chart-pad-x) + (100% - (var(--chart-pad-x) * 2)) * var(--x-ratio));
  top: var(--y);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.performance-dot.hit {
  background: var(--good);
}

.performance-dot.early {
  background: var(--warn);
}

.performance-dot.late {
  background: var(--accent);
}

.performance-dot.miss {
  width: 9px;
  height: 9px;
  border: 1.5px dashed var(--bad);
  background: var(--paper-2);
}

.performance-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--ink-3);
  font-size: 0.86rem;
}

.performance-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.legend-dot.hit { background: var(--good); }
.legend-dot.early { background: var(--warn); }
.legend-dot.late { background: var(--accent); }
.legend-dot.miss {
  border: 2px dashed var(--bad);
  background: transparent;
}

.take-inline-panel {
  display: grid;
  grid-template-columns: minmax(190px, 0.72fr) minmax(0, 1.8fr);
  gap: 24px;
  padding: 22px 28px 24px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  background: color-mix(in oklab, var(--paper-2) 72%, var(--paper));
}

.take-inline-panel[hidden] {
  display: none;
}

.take-inline-panel.is-pending .take-inline-score strong,
.take-inline-panel.is-pending .take-inline-stats strong {
  color: var(--ink-3);
}

.take-inline-panel.is-pending .compact-report-btn,
.take-inline-panel.is-pending .take-inline-actions {
  display: none;
}

.take-inline-panel.is-pending .performance-chart {
  opacity: .82;
}

.take-inline-title {
  margin: 4px 0 12px;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.7rem, 3.6vw, 2.4rem);
  line-height: 1.05;
  font-weight: 500;
}

.take-inline-score {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.take-inline-score strong {
  font-family: var(--serif);
  font-size: clamp(3rem, 6vw, 4rem);
  line-height: 1;
  font-weight: 700;
  color: var(--accent);
}

.take-inline-score span {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink-3);
}

.take-inline-phrase {
  margin: 0;
  max-width: 36ch;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.86rem;
  line-height: 1.3;
  color: var(--ink-2);
}

.take-inline-detail {
  min-width: 0;
}

.take-inline-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 14px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.take-inline-stats span {
  display: grid;
  gap: 6px;
  padding: 11px 14px;
  border-right: 1px solid var(--rule);
}

.take-inline-stats span:last-child {
  border-right: 0;
}

.take-inline-stats small {
  color: var(--ink-3);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.take-inline-stats strong {
  font-family: var(--mono);
  font-size: 1.35rem;
  line-height: 1;
}

.take-inline-actions {
  margin-top: 12px;
}

.take-inline-actions .secondary,
.take-inline-actions .primary {
  min-height: 34px;
}

.hit   { color: var(--good); }
.early { color: var(--warn); }
.late, .extra, .miss { color: var(--bad); }

.time-report-backdrop {
  position: fixed;
  inset: 0;
  z-index: 58;
  background: rgba(20, 18, 15, 0.16);
}

.time-report-backdrop[hidden],
.time-report-panel[hidden] {
  display: none;
}

.time-report-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 59;
  display: flex;
  flex-direction: column;
  width: min(420px, 92vw);
  border-left: 1px solid var(--rule-2);
  background: var(--paper);
  box-shadow: -18px 0 50px rgba(12, 11, 10, 0.16);
}

.time-report-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 28px 24px 18px;
  border-bottom: 1px solid var(--rule);
}

.time-report-head h2 {
  margin: 4px 0 8px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.75rem;
  line-height: 1.05;
  font-weight: 700;
}

.time-report-head p:last-child {
  margin: 0;
  color: var(--ink-3);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
}

.time-report-table-wrap {
  min-height: 0;
  overflow-y: auto;
}

.time-report-table {
  width: 100%;
  border-collapse: collapse;
}

.time-report-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 24px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
  color: var(--ink-3);
  font-size: 0.68rem;
  letter-spacing: .12em;
  text-align: left;
  text-transform: uppercase;
}

.time-report-table td {
  padding: 14px 24px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.84rem;
  white-space: nowrap;
}

.time-report-table td:first-child {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
}

.time-report-table td:nth-child(2),
.time-report-table td:nth-child(3) {
  text-align: right;
}

.time-report-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}

.time-report-dot.hit { color: var(--good); }
.time-report-dot.early { color: var(--warn); }
.time-report-dot.late,
.time-report-dot.extra { color: var(--accent); }
.time-report-dot.miss {
  color: var(--bad);
  background: transparent;
  border: 1.5px dashed currentColor;
}

/* About section */
.about-section {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 42px;
  margin-top: 18px;
  padding-top: 0;
}

.about-copy h2 {
  margin: 8px 0 16px;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(2rem, 4.4vw, 3.2rem);
  font-weight: 500;
  line-height: 1.05;
  color: var(--ink);
}

.about-copy p,
.about-steps {
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.58;
  color: var(--ink-2);
}

.about-copy p {
  margin: 0 0 18px;
}

.about-copy .drop-cap {
  color: var(--ink);
  font-size: 1.08rem;
}

.drop-cap::first-letter {
  float: left;
  margin: 5px 10px 0 0;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 5.2em;
  font-weight: 700;
  line-height: .82;
}

.about-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 20px 24px;
  margin: 26px 0 30px;
}

.about-feature {
  padding-left: 18px;
  border-left: 3px solid var(--accent);
}

.about-feature h3,
.about-subtitle {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.2;
  color: var(--ink);
}

.about-feature p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

.about-subtitle {
  margin-top: 28px;
  font-style: italic;
  font-weight: 500;
  font-size: 1.35rem;
}

.about-steps {
  margin: 0;
  padding-left: 24px;
}

.about-steps li {
  margin-bottom: 6px;
}

.about-side {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.about-contact {
  padding: 22px 24px;
  border: 1px solid var(--rule-2);
  border-radius: 10px;
  background: var(--paper-2);
}

.about-contact p {
  margin: 9px 0 16px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.98rem;
  line-height: 1.35;
  color: var(--ink-2);
}

.about-contact a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 2px;
  border-bottom: 1px solid currentColor;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
}

.about-contact hr {
  height: 1px;
  margin: 18px 0;
  border: 0;
  background: var(--rule);
}

.about-contact .about-note {
  margin: 0 0 8px;
  color: var(--ink-3);
  font-size: 0.88rem;
}

.about-keywords {
  padding: 0 4px;
}

.about-keywords .eyebrow {
  color: var(--ink-3);
  margin-bottom: 10px;
}

.about-keywords div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.about-keywords span {
  padding: 3px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--ink-3);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.86rem;
  line-height: 1.2;
}

.about-copyright {
  margin: 0;
  padding: 0 4px;
  color: var(--ink-3);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  line-height: 1.5;
}

.stat-good { color: var(--good); }
.stat-warn { color: var(--warn); }
.stat-bad  { color: var(--bad); }

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 46px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  color: var(--ink-3);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
}

.site-footer strong {
  color: var(--ink);
}

/* ── Shared button styles ────────────────────────────────────── */
.secondary {
  padding: 6px 12px;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  background: var(--paper-2);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  min-height: 0;
  transition: background .12s;
}
.secondary:hover { background: var(--paper-3); }

.primary {
  padding: 6px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  min-height: 0;
  transition: background .12s, border-color .12s, opacity .12s;
}

.primary:hover {
  background: color-mix(in oklab, var(--accent) 88%, var(--ink));
  border-color: color-mix(in oklab, var(--accent) 88%, var(--ink));
}

.primary:disabled,
.secondary:disabled {
  cursor: default;
  opacity: .45;
}

.icon-button {
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  background: var(--paper-2);
  color: var(--ink-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}
.icon-button:hover { background: var(--paper-3); }

/* ── Modals ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(2px);
}

.modal-backdrop[hidden] { display: none; }

.modal-card {
  width: min(540px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow-y: auto;
  border: 1px solid var(--rule-2);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 24px 72px rgba(0, 0, 0, .3);
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.4rem;
  font-weight: 500;
}

.study-picker-card {
  width: min(720px, 100%);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.study-picker-head {
  padding: 32px 34px 26px;
  border-bottom: 1px solid var(--rule);
}

.study-picker-head h2 {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: clamp(2.2rem, 5vw, 3rem);
  font-style: italic;
  font-weight: 700;
  line-height: 1.05;
}

.study-picker-body {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  gap: 22px;
  padding: 28px 34px 30px;
}

.study-picker-field {
  display: grid;
  gap: 9px;
  margin: 0;
}

.study-picker-field > span,
.meter-picker legend,
.length-picker legend {
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 1.15rem;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
}

.study-picker-field .header-select {
  width: 100%;
  min-height: 48px;
  height: 48px;
  padding-left: 16px;
  border-radius: 8px;
  font-size: 1rem;
}

.meter-picker,
.length-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
}

.meter-picker legend,
.length-picker legend {
  width: 100%;
}

.study-picker-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.meter-picker button,
.length-picker button {
  min-width: 86px;
  min-height: 52px;
  padding: 8px 18px;
  border: 1px solid var(--rule-2);
  border-radius: 10px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.55rem;
  font-style: italic;
  font-weight: 700;
}

.length-picker button {
  min-width: 76px;
}

.meter-picker button.active,
.length-picker button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.meter-picker button:disabled,
.length-picker button:disabled {
  cursor: not-allowed;
  opacity: .38;
}

.study-picker-actions {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 14px;
  padding: 20px 34px 28px;
  border-top: 1px solid var(--rule);
}

.study-picker-actions button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
}

.take-summary-card {
  width: min(720px, 100%);
  padding: 28px 32px 24px;
}

.take-summary-title {
  margin: 6px 0 14px;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(2.05rem, 5vw, 2.85rem);
  line-height: 1.05;
  font-weight: 500;
  color: var(--ink);
}

.take-score-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.take-score-value {
  font-family: var(--serif);
  font-size: clamp(4rem, 9vw, 5.35rem);
  line-height: 1;
  font-weight: 700;
  color: var(--accent);
}

.take-score-total {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.4rem;
  color: var(--ink-3);
}

.take-summary-phrase {
  margin: 0 0 20px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--ink-2);
}

.take-modal-performance {
  margin-bottom: 18px;
}

.take-modal-performance .performance-chart {
  height: 58px;
}

.take-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin: 0 -32px 20px;
}

.take-summary-grid span {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 16px 22px;
  border-right: 1px solid var(--rule);
}

.take-summary-grid span:last-child {
  border-right: 0;
}

.take-summary-grid small {
  color: var(--ink-3);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.take-summary-grid strong {
  font-family: var(--mono);
  font-size: 1.75rem;
  line-height: 1;
}

.take-summary-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.take-summary-actions button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
}

.action-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Settings sections */
.settings-section {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}
.settings-section:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}
.settings-section h3 {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink-2);
}

/* Labels & inputs in settings */
label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-2);
}

.audio-meter {
  display: grid;
  gap: 6px;
  margin: 6px 0 10px;
}

.audio-meter-track {
  height: 14px;
  overflow: hidden;
  border: 1px solid var(--rule-2);
  border-radius: 999px;
  background:
    linear-gradient(
      90deg,
      #2fb66d 0 58%,
      #e1b341 58% 82%,
      #cf3a2f 82% 100%
    );
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.13);
}

.audio-meter-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-right: 2px solid rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.2);
  transition: width .08s linear;
}

.audio-meter-scale {
  display: flex;
  justify-content: space-between;
  color: var(--ink-3);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

input, select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}

input {
  background: var(--paper);
  padding: 6px 10px;
}

select {
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--select-bg, var(--paper));
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding: 6px 30px 6px 10px;
}

select::-ms-expand {
  display: none;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 15%, transparent);
}

input[type="range"] {
  padding: 0;
  min-height: 0;
  height: 4px;
  accent-color: var(--accent);
  border: none;
  box-shadow: none;
}
input[type="range"]:focus { box-shadow: none; border: none; }

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
  border: 1px solid var(--rule-2);
  border-radius: 3px;
  padding: 0;
}

.inline-value {
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.strong-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.small-text {
  font-size: 0.78rem;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-2);
}
.inline-check input {
  width: 16px;
  min-height: 16px;
  flex-shrink: 0;
}

/* BPM presets */
.bpm-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin: -4px 0 12px;
}

.bpmPreset {
  padding: 5px 0;
  border: 1px solid var(--rule-2);
  border-radius: 5px;
  background: var(--paper-2);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  min-height: 32px;
  transition: all .12s;
}
.bpmPreset:hover { background: var(--paper-3); }
.bpmPreset.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* Source tabs */
.source-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--rule-2);
  border-radius: 8px;
  background: var(--paper-2);
  padding: 3px;
  gap: 3px;
  margin-bottom: 12px;
}

.source-tab {
  min-height: 34px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  transition: all .12s;
}
.source-tab.active {
  background: var(--paper);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.configure-source {
  width: 100%;
  margin-bottom: 16px;
}

/* Status pills */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--paper-2);
  color: var(--ink-3);
  border: 1px solid var(--rule);
}
.status-pill.live {
  background: color-mix(in oklab, var(--good) 14%, var(--paper));
  color: var(--good);
  border-color: color-mix(in oklab, var(--good) 35%, transparent);
}
.status-pill.warn {
  background: color-mix(in oklab, var(--warn) 14%, var(--paper));
  color: var(--warn);
  border-color: color-mix(in oklab, var(--warn) 35%, transparent);
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

/* Toggle buttons */
.toggle-button {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--rule-2);
  background: var(--paper-2);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  min-height: 0;
  transition: all .12s;
}
.toggle-button.activate {
  border-color: color-mix(in oklab, var(--good) 40%, transparent);
  background: color-mix(in oklab, var(--good) 12%, var(--paper));
  color: var(--good);
}
.toggle-button.deactivate {
  border-color: color-mix(in oklab, var(--bad) 40%, transparent);
  background: color-mix(in oklab, var(--bad) 10%, var(--paper));
  color: var(--bad);
}

/* Danger button */
.danger-button {
  width: 100%;
  padding: 8px;
  border: 1px solid color-mix(in oklab, var(--bad) 28%, var(--paper-3));
  border-radius: 6px;
  background: color-mix(in oklab, var(--bad) 8%, var(--paper));
  color: var(--bad);
  font-size: 13px;
  font-weight: 600;
  transition: background .12s;
}
.danger-button:hover {
  background: color-mix(in oklab, var(--bad) 14%, var(--paper));
}

/* Misc */
#midiRefreshBtn, #learnBtn {
  width: 100%;
  margin-bottom: 8px;
}

.input-settings-pane[hidden] { display: none; }

/* ── Scrollbars ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .header-brand-row {
    padding-left: 22px;
    padding-right: 20px;
  }

  .brand-title {
    font-size: clamp(1.85rem, 3.5vw, 2.35rem);
  }

  .brand-mark {
    width: clamp(48px, 5.5vw, 54px);
    height: clamp(48px, 5.5vw, 54px);
  }

  .header-utils {
    padding-left: 16px;
    padding-right: 16px;
  }

  .language-picker select {
    max-width: 190px;
  }
}

@media (max-width: 860px) {
  :root { --rail-w: 78px; }

  .score-shortcut-hint {
    display: none;
  }

  .app-header {
    display: block;
  }

  .header-brand-row {
    min-height: 68px;
    padding: 0 16px;
    border-bottom: 1px solid var(--rule);
  }

  .toolbar-menu-btn {
    display: inline-flex;
    flex: 0 0 auto;
  }

  .toolbar-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(12, 11, 10, 0.34);
    z-index: 39;
  }

  .toolbar-drawer-backdrop[hidden] {
    display: none;
  }

  .toolbar-drawer {
    display: flex;
    flex-direction: column;
    gap: 18px;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(390px, calc(100vw - 32px));
    max-width: 100vw;
    padding: 18px;
    background: var(--paper);
    border-left: 1px solid var(--rule);
    box-shadow: -18px 0 50px rgba(12, 11, 10, 0.18);
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(100%);
    transition: transform .22s ease;
    z-index: 40;
  }

  .toolbar-drawer.is-open {
    transform: translateX(0);
  }

  .toolbar-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--rule);
    font-family: var(--serif);
    font-style: italic;
    font-weight: 700;
    color: var(--ink);
  }

  body.toolbar-drawer-open {
    overflow: hidden;
  }

  .header-utils {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    min-height: 0;
    padding: 0;
    border-bottom: 0;
    flex-wrap: nowrap;
    gap: 10px;
  }

  .language-picker {
    display: block;
    width: 100%;
  }

  .language-picker select {
    width: 100%;
    max-width: none;
  }

  .theme-toggle,
  .header-settings-btn {
    width: 100%;
    padding: 0 12px;
    justify-content: flex-start;
  }

  .header-controls-row {
    min-height: 0;
    padding: 12px 16px;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--rule);
  }

  .current-study {
    flex: 1 1 100%;
  }

  .loop-toggle-pill {
    height: 36px;
    justify-content: center;
  }

  .phase-display {
    display: none;
  }

  .transport {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .transport .ghost-btn {
    max-width: 210px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-flex-spacer {
    display: none;
  }

  .left-rail {
    padding-top: 13px;
    gap: 11px;
  }

  .rail-label {
    font-size: 11px;
  }

  .rail-value-btn {
    width: 56px;
    height: 56px;
    min-height: 56px;
    border-radius: 13px;
  }

  .rail-number { font-size: 18px; }

  .rail-small,
  #railInputDisplay,
  .rail-import-btn .rail-number {
    font-size: 12px;
  }

  .rail-unit { font-size: 10px; }
  .count-badge { min-width: 34px; height: 34px; font-size: 14px; }
  .restart-btn { width: 40px; height: 40px; font-size: 22px; }
  .play-btn { width: 48px; height: 48px; font-size: 14px; }

  .take-summary-card {
    padding: 28px 24px 24px;
  }

  .take-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-left: -24px;
    margin-right: -24px;
  }

  .take-summary-grid span:nth-child(2) {
    border-right: 0;
  }

  .take-summary-grid span:nth-child(-n + 2) {
    border-bottom: 1px solid var(--rule);
  }

  .take-inline-panel {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 24px;
  }

  .take-inline-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .take-inline-stats span:nth-child(2) {
    border-right: 0;
  }

  .take-inline-stats span:nth-child(-n + 2) {
    border-bottom: 1px solid var(--rule);
  }

  .about-section {
    grid-template-columns: 1fr;
    gap: 28px;
  }
}

@media (max-width: 640px) {
  .brand-title {
    font-size: clamp(1.75rem, 7vw, 2.05rem);
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .toolbar-drawer {
    width: min(360px, calc(100vw - 24px));
    padding: 16px;
  }

  .modal-backdrop {
    padding: 12px;
    align-items: center;
  }

  .study-picker-card {
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 24px);
    border-radius: 12px;
  }

  .study-picker-head {
    flex: 0 0 auto;
    padding: 24px 24px 20px;
  }

  .study-picker-head h2 {
    white-space: nowrap;
    font-size: clamp(1.25rem, 6.2vw, 2rem);
    line-height: .98;
  }

  .study-picker-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    gap: 18px;
    padding: 24px;
  }

  .study-picker-options {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 8px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .meter-picker button,
  .length-picker button {
    flex: 0 0 auto;
    min-width: 56px;
    min-height: 40px;
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 1.08rem;
  }

  .study-picker-actions {
    flex: 0 0 auto;
    padding: 14px 24px 18px;
  }

  .study-picker-actions button,
  .take-summary-actions button {
    min-height: 44px;
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  :root { --rail-w: 64px; }

  .left-rail {
    display: flex;
    padding-top: 12px;
    gap: 10px;
  }

  .rail-label {
    font-size: 10px;
  }

  .rail-value-btn {
    width: 48px;
    height: 48px;
    min-height: 48px;
    border-radius: 12px;
  }

  .rail-number {
    font-size: 15px;
  }

  .rail-small,
  #railInputDisplay,
  .rail-import-btn .rail-number {
    font-size: 11px;
  }

  .rail-unit {
    font-size: 9px;
  }

  .header-controls-row > .ghost-btn,
  .transport .ghost-btn {
    display: none;
  }

  .score-wrap,
  .event-log {
    padding-left: 16px;
    padding-right: 16px;
  }

  .performance-chart {
    height: 46px;
  }

  .take-summary-actions {
    justify-content: stretch;
  }

  .take-summary-actions button {
    width: 100%;
  }

  .take-inline-panel {
    padding-left: 16px;
    padding-right: 16px;
  }

  .take-inline-actions button {
    width: 100%;
  }

  .study-picker-body,
  .meter-picker,
  .length-picker {
    min-width: 0;
  }

  .study-picker-options {
    display: flex;
    flex-wrap: nowrap !important;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .about-section {
    margin-top: 18px;
    padding-top: 0;
  }

  .about-copy h2 {
    font-size: clamp(1.9rem, 9vw, 2.7rem);
  }

  .about-copy p,
  .about-steps {
    font-size: 0.98rem;
  }

  .drop-cap::first-letter {
    font-size: 4.2em;
  }
}
