:root {
  --bg: #0b1220;
  --bg2: #0f172a;
  --card: #131c31;
  --card2: #1a2540;
  --line: #24314f;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --dim: #64748b;
  --accent: #38bdf8;
  --accent2: #0284c7;
  --ok: #22c55e;
  --warn: #facc15;
  --bad: #f43f5e;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ---------- En-tête ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: linear-gradient(180deg, #0b1220 70%, rgba(11,18,32,0.85));
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .02em; color: var(--accent); font-size: 1.05rem; margin-bottom: 10px; }
.logo { width: 22px; height: 22px; border-radius: 7px; background: conic-gradient(from 200deg, #38bdf8, #a78bfa, #f472b6, #facc15, #38bdf8); box-shadow: 0 0 12px rgba(56,189,248,.45); }
.inst-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--bg2); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.inst-tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 0; border-radius: 9px; padding: 7px 2px; color: var(--muted); font-size: .76rem; font-weight: 600;
}
.inst-tabs button svg { width: 22px; height: 22px; }
.inst-tabs button.on { background: var(--accent2); color: #fff; }

main { flex: 1; padding: 12px 12px calc(84px + var(--safe-b)); max-width: 980px; width: 100%; margin: 0 auto; }

/* ---------- Navigation basse ---------- */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(11,18,32,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + var(--safe-b));
}
.bottom button { background: none; border: 0; color: var(--dim); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; padding: 4px 0; }
.bottom button svg { width: 23px; height: 23px; }
.bottom button.on { color: var(--accent); }

