/* ALTAR — diseño para escenario: oscuro, contraste alto, botones grandes. */
:root {
  --bg: #0b0d12; --bg-2: #10141c; --panel: #141824; --panel-2: #1a2030; --line: #232a3a; --line-2: #2e3750;
  --text: #e8ecf3; --muted: #8b95ab; --faint: #5b6478;
  --accent: #f5b942; --accent-2: #ffd27a; --teal: #3fd0c9; --red: #ff5f6d; --green: #6ee7a8;
  --radius: 14px; --radius-s: 9px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.35; overscroll-behavior: none; }
body { touch-action: manipulation; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--radius-s); padding: 8px 12px; transition: background .12s, border-color .12s, transform .06s; }
button:hover { border-color: var(--line-2); background: #202839; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: #1a1200; border-color: transparent; font-weight: 700; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); }
.btn-xl { font-size: 20px; padding: 16px 40px; border-radius: 16px; }
.btn-sm { padding: 5px 9px; font-size: 13px; border-radius: 7px; }
.icon { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; font-size: 16px; }
.sr { position: absolute; left: -9999px; }

/* ---- Puerta de entrada ---- */
.gate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% -10%, #1d2438 0%, var(--bg) 60%); }
.gate.hidden { display: none; }
.gate-card { text-align: center; padding: 40px 28px; max-width: 520px; }
.gate-logo { display: inline-flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.logo-mark { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(160deg, #1a2030, #0b0d12); color: var(--accent); font-weight: 900; font-size: 32px; border: 1px solid var(--line-2); }
.logo-word { font-size: 40px; font-weight: 900; letter-spacing: .12em; }
.gate-sub { color: var(--muted); margin: 0 0 28px; font-size: 17px; }
.gate-hint { color: var(--faint); font-size: 13px; margin-top: 22px; line-height: 1.5; }

/* ---- Layout ---- */
.app { display: grid; grid-template-rows: auto auto 1fr auto; height: 100dvh; }
.app.hidden { visibility: hidden; }
header.top { display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; letter-spacing: .1em; font-size: 18px; }
.brand .logo-mark { width: 32px; height: 32px; font-size: 19px; border-radius: 9px; }
.top .grow { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); transition: background .1s, box-shadow .1s; }
.dot.on { background: var(--green); box-shadow: 0 0 10px var(--green); }
.dot.blink { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.dot.off { background: var(--red); }
select.plain { background: transparent; border: 0; color: var(--text); max-width: 200px; outline: none; }
.transpose { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.transpose .val { min-width: 130px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.transpose .val small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.transpose button { width: 40px; height: 40px; padding: 0; font-size: 20px; font-weight: 700; border-radius: 9px; }
.master { display: flex; align-items: center; gap: 8px; min-width: 160px; }
.meter { width: 6px; height: 34px; background: var(--line); border-radius: 3px; overflow: hidden; display: flex; align-items: flex-end; }
.meter > i { display: block; width: 100%; height: 0%; background: linear-gradient(to top, var(--green), var(--accent) 75%, var(--red)); transition: height .05s linear; }
.meter.h { width: 100%; height: 4px; flex-direction: row; align-items: stretch; }
.meter.h > i { width: 0%; height: 100%; transition: width .05s linear; }

/* ---- Escenas ---- */
.scenes { display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: thin; align-items: stretch; }
.scene { flex: 0 0 auto; min-width: 150px; text-align: left; padding: 10px 12px 10px 14px; border-radius: 12px; border-left: 4px solid var(--c, var(--accent)); position: relative; display: flex; flex-direction: column; gap: 2px; }
.scene .n { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.scene .name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.scene .layers-count { font-size: 11px; color: var(--faint); }
.scene.active { background: color-mix(in srgb, var(--c, var(--accent)) 18%, var(--panel-2)); border-color: color-mix(in srgb, var(--c, var(--accent)) 60%, var(--line)); border-left-color: var(--c); }
.scene.loading::after { content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: 40%; background: var(--c, var(--accent)); animation: slide 1s infinite linear; border-radius: 2px; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
.scene-tools { display: flex; gap: 6px; align-items: center; flex: 0 0 auto; padding-left: 6px; border-left: 1px solid var(--line); margin-left: 4px; }

/* ---- Cuerpo ---- */
main.body { display: grid; grid-template-columns: 1fr 300px; gap: 14px; padding: 14px 16px; overflow: auto; min-height: 0; }
.layers { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; align-content: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; position: relative; }
.card.add { display: grid; place-items: center; min-height: 160px; color: var(--muted); border-style: dashed; cursor: pointer; font-weight: 600; }
.card.add:hover { color: var(--text); border-color: var(--line-2); }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head .inst { flex: 1; min-width: 0; text-align: left; padding: 6px 10px; display: flex; flex-direction: column; gap: 1px; background: var(--panel-2); }
.card-head .inst b { display: block; font-size: 15px; line-height: 1.15; }
.card-head .inst small { color: var(--muted); font-size: 11px; }
.toggle { width: 36px; height: 36px; padding: 0; font-weight: 800; font-size: 13px; letter-spacing: .04em; }
.toggle.on.m { background: var(--red); color: #fff; border-color: transparent; }
.toggle.on.h { background: var(--teal); color: #052a28; border-color: transparent; }
.row { display: grid; grid-template-columns: 78px 1fr auto; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.row output { min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); font-size: 12px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; background: var(--line); border-radius: 3px; }
input[type=range]::-moz-range-track { height: 6px; background: var(--line); border-radius: 3px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%; background: var(--text); border: 3px solid var(--panel); box-shadow: 0 1px 4px rgba(0,0,0,.5); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--text); border: 3px solid var(--panel); }
input[type=range].vol::-webkit-slider-runnable-track { background: linear-gradient(90deg, var(--accent) var(--p, 0%), var(--line) var(--p, 0%)); }
input[type=range].vol::-moz-range-progress { background: var(--accent); height: 6px; }
.steppers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stepper { display: grid; grid-template-columns: 34px 1fr 34px; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel-2); }
.stepper button { border: 0; border-radius: 0; height: 36px; padding: 0; font-size: 18px; font-weight: 700; background: transparent; }
.stepper .v { text-align: center; font-size: 12px; color: var(--muted); line-height: 1.1; }
.stepper .v b { display: block; color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.zone { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.zone .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.zone .seg button { border: 0; border-radius: 0; padding: 6px 10px; font-size: 12px; background: transparent; }
.zone .seg button.on { background: var(--panel-2); color: var(--accent); font-weight: 700; }
.zone select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font-size: 12px; }
.status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; min-height: 16px; }
.status .bar { flex: 1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.status .bar > i { display: block; height: 100%; width: 0; background: var(--teal); transition: width .15s; }
.status.err { color: var(--red); }
.status.ready { color: var(--green); }

/* ---- Panel lateral ---- */
aside.side { display: flex; flex-direction: column; gap: 12px; }
.side h3 { margin: 0; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.padkeys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.padkeys button { height: 48px; font-weight: 800; font-size: 16px; border-radius: 10px; }
.padkeys button.on { background: var(--accent); color: #1a1200; border-color: transparent; box-shadow: 0 0 18px rgba(245,185,66,.45); }
.padkeys button.stop { grid-column: span 4; background: var(--panel-2); color: var(--muted); height: 40px; font-size: 13px; letter-spacing: .1em; }
.padkeys button.stop.on { color: var(--red); border-color: var(--red); }
.kv { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.kv b { color: var(--text); font-variant-numeric: tabular-nums; }
.help { font-size: 12px; color: var(--faint); line-height: 1.5; }
.help kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-family: var(--mono); font-size: 11px; }

/* ---- Teclado ---- */
footer.kb { border-top: 1px solid var(--line); background: var(--bg-2); padding: 8px 16px 10px; user-select: none; }
.kb-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.kb-bar .grow { flex: 1; }
.keys { position: relative; height: 120px; display: flex; touch-action: none; }
.key { position: relative; flex: 1; border: 1px solid #0a0c10; border-radius: 0 0 6px 6px; background: linear-gradient(#f4f5f7, #d9dce3); cursor: pointer; }
.key.black { position: absolute; top: 0; height: 62%; width: calc(var(--w) * .62); margin-left: calc(var(--w) * -.31); background: linear-gradient(#2a2f3a, #0e1117); border-radius: 0 0 5px 5px; z-index: 2; box-shadow: 0 3px 6px rgba(0,0,0,.5); }
.key.c::after { content: attr(data-label); position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 10px; color: #6b7280; font-weight: 700; }
.key.on { background: linear-gradient(var(--accent-2), var(--accent)); }
.key.black.on { background: linear-gradient(#ffdc8f, #e6a82d); }
.key.out { filter: brightness(.55); }
.zones { position: relative; height: 5px; margin-bottom: 4px; }
.zones > i { position: absolute; top: 0; height: 100%; border-radius: 3px; opacity: .85; }

/* ---- Modal / navegador ---- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(4,6,10,.7); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 16px; }
.modal.hidden { display: none; }
.sheet { width: min(960px, 100%); max-height: min(85dvh, 760px); background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; box-shadow: var(--shadow); display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 17px; flex: 1; }
.sheet-head input { flex: 1; max-width: 320px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; outline: none; }
.sheet-body { display: grid; grid-template-columns: 200px 1fr; min-height: 0; }
.cats { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-right: 1px solid var(--line); overflow: auto; }
.cats button { text-align: left; background: transparent; border-color: transparent; }
.cats button.on { background: var(--panel-2); border-color: var(--line); color: var(--accent); font-weight: 700; }
.list { overflow: auto; padding: 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; align-content: start; }
.inst-card { text-align: left; padding: 12px; border-radius: 12px; display: flex; flex-direction: column; gap: 4px; min-height: 96px; }
.inst-card b { font-size: 15px; }
.inst-card small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.inst-card .size { margin-top: auto; font-size: 11px; color: var(--faint); }
.inst-card.sel { border-color: var(--accent); }
.menu { position: absolute; right: 16px; top: 56px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; min-width: 240px; z-index: 30; }
.menu button { text-align: left; background: transparent; border-color: transparent; }
.menu button:hover { background: var(--panel-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.toast { position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); z-index: 60; font-size: 14px; max-width: 90vw; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  main.body { grid-template-columns: 1fr; }
  .layers { grid-template-columns: 1fr; }
  .transpose .val { min-width: 96px; }
  .master { min-width: 120px; }
  .sheet-body { grid-template-columns: 1fr; }
  .cats { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .cats button { white-space: nowrap; }
  .keys { height: 100px; }
}
@media (max-width: 560px) {
  header.top { padding: 8px 10px; gap: 8px; }
  .brand .word { display: none; }
  .chip.lat { display: none; }
  main.body { padding: 10px; }
  .scenes { padding: 8px 10px; }
  footer.kb { padding: 6px 10px 8px; }
}
