:root {
  --bg: #0b0d10;
  --panel: #141820;
  --panel-2: #1a2030;
  --line: #2a3344;
  --text: #e8eef8;
  --muted: #8b97ab;
  --accent: #5b9dff;
  --good: #3dd68c;
  --warn: #f0b429;
  --bad: #ff6b6b;
  --target: #ffd166;
  --ghost: #c084fc;
  --radius: 10px;
  --font: "SF Pro Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --pad: clamp(4px, 0.9vh, 10px);
  --gap: clamp(4px, 0.8vh, 8px);
  --rail-w: clamp(260px, 24vw, 340px);
  --hud-w: clamp(220px, 22vw, 300px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%;
  height: 100%; height: 100dvh;
  overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}
#app {
  height: 100dvh; max-height: 100dvh; width: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--gap);
  padding: calc(var(--pad) + var(--safe-t)) calc(var(--pad) + var(--safe-r)) calc(var(--pad) + var(--safe-b)) calc(var(--pad) + var(--safe-l));
  transition: background-color 0.12s ease;
}
/* Strong wash on whole app */
#app[data-wash="green"] {
  background: color-mix(in srgb, var(--good) 32%, var(--bg));
}
#app[data-wash="amber"] {
  background: color-mix(in srgb, var(--warn) 34%, var(--bg));
}
#app[data-wash="red"] {
  background: color-mix(in srgb, var(--bad) 30%, var(--bg));
}

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex-shrink: 0;
}
.brand-row { display: flex; align-items: center; gap: 6px; }
.brand-row h1 { margin: 0; font-size: clamp(0.95rem, 2vw, 1.2rem); letter-spacing: -0.02em; }
.status-pill {
  padding: 3px 8px; border-radius: 999px; background: var(--panel);
  border: 1px solid var(--line); font-weight: 600; font-size: 0.72rem; white-space: nowrap;
}
.status-pill[data-state="on"] { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, transparent); }
.status-pill[data-state="err"] { color: var(--bad); }

.tabs { display: flex; gap: 3px; flex: 1; justify-content: center; min-width: 0; }
.tab {
  padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font-weight: 600;
  font-size: clamp(0.72rem, 1.4vw, 0.88rem); cursor: pointer; min-height: 32px;
}
.tab.active { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); }

.actions { display: flex; gap: 4px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font: inherit; font-size: clamp(0.72rem, 1.4vw, 0.88rem); font-weight: 600;
  padding: 5px 10px; border-radius: 8px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; min-height: 32px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #061018; }
.btn.danger { background: #3a1518; border-color: var(--bad); color: #ffb4b4; }
.btn.ghost { background: transparent; }
.btn.tiny { min-height: 26px; padding: 3px 8px; font-size: 0.72rem; }
.btn.hidden, .hidden { display: none !important; }
.file-btn { cursor: pointer; }

/* progress | canvas | hud */
.workspace {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--hud-w);
  gap: var(--gap);
  min-height: 0; overflow: hidden;
}

.progress-rail {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; min-width: 0; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: 6px;
}
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.rail-head strong { font-size: 0.85rem; }
.rail-actions { display: flex; gap: 3px; }
.export-tip { margin: 0; font-size: 0.65rem; color: var(--muted); line-height: 1.25; }
.pb-row { display: flex; flex-wrap: wrap; gap: 4px; }
.pb {
  flex: 1 1 45%; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 6px; font-size: 0.68rem;
}
.pb b { display: block; font-size: 0.9rem; font-family: var(--mono); }
.pb .trend { color: var(--accent); }
.charts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  flex: 0 0 auto; max-height: 38%; overflow: hidden;
}
.chart {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 6px; min-height: 0;
}
.chart .label { font-size: 0.65rem; color: var(--muted); display: flex; justify-content: space-between; }
.chart canvas { width: 100%; height: 52px; display: block; }
.board-title { font-size: 0.7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.hold-board, .history-list-wrap {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 6px; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 3px;
}
.hold-board { flex: 0 0 auto; max-height: 22%; }
.history-list-wrap { flex: 1 1 auto; min-height: 0; }
.board-list, .history-list {
  overflow: auto; display: flex; flex-direction: column; gap: 3px; min-height: 0; flex: 1;
}
.board-row, .hist-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 4px; align-items: center;
  font-size: 0.7rem; padding: 3px 4px; border-radius: 4px; background: #121722;
}
.board-row b, .hist-row b { font-family: var(--mono); }
.hist-row .del {
  border: 1px solid var(--line); background: transparent; color: var(--bad);
  border-radius: 4px; font-size: 0.65rem; padding: 2px 6px; cursor: pointer; font-weight: 700;
}
.rail-foot { margin: 0; font-size: 0.6rem; color: var(--muted); line-height: 1.25; flex-shrink: 0; }

