:root {
  --bg: #11141d;
  --panel: #191d29;
  --panel2: #222738;
  --line: #2d3348;
  --text: #e8ebf5;
  --muted: #8d94ad;
  --accent: #8b9bff;
  --accent-ink: #0f1220;
  --chord: #5fd4c6;
  --danger: #ff7a8c;
  --ok: #6fd29a;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; display: grid; gap: 12px; }
.login h1 { margin: 0; font-size: 28px; }
.login p { margin: 0; color: var(--muted); }
.error { color: var(--danger) !important; min-height: 1.4em; }

input, textarea, select { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }

.btn { border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 9px 16px; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 14px; }
.linkbtn { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 4px 8px; }
.linkbtn:hover { color: var(--text); }

.app { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.nav { display: flex; flex-direction: column; gap: 4px; padding: 20px 14px; background: var(--panel); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 20px; margin-bottom: 16px; color: var(--accent); }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); }
.nav a.active { background: var(--panel2); color: var(--text); }
.sync { margin-top: auto; font-size: 13px; color: var(--muted); padding: 0 12px; }
.sync.off { color: var(--danger); }
main { padding: 28px clamp(16px, 4vw, 48px) 80px; max-width: 1200px; width: 100%; }
h2 { margin: 0 0 16px; font-size: 24px; }
.muted { color: var(--muted); }

.capture { display: grid; gap: 10px; margin-bottom: 24px; }
.capture textarea { min-height: 96px; font-size: 17px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.card .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.card .meta { color: var(--muted); font-size: 13px; margin-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.songcard { display: block; }
.songcard:hover { border-color: var(--muted); }
.songcard h3 { margin: 0 0 4px; font-size: 18px; }
.chip { font-size: 12px; padding: 1px 9px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.chip.borrador { color: var(--accent); border-color: var(--accent); }
.chip.terminada { color: var(--ok); border-color: var(--ok); }

.editor { display: grid; gap: 16px; }
.fields { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1.2fr; gap: 10px; }
.fields label { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.editor textarea { min-height: 55vh; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 15px; line-height: 1.7; }
.preview { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; min-height: 55vh; overflow: auto; }
.preview .sec { color: var(--accent); font-weight: 700; margin: 18px 0 6px; text-transform: uppercase; font-size: 13px; letter-spacing: .06em; }
.preview .ln { display: flex; flex-wrap: wrap; align-items: flex-end; min-height: 2.6em; }
.preview .seg { display: inline-flex; flex-direction: column; }
.preview .c { color: var(--chord); font-weight: 700; font-size: 14px; height: 1.3em; padding-right: 8px; font-family: ui-monospace, Consolas, monospace; }
.preview .l { white-space: pre; min-height: 1.4em; }
.hint { color: var(--muted); font-size: 13px; }
.status { font-size: 13px; color: var(--muted); }
.status.bad { color: var(--danger); }
.banner { background: #2f1d28; border: 1px solid var(--danger); border-radius: var(--radius); padding: 12px 16px; }

/* Compositor */
.studio { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; margin-top: 12px; }
.composer { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.chatlog { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; min-height: 160px; flex: 1; padding-right: 2px; }
.msg { border-radius: 10px; padding: 8px 12px; font-size: 15px; overflow-wrap: anywhere; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg.user { background: var(--panel2); align-self: flex-end; max-width: 92%; }
.msg.assistant { background: var(--bg); border: 1px solid var(--line); }
.msg.note { color: var(--muted); font-size: 14px; border: 1px dashed var(--line); }
.msg.error { color: var(--danger); border-color: var(--danger); }
.msg code { background: var(--panel2); padding: 0 4px; border-radius: 4px; font-size: 13px; }
.proposal { background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; padding: 10px; margin: 8px 0; }
.proposal pre { margin: 0 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.6 ui-monospace, Consolas, monospace; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { background: var(--panel2); color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 3px 11px; font: 13px system-ui, sans-serif; cursor: pointer; }
.chip-btn:hover { color: var(--text); border-color: var(--muted); }
.chatin { display: grid; gap: 8px; }
.chatin textarea { min-height: 0; font-size: 15px; }

/* Diagramas de acordes */
.h3 { margin: 0; font-size: 18px; }
.chords { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.cd { width: 92px; height: 112px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.cd-name { fill: var(--text); font: 700 12px system-ui, sans-serif; }
.cd-na { fill: var(--muted); font: 10px system-ui, sans-serif; }
.cd-line { stroke: var(--muted); stroke-width: 1; }
.cd-nut { stroke: var(--text); stroke-width: 3; }
.cd-dot { fill: var(--accent); }
.cd-open { fill: none; stroke: var(--text); stroke-width: 1.2; }
.cd-x { fill: var(--muted); font: 12px system-ui, sans-serif; }
.cd-fr { fill: var(--muted); font: 10px system-ui, sans-serif; }

/* Herramientas */
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.tool { padding: 20px; }
.tool h3 { margin: 0 0 14px; font-size: 18px; }
.tuner { text-align: center; margin-bottom: 14px; }
.tnote { font-size: 72px; font-weight: 700; line-height: 1.1; }
.tnote.tuned { color: var(--ok); }
.meter { position: relative; height: 14px; border-radius: 7px; background: var(--panel2); margin: 14px 4px 8px; }
.meter .mid { position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; background: var(--muted); transform: translateX(-1px); }
.needle { position: absolute; left: 50%; top: -6px; width: 6px; height: 26px; border-radius: 3px; background: var(--accent); transform: translateX(-3px); transition: left .12s; }
.needle.tuned { background: var(--ok); }
.bpm { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.bpm div { font-size: 56px; font-weight: 700; line-height: 1; }
.bpm small { font-size: 16px; color: var(--muted); font-weight: 400; }
.bpm .btn { width: 48px; height: 48px; font-size: 24px; padding: 0; }
input[type=range] { padding: 0; accent-color: var(--accent); }
.dots { display: flex; gap: 10px; justify-content: center; margin: 16px 0; }
.dots i { width: 18px; height: 18px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); }
.dots i.acc { border-color: var(--accent); }
.dots i.on { background: var(--accent); }

@media (max-width: 1150px) {
  .studio { grid-template-columns: 1fr; }
  .composer { position: static; max-height: none; }
  .chatlog { max-height: 60vh; }
}

@media (max-width: 800px) {
  .tools { grid-template-columns: 1fr; }
  .app { grid-template-columns: 1fr; padding-bottom: 64px; }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; align-items: center; justify-content: space-around; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 10; }
  .brand { display: none; }
  .sync { margin: 0; padding: 0; }
  main { padding: 18px 16px 90px; }
  .fields { grid-template-columns: 1fr 1fr; }
  .fields label:first-child { grid-column: 1 / -1; }
  .cols { grid-template-columns: 1fr; }
  .editor textarea, .preview { min-height: 40vh; }
}
