/* JoyTune — estilos. Padrões de aplicativo: barra de ferramentas, palco, painel lateral, mixer e barra de status. */
:root {
  --app: #f2f2f4; --surface: #ffffff; --surface-2: #f7f7f8; --stage: #e9e9ec;
  --border: #dcdce1; --border-2: #c7c7cd; --text: #1c1c1e; --text-2: #5b5b63; --text-3: #8a8a92;
  --accent: #0a6cdf; --accent-hover: #075bbd; --accent-weak: rgba(10,108,223,.12); --on-accent: #ffffff;
  --rec: #d92d20; --ok: #1f8a3b; --warn: #b26a00; --bad: #c4321f;
  --meter-lo: #34a853; --meter-mid: #e7b416; --meter-hi: #d92d20;
  --radius: 6px; --radius-lg: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --app: #1c1c1e; --surface: #252527; --surface-2: #2c2c2f; --stage: #18181a;
    --border: #39393d; --border-2: #4a4a4f; --text: #f1f1f3; --text-2: #b3b3ba; --text-3: #85858d;
    --accent: #3d8bfd; --accent-hover: #5b9dfd; --accent-weak: rgba(61,139,253,.18);
    --rec: #ff5145; --ok: #4cc26b; --warn: #e0a030; --bad: #ff6a55;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --app: #1c1c1e; --surface: #252527; --surface-2: #2c2c2f; --stage: #18181a;
  --border: #39393d; --border-2: #4a4a4f; --text: #f1f1f3; --text-2: #b3b3ba; --text-3: #85858d;
  --accent: #3d8bfd; --accent-hover: #5b9dfd; --accent-weak: rgba(61,139,253,.18);
  --rec: #ff5145; --ok: #4cc26b; --warn: #e0a030; --bad: #ff6a55;
  color-scheme: dark;
}

* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 var(--font); color: var(--text); background: var(--app); -webkit-font-smoothing: antialiased;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; height: 100vh; height: 100dvh; overflow: hidden;
}
button, select, input, output { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Controles base ---------- */
.btn { height: 32px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--surface); font-size: 13.5px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; }
select, input[type="text"], input:not([type]) { height: 32px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--surface); padding: 0 8px; font-size: 13.5px; }
select { padding-right: 24px; }
input[type="range"] { accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 12px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border-2); }
.seg button[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.seg svg { width: 16px; height: 16px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 34px; height: 20px; border-radius: 10px; background: var(--border-2); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd, .key { display: inline-block; min-width: 24px; padding: 1px 6px; border: 1px solid var(--border-2); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); font: 600 12px/1.5 var(--font); text-align: center; color: var(--text); }

/* ---------- Barra de ferramentas ---------- */
.toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; margin-right: 8px; }
.brand img { border-radius: 5px; }
.tgroup { display: flex; align-items: center; gap: 6px; padding: 0 10px; border-left: 1px solid var(--border); }
.tlabel { font-size: 12.5px; color: var(--text-2); }
.tbtn { height: 32px; padding: 0 10px; border-radius: var(--radius); border: 1px solid transparent; background: transparent; display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--text); white-space: nowrap; }
.tbtn:hover { background: var(--surface-2); border-color: var(--border); }
.tbtn.icon { width: 32px; padding: 0; justify-content: center; }
.tbtn.sm { width: 26px; height: 26px; border-color: var(--border-2); font-size: 15px; }
.tbtn[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); }
#btn-play { border-color: var(--border-2); }
#btn-play.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tbtn.rec svg { color: var(--rec); }
.tbtn.rec.on { background: var(--rec); border-color: var(--rec); color: #fff; font-variant-numeric: tabular-nums; }
.tbtn.rec.on svg { color: #fff; }
.tempo output { min-width: 34px; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; }
.beats { display: inline-flex; gap: 4px; margin-left: 4px; }
.beats i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-2); }
.beats i.on { background: var(--accent); }
.beats i.on:first-child { background: var(--rec); }
.count { font-size: 12px; color: var(--text-3); }
.spacer { flex: 1; }

