/* Bajo Tab · estilos */
:root {
  --bg: #f3f0e8; --surface: #fffdf8; --surface-2: #ece7dc; --ink: #1b1a17; --muted: #6b665c;
  --line: #dcd4c4; --accent: #d9480f; --accent-ink: #fff; --accent-soft: rgba(217, 72, 15, .12);
  --paper: #ffffff; --paper-line: #e6e0d3; --cursor: rgba(217, 72, 15, .16); --cursor-edge: #d9480f;
  --play: rgba(25, 113, 194, .16); --play-edge: #1971c2; --danger: #c92a2a; --ok: #2b8a3e;
  --radius: 12px; --shadow: 0 1px 2px rgba(40, 30, 10, .08), 0 6px 20px rgba(40, 30, 10, .06);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --surface: #1f2226; --surface-2: #2a2e33; --ink: #ece8df; --muted: #9a958b;
    --line: #353a40; --accent: #ff7a3d; --accent-ink: #1b1a17; --accent-soft: rgba(255, 122, 61, .16);
    --paper: #fbfaf6; --paper-line: #2c3035; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.muted { color: var(--muted); }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.fill { fill: currentColor; stroke: none; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.icon { width: 40px; padding: 0; }
.btn.block { width: 100%; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.toggle[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Barra superior */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
  background: var(--bg); border-bottom: 1px solid var(--line); min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 19px; letter-spacing: -.01em; flex: 1; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.sync { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sync.warn { color: var(--danger); }
.sync.ok { color: var(--ok); }

/* Acceso */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.login-logo { width: 64px; height: 64px; border-radius: 16px; }
.login-card h1 { margin: 10px 0 4px; font-size: 24px; }
.login-card input { width: 100%; margin: 16px 0 12px; }
.error { color: var(--danger); min-height: 1.4em; margin: 10px 0 0; font-size: 14px; }

input[type=text], input[type=password], input[type=search], input[type=url], input[type=number], select {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-size: 16px; /* 16px evita el zoom automático del iPhone */
  width: 100%;
}

/* Biblioteca */
.lib-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 14px calc(14px + var(--safe-r)) calc(24px + var(--safe-b)) calc(14px + var(--safe-l));
  width: 100%; max-width: 760px; margin: 0 auto; }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; color: var(--muted); }
.search input { border: 0; padding: 0; background: transparent; color: var(--ink); }
.search input:focus { outline: none; }
.song-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.song-item { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.song-item .open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; background: none; border: 0; padding: 12px 6px 12px 12px; }
.song-item .badge { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; flex: none; }
.song-item .txt { min-width: 0; }
.song-item .t { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-item .a { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-item .more { width: 44px; height: 56px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; }
.empty { text-align: center; padding: 48px 10px; }
.empty h2 { margin: 0 0 6px; font-size: 19px; }
.row-gap { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

/* Editor */
.song-head { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; background: none; border: 0; padding: 2px 4px; text-align: left; }
.song-head .t { font-weight: 700; font-size: 16px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-head .a { font-size: 12px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l)); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.toolbar::-webkit-scrollbar { display: none; }
.btn.play { width: 44px; height: 44px; padding: 0; border-radius: 50%; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); flex: none; }
.btn.play .i-stop { display: none; }
.btn.play.on .i-stop { display: block; }
.btn.play.on .i-play { display: none; }
.speed { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); flex: none; }
.speed span { width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.speed input { width: 90px; accent-color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; flex: none; margin-left: auto; }
.seg button { border: 0; background: transparent; padding: 0 10px; min-height: 34px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
#editToggle { flex: none; }

.score-wrap { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; position: relative; padding: 12px calc(10px + var(--safe-r)) 24px calc(10px + var(--safe-l)); }
.paper { background: var(--paper); color: #1b1a17; border-radius: 6px; box-shadow: var(--shadow); max-width: 1100px; margin: 0 auto; padding: 16px 10px 20px; border: 1px solid var(--paper-line); }
.paper-head { text-align: center; padding: 4px 8px 6px; }
.paper-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; color: #1b1a17; }
.paper-head .meta { font-size: 12.5px; color: #6b665c; margin-top: 3px; }
.paper-head .meta a { color: #b8400c; }
.score { position: relative; touch-action: manipulation; }
.short { display: none; }
.system { position: relative; margin-top: 4px; }
.system svg { display: block; }
.score.editing .system { cursor: crosshair; }
.cursor, .playhead { position: absolute; pointer-events: none; border-radius: 6px; }
.cursor { background: var(--cursor); box-shadow: inset 0 0 0 1.5px var(--cursor-edge); }
.cursor .str { position: absolute; left: -3px; right: -3px; height: 16px; margin-top: -8px; border-radius: 5px; background: var(--cursor-edge); opacity: .85; }
.cursor.slot { background: transparent; box-shadow: none; border-left: 2px dashed var(--cursor-edge); border-radius: 0; }
.cursor.slot .str { left: -9px; width: 16px; right: auto; }
.playhead { background: var(--play); box-shadow: inset 0 0 0 1.5px var(--play-edge); transition: left .05s linear; }

.toast { position: sticky; bottom: 8px; margin: 10px auto 0; width: fit-content; max-width: 92%; background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13.5px; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }

/* Panel de entrada */
.panel { border-top: 1px solid var(--line); background: var(--surface); padding: 8px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l)); display: grid; gap: 8px; }
.panel-row { display: flex; align-items: center; gap: 8px; }
.panel-row.tools { justify-content: space-between; }
.durs, .acts, .strings, .techs { display: flex; gap: 4px; }
.durs button, .acts button, .strings button, .techs button, .panel .nav {
  width: 40px; height: 40px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg);
  display: grid; place-items: center; padding: 0; color: var(--ink);
}
.durs svg { width: 26px; height: 26px; }
.durs svg .f { fill: currentColor; } .durs svg .o { fill: none; stroke: currentColor; stroke-width: 1.8; }
.durs svg .s { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.durs button.on, .strings button.on, .techs button.on, .clip button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.strings button { font-weight: 800; width: 52px; }
.strings-row .lbl { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.strings-row .acts, .techs-row .clip { margin-left: auto; }
.techs .tl { font-weight: 800; font-size: 13px; letter-spacing: -.02em; }
.techs svg .f { fill: currentColor; } .techs svg .s { stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.techs svg:not(.ic) { width: 22px; height: 22px; }
.selbar { display: flex; align-items: center; gap: 6px; background: var(--ink); color: var(--bg); border-radius: 10px; padding: 5px 6px 5px 12px; font-size: 13.5px; }
.selbar span { flex: 1; font-weight: 600; }
.selbar button { border: 0; background: rgba(255,255,255,.14); color: inherit; border-radius: 7px; min-height: 32px; padding: 0 10px; font-weight: 600; font-size: 13.5px; }
.selrect { position: absolute; pointer-events: none; background: rgba(25, 113, 194, .13); box-shadow: inset 0 0 0 1.5px rgba(25, 113, 194, .55); border-radius: 6px; }
.frets { display: grid; grid-template-columns: repeat(13, 1fr); gap: 4px; }
.frets button { height: 40px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; font-variant-numeric: tabular-nums; padding: 0; }
.frets button:active, .durs button:active, .acts button:active, .strings button:active { background: var(--accent-soft); }
.frets button.dot { background: var(--surface-2); }
.frets button.cur { box-shadow: inset 0 0 0 2px var(--accent); }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.hint b { color: var(--ink); font-weight: 650; }

@media (max-width: 720px) {
  .long { display: none; } .short { display: inline; }
  #editToggle { width: 44px; padding: 0; }
  .strings-row .lbl { display: none; }
  .durs button, .acts button, .techs button, .panel .nav { width: 38px; }
  .techs, .acts { gap: 3px; }
  .strings button { width: 44px; }
  .panel-row { gap: 6px; }
  .frets { grid-template-columns: repeat(9, 1fr); }
  .frets button { height: 38px; }
  .desktop-only { display: none; }
  .seg button { padding: 0 8px; }
  .speed input { width: 70px; }
}
@media (max-width: 380px) {
  .durs button, .acts button, .techs button, .panel .nav { width: 34px; }
  .acts, .durs, .strings { gap: 3px; }
  .strings button { width: 38px; }
  .speed input { width: 56px; }
}
@media (max-width: 350px) {
  .durs button, .acts button, .techs button, .panel .nav { width: 30px; height: 36px; }
  .durs svg { width: 22px; height: 22px; }
  .acts, .durs, .strings { gap: 2px; } .panel-row { gap: 4px; }
  .strings button { width: 32px; height: 36px; }
  .btn.play { width: 40px; height: 40px; } .speed input { width: 44px; }
  .seg button { padding: 0 6px; font-size: 12px; }
}
@media (hover: none) { .desktop-only { display: none; } }
@media (orientation: landscape) and (max-height: 500px) {
  /* iPhone en horizontal: partitura a la izquierda, panel a la derecha */
  #editor { display: grid; grid-template-columns: 1fr minmax(300px, 42%); grid-template-rows: auto auto 1fr; }
  #editor > .bar, #editor > .toolbar { grid-column: 1 / -1; }
  #editor > .score-wrap { grid-column: 1; grid-row: 3; min-height: 0; }
  #editor > .panel { grid-column: 2; grid-row: 3; overflow-y: auto; border-top: 0; border-left: 1px solid var(--line); align-content: start; }
  .frets { grid-template-columns: repeat(7, 1fr); }
  .frets button { height: 32px; }
  .panel { gap: 5px; padding-top: 6px; }
  .durs button, .acts button, .strings button, .techs button, .panel .nav { height: 34px; width: 32px; }
  .strings button { width: 36px; }
  .durs, .acts, .strings { gap: 3px; } .panel-row { gap: 4px; }
  .strings-row .lbl, .hint { display: none; }
  .toolbar { padding-top: 4px; padding-bottom: 4px; }
  .bar { min-height: 44px; padding-top: calc(2px + var(--safe-t)); padding-bottom: 2px; }
}

/* Modal */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--ink); width: min(440px, calc(100% - 28px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 8, 4, .45); }
#modalForm { padding: 20px; display: grid; gap: 14px; }
#modalForm h2 { margin: 0; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 650; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.kbd-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 14px; }
.kbd-list li { display: flex; justify-content: space-between; gap: 12px; }
kbd { background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; font: 600 12.5px ui-monospace, Menlo, monospace; }

/* Menú */
.menu { position: fixed; z-index: 50; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.2); padding: 6px; min-width: 220px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 12px; border: 0; background: none; border-radius: 8px; text-align: left; font-size: 15px; }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