.canvas-wrap {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; min-width: 0; min-height: 0; height: 100%;
}
#pitchCanvas { display: block; width: 100%; height: 100%; touch-action: none; position: relative; z-index: 2; }
.wash {
  pointer-events: none; position: absolute; inset: 0; opacity: 0; z-index: 1;
  transition: opacity 0.1s ease, background 0.1s ease;
}
#app[data-wash="green"] .wash {
  opacity: 0.55;
  background: radial-gradient(ellipse at 85% 50%, rgba(61,214,140,0.85), rgba(61,214,140,0.25) 45%, transparent 75%);
}
#app[data-wash="amber"] .wash {
  opacity: 0.55;
  background: radial-gradient(ellipse at 85% 50%, rgba(240,180,41,0.9), rgba(240,180,41,0.28) 45%, transparent 75%);
}
#app[data-wash="red"] .wash {
  opacity: 0.55;
  background: radial-gradient(ellipse at 85% 50%, rgba(255,107,107,0.9), rgba(255,107,107,0.28) 45%, transparent 75%);
}
.glow-border {
  pointer-events: none; position: absolute; inset: 0; z-index: 3; border-radius: var(--radius);
  box-shadow: inset 0 0 0 0 transparent; transition: box-shadow 0.12s ease;
}
#app[data-wash="green"] .glow-border {
  box-shadow: inset 0 0 0 3px rgba(61,214,140,0.95), inset 0 0 28px rgba(61,214,140,0.45);
}
#app[data-wash="amber"] .glow-border {
  box-shadow: inset 0 0 0 3px rgba(240,180,41,0.95), inset 0 0 28px rgba(240,180,41,0.45);
}
#app[data-wash="red"] .glow-border {
  box-shadow: inset 0 0 0 3px rgba(255,107,107,0.95), inset 0 0 28px rgba(255,107,107,0.45);
}

.hold-timer {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 5; text-align: center; pointer-events: none;
  background: rgba(10,14,20,0.72); border: 2px solid var(--good); border-radius: 12px;
  padding: 8px 18px; min-width: 120px;
  box-shadow: 0 0 24px rgba(61,214,140,0.35);
}
.hold-timer-label { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.12em; color: var(--good); }
.hold-timer-val {
  font-size: clamp(2.2rem, 8vh, 3.6rem); font-weight: 800; font-family: var(--mono);
  line-height: 1; color: var(--text);
}
.hold-timer-unit { font-size: 0.75rem; color: var(--muted); }

.new-record {
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center;
  pointer-events: none; font-size: clamp(2rem, 6vw, 3.5rem); font-weight: 900;
  letter-spacing: 0.04em; color: #fff;
  text-shadow: 0 0 20px rgba(61,214,140,0.9), 0 0 40px rgba(255,209,102,0.7);
  animation: recordPop 1.6s ease forwards;
  background: radial-gradient(circle, rgba(61,214,140,0.35), transparent 60%);
}
@keyframes recordPop {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.12); }
  40% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.loud-curve {
  position: absolute; left: 48px; right: 8px; bottom: 8px; height: 48px; z-index: 4;
  background: color-mix(in srgb, var(--panel) 70%, transparent); border-radius: 6px; border: 1px solid var(--line);
}
.loud-curve canvas { width: 100%; height: 100%; display: block; }