/* ---------- Área principal ---------- */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
.stage { position: relative; background: var(--stage); min-height: 0; overflow: hidden; border-right: 1px solid var(--border); }
.view { position: absolute; inset: 0; }
.view canvas.gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.view.grabbing canvas.gl { cursor: grabbing; }
.view svg.flat { position: absolute; left: 22%; top: 9%; width: 56%; height: 78%; overflow: visible; }
.view.mode3d svg.flat { display: none; }
.view:not(.mode3d) canvas.gl { display: none; }
.stage-tools { position: absolute; top: 12px; right: 12px; z-index: 3; }
.stage-hint { position: absolute; left: 14px; top: 12px; margin: 0; font-size: 12.5px; color: var(--text-3); z-index: 3; }
svg.leaders { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.leaders line { stroke: var(--border-2); stroke-width: 1; }
.leaders circle { fill: var(--border-2); }
.leaders .on { stroke: var(--accent); fill: var(--accent); }
.co { position: absolute; transform: translateY(-50%); width: 20%; max-width: 240px; font-size: 13px; line-height: 1.35; pointer-events: none; }
.co.l { text-align: right; }
.co .fn { color: var(--text); font-weight: 600; }
.co .h { display: block; color: var(--text-3); font-size: 12px; }
.co .key { margin: 0 6px; }
.co.on .key { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.co.hint .key { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
.bottomrow { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 22px; white-space: nowrap; }
.bottomrow .co { position: static; transform: none; width: auto; max-width: none; text-align: center; }
.legend { display: none; }

.empty { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(380px, calc(100% - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px 22px 18px; text-align: center; z-index: 4; box-shadow: 0 6px 24px rgba(0,0,0,.08); }
.empty-icon { width: 36px; height: 36px; color: var(--text-3); }
.empty h2 { font-size: 17px; margin: 8px 0 6px; }
.empty p { margin: 0 0 14px; color: var(--text-2); font-size: 13.5px; }
.empty .empty-note { margin: 12px 0 0; font-size: 12.5px; color: var(--text-3); }

.coach { position: absolute; left: 14px; bottom: 14px; width: 300px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; z-index: 4; box-shadow: 0 6px 24px rgba(0,0,0,.08); }
.coach-step { font-size: 12px; color: var(--text-3); }
.coach-title { font-size: 15px; font-weight: 650; margin: 2px 0 4px; }
.coach-text { color: var(--text-2); font-size: 13px; }
.coach-actions { margin-top: 12px; display: flex; gap: 8px; }

/* ---------- Painel lateral ---------- */
.inspector { background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 8px; }
.tabs button { border: 0; background: none; padding: 10px 10px 9px; font-size: 13.5px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.pane { padding: 14px 16px 20px; overflow: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; flex: 1; }
.cap { font-size: 12px; color: var(--text-3); }
.help { font-size: 12.5px; color: var(--text-3); margin: -4px 0 0; }
.now { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.now-big { font-size: 28px; font-weight: 650; line-height: 1.15; font-variant-numeric: tabular-nums; }
.now-big.dim { color: var(--text-3); }
.now-sub { font-size: 12.5px; color: var(--text-2); min-height: 18px; }
.chordgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.chordgrid button { height: 44px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); display: grid; align-content: center; justify-items: center; line-height: 1.15; padding: 0 2px; }
.chordgrid button b { font-size: 13.5px; font-weight: 650; }
.chordgrid button small { font-size: 11px; color: var(--text-3); }
.chordgrid button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chordgrid button.on small { color: inherit; opacity: .85; }
.chordgrid button.next { border-color: var(--accent); }
.chordgrid .center { border: 1px dashed var(--border); border-radius: var(--radius); position: relative; }
.chordgrid .center i { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px; border-radius: 50%; background: var(--text-3); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.field select, .field input { width: 100%; color: var(--text); }
.field output { float: right; color: var(--text-3); font-variant-numeric: tabular-nums; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; cursor: pointer; }
.pad-card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; display: grid; gap: 8px; }
.pad-card select, .pad-card .btn { width: 100%; }
.pad-name { font-weight: 650; }
.pad-sub { font-size: 12.5px; color: var(--text-3); margin-top: -6px; }
.tester { display: flex; flex-wrap: wrap; gap: 4px; }
.tester .key { color: var(--text-3); }
.tester .key.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.group-title { font-size: 12px; color: var(--text-3); margin: 6px 0 2px; }
.maprow { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.maprow small { display: block; font-size: 11.5px; color: var(--text-3); }
.maprow .key { min-width: 64px; }
.maprow.learning .key { border-color: var(--accent); color: var(--accent); }
.maprow .btn { height: 26px; padding: 0 8px; font-size: 12.5px; }
.lat-table { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; font-size: 13px; }
.lat-table dt { color: var(--text-2); } .lat-table dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Mixer ---------- */
.mixer { display: flex; gap: 0; background: var(--surface); border-top: 1px solid var(--border); overflow-x: auto; }
.strip { flex: 1 1 150px; min-width: 140px; max-width: 210px; padding: 10px 12px 10px; border-right: 1px solid var(--border); display: grid; grid-template-rows: auto auto 1fr auto; gap: 6px; }
.strip.master { margin-left: auto; border-left: 1px solid var(--border); border-right: 0; }
.strip h3 { margin: 0; font-size: 13px; font-weight: 650; display: flex; justify-content: space-between; align-items: center; }
.strip h3 output { font-weight: 400; color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.strip select { width: 100%; height: 28px; font-size: 12.5px; }
.strip .fx-note { height: 28px; font-size: 12px; color: var(--text-3); display: flex; align-items: center; }
.fader-wrap { display: flex; gap: 10px; align-items: stretch; height: 104px; justify-content: center; }
.fader { writing-mode: vertical-lr; direction: rtl; width: 22px; height: 104px; margin: 0; }
.meter-v { width: 8px; border-radius: 2px; background: var(--surface-2); border: 1px solid var(--border); position: relative; overflow: hidden; }
.meter-v i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(to top, var(--meter-lo) 0 65%, var(--meter-mid) 65% 85%, var(--meter-hi) 85%); background-size: 100% 104px; background-position: bottom; }
.strip-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-3); }
.strip-foot input[type="range"] { flex: 1; min-width: 0; }
.mbtn { width: 26px; height: 24px; border-radius: 4px; border: 1px solid var(--border-2); background: var(--surface); font-size: 11.5px; font-weight: 700; color: var(--text-2); padding: 0; }
.mbtn[aria-pressed="true"] { background: var(--warn); border-color: var(--warn); color: #fff; }
.strip-sw { font-size: 12px; }

/* ---------- Barra de status ---------- */
.statusbar { display: flex; align-items: center; gap: 16px; padding: 4px 12px; background: var(--surface-2); border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); min-height: 30px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
.st-pad { display: inline-flex; align-items: center; gap: 6px; max-width: 34%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-pad svg { width: 16px; height: 16px; }
.st-msg { flex: 1; display: flex; gap: 10px; align-items: center; overflow: hidden; white-space: nowrap; }
.st-msg #msg-text { overflow: hidden; text-overflow: ellipsis; }
.st-lat { background: none; border: 0; padding: 0; display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-2); display: inline-block; }
.dot.good { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

/* ---------- Diálogos ---------- */
.dlg { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dlg.wide { width: min(680px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 10px 18px; border-bottom: 1px solid var(--border); }
.dlg h2 { font-size: 16px; margin: 0; }
.dlg h3 { font-size: 13px; color: var(--text-2); margin: 18px 0 6px; font-weight: 600; }
.dlg-body { padding: 14px 18px 18px; display: grid; gap: 12px; max-height: 70vh; overflow: auto; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input { flex: 1; min-width: 160px; }
.inline.end { justify-content: flex-end; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table td { padding: 7px 10px 7px 0; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text-2); }
.table td:first-child { white-space: nowrap; width: 1%; color: var(--text); font-weight: 600; padding-right: 16px; }
.rec-item { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.rec-item .row { display: flex; align-items: center; gap: 8px; }
.rec-item .row b { flex: 1; font-weight: 600; }
.rec-item .row span { color: var(--text-3); font-variant-numeric: tabular-nums; }
.rec-item audio { width: 100%; height: 34px; }
.empty-list { color: var(--text-3); padding: 8px 0; }
.cal-step { font-size: 12.5px; color: var(--text-3); }
.cal-big { font-size: 22px; font-weight: 650; }
.cal-sub { color: var(--text-2); min-height: 20px; }
progress { width: 100%; height: 6px; accent-color: var(--accent); }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
  .main { grid-template-columns: minmax(0, 1fr) 300px; }
  .toolbar .lbl { display: none; }
}
@media (max-width: 820px) {
  body { height: auto; min-height: 100vh; overflow: auto; grid-template-rows: auto auto auto auto; }
  .main { grid-template-columns: 1fr; }
  .stage { height: 52vh; min-height: 300px; border-right: 0; }
  .co.l, .co.r, svg.leaders, .bottomrow, .stage-hint { display: none; }
  .view svg.flat { left: 5%; width: 90%; top: 8%; height: 84%; }
  .legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 12px; background: color-mix(in srgb, var(--stage) 92%, transparent); font-size: 12.5px; }
  .legend .co { position: static; transform: none; width: auto; max-width: none; text-align: left; }
  .legend .co .key { margin: 0 6px 0 0; }
  .legend .co .h { display: none; }
  .coach { left: 12px; right: 12px; width: auto; bottom: auto; top: 12px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; }
  .coach-step, .coach-text { display: none; }
  .coach-actions { margin: 0; grid-row: 1 / span 2; grid-column: 2; }
  .inspector { border-top: 1px solid var(--border); }
  .pane { overflow: visible; }
  .tgroup { border-left: 0; padding: 0 4px; }
  .mixer { overflow-x: auto; }
}
@media (max-width: 1000px) {
  .toolbar .tlabel, .beats { display: none; }
  #style-select { max-width: 140px; }
  .tgroup { padding: 0 6px; }
}
/* Celular deitado e janelas baixas: o mixer vira gaveta sobre o palco */
@media (max-height: 560px) and (min-width: 821px) {
  .toolbar { padding: 4px 10px; flex-wrap: nowrap; overflow-x: auto; }
  .brand { font-size: 0; margin-right: 2px; gap: 0; }
  .main { grid-template-columns: minmax(0, 1fr) 290px; }
  .co.l, .co.r, svg.leaders, .bottomrow, .stage-hint { display: none; }
  .view svg.flat { left: 8%; width: 84%; top: 6%; height: 88%; }
  .mixer { position: fixed; left: 0; right: 0; bottom: 30px; z-index: 30; max-height: calc(100dvh - 80px); box-shadow: 0 -8px 30px rgba(0,0,0,.18); }
  .coach { width: 260px; padding: 10px 12px; }
  .coach-text { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