/* ---------- Éléments communs ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h3 { font-size: .95rem; margin-bottom: 10px; color: #f1f5f9; }
.hint { color: var(--muted); font-size: .82rem; margin: 6px 0; }
.row { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.row.center { justify-content: center; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent2); color: #fff; border: 0; border-radius: 11px;
  padding: 11px 16px; font-weight: 700; min-height: 44px;
}
.btn.ghost { background: var(--card2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: #3b0d18; color: #fecdd3; border: 1px solid #7f1d1d; }
.btn svg { width: 18px; height: 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 8px 12px; font-size: .82rem; font-weight: 600; white-space: nowrap;
}
.chip svg { width: 17px; height: 17px; }
.chip.on { color: #dcfce7; background: #12351f; border-color: #166534; }
.chip.chip-accent { color: #e0f2fe; background: #0c3a57; border-color: #0369a1; }
.chip.sm { padding: 5px 9px; font-size: .74rem; }
.inputs-strip { display: flex; gap: 8px; flex-wrap: wrap; padding-bottom: 4px; }
select, input[type=text], input[type=number] {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; width: 100%; min-height: 42px;
}
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; }
.form label { display: block; margin: 10px 0; font-size: .88rem; color: var(--text); }
.form label > select, .form label > input { margin-top: 6px; }
.switch { display: flex !important; gap: 10px; align-items: flex-start; font-size: .86rem; margin: 10px 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; margin-top: 1px; }

/* ---------- Bibliothèque ---------- */
.lib-group { margin-top: 14px; }
.lib-group h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin: 0 4px 8px; }
.song {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 12px; margin-bottom: 8px; color: var(--text);
}
.song:active { background: var(--card2); }
.song .sbody { flex: 1; min-width: 0; }
.song .stitle { font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song .smeta { color: var(--muted); font-size: .78rem; }
.song .sbest { text-align: right; font-size: .75rem; color: var(--muted); }
.mini-stars { display: flex; gap: 1px; justify-content: flex-end; color: #334155; }
.mini-stars svg { width: 15px; height: 15px; }
.mini-stars .lit { color: var(--warn); }
.song .del { background: none; border: 0; color: var(--dim); padding: 8px; }
.lvl { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .7rem; font-weight: 700; margin-right: 4px; }
.lvl1 { background: #12351f; color: #86efac; }
.lvl2 { background: #3a2a07; color: #fcd34d; }
.lvl0 { background: #0c3a57; color: #7dd3fc; }

/* ---------- Entraînement ---------- */
.practice {
  position: fixed; inset: 0; z-index: 20; background: #070b14;
  display: flex; flex-direction: column;
  padding: var(--safe-t) 0 var(--safe-b);
}
.pr-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--bg); }
.pr-title { flex: 1; min-width: 0; }
.pr-title b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.pr-title small { color: var(--muted); font-size: .74rem; }
.pr-stats { display: flex; gap: 12px; text-align: center; }
.pr-stats small { display: block; color: var(--dim); font-size: .64rem; text-transform: uppercase; letter-spacing: .04em; }
.pr-stats b { font-size: .95rem; font-variant-numeric: tabular-nums; }
.pr-stage { position: relative; flex: 1; min-height: 160px; }
.pr-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.flash {
  position: absolute; top: 42px; left: 50%; transform: translateX(-50%);
  font-weight: 900; font-size: 1.35rem; letter-spacing: .02em; pointer-events: none;
  opacity: 0; transition: opacity .35s; text-shadow: 0 2px 10px rgba(0,0,0,.8);
}
.flash.show { opacity: 1; transition: none; }
.pr-info { display: flex; align-items: center; gap: 14px; padding: 8px 12px; background: var(--bg); border-top: 1px solid var(--line); }
.pr-info small { display: block; color: var(--dim); font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; }
.pr-info .tgt b { color: var(--warn); font-size: 1.1rem; }
.pr-info .heard b { color: #67e8f9; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.pr-info .tgt, .pr-info .heard { min-width: 0; }
.pr-info .tgt b, .pr-info .heard b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.pr-chips { margin-left: auto; display: flex; gap: 6px; }
.pr-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px calc(8px);
  background: var(--bg); border-top: 1px solid var(--line); flex-wrap: wrap;
}
.icon { background: var(--card); border: 1px solid var(--line); color: var(--text); border-radius: 12px; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon svg { width: 22px; height: 22px; }
.icon.big { width: 52px; height: 52px; border-radius: 16px; }
.icon.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.seg { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.seg button { background: none; border: 0; color: var(--muted); padding: 7px 10px; border-radius: 8px; font-size: .8rem; font-weight: 700; }
.seg button.on { background: var(--card2); color: var(--accent); }
.speed { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 110px; font-size: .74rem; color: var(--muted); }

/* ---------- Feuilles (dialogues) ---------- */
dialog.sheet {
  margin: auto auto 0; width: 100%; max-width: 560px; max-height: 88dvh;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + var(--safe-b)); overflow-y: auto;
}
@media (min-width: 640px) { dialog.sheet { margin: auto; border-radius: 18px; } }
dialog::backdrop { background: rgba(2,6,15,.7); }
dialog h3 { margin-bottom: 10px; }
dialog label { display: block; margin: 8px 0; font-size: .88rem; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; font-size: .88rem; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); font-size: 1.2rem; }
.stepper output { min-width: 42px; text-align: center; font-weight: 700; }
.loop-in { display: flex; align-items: center; gap: 6px; }
.loop-in input { width: 64px; text-align: center; }
.parts { display: flex; flex-direction: column; gap: 6px; }
.part { display: flex !important; gap: 10px; align-items: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 0 !important; }
.part input { width: 20px; height: 20px; accent-color: var(--accent); }
.part small { color: var(--muted); display: block; }
.stars { display: flex; justify-content: center; gap: 6px; color: #334155; margin-bottom: 6px; }
.stars svg { width: 40px; height: 40px; }
.stars .lit { color: var(--warn); filter: drop-shadow(0 0 8px rgba(250,204,21,.5)); }
#resTitle { text-align: center; }
.res-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.res-grid div { background: var(--bg2); border-radius: 10px; padding: 8px; text-align: center; }
.res-grid small { display: block; color: var(--dim); font-size: .7rem; }
.res-grid b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }

/* ---------- Accordeur ---------- */
.tuner { text-align: center; }
.tn-note { font-size: 4.2rem; font-weight: 900; line-height: 1; margin: 6px 0 10px; color: var(--text); }
.tn-note small { font-size: 1.4rem; color: var(--muted); margin-left: 4px; }
.tn-note.ok { color: var(--ok); text-shadow: 0 0 24px rgba(34,197,94,.45); }
.tn-gauge { position: relative; height: 120px; overflow: hidden; margin: 0 auto; max-width: 340px; }
.tn-scale {
  position: absolute; left: 50%; bottom: -150px; width: 300px; height: 300px; margin-left: -150px; border-radius: 50%;
  background: repeating-conic-gradient(from -60deg, #475569 0 0.6deg, transparent 0.6deg 6deg);
  -webkit-mask: radial-gradient(circle, transparent 128px, #000 129px, #000 150px, transparent 151px);
          mask: radial-gradient(circle, transparent 128px, #000 129px, #000 150px, transparent 151px);
  clip-path: polygon(0 0, 100% 0, 50% 50%);
}
.tn-zone { position: absolute; left: 50%; bottom: 0; width: 34px; height: 150px; margin-left: -17px; background: linear-gradient(180deg, rgba(34,197,94,.35), transparent 40%); clip-path: polygon(0 0, 100% 0, 50% 100%); }
.tn-needle { position: absolute; left: 50%; bottom: 0; width: 3px; height: 140px; margin-left: -1.5px; background: var(--warn); border-radius: 2px; transform-origin: 50% 100%; transform: rotate(0deg); transition: transform .08s linear; }
.tn-needle.ok { background: var(--ok); }
.tn-read { color: var(--muted); margin: 8px 0; font-variant-numeric: tabular-nums; }
.tn-strings { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.tn-strings button { min-width: 48px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); font-weight: 700; }
.tn-strings button.near { border-color: var(--accent); color: var(--accent); }
.level { position: relative; height: 8px; background: var(--bg2); border-radius: 4px; margin: 10px 0 4px; overflow: hidden; }
.level-bar { height: 100%; width: 0; background: linear-gradient(90deg, #22c55e, #facc15 70%, #f43f5e); transition: width .06s; }
.level-gate { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff; left: 0; }

/* ---------- Métronome ---------- */
.metro { text-align: center; }
.bpm-row { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 4px 0 8px; }
.bpm output { display: block; font-size: 4rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.bpm small { color: var(--muted); font-weight: 700; letter-spacing: .1em; }
.round { width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--line); background: var(--card2); font-size: 1.6rem; font-weight: 700; }
.beats { display: flex; justify-content: center; gap: 10px; margin: 16px 0; min-height: 26px; }
.beats span { width: 22px; height: 22px; border-radius: 50%; background: var(--bg2); border: 2px solid var(--line); transition: background .05s; }
.beats span.acc { border-color: var(--warn); }
.beats span.lit { background: var(--accent); border-color: var(--accent); }
.beats span.acc.lit { background: var(--warn); border-color: var(--warn); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.grid2 label { font-size: .85rem; color: var(--muted); }
.grid2 select { margin-top: 4px; }

/* ---------- Progrès ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi small { color: var(--muted); font-size: .74rem; display: block; }
.kpi b { font-size: 1.45rem; font-variant-numeric: tabular-nums; }
#pgChart { width: 100%; height: 160px; display: block; }
.list-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .86rem; }
.list-row:last-child { border-bottom: 0; }
.list-row span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .r { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.version { text-align: center; margin-top: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #1e293b; color: var(--text); border: 1px solid var(--line); padding: 10px 14px; border-radius: 12px;
  font-size: .86rem; max-width: 92vw; opacity: 0; pointer-events: none; transition: all .25s; z-index: 50; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Paysage / petits écrans ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .pr-top { padding: 3px 8px; }
  .pr-title b { font-size: .85rem; }
  .pr-info { padding: 2px 10px; gap: 10px; }
  .pr-info small { display: inline; margin-right: 6px; }
  .pr-info .tgt b, .pr-info .heard b { display: inline; font-size: .95rem; }
  .pr-info .tgt, .pr-info .heard { white-space: nowrap; overflow: hidden; }
  .chip.sm { padding: 3px 8px; }
  .pr-bar { padding: 4px 8px; flex-wrap: nowrap; }
  .icon { width: 38px; height: 38px; }
  .icon.big { width: 42px; height: 42px; }
  .pr-stats small { display: none; }
}
@media (max-width: 380px) {
  .seg button { padding: 7px 7px; font-size: .74rem; }
  .pr-stats { gap: 8px; }
}
