:root {
  --bg: #14161c;
  --card: #1d2029;
  --line: #2d3140;
  --text: #eceef4;
  --muted: #9aa1b5;
  --accent: #5fd0a6;
  --accent2: #f3b562;
  --warn: #f08a7e;
  --amb: #5aa9e6;
  --amb-soft: rgba(90, 169, 230, .18);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
main { max-width: 560px; margin: 0 auto; padding: 14px 14px 40px; }
header { display: flex; align-items: baseline; gap: 10px; margin: 4px 2px 12px; }
h1 { font-size: 1.5rem; margin: 0; }
.tag { font-size: .75rem; color: var(--accent); border: 1px solid var(--accent); border-radius: 99px; padding: 1px 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: .9rem; margin: 6px 0; }
.warn { color: var(--warn); font-size: .9rem; margin: 6px 0; }
.field { display: block; }
.field > span { display: block; color: var(--muted); font-size: .85rem; margin-bottom: 4px; }
select {
  width: 100%; background: #12141a; color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; font-size: 1rem;
}
.row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.row select { width: auto; flex: 1; }
.lbl { width: 84px; color: var(--muted); font-size: .9rem; flex: none; }
.sep { color: var(--muted); }
input[type=range] { flex: 1; accent-color: var(--accent); min-width: 0; }
output { width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; color: var(--text);
  background: var(--line); border-radius: 12px; padding: 10px 16px; display: inline-block;
}
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: .9rem; }
.btn.big { width: 100%; font-size: 1.3rem; font-weight: 600; padding: 18px; background: var(--accent); color: #0c1a14; }
.btn.big.playing { background: var(--accent2); color: #2a1b04; }
.transport { margin: 0 0 12px; }

.seg { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; background: transparent; color: var(--text); border: 0; padding: 10px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--accent); color: #0c1a14; font-weight: 600; }

.switch { position: relative; display: inline-block; width: 52px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(22px); }

.status { text-align: center; }
.status-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; text-align: left; }
.phase { color: var(--muted); font-size: .95rem; min-height: 1.4em; }
.root { font-size: 1.1rem; font-weight: 700; letter-spacing: .02em; }
.root::before { content: "♪ "; color: var(--muted); font-weight: 400; }

/* Portée */
.staff { display: flex; margin: 2px 0 6px; background: #12141a; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.staff-clef { flex: none; width: 54px; border-right: 1px solid var(--line); }
.staff-view { position: relative; flex: 1; overflow: hidden; min-width: 0; }
.staff svg { display: block; overflow: hidden; }
.cursor { position: absolute; top: 4px; bottom: 4px; left: -1px; width: 2px; border-radius: 1px; background: var(--accent); opacity: .75; pointer-events: none; will-change: transform; }
.staff .sl { stroke: #6f778c; stroke-width: 1; }
.staff .bar { stroke: #9aa1b5; stroke-width: 1.2; }
.staff .bar.thick { stroke-width: 3; }
.staff .ledger { stroke: currentColor; stroke-width: 1.2; }
.staff .stem { stroke: currentColor; stroke-width: 1.2; }
.staff .flag { stroke: currentColor; stroke-width: 1.5; fill: none; }
.staff .beam { fill: var(--text); }
.staff .n { color: var(--text); }
.staff .n.cur { color: var(--accent); }
.staff .clef, .staff .ts, .staff .eight { fill: var(--text); }
.staff .ts { font-family: Georgia, "Times New Roman", serif; font-weight: 700; }
.staff .eight { font-family: Georgia, "Times New Roman", serif; }
.staff .trip { fill: var(--muted); font-style: italic; font-family: Georgia, serif; }
.beats { display: flex; justify-content: center; gap: 10px; min-height: 22px; margin-bottom: 12px; }
.beat { width: 18px; height: 18px; border-radius: 50%; background: var(--line); transition: background .06s, transform .06s; }
.beat.on { background: var(--accent); transform: scale(1.25); }
.beat.on.accent { background: var(--accent2); }

.sep-line { border: 0; border-top: 1px solid var(--line); margin: 6px 0 12px; }
.amb-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; text-align: left; }
.card-title { font-size: .8rem; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.amb-range { color: var(--amb); font-weight: 700; font-size: 1.05rem; }
.amb-warn { color: var(--warn); font-size: .8rem; margin-left: auto; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; text-align: left; }
.pill {
  appearance: none; font: inherit; font-size: .8rem; cursor: pointer;
  color: var(--amb); background: var(--amb-soft); border: 1px solid var(--amb);
  border-radius: 99px; padding: 4px 11px;
}
.pill.on { background: var(--amb); color: #0b1a26; font-weight: 600; }

/* Réglette d'ambitus (comme la carte AMBITUS de PCV3) */
.amb-area { position: relative; height: 96px; margin: 4px 2px 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.amb-track { position: absolute; left: 0; right: 0; top: 50%; height: 5px; margin-top: -2px; background: var(--line); border-radius: 3px; }
.amb-fill { position: absolute; top: 50%; height: 20px; margin-top: -10px; background: var(--amb-soft); border: 2px solid var(--amb); border-radius: 99px; }
.amb-win { position: absolute; top: 50%; height: 14px; margin-top: -7px; background: var(--amb); border-radius: 99px; transition: left .1s, width .1s; }
.handle {
  position: absolute; top: 50%; width: 30px; height: 30px; margin-top: -15px;
  background: var(--card); border: 3px solid var(--amb); border-radius: 50%; cursor: grab; touch-action: none;
}
.handle::after { content: ""; position: absolute; inset: -10px; } /* zone de toucher élargie */
.handle.drag { box-shadow: 0 0 0 6px var(--amb-soft); }
.amb-lab { position: absolute; top: 4px; width: 40px; text-align: center; color: var(--amb); font-size: .85rem; font-weight: 600; }
.amb-tick { position: absolute; top: 50%; width: 1px; height: 12px; margin-top: -6px; background: var(--muted); opacity: .5; }
.amb-tick-lab { position: absolute; bottom: 4px; width: 36px; text-align: center; color: var(--muted); font-size: .72rem; }

footer { text-align: center; margin-top: 18px; }

/* onglets Arpèges / Vaccai */
.tabs { display: flex; gap: 4px; background: #12141a; border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.tabs button { flex: 1; background: transparent; color: var(--muted); border: 0; border-radius: 9px; padding: 9px 8px; font: inherit; font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--accent); color: #0c1a14; }

/* paroles sous la portée (leçons Vaccai) */
.staff .lyr { fill: var(--text); font-style: italic; font-family: Georgia, "Times New Roman", serif; }
.staff .n.cur .lyr { fill: var(--accent); font-weight: 700; }
