/* Stem Studio — layout a corsie (controlli dello stem a sinistra, forma d'onda a destra, trasporto in basso) */
:root {
  --side: 300px;          /* larghezza dei controlli di ogni stem */
  --lane-h: 112px;        /* altezza di ogni corsia */
  --bar-h: 92px;          /* altezza della barra in basso */
  --lib-w: 280px;
  --wave-c: #4a4d57;      /* forma d'onda (grigia, come nello screenshot) */
  --teal: #2dd4bf;
}

body { grid-template-columns: var(--lib-w) 1fr; transition: grid-template-columns .2s; }
body.lib-closed { grid-template-columns: 0 1fr; }
body.lib-closed #sidebar { padding: 0; border: 0; overflow: hidden; }
.brand { position: relative; }
.lib-close { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px; }
.lib-close:hover { color: var(--text); }
.lib-scrim { display: none; }

/* ---------- player a tutta altezza ---------- */
body.has-track #main { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
body.has-track #player { flex: 1; min-height: 0; display: flex; flex-direction: column; }
body.has-track #ready { flex: 1; min-height: 0; display: flex; flex-direction: column; }
body.has-track #processing { margin: 28px; }

/* accordi in alto, compatti */
.chordbar { display: grid; grid-template-columns: var(--side) 1fr; align-items: center; border-bottom: 1px solid var(--line); background: var(--bg); }
.chordbar .chord-now { margin: 0; padding: 8px 20px; gap: 22px; border-right: 1px solid var(--line); height: 100%; align-items: center; }
#chord-cur { font-size: 30px; min-width: 90px; }
.chord-now .next div { font-size: 19px; }
.chordbar #chords { height: 56px; border-radius: 0; background: transparent; margin: 0; }

