:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel-2: #262a32;
  --line: #333844;
  --text: #e8e6e1;
  --muted: #9aa0ab;
  --accent: #f2a541;
  --accent-ink: #1b1305;
  --good: #5cc98a;
  --warn: #e86a5a;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
h1, h2 { margin: 0 0 .4rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 1rem;
  background: #101216ee; backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; white-space: nowrap; font-size: 1.15rem; color: var(--text); text-decoration: none; letter-spacing: .02em; }
.brand::before { content: "♪ "; color: var(--accent); }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a {
  color: var(--muted); text-decoration: none; padding: .35rem .7rem; border-radius: 999px;
}
.nav a.active, .nav a:hover { color: var(--text); background: var(--panel-2); }

.view { max-width: 1200px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem;
}
.panel > summary, details > summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: .6rem; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }

/* controls */
button, .button, input, select, textarea {
  font: inherit; color: var(--text);
}
button, .button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: .45rem .85rem; cursor: pointer; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.ghost { background: transparent; }
button.small { padding: .25rem .55rem; font-size: .85rem; }
button.big { padding: .6rem 1.2rem; font-size: 1.05rem; min-width: 7rem; }
button.danger { color: var(--warn); }
input[type=search], input:not([type]), input[type=number], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem;
}
input[type=number] { width: 4.5rem; }
input[type=range] { accent-color: var(--accent); }
textarea { width: 100%; font-family: var(--mono); font-size: 13px; resize: vertical; }
label { display: inline-flex; gap: .35rem; align-items: center; color: var(--muted); }
.toggle { cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); width: 1rem; height: 1rem; }
.pill { background: var(--panel-2); border-radius: 999px; padding: .15rem .6rem; font-variant-numeric: tabular-nums; min-width: 3.5rem; text-align: center; }

