:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1d222b;
  --line: #2a303b;
  --line-soft: #222731;
  --text: #e9ecf1;
  --muted: #8a93a3;
  --accent: #ff5a36;
  --accent-soft: rgba(255, 90, 54, .16);
  --rec: #ff3b4e;
  --head-w: 96px;
  --lane-h: 76px;
  --ruler-h: 26px;
  --ease: cubic-bezier(.23, 1, .32, 1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button:disabled { opacity: .35; cursor: default; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
input, select { font: inherit; font-size: 16px; }

#app { position: relative; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* Top */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(8px + var(--sat)) 12px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; letter-spacing: -.01em; }
.logo { background: var(--accent); color: #fff; border-radius: 7px; padding: 2px 6px; font-size: 13px; }
.brand-name { font-size: 16px; }
/* Pestañas Audio / Vídeo (son dos páginas independientes) */
.tabs { margin-left: 4px; }
.tabs .seg-btn { text-decoration: none; padding: 5px 10px; font-weight: 600; }
@media (max-width: 400px) { .logo { display: none; } .tabs { margin-left: 0; } .tabs .seg-btn { padding: 5px 8px; } .btn-export { padding: 0 10px; } }
.top-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; color: var(--text); transition: background-color .15s, transform .12s var(--ease); }
.icon-btn.sm { width: 34px; height: 34px; }
.icon-btn:active:not(:disabled) { transform: scale(.94); background: var(--panel-2); }
.btn-export { height: 34px; padding: 0 12px; margin: 0 4px; border-radius: 9px; background: var(--accent); color: #fff; font-weight: 600; font-size: 13px; transition: transform .12s var(--ease); white-space: nowrap; }
.btn-export:active { transform: scale(.96); }

/* Toolbar */
.toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg.full { display: flex; }
.seg.full .seg-btn { flex: 1; }
.seg-btn { padding: 6px 11px; border-radius: 7px; color: var(--muted); font-size: 13px; font-weight: 500; transition: background-color .15s, color .15s; }
.seg-btn.on { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset; }
.chip { padding: 6px 11px; border-radius: 9px; border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 500; }
.chip.on { color: var(--accent); border-color: rgba(255,90,54,.45); background: var(--accent-soft); }
.zoom { margin-left: auto; display: flex; gap: 2px; }

/* Editor */
.editor { position: relative; flex: 1; display: flex; min-height: 0; background: var(--bg); }
.heads { width: var(--head-w); flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; z-index: 3; }
.ruler-corner { height: var(--ruler-h); flex: none; border-bottom: 1px solid var(--line); }
#headInner { flex: none; will-change: transform; }
.head { height: var(--lane-h); border-bottom: 1px solid var(--line-soft); padding: 6px 6px 6px 8px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.head::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--c); }
.head.sel { background: var(--panel-2); }
.head-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: 0; color: var(--text); padding: 0; width: 100%; outline: none; font-size: 12px; }
.head-btns { display: flex; gap: 3px; }
.hb { width: 24px; height: 22px; border-radius: 5px; font-size: 11px; font-weight: 700; background: var(--bg); color: var(--muted); border: 1px solid var(--line); display: grid; place-items: center; }
.hb svg { width: 13px; height: 13px; }
.hb.m.on { background: #3a3f4a; color: #fff; }
.hb.s.on { background: #e6b422; color: #111; border-color: #e6b422; }
.head input[type=range] { width: 100%; height: 16px; margin: 0; }
.add-track { margin: 8px; height: 40px; border-radius: 10px; border: 1px dashed var(--line); color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 12px; flex: none; }
.add-track svg { width: 16px; height: 16px; }
.add-track:active { background: var(--panel-2); }

.scroller { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; position: relative; -webkit-overflow-scrolling: touch; }
.timeline { position: relative; min-width: 100%; min-height: 100%; }
.tl-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ruler { flex: none; display: block; width: 100%; height: var(--ruler-h); background: var(--panel); border-bottom: 1px solid var(--line); touch-action: none; cursor: pointer; }
.lane { height: var(--lane-h); border-bottom: 1px solid var(--line-soft); position: relative; }
.lane.sel { background: rgba(255,255,255,.02); }
.lane-spacer { height: 64px; }
.playhead { position: absolute; top: 0; bottom: 0; left: 0; width: 2px; margin-left: -1px; background: var(--accent); z-index: 4; pointer-events: none; will-change: transform; }
.playhead span { position: absolute; top: 0; left: -6px; width: 14px; height: 14px; background: var(--accent); clip-path: polygon(0 0, 100% 0, 100% 55%, 50% 100%, 0 55%); }

/* Clips */
.clip { position: absolute; top: 5px; bottom: 5px; border-radius: 8px; background: color-mix(in srgb, var(--c) 22%, #12151b); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.clip.sel { border-color: #fff; box-shadow: 0 0 0 1px #fff, 0 6px 18px rgba(0,0,0,.45); z-index: 2; }
.clip.drag { cursor: grabbing; opacity: .92; z-index: 3; }
.clip canvas { position: absolute; inset: 16px 0 0 0; width: 100%; height: calc(100% - 16px); pointer-events: none; }
.clip-label { position: absolute; left: 0; right: 0; top: 0; height: 16px; padding: 1px 6px; font-size: 10.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: color-mix(in srgb, var(--c) 40%, transparent); color: #fff; pointer-events: none; }
.clip-rate { position: absolute; right: 4px; bottom: 3px; font-size: 10px; font-weight: 700; padding: 0 4px; border-radius: 4px; background: rgba(0,0,0,.55); color: #ffd36b; pointer-events: none; }
.fade { position: absolute; top: 16px; bottom: 0; pointer-events: none; }
.fade.in { left: 0; background: linear-gradient(to bottom right, rgba(0,0,0,.55) 50%, transparent 50.5%); }
.fade.out { right: 0; background: linear-gradient(to bottom left, rgba(0,0,0,.55) 50%, transparent 50.5%); }
.handle { position: absolute; top: 0; bottom: 0; width: 22px; z-index: 1; touch-action: none; }
.handle::after { content: ""; position: absolute; top: 50%; width: 4px; height: 26px; margin-top: -13px; border-radius: 3px; background: rgba(255,255,255,.75); opacity: 0; transition: opacity .15s; }
.handle.l { left: 0; cursor: w-resize; } .handle.l::after { left: 3px; }
.handle.r { right: 0; cursor: e-resize; } .handle.r::after { right: 3px; }
.clip.sel .handle::after { opacity: 1; }
body.stretch .clip.sel .handle::after { background: #ffd36b; width: 6px; }
.clip.pending { opacity: .6; }
.snapline { position: absolute; top: 0; bottom: 0; width: 1px; background: #ffd36b; z-index: 5; pointer-events: none; }

/* Empty */
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; background: var(--bg); z-index: 5; }
.empty[hidden] { display: none; }
.empty-icon { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 14px; }
.empty-icon svg { width: 30px; height: 30px; }
.empty h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: -.01em; }
.empty p { margin: 0 0 20px; color: var(--muted); max-width: 30ch; }
.empty-actions { display: flex; gap: 10px; }
.btn { height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 600; transition: transform .12s var(--ease); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:active { transform: scale(.97); }

/* Sheet */
.sheet { position: absolute; left: 0; right: 0; bottom: calc(68px + var(--sab)); max-height: 58dvh; overflow-y: auto; background: var(--panel); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 10px 14px 14px; z-index: 20; transform: translateY(calc(100% + 80px)); transition: transform .28s var(--ease); box-shadow: 0 -10px 30px rgba(0,0,0,.4); overscroll-behavior: contain; }
.sheet.open { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.clip-name { flex: 1; min-width: 0; background: none; border: 0; color: var(--text); font-weight: 700; font-size: 16px; padding: 6px 0; outline: none; border-bottom: 1px solid transparent; }
.clip-name:focus { border-bottom-color: var(--line); }
.sheet-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0 10px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 9px 0 7px; border-radius: 11px; background: var(--panel-2); font-size: 11.5px; font-weight: 600; color: var(--text); transition: transform .12s var(--ease); }
.act:active { transform: scale(.95); }
.act.danger { color: #ff7a7a; }
.ctrl { margin: 10px 0; }
.ctrl label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.ctrl output { color: var(--text); font-variant-numeric: tabular-nums; }
.ctrl.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.presets { display: flex; gap: 4px; margin-top: 6px; }
.presets button { flex: 1; padding: 5px 0; font-size: 11.5px; border-radius: 7px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.presets button.on { color: var(--accent); border-color: rgba(255,90,54,.5); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin-top: 8px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.check.small { font-size: 12px; margin: 0; }
.check.small input { width: 15px; height: 15px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: #fff; margin-top: -8px; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: #fff; }
.head input[type=range]::-webkit-slider-thumb { width: 13px; height: 13px; margin-top: -5px; background: var(--c); }
.head input[type=range]::-moz-range-thumb { width: 13px; height: 13px; background: var(--c); }
.head input[type=range]::-webkit-slider-runnable-track { height: 3px; }

/* Transport */
.transport { position: relative; z-index: 21; display: flex; align-items: center; gap: 10px; padding: 10px 16px calc(10px + var(--sab)); height: calc(68px + var(--sab)); background: var(--panel); border-top: 1px solid var(--line); }
.t-btn { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); transition: transform .12s var(--ease), background-color .15s; }
.t-btn:active { transform: scale(.93); }
.t-btn.play { background: #fff; color: #111; }
.t-btn.play svg { width: 22px; height: 22px; }
.t-btn .i-pause { display: none; }
body.playing .t-btn .i-pause { display: block; }
body.playing .t-btn .i-play { display: none; }
.rec-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--rec); transition: border-radius .2s var(--ease), transform .2s var(--ease); }
body.recording .rec-dot { border-radius: 4px; transform: scale(.85); }
body.recording .t-btn.rec { background: rgba(255,59,78,.18); }
.time { margin-left: auto; font: 600 20px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

.rec-banner { position: absolute; left: 50%; transform: translateX(-50%); top: calc(110px + var(--sat)); z-index: 30; display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: rgba(22,26,33,.96); border: 1px solid rgba(255,59,78,.5); border-radius: 999px; font: 600 13px/1 ui-monospace, Menlo, Consolas, monospace; box-shadow: 0 8px 24px rgba(0,0,0,.4); white-space: nowrap; }
.rec-banner[hidden] { display: none; }
.rec-pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: pulse 1s ease-in-out infinite; }
#recMeter { width: 80px; height: 8px; border-radius: 4px; background: var(--bg); }
@keyframes pulse { 50% { opacity: .3; } }

/* Menu */
.menu { position: absolute; top: calc(52px + var(--sat)); right: 10px; z-index: 40; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; min-width: 190px; box-shadow: 0 12px 30px rgba(0,0,0,.5); transform-origin: top right; animation: pop .16s var(--ease); }
.menu[hidden] { display: none; }
.menu button { display: block; width: 100%; text-align: left; padding: 11px 12px; border-radius: 8px; }
.menu button:active { background: var(--line); }
.menu .danger { color: #ff7a7a; }
@keyframes pop { from { opacity: 0; transform: scale(.95); } }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; padding: 12px; padding-bottom: calc(12px + var(--sab)); }
.modal[hidden] { display: none; }
.modal-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; animation: up .25s var(--ease); }
.modal-card h3 { margin: 0 0 6px; font-size: 18px; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.text { width: 100%; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); outline: none; }
.text:focus { border-color: var(--accent); }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 14px; }
.progress[hidden] { display: none; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.hint { color: var(--muted); font-size: 12px; min-height: 16px; margin: 8px 0 0; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

.busy { position: fixed; inset: 0; z-index: 60; background: rgba(15,17,21,.7); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-weight: 600; }
.busy[hidden] { display: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: calc(84px + var(--sab)); transform: translate(-50%, 20px); opacity: 0; z-index: 70; background: #fff; color: #111; padding: 10px 14px; border-radius: 10px; font-weight: 600; font-size: 13px; pointer-events: none; transition: opacity .2s, transform .25s var(--ease); max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (hover: hover) {
  .icon-btn:hover:not(:disabled) { background: var(--panel-2); }
  .clip:hover .handle::after { opacity: .6; }
}
@media (min-width: 720px) {
  :root { --head-w: 150px; --lane-h: 92px; }
  .sheet { left: auto; right: 16px; bottom: calc(80px + var(--sab)); width: 380px; border-radius: 16px; border: 1px solid var(--line); }
  .modal { align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.ctrl label.check { justify-content: flex-start; color: var(--text); font-weight: 500; font-size: 13px; }