.hud {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; min-width: 0; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: 6px;
}
.coach-banner {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
.arrow {
  width: 28px; height: 28px; border-radius: 6px; background: #222938;
  display: grid; place-items: center; font-size: 1.1rem; font-weight: 800; color: var(--muted);
}
.arrow[data-dir="up"]::before { content: "↑"; color: var(--good); }
.arrow[data-dir="down"]::before { content: "↓"; color: var(--warn); }
.arrow[data-dir="none"]::before { content: "·"; }
.cue {
  font-size: clamp(0.95rem, 2.2vh, 1.25rem); font-weight: 700; line-height: 1.15;
}
.readout { text-align: center; }
.note-big {
  font-size: clamp(2rem, 7vh, 3.8rem); font-weight: 700; letter-spacing: -0.04em;
  line-height: 0.95; font-variant-numeric: tabular-nums;
}
.note-big.in-tune { color: var(--good); }
.note-big.near { color: var(--warn); }
.note-big.off { color: var(--bad); }
.note-big.quiet { color: var(--muted); }
.cents-row { display: flex; justify-content: center; gap: 8px; align-items: baseline; }
.cents { font-size: clamp(1rem, 2.8vh, 1.5rem); font-family: var(--mono); font-weight: 600; }
.hz { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; }

.meters { display: grid; gap: 4px; }
.meter { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.meter-label { color: var(--muted); font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.05em; }
.meter-track { height: 7px; background: #0f131a; border-radius: 999px; overflow: hidden; border: 1px solid var(--line); margin-top: 2px; }
.meter-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--bad), var(--warn), var(--good)); }
.meter-val { margin-top: 2px; font-family: var(--mono); font-size: 0.72rem; }
.meter-val.big { font-size: clamp(0.85rem, 2vh, 1.1rem); font-weight: 700; margin: 0; }
.meter-compact { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.vib-gauge .gauge-track {
  position: relative; height: 10px; background: #0f131a; border-radius: 999px; border: 1px solid var(--line); margin-top: 3px;
}
.vib-gauge .gauge-zone {
  position: absolute; left: 25%; width: 40%; top: 0; bottom: 0;
  background: color-mix(in srgb, var(--good) 35%, transparent); border-radius: 999px;
}
.vib-gauge .gauge-needle {
  position: absolute; top: -2px; width: 3px; height: 14px; background: var(--target);
  border-radius: 2px; left: 0%; transform: translateX(-50%);
}
.run-status {
  text-align: center; font-weight: 700; font-size: 0.85rem;
  color: var(--accent); background: var(--panel-2); border-radius: 6px; padding: 4px;
}

.tab-panels { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.panel { display: none; flex-direction: column; gap: 6px; min-height: 0; overflow: auto; }
.panel.active { display: flex; }
.how { margin: 0; font-size: 0.72rem; color: var(--muted); line-height: 1.3; }
.field { display: flex; flex-direction: column; gap: 2px; font-size: 0.65rem; color: var(--muted); min-width: 0; }
.field select {
  font: inherit; font-size: 0.88rem; font-weight: 600; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 6px; min-height: 30px; width: 100%;
}
.field.toggle {
  flex-direction: row; align-items: center; justify-content: space-between; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 6px; min-height: 30px;
}
.field.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch {
  width: 34px; height: 18px; border-radius: 999px; background: #2a3140; border: 1px solid var(--line); position: relative; flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; top: 1px; left: 1px; width: 14px; height: 14px; border-radius: 50%; background: #c8d0de;
  transition: transform 0.15s ease;
}
.field.toggle input:checked + .switch { background: color-mix(in srgb, var(--good) 45%, #1a2030); border-color: var(--good); }
.field.toggle input:checked + .switch::after { transform: translateX(14px); background: var(--good); }
.quick-controls, .settings-inline { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-items: end; }
.param-row { display: flex; flex-wrap: wrap; gap: 4px; }
.param-row .field { flex: 1 1 40%; }
.row-btns { display: flex; flex-wrap: wrap; gap: 4px; }
.score-line { font-family: var(--mono); font-size: 0.75rem; color: var(--text); }
.scale-progress { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.scale-steps { display: flex; gap: 3px; }
.scale-step {
  flex: 1; text-align: center; padding: 4px 2px; border-radius: 5px; border: 1px solid var(--line);
  font-weight: 700; font-size: 0.72rem; color: var(--muted);
}
.scale-step.current { border-color: var(--target); color: var(--target); }
.scale-step.done { border-color: var(--good); color: var(--good); }
.takes-list { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.take-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
  font-size: 0.72rem;
}
.take-item input { width: 100%; background: transparent; border: none; color: var(--text); font: inherit; font-weight: 600; }
.take-actions { display: flex; gap: 3px; }
.hud-tip {
  margin: 0; font-size: 0.62rem; color: var(--muted); line-height: 1.3; flex-shrink: 0;
}

.undo-toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); font-size: 0.85rem;
}

@media (max-height: 860px) {
  .hz { display: none; }
  .rail-foot { display: none; }
  .chart canvas { height: 40px; }
  .export-tip { display: none; }
}
@media (max-height: 720px) {
  .meter-val:not(.big) { display: none; }
  .hud-tip { display: none; }
}

/* Phone / narrow: stack progress below canvas+hud */
@media (max-width: 960px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 240px);
    grid-template-rows: minmax(0, 1fr) minmax(140px, 32%);
  }
  .progress-rail {
    grid-column: 1 / -1;
    grid-row: 2;
    max-height: 100%;
  }
  .canvas-wrap { grid-column: 1; grid-row: 1; }
  .hud { grid-column: 2; grid-row: 1; }
  .charts { grid-template-columns: 1fr 1fr 1fr 1fr; max-height: none; }
  .chart canvas { height: 36px; }
  .hold-board, .history-list-wrap { max-height: none; }
  .actions .btn { font-size: 0.7rem; padding: 5px 7px; }
}

@media (max-width: 600px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) minmax(160px, 34%);
  }
  .hud { grid-column: 1; grid-row: 1; max-height: 34%; flex-direction: row; flex-wrap: wrap; }
  .canvas-wrap { grid-column: 1; grid-row: 2; }
  .progress-rail { grid-column: 1; grid-row: 3; }
  .tabs { order: 3; flex: 1 1 100%; }
  .tab { flex: 1; padding: 5px 4px; font-size: 0.7rem; }
  .coach-banner { flex: 1 1 120px; }
  .readout { display: flex; align-items: baseline; gap: 8px; text-align: left; }
  .note-big { font-size: clamp(1.5rem, 6vw, 2.2rem); }
  .meters { display: flex; flex: 1 1 160px; gap: 4px; }
  .meter { flex: 1; }
  .tab-panels { flex: 1 1 100%; }
  .settings-inline { grid-template-columns: 1fr 1fr; }
  .btn { font-size: 0.68rem; }
}