/* library */
.find form input { flex: 1 1 220px; }
.drop-zone {
  margin: .8rem 0; padding: 1rem; border: 2px dashed var(--line); border-radius: var(--radius);
  text-align: center; color: var(--muted);
}
.drop-zone.over { border-color: var(--accent); color: var(--text); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.card {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; display: grid; gap: .35rem; cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card .title { font-weight: 700; }
.card .meta { font-size: .85rem; color: var(--muted); display: flex; gap: .5rem; flex-wrap: wrap; }
.badge { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; padding: .05rem .4rem; border-radius: 4px; background: var(--bg); color: var(--accent); }
.card .actions { display: flex; gap: .3rem; justify-content: flex-end; }
.empty { color: var(--muted); padding: 1rem 0; }

/* player */
/* The player fills the window: a one-line title, the score, and the play bar docked at
   the bottom (its height is measured into --dock-h by player.js). */
.player-view {
  max-width: none; display: flex; flex-direction: column; gap: .5rem;
  height: calc(var(--vvh, 100svh) - var(--top-h, 52px)); padding-bottom: calc(var(--dock-h, 110px) + .5rem);
}
/* The player never scrolls the page: only the score scrolls, so the bar can't slide away. */
body.in-player { overflow: hidden; }
.player-head { display: flex; gap: .3rem 1rem; flex-wrap: wrap; align-items: baseline; }
.player-head h1 { margin: 0; font-size: 1.25rem; }
.player-head > div { flex-basis: 100%; }
/* --vv-bottom: browser UI (phone toolbars, on-screen keyboard) over the bottom of the page.
   --lift: room kept free under the controls for the Windows taskbar or a phone's home bar. */
.playdock { position: fixed; left: 0; right: 0; bottom: var(--vv-bottom, 0px); z-index: 25; }
.playbar {
  --pb: .5rem;
  background: #101216f2; backdrop-filter: blur(6px); border-top: 1px solid var(--line);
  padding: 0 1rem calc(var(--pb) + env(safe-area-inset-bottom, 0px) + var(--lift, 0px));
}
.playbar-row { display: flex; gap: .4rem .7rem; align-items: center; flex-wrap: wrap; }
.playbar .big { min-width: 6rem; padding: .5rem 1rem; }
.playbar .toggle { font-size: .9rem; }
.playbar-end { margin-left: auto; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
#pl-track { max-width: 15rem; }
.sheet-btns { display: flex; gap: .25rem; }
.sheet-btns button.on { background: var(--panel-2); border-color: var(--accent); color: var(--accent); }
.sheet-btns button.live::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: .35rem; border-radius: 50%; background: var(--good); vertical-align: middle; }
/* Song position: a thin full-width bar on top of the play bar. */
.seek { display: block; width: calc(100% + 2rem); margin: -1px -1rem .45rem; height: 6px; cursor: pointer; accent-color: var(--accent); }
.chord-now {
  display: flex; align-items: baseline; gap: .45rem; padding: .15rem .7rem; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); min-width: 5.5rem;
}
.chord-now b { font-size: 1.25rem; color: var(--accent); }
.chord-now span:not(:empty)::before { content: "→ "; }
.sheets { position: absolute; left: 0; right: 0; bottom: 100%; display: flex; justify-content: center; pointer-events: none; }
.sheet {
  pointer-events: auto; width: min(1100px, calc(100% - 1rem)); max-height: min(65vh, 640px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0;
  padding: .8rem 1rem 1rem; box-shadow: 0 -10px 30px #0008;
}
.sheet > .row { margin: .5rem 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; position: sticky; top: -.8rem; background: var(--panel); padding: .2rem 0; z-index: 1; }
.sheet-head h2 { margin: 0; }
.speed { display: flex; gap: .3rem; align-items: center; }
.speed input { width: 90px; }
#tr-status:empty { display: none; }
.trainer input[type=number] { width: 4rem; }
.mixer-row { display: flex; gap: .6rem; align-items: center; padding: .25rem 0; border-bottom: 1px solid var(--line); }
.mixer-row .name { flex: 1; }
.mixer-row button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.loading { color: var(--muted); padding: 1rem; text-align: center; }
.score-scroll {
  background: #fbfaf7; color: #111; border-radius: var(--radius);
  overflow: auto; flex: 1 1 auto; min-height: 100px;
}
#alphatab { min-height: 200px; }
/* alphaTab cursor & selection colors */
.at-cursor-bar { background: rgba(242, 165, 65, .18); }
.at-selection div { background: rgba(242, 165, 65, .28); }
.at-cursor-beat { background: #e07b00; width: 3px; }
.at-highlight * { fill: #d0570b; stroke: #d0570b; }

/* text tab */
.text-tab {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin: 0; overflow-x: auto; font-family: var(--mono); font-size: 15px; line-height: 1.35;
  white-space: pre;
}
.text-tab .tab-line { color: #e9dfc9; }
.text-tab .section { color: var(--accent); font-weight: 700; }
.text-tab .chord { color: #7cc4ff; font-weight: 700; }

/* metronome */
.metro { display: grid; gap: .8rem; justify-items: start; }
.bpm-display { font-size: 3.5rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.bpm-display small { font-size: 1rem; color: var(--muted); margin-left: .4rem; }
#mt-bpm { width: 260px; }
.dots { display: flex; gap: .6rem; }
.dot { width: 22px; height: 22px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); transition: background .05s; }
.dot.accent { border-color: var(--accent); }
.dot.hit { background: var(--accent); }

/* tuner */
.tuner { display: grid; justify-items: center; gap: .3rem; padding: 1rem 0; }
.tn-note { font-size: 4rem; font-weight: 800; line-height: 1; }
.tn-note.in-tune { color: var(--good); }
.meter { position: relative; width: min(420px, 90%); height: 34px; background: linear-gradient(90deg, var(--warn), var(--accent) 35%, var(--good) 50%, var(--accent) 65%, var(--warn)); border-radius: 6px; opacity: .85; }
.meter-mid { position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; background: var(--text); }
.needle { position: absolute; left: 50%; top: -8px; bottom: -8px; width: 4px; margin-left: -2px; background: #fff; border-radius: 2px; box-shadow: 0 0 6px #000; transition: left .08s linear; }

/* log */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stat b { display: block; font-size: 1.8rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.log-row { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.log-row:last-child { border-bottom: 0; }
.log-day { margin-top: .8rem; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }

/* dialog / toast */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(800px, 94vw); padding: 1rem;
}
dialog::backdrop { background: #000a; }
dialog form { display: grid; gap: .7rem; }
dialog .row input { flex: 1 1 200px; }
.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: .6rem 1rem; border-radius: 8px; z-index: 50;
}

@media (max-width: 640px) {
  .view { padding: .6rem; }
  .playbar { --pb: .4rem; padding-left: .5rem; padding-right: .5rem; }
  .seek { width: calc(100% + 1rem); margin: -1px -.5rem .4rem; }
  .playbar .toggle, #pl-clear-sel, #pl-bpm { font-size: .8rem; }
  .playbar-end { margin-left: 0; width: 100%; flex-wrap: nowrap; gap: .3rem; }
  #pl-track { flex: 1 1 5rem; min-width: 0; max-width: none; }
  /* Keep the bar to three short rows on a phone: no speed slider (− and + still work). */
  .speed input { display: none; }
  .playbar .big { min-width: 4.5rem; padding: .4rem .8rem; }
  .sheet-btns { gap: .15rem; }
  .sheet-btns button { padding: .3rem .4rem; font-size: .8rem; }
  /* .view's smaller padding above must not eat the room kept for the play bar. */
  .view.player-view { padding-bottom: calc(var(--dock-h, 110px) + .4rem); }
  /* One-line top bar in the player: the menu scrolls sideways instead of wrapping. */
  .in-player .topbar { flex-wrap: nowrap; gap: .8rem; padding: .4rem .6rem; }
  .in-player .nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .in-player .nav a { white-space: nowrap; padding: .3rem .55rem; }
}

/* Scale diagram */
.view > * { min-width: 0; }
.fretboard { overflow-x: auto; margin: 12px 0 4px; }
.fretboard svg { display: block; min-width: 760px; width: 100%; height: auto; }
.fb-window { fill: var(--accent); opacity: 0.08; rx: 6; }
.fb-fret { stroke: #5b616c; stroke-width: 1.5; }
.fb-nut { stroke: #d9dce1; stroke-width: 5; }
.fb-string { stroke: #9aa0aa; }
.fb-inlay { fill: #2c3038; }
.fb-num { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.fb-dot circle { fill: #3a3f48; }
.fb-dot.root circle { fill: #6b4f2a; }
.fb-dot.on circle { fill: #e8eaed; }
.fb-dot.on.root circle { fill: var(--accent); }
.fb-dot text { fill: #14161a; font: 600 11px system-ui, sans-serif; text-anchor: middle; }
button.primary.danger { background: var(--warn); border-color: var(--warn); color: #fff; }

/* Keep alphaTab's cursor layers below the sticky top bar. */
.score-scroll { isolation: isolate; }
.small-text { font-size: .85rem; }
kbd { font: .78rem var(--mono); padding: 0 .35em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--panel-2); color: var(--text); }
.keys-hint { margin: .6rem 0 0; line-height: 1.9; }

/* amp simulator */
.amp-on:empty { display: none; }
.amp-on { background: var(--good); color: #0b1f13; font-size: .75rem; font-weight: 700; margin-left: .4rem; }
.amp-warn { border-left: 3px solid var(--accent); background: var(--panel-2); padding: .5rem .7rem; border-radius: 6px; margin: 0 0 .6rem; font-size: .9rem; }
.amp-error { color: var(--warn); margin: 0; }
.amp-error:empty { display: none; }
.amp-meter { width: min(260px, 60vw); height: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.amp-meter-bar { height: 100%; width: 0; background: var(--good); transition: width .05s linear; }
.amp-meter-bar.hot { background: var(--accent); }
.amp-meter-bar.clip { background: var(--warn); }
.amp-knobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .3rem 1.2rem; margin: .6rem 0; }
.amp-knob { display: grid; grid-template-columns: 4.6rem 1fr 3.9rem; gap: .4rem; align-items: center; }
.amp-knob input { width: 100%; min-width: 0; }
.amp-knob-val { font-size: .8rem; color: var(--text); text-align: right; }
.amp-playalong { border-top: 1px solid var(--line); padding-top: .6rem; }
.amp-playalong input[type=range] { width: 140px; }
#amp-dialog { width: min(420px, 94vw); }
#amp-dialog input { width: 100%; }
.amp-top { margin-left: auto; border-color: var(--good); color: var(--good); }

/* Singing mode: live pitch readout in the play bar and the score in the Sing sheet. */
.sing-now {
  display: flex; align-items: center; gap: .45rem; padding: .15rem .6rem; border-radius: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); transition: border-color .1s;
}
.sing-lane { width: 140px; height: 34px; display: block; background: var(--bg); border-radius: 5px; }
.sing-now b { font-size: 1.15rem; min-width: 2.4rem; }
#sg-state { min-width: 5.5rem; font-weight: 700; color: var(--muted); }
.sing-now[data-status=in] { border-color: var(--good); }
.sing-now[data-status=in] #sg-state, .sing-now[data-status=in] b { color: var(--good); }
.sing-now[data-status=flat] { border-color: var(--accent); }
.sing-now[data-status=flat] #sg-state { color: var(--accent); }
.sing-now[data-status=sharp] { border-color: var(--warn); }
.sing-now[data-status=sharp] #sg-state { color: var(--warn); }
.sing-result { background: var(--panel-2); border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0; }
.sing-result b { font-size: 2rem; color: var(--good); }
.sing-result p { margin: .3rem 0; }
.sing-result .row { justify-content: space-between; }

/* chords & keys */
.cof-layout { display: grid; grid-template-columns: minmax(260px, 380px) 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 760px) { .cof-layout { grid-template-columns: 1fr; } .cof { max-width: 380px; margin: 0 auto; width: 100%; } }
.cof svg { width: 100%; height: auto; display: block; }
.cof-key { cursor: pointer; outline: none; }
.cof-key path { fill: var(--panel-2); stroke: var(--bg); stroke-width: 2; transition: fill .15s; }
.cof-key.minor path { fill: #20242b; }
.cof-key.near path { fill: #3a3326; }
.cof-key:hover path, .cof-key:focus-visible path { fill: #4a4030; }
.cof-key.active path { fill: var(--accent); }
.cof-key text { fill: var(--text); font: 700 15px system-ui, sans-serif; text-anchor: middle; pointer-events: none; }
.cof-key.minor text { font-size: 12.5px; font-weight: 600; }
.cof-key text.alt { font-size: 10px; font-weight: 500; fill: var(--muted); }
.cof-key.active text { fill: var(--accent-ink); }
.cof-sig { fill: var(--muted); font: 10px system-ui, sans-serif; text-anchor: middle; }
.key-info h3 { margin: 0 0 .3rem; font-size: 1.15rem; }
.key-info p { margin: .3rem 0 .6rem; }
.degree-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .3rem; margin: .4rem 0 .6rem; }
.degree { display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .35rem .1rem; min-width: 0; }
.degree .roman { font-size: .75rem; color: var(--accent); font-family: Georgia, serif; }
.degree b { font-size: .95rem; white-space: nowrap; }
.degree.active { border-color: var(--accent); background: #3a3326; }
@media (max-width: 480px) { .degree-row { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.key-chord { display: flex; gap: .75rem; align-items: center; margin-bottom: .5rem; }
.key-chord p { margin: 0; }
.key-info input[type=number] { width: 4.5em; }
.progressions { list-style: none; padding: 0; margin: .3rem 0 0; display: grid; gap: .35rem; }
.progressions li { display: flex; gap: .6rem; align-items: center; }
.prog-chord { display: inline-block; padding: 0 .25rem; border-radius: 4px; font-weight: 600; }
.prog-chord.on { background: var(--accent); color: var(--accent-ink); }
.chord-grid { display: flex; flex-wrap: wrap; gap: .6rem; }
.chord-card { display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .3rem .4rem .45rem; background: var(--panel-2); }
.chord-box { width: 110px; height: auto; display: block; }
.cb-title { fill: var(--text); font: 700 13px system-ui, sans-serif; text-anchor: middle; }
.cb-nut { stroke: #d9dce1; stroke-width: 4; }
.cb-fret { stroke: #5b616c; stroke-width: 1.2; }
.cb-string { stroke: #9aa0aa; stroke-width: 1; }
.cb-start { fill: var(--muted); font: 11px system-ui, sans-serif; text-anchor: end; }
.cb-mark { fill: var(--muted); font: 12px system-ui, sans-serif; text-anchor: middle; }
.cb-open { fill: none; stroke: #e8eaed; stroke-width: 1.5; }
.cb-open.root { stroke: var(--accent); }
.cb-barre { fill: #e8eaed; opacity: .35; }
.cb-dot circle { fill: #e8eaed; }
.cb-dot.root circle { fill: var(--accent); }
.cb-dot text { fill: #14161a; font: 700 8.5px system-ui, sans-serif; text-anchor: middle; }
.drill-shapes { display: flex; align-items: center; gap: .75rem; margin: .6rem 0; }
.drill-arrow { font-size: 1.5rem; color: var(--muted); }
.drill-chord { border-radius: var(--radius); outline: 3px solid transparent; transition: outline-color .1s; }
.drill-chord.now { outline-color: var(--accent); }
.drill-status { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.note-buttons { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.note-buttons button { min-width: 3.2rem; font-weight: 700; }
.note-buttons button.right { background: var(--good); border-color: var(--good); color: #0c1a12; }
.note-buttons button.wrong { background: var(--warn); border-color: var(--warn); color: #fff; }
#fn-strings label { white-space: nowrap; }
