/* Coralcrafter – estilos (sem dependências externas) */
:root {
  --bg: #0a0c13;
  --panel: #111522;
  --panel2: #171c2e;
  --panel3: #1e2439;
  --line: #262d45;
  --text: #eef0f7;
  --muted: #8d95b0;
  --accent: #e0553f;       /* coral */
  --accent-h: #ee664f;
  --accent-soft: rgba(224, 85, 63, .16);
  --ok: #2fbf86;
  --danger: #ef5a6f;
  --key-w: 54px;
  --ruler-h: 28px;
  --row-h: 20px;
  --r: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  font-size: 14px;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.only-mobile { display: none !important; }
:focus-visible { outline: 2px solid #ffb09f; outline-offset: 2px; }

svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }

/* ───────── Botões ───────── */
.btn, .icon-btn, .sq, .tool, .dur {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  border-radius: 10px; transition: background .15s, border-color .15s, transform .08s;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.btn { padding: 0 12px; height: 36px; font-weight: 600; font-size: 13px; }
.icon-btn { width: 36px; height: 36px; }
.sq { min-width: 34px; height: 34px; padding: 0 6px; font-weight: 700; font-size: 12px; }
.sq.wide { min-width: 40px; }
.sq.big { width: 42px; height: 42px; border-radius: 12px; }
.btn:hover, .icon-btn:hover, .sq:hover, .tool:hover, .dur:hover { background: var(--panel3); }
.btn:active, .icon-btn:active, .sq:active, .tool:active, .dur:active, .play:active { transform: scale(.95); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-h); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #04150e; }
.btn.danger { color: var(--danger); background: rgba(239, 90, 111, .09); border-color: rgba(239, 90, 111, .3); }
.btn.danger:hover { background: rgba(239, 90, 111, .18); }
.toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: #ffb3a4; }

/* ───────── Cabeçalho ───────── */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: rgba(10, 12, 19, .92); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px); flex: none; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { border-radius: 9px; display: block; }
.brand h1 { margin: 0; font-size: 17px; letter-spacing: .2px; line-height: 1.1; }
.tagline { font-size: 11px; color: var(--muted); }
.projname {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; max-width: 340px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0 12px; height: 34px;
}
.projname input[type="text"] { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; font-weight: 600; font-size: 13px; padding: 0; height: 32px; border-radius: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #f0b429; flex: none; }
.dot.saved { background: var(--ok); }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* ───────── Corpo ───────── */
.body { flex: 1; min-height: 0; display: flex; position: relative; }

.sidebar {
  width: 300px; flex: none; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px;
  background: var(--bg); border-right: 1px solid var(--line);
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.card h3 { margin: 0 0 8px; font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.hint { margin: 0 0 10px; font-size: 12px; line-height: 1.45; color: var(--muted); }
.card.small .hint { margin: 0; }
.hint strong { color: #c9cfe4; }

.row-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; font-size: 12.5px; color: #c4cadf; }
select, input[type="number"], input[type="text"] {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; height: 32px; padding: 0 8px; min-width: 0;
}
select { max-width: 150px; }
.row-field input[type="range"] { width: 130px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper output { min-width: 28px; text-align: center; font-weight: 700; color: #ffb3a4; }

input[type="range"] { accent-color: var(--accent); height: 28px; }

/* vozes */
.voice-list { display: flex; flex-direction: column; gap: 8px; }
.voice {
  --vc: #fff; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2);
  padding: 8px; display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 6px 8px; cursor: pointer;
  border-left: 4px solid var(--vc);
}
.voice.active { background: color-mix(in srgb, var(--vc) 14%, var(--panel2)); border-color: var(--vc); box-shadow: 0 0 0 1px var(--vc) inset; }
.voice .badge {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  font-weight: 800; background: var(--vc); color: #10121b;
}
.voice .vname { font-weight: 700; font-size: 13px; line-height: 1.1; }
.voice .vrange { font-size: 10.5px; color: var(--muted); }
.voice select { height: 28px; min-width: 62px; max-width: 74px; padding: 0 4px; font-size: 12px; grid-column: 3 / 4; }
.voice .ms { display: flex; gap: 4px; }
.voice .ms button {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel);
  font-weight: 800; font-size: 11px; color: var(--muted);
}
.voice .ms button[aria-pressed="true"].m { background: #f0b429; border-color: #f0b429; color: #231a00; }
.voice .ms button[aria-pressed="true"].s { background: var(--ok); border-color: var(--ok); color: #04150e; }
.voice .vol { grid-column: 1 / -1; width: 100%; margin: 0; height: 22px; accent-color: var(--vc); }

.demo-list { display: flex; flex-direction: column; gap: 6px; }
.demo {
  text-align: left; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2);
}
.demo:hover { background: var(--panel3); border-color: #39425f; }
.demo b { display: block; font-size: 13px; }
.demo span { font-size: 11.5px; color: var(--muted); }

/* ───────── Palco ───────── */
.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.toolbar, .selbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; flex: none;
  overflow-x: auto; white-space: nowrap; scrollbar-width: thin;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.selbar {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 15; border: 1px solid #4a2f52; border-radius: 14px;
  background: rgba(30, 20, 40, .97); box-shadow: 0 10px 30px rgba(0,0,0,.55); width: fit-content; max-width: calc(100% - 20px);
}
.selbar strong { font-size: 12.5px; color: #ffb3a4; }
.group { display: flex; align-items: center; gap: 4px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; flex: none; }
.tool { height: 34px; padding: 0 11px; font-weight: 600; font-size: 12.5px; border-color: transparent; background: transparent; }
.tool.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.dur { height: 34px; min-width: 40px; padding: 0 8px; font-weight: 700; font-size: 12px; border-color: transparent; background: transparent; color: #c4cadf; }
.dur.on { background: var(--accent-soft); border-color: var(--accent); color: #ffb3a4; }
.chord-sel { max-width: 160px; flex: none; }
.group .vbtn {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid transparent; background: transparent; font-weight: 800; color: #10121b;
}
.group .vbtn { background: var(--vc); opacity: .55; }
.group .vbtn:hover { opacity: .85; }

/* ───────── Grade melódica (piano roll) ───────── */
.roll {
  flex: 1; min-height: 0; overflow: auto; position: relative; background: #0d101b;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.roll-inner {
  display: grid; position: relative;
  grid-template-columns: var(--key-w) var(--grid-w);
  grid-template-rows: var(--ruler-h) var(--grid-h);
  width: calc(var(--key-w) + var(--grid-w)); height: calc(var(--ruler-h) + var(--grid-h));
}
.corner { position: sticky; top: 0; left: 0; z-index: 6; background: var(--panel); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.ruler {
  position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line); cursor: pointer;
  background-image:
    linear-gradient(to right, rgba(255,255,255,.45) 1px, transparent 1px),
    linear-gradient(to right, rgba(255,255,255,.16) 1px, transparent 1px);
  background-size: var(--measure-w) 100%, var(--beat-w) 40%;
  background-position: 0 0, 0 100%;
  background-repeat: repeat-x;
}
.ruler .mnum { position: absolute; top: 3px; font-size: 11px; font-weight: 700; color: #cdd2e6; padding-left: 5px; pointer-events: none; }
.keys { position: sticky; left: 0; z-index: 4; background: var(--panel); border-right: 1px solid var(--line); }
.key {
  height: var(--row-h); display: flex; align-items: center; justify-content: flex-end; padding-right: 6px;
  font-size: 10px; color: #8d95b0; background: #161b2c; border-bottom: 1px solid #0d101b; cursor: pointer; user-select: none; -webkit-user-select: none;
}
.key.blk { background: #0b0e18; color: transparent; }
.key.c { color: #eef0f7; font-weight: 700; border-bottom-color: #3a4263; }
.key:hover { background: #232a45; }
.key.rng::before { content: ""; width: 3px; height: 100%; background: var(--vc); margin-right: auto; }

.grid { position: relative; touch-action: pan-x pan-y; cursor: crosshair; overflow: hidden; }
.grid.erasing { cursor: not-allowed; }
.row { height: var(--row-h); background: #121726; border-bottom: 1px solid rgba(255,255,255,.035); }
.row.blk { background: #0e1220; }
.row.c { border-bottom-color: rgba(255,255,255,.14); }
.row.rng { background: color-mix(in srgb, var(--vc) 8%, #121726); }
.row.rng.blk { background: color-mix(in srgb, var(--vc) 6%, #0e1220); }
.vlines {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background-image:
    linear-gradient(to right, rgba(255,255,255,.34) 1px, transparent 1px),
    linear-gradient(to right, rgba(255,255,255,.13) 1px, transparent 1px),
    linear-gradient(to right, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: var(--measure-w) 100%, var(--beat-w) 100%, var(--step-w) 100%;
}
.notes { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.note {
  --nc: #fff; position: absolute; pointer-events: auto; touch-action: none; cursor: grab;
  background: var(--nc); border-radius: 5px; box-shadow: 0 1px 0 rgba(0,0,0,.35), inset 0 -3px 0 rgba(0,0,0,.14);
  color: rgba(10, 12, 20, .88); font-size: 10.5px; font-weight: 800; line-height: calc(var(--row-h) - 2px);
  padding-left: 5px; overflow: hidden; white-space: nowrap; user-select: none; -webkit-user-select: none;
}
.note:active { cursor: grabbing; }
.note::after { content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 7px; cursor: ew-resize; background: linear-gradient(90deg, transparent, rgba(0,0,0,.2)); }
.note.sel { outline: 2px solid #fff; outline-offset: 0; z-index: 3; box-shadow: 0 0 0 4px rgba(255,255,255,.18), 0 2px 8px rgba(0,0,0,.5); }
.note.out { background: repeating-linear-gradient(135deg, var(--nc) 0 6px, color-mix(in srgb, var(--nc) 55%, #000) 6px 12px); }
.note.playing { filter: brightness(1.25); }
.erasing .note { cursor: not-allowed; }
.playhead {
  position: absolute; top: 0; bottom: 0; left: 0; width: 2px; background: #fff; z-index: 4; pointer-events: none;
  box-shadow: 0 0 10px 2px rgba(255, 255, 255, .5); will-change: transform;
}
.phead-cap { position: absolute; top: 0; left: 0; z-index: 7; pointer-events: none; will-change: transform; width: 0; height: 0;
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 9px solid #fff; margin-left: -5px; }

/* ───────── Transporte ───────── */
.transport {
  flex: none; display: flex; align-items: center; gap: 18px; padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  background: rgba(10, 12, 19, .95); border-top: 1px solid var(--line); z-index: 20;
}
.t-main { display: flex; align-items: center; gap: 6px; }
.play {
  width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(224, 85, 63, .35); transition: transform .08s, background .15s;
}
.play:hover { background: var(--accent-h); }
.play svg.i { width: 24px; height: 24px; }
.t-pos, .t-bpm { display: flex; align-items: center; gap: 6px; }
.t-label { font-size: 10.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
#posLabel { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 17px; min-width: 52px; }
#bpmInput { width: 58px; text-align: center; font-weight: 800; font-size: 15px; height: 34px; -moz-appearance: textfield; appearance: textfield; }
#bpmInput::-webkit-outer-spin-button, #bpmInput::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.t-vol { display: flex; align-items: center; gap: 8px; margin-left: auto; color: var(--muted); }
.t-vol input { width: 120px; }

/* ───────── Diálogos ───────── */
.dlg { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.dlg::backdrop { background: rgba(4, 5, 10, .72); backdrop-filter: blur(4px); }
.dlg[open] { display: flex; flex-direction: column; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); margin: 0; }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-body { padding: 14px 16px 16px; overflow-y: auto; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin: 12px 0 6px; }
.file-btn { cursor: pointer; }

.lib-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.lib-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; }
.lib-item .info { flex: 1; min-width: 0; }
.lib-item .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .info small { color: var(--muted); }
.lib-empty { padding: 22px 8px; text-align: center; color: var(--muted); }

.fmt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fmt { display: block; cursor: pointer; }
.fmt input { position: absolute; opacity: 0; pointer-events: none; }
.fmt span { display: block; padding: 10px 12px; border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; height: 100%; }
.fmt b { display: block; font-size: 14px; }
.fmt small { color: var(--muted); font-size: 11.5px; line-height: 1.3; display: block; margin-top: 2px; }
.fmt input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.fmt input:focus-visible + span { outline: 2px solid #ffb09f; }
.range-box { margin: 12px 0 8px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 10px; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.range-box legend { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); padding: 0 6px; }
.range-box.disabled { opacity: .45; pointer-events: none; }
.inline { display: flex; align-items: center; gap: 6px; }
.inline input[type="number"] { width: 64px; height: 30px; }
.help ol { padding-left: 18px; margin: 0 0 12px; line-height: 1.55; color: #cfd4e6; }
.help h4 { margin: 8px 0; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.keys-table, table.keys { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.keys td { padding: 5px 6px; border-bottom: 1px solid var(--line); color: #c4cadf; vertical-align: top; }
kbd { background: var(--panel3); border: 1px solid #38405d; border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; font-size: 11px; font-family: inherit; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #212843; border: 1px solid #39425f; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--danger); }

/* ───────── Responsivo ───────── */
@media (max-width: 960px) {
  .only-mobile { display: inline-flex !important; }
  .tagline { display: none; }
  .btn .lbl { display: none; }
  .btn { padding: 0; width: 36px; }
  .sidebar {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: min(330px, 88vw); padding-top: max(12px, env(safe-area-inset-top));
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: 10px 0 40px rgba(0,0,0,.6);
  }
  .sidebar.open { transform: none; }
  .side-head { display: flex !important; justify-content: space-between; align-items: center; }
  .side-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(4,5,10,.6); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .side-backdrop.show { opacity: 1; pointer-events: auto; }
  .projname { max-width: none; }
  .tool .lbl { display: none; }
  .tool { padding: 0 10px; }
  .selbar .btn .lbl { display: none; }
  .selbar .btn { width: 36px; padding: 0; }
}
@media (max-width: 640px) {
  .topbar { padding: 6px 10px; gap: 8px; }
  .brand h1 { font-size: 15px; }
  .logo { width: 28px; height: 28px; }
  .transport { flex-wrap: wrap; gap: 8px 12px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); justify-content: space-between; }
  .t-pos { order: 3; }
  .t-vol { margin-left: 0; order: 4; flex: 1; }
  .t-vol input { width: 100%; }
  .play { width: 48px; height: 48px; }
  .sq.big { width: 38px; height: 38px; }
  .t-main { gap: 4px; }
  .t-label { display: none; }
  .fmt-grid { grid-template-columns: 1fr; }
  .toast { bottom: 140px; }
  #btnHelp { display: none; }
}
@media (max-width: 420px) {
  .brand-text { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.side-head { display: none; }