.signature {
  margin: 0; font-size: clamp(0.85rem, 2vh, 1.05rem); font-weight: 700;
  color: var(--ghost); line-height: 1.25; font-style: italic;
}
.trait-cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  min-height: 0; overflow: auto; flex: 1;
}
.trait {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.trait canvas { width: 100%; height: 28px; display: block; }
.trait .t-label { font-size: 0.68rem; font-weight: 700; }
.trait .t-words { font-size: 0.62rem; color: var(--muted); line-height: 1.25; flex: 1; }
.trait .btn { width: 100%; }

.recap-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 70;
}
.recap-card {
  position: fixed; z-index: 80; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: min(560px, calc(100vw - 20px)); max-height: min(88dvh, 640px);
  overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  display: flex; flex-direction: column; gap: 10px;
}
.recap-head { display: flex; align-items: center; justify-content: space-between; }
.recap-head h2 { margin: 0; font-size: 1.2rem; }
.recap-vs { margin: 0; font-size: 0.9rem; color: var(--muted); line-height: 1.35; }
.recap-metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.recap-metric {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
.recap-metric .k { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; }
.recap-metric .v { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; }
.recap-metric .d { font-size: 0.7rem; color: var(--ghost); margin-top: 2px; }
#recapCanvas {
  width: 100%; height: auto; background: #0f131a; border-radius: 8px; border: 1px solid var(--line);
}
.recap-fix {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-2));
  border: 1px solid var(--accent); border-radius: 8px; padding: 8px 10px;
  font-size: 0.9rem; font-weight: 600; line-height: 1.35;
}
.take-item { display: grid; grid-template-columns: 1fr auto; gap: 4px; align-items: center; }
.take-meta { font-size: 0.65rem; color: var(--muted); font-family: var(--mono); }
.hist-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hist-main span { color: var(--muted); font-size: 0.62rem; }
.board-del { border: 1px solid var(--line); background: transparent; color: var(--bad);
  border-radius: 4px; font-size: 0.65rem; padding: 2px 6px; cursor: pointer; font-weight: 700; }