/* ---------- corsie ---------- */
.lanes { position: relative; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding-bottom: calc(var(--bar-h) + 16px + env(safe-area-inset-bottom, 0px)); }
.lane-top { display: grid; grid-template-columns: var(--side) 1fr; position: sticky; top: 0; z-index: 3; background: var(--bg); border-bottom: 1px solid var(--line); }
.side-top { display: flex; align-items: center; padding: 0 20px; border-right: 1px solid var(--line); }
.lane-hint { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.lane-top #wave { height: 44px; border-radius: 0; background: #17181c; }

#mixer { display: block; gap: 0; }
.stem { display: grid !important; grid-template-columns: var(--side) 1fr; gap: 0 !important; padding: 0 !important; border-radius: 0 !important; background: transparent !important; border-bottom: 1px solid var(--line); min-height: var(--lane-h); align-items: stretch !important; }
.stem.take { border: 0; border-bottom: 1px solid rgba(239, 68, 68, .35); }
.stem .side { display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 12px 18px 12px 20px; background: var(--panel); border-right: 1px solid var(--line); min-width: 0; }
.stem .side-r1 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stem .side-r2 { display: flex; align-items: center; gap: 8px; }
.stem .nm { flex: 1; font-size: 17px; font-weight: 500; }
.stem .nm .dot { width: 8px; height: 8px; }
.stem .vol { flex: 1; min-width: 60px; }
.stem .pan { display: none; }
.stem .acts { display: none !important; }
.stem .ms { gap: 4px; }
.stem .ms button { width: 30px; height: 28px; border-radius: 6px; border: 0; background: #2a2b32; color: #9c9aa8; font-weight: 600; font-size: 13px; }
.stem .ms .m { color: #e3b341; }
.stem .ms .m.on { background: #e3b341; color: #1a1408; }
.stem .ms .s.on { background: var(--teal); color: #08201c; }
.stem > canvas { height: var(--lane-h) !important; width: 100%; border-radius: 0; cursor: text; touch-action: pan-y; }
.stem.off > canvas { opacity: .35; }

/* volume: slider sottile col pallino bianco */
.stem input.vol { -webkit-appearance: none; appearance: none; height: 22px; background: transparent; cursor: pointer; }
.stem input.vol::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--teal) var(--p, 66%), #2c2e36 var(--p, 66%)); }
.stem input.vol::-moz-range-track { height: 4px; border-radius: 2px; background: #2c2e36; }
.stem input.vol::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--teal); }
.stem input.vol::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 16px; border-radius: 8px; background: #fff; margin-top: -6px; box-shadow: 0 1px 4px rgba(0, 0, 0, .4); }
.stem input.vol::-moz-range-thumb { width: 26px; height: 16px; border-radius: 8px; background: #fff; border: 0; }

/* manopola del pan */
.knob { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid #4a4c55; background: radial-gradient(circle at 50% 40%, #2a2b32, #1d1e23); position: relative; flex: none; cursor: ns-resize; touch-action: none; }
.knob::after { content: ''; position: absolute; left: 50%; top: 3px; width: 2px; height: 10px; margin-left: -1px; background: #d8d6de; border-radius: 1px; transform-origin: 1px 12px; transform: rotate(var(--a, 0deg)); }
.knob:hover { border-color: var(--teal); }
.knob.moved { border-color: var(--teal); }

/* menu ⋮ dello stem */
.kebab { background: none; border: 0; color: var(--muted); width: 26px; height: 26px; border-radius: 6px; cursor: pointer; display: grid; place-items: center; flex: none; padding: 0; }
.kebab:hover { background: var(--panel-2); color: var(--text); }
.kebab svg, .ib svg, .pill svg, .art svg { width: 18px; height: 18px; }
.stem-menu { position: fixed; z-index: 60; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; min-width: 190px; box-shadow: 0 12px 30px rgba(0, 0, 0, .45); }

/* testina e loop sopra le corsie */
.ph-layer { position: absolute; top: 0; left: var(--side); right: 0; height: var(--ph-h, 100%); pointer-events: none; z-index: 4; }
#lane-ph { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); display: none; }
#lane-ph.rec { background: var(--rec); }
#lane-loop { position: absolute; top: 0; bottom: 0; background: rgba(45, 212, 191, .10); border-left: 2px solid rgba(45, 212, 191, .8); border-right: 2px solid rgba(45, 212, 191, .8); display: none; }
#lane-loop.off { background: rgba(255, 255, 255, .03); border-color: rgba(255, 255, 255, .25); }
#lane-sel { position: absolute; top: 0; bottom: 0; background: rgba(45, 212, 191, .18); display: none; }

/* ---------- barra in basso ---------- */
.tbar { position: fixed; left: var(--lib-w); right: 0; bottom: 0; z-index: 20; min-height: var(--bar-h); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom, 0px)) 64px; background: #16171b; border-top: 1px solid var(--line); transition: left .2s; }
body.lib-closed .tbar { left: 0; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-right { justify-content: flex-end; }
.tb-center { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tb-row { display: flex; align-items: center; gap: 14px; }
.tb-time { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tb-time #t-cur { color: var(--text); }
.art { width: 52px; height: 52px; border-radius: 8px; border: 0; background: #24252b; color: var(--text); display: grid; place-items: center; cursor: pointer; flex: none; }
.art:hover { background: #2d2e35; }
.art svg { width: 20px; height: 20px; }
#title { font: 500 17px var(--f-body); margin: 0; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; outline: none; border-radius: 6px; padding: 2px 4px; letter-spacing: 0; }
#title:focus { box-shadow: 0 0 0 2px var(--accent); text-overflow: clip; }
.ib { background: none; border: 1px solid transparent; color: var(--text); width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; cursor: pointer; padding: 0; flex: none; }
.ib:hover { background: #24252b; }
.ib.big svg { width: 26px; height: 26px; }
.ib.tog.on { color: var(--teal); }
.ib.rec { color: #9c9aa8; }
.ib.rec.on { color: var(--rec); }
.ib:disabled { opacity: .4; cursor: default; }
#more-btn { border: 1px solid var(--line); width: 30px; }
.tbar .play { width: 50px; height: 50px; border-radius: 50%; background: transparent; color: #fff; font-size: 26px; line-height: 1; border: 0; display: grid; place-items: center; padding: 0 0 0 3px; }
.tbar .play:hover { background: #24252b; }
.pill { display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--text); cursor: pointer; white-space: nowrap; font-size: 15px; }
.pill:hover { border-color: #4a4c55; }
.pill:disabled { opacity: .45; cursor: default; }
#tune-btn b { font-weight: 500; }
#tune-btn .sep { color: var(--muted); }
#tune-btn i { font-style: normal; color: var(--teal); }
#tune-btn .car { width: 15px; height: 15px; color: var(--muted); }
.grp { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; height: 44px; }
.grp .ib { height: 42px; border-radius: 8px 0 0 8px; }
.grp .car-btn { width: 30px; border-left: 1px solid var(--line); border-radius: 0 8px 8px 0; color: var(--muted); }
.grp .car-btn svg { width: 15px; height: 15px; }
.meter-btn { width: 44px; font: 600 13px var(--f-body); }

/* durante l'elaborazione i comandi del lettore non servono */
body:not(.track-ready) .tb-center, body:not(.track-ready) .tb-right, body:not(.track-ready) #export { visibility: hidden; }

/* ---------- popover ---------- */
.pop { position: fixed; z-index: 40; bottom: calc(var(--bar-h) + 10px + env(safe-area-inset-bottom, 0px)); right: 20px; width: min(560px, calc(100vw - 24px)); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: 0 18px 40px rgba(0, 0, 0, .5); }
.pop-sm { width: min(300px, calc(100vw - 24px)); }
.pop .controls { grid-template-columns: 1fr 1fr; }
.pop .ctl { background: var(--panel-2); }
.pop-title { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.pop-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; color: var(--muted); }
.pop-row input[type=range] { flex: 1; }
.pop-menu { padding: 6px; width: 230px; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--text); }
.menu-item:hover { background: var(--panel-2); }
.menu-item.danger { color: var(--danger); }
.menu-item:disabled { opacity: .45; cursor: default; }
.rec-panel.pop-panel { position: fixed; z-index: 30; left: calc(var(--lib-w) + 20px); right: 20px; bottom: calc(var(--bar-h) + 10px + env(safe-area-inset-bottom, 0px)); margin: 0; box-shadow: 0 18px 40px rgba(0, 0, 0, .5); }
body.lib-closed .rec-panel.pop-panel { left: 20px; }
#toast { bottom: calc(var(--bar-h) + 18px + env(safe-area-inset-bottom, 0px)); z-index: 70; }

/* ---------- tablet e telefono ---------- */
@media (max-width: 900px) {
  :root { --side: 150px; --lane-h: 108px; --lib-w: 0px; }
  body.has-track { display: block; height: 100dvh; overflow: hidden; }
  body.has-track #main { height: 100dvh; }
  body.has-track #sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); height: 100dvh; transform: translateX(-102%); transition: transform .2s; border-right: 1px solid var(--line); border-bottom: 0; }
  body.has-track.lib-open #sidebar { transform: none; }
  body.has-track.lib-open .lib-scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, .5); }
  body.has-track #library { max-height: none; }
  body:not(.has-track) .lib-close { display: none; }
  .tbar { left: 0 !important; grid-template-columns: minmax(0, 1fr); grid-template-areas: "l" "r" "c"; padding: 8px 12px calc(6px + env(safe-area-inset-bottom, 0px)) 58px; gap: 6px; }
  .tb-left { grid-area: l; } .tb-right { grid-area: r; gap: 6px; justify-content: space-between; } .tb-center { grid-area: c; }
  :root { --bar-h: 176px; }
  #title { flex: 1; }
  #chord-cur { font-size: 24px; } .chord-now .next div { font-size: 16px; }
  .chordbar .chord-now small { font-size: 9.5px; }
  .art { width: 40px; height: 40px; }
  #title { font-size: 15px; }
  #export { padding: 0 10px; height: 38px; font-size: 0; gap: 0; }
  #export svg { width: 18px; height: 18px; }
  .pill { height: 38px; padding: 0 10px; font-size: 13.5px; gap: 5px; }
  .grp { height: 38px; } .grp .ib { height: 36px; width: 34px; } .grp .car-btn { width: 24px; }
  .ib { width: 36px; height: 36px; }
  .stem .side { padding: 8px 10px; gap: 6px; }
  .stem .nm { font-size: 13.5px; gap: 6px; }
  .stem .side-r2 { flex-wrap: wrap; gap: 6px; }
  .stem .side .vol { display: block; order: 3; flex-basis: 100%; }
  .stem .side .ms { display: flex; }
  .knob { width: 26px; height: 26px; }
  .knob::after { height: 8px; transform-origin: 1px 10px; }
  .chordbar { grid-template-columns: 1fr; }
  .chordbar .chord-now { border-right: 0; padding: 6px 12px 0; }
  .chordbar #chords { height: 48px; }
  .side-top { padding: 0 10px; }
  .lane-hint { font-size: 10.5px; }
  .rec-panel.pop-panel { left: 10px !important; right: 10px; max-height: 60dvh; overflow-y: auto; }
  .pop { right: 10px; }
  .pop .controls { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  :root { --side: 124px; --lane-h: 108px; }
  #tune-btn .sep, #tune-btn .car { display: none; }
  .tb-right .grp:nth-of-type(2) .car-btn { display: none; }
  .tb-row { gap: 8px; }
  .lane-hint { display: none; }
}
@media (hover: none) {
  .stem > canvas { cursor: default; }
}
