:root {
  --bg: #0a0a0c;
  --panel: #141419;
  --panel2: #1c1c24;
  --line: #2a2a34;
  --text: #e6e6ea;
  --muted: #8a8a96;
  --accent: #ff3b6b;      /* VHS magenta-red */
  --accent2: #29d3c2;     /* cyan */
  --amber: #ffcf4d;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;

  /* semantic stacking order — never write a bare 999 anywhere */
  --z-card: 1;
  --z-seam: 2;
  --z-handle: 3;
  --z-sticky: 10;
  --z-playhead: 20;
  --z-popover: 40;
  --z-modal: 100;

  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent2);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 140ms;
  --t-base: 200ms;
}

:focus-visible { outline: none; box-shadow: var(--focus); }

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 13px; overflow: hidden;
}
body { display: flex; flex-direction: column; height: 100vh; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 10px; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 16px 0 6px; }
button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.big { padding: 10px 16px; font-size: 13px; }
.muted { color: var(--muted); font-size: 11px; }
.hidden { display: none !important; }

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 16px;
  background: linear-gradient(180deg, #16161c, #101014);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .1em; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand em { color: var(--muted); font-weight: 400; font-style: normal; font-size: 11px; text-transform: uppercase; letter-spacing: .2em; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: .15; } }
.transport { display: flex; align-items: center; gap: 8px; flex: 1; }
.transport button { min-width: 38px; font-size: 13px; }
.timecode { font-family: var(--mono); color: var(--accent2); font-size: 13px; margin-left: 6px; }
.badge { font-family: var(--mono); font-size: 11px; color: var(--amber); border: 1px solid var(--line); padding: 3px 8px; border-radius: 4px; }
.topActions { display: flex; gap: 8px; align-items: center; }

/* ---- session save state ---- */
/* Reads as instrument telemetry, not a button — it reports, you don't press it.
   The dot is the only moving part, so a save is visible in peripheral vision
   without the row reflowing. */
.saveState {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  padding: 3px 8px; border: 1px solid var(--line); border-radius: 4px;
  white-space: nowrap; cursor: default;
}
.saveState::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent2); opacity: .35;
  transition: opacity var(--t-base) var(--ease-out), box-shadow var(--t-base) var(--ease-out);
}
/* toggled for one beat on each actual write */
.saveState.writing::before { opacity: 1; box-shadow: 0 0 7px var(--accent2); }
.saveState.writing { color: var(--accent2); border-color: var(--accent2); }
/* localStorage unavailable, or a write that failed outright */
.saveState.off { color: var(--amber); border-color: color-mix(in oklab, var(--amber) 45%, var(--line)); }
.saveState.off::before { background: var(--amber); opacity: .9; box-shadow: none; }

.iconBtn { font-size: 13px; line-height: 1; padding: 5px 8px; color: var(--muted); }
.iconBtn:hover { color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  .saveState::before { transition: none; }
}

/* ---- mode switch ---- */
.modeSwitch { display: flex; gap: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.modeBtn {
  background: transparent; border: none; border-radius: 5px; color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .1em; padding: 5px 12px;
  transition: color var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out);
}
.modeBtn:hover { color: var(--text); border-color: transparent; }
.modeBtn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ---- mode visibility ---- */
body[data-mode="edit"] .sbLayout { display: none; }
body[data-mode="storyboard"] .layout,
body[data-mode="storyboard"] .timelineWrap { display: none; }

/* the single monitor node is moved between per-mode slots, so one WebGL
   context serves edit, storyboard and compose */
.monitorSlot { flex: 1; min-height: 0; min-width: 0; display: flex; }

/* ---- layout ---- */
.layout { flex: 1; display: grid; grid-template-columns: 230px 1fr 250px; min-height: 0; }
.bin, .fx { background: var(--panel); overflow-y: auto; padding: 14px; }
.bin { border-right: 1px solid var(--line); }
.fx { border-left: 1px solid var(--line); }

/* ---- sidebar tabs ---- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { flex: 1; padding: 7px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- ideas panel ---- */
.ideaHint { font-size: 10px; color: var(--muted); line-height: 1.5; margin: 0 0 12px; }
.ideaGroup { margin-bottom: 16px; }
.ideaList { display: flex; flex-direction: column; gap: 6px; }
.ideaCard { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; }
.ideaCard:hover { border-color: var(--accent); }
.icard-main { min-width: 0; }
.icard-name { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.icard-desc { font-size: 10px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.icard-action { font-size: 11px; padding: 5px 10px; white-space: nowrap; }
.tag { font-size: 8px; text-transform: uppercase; letter-spacing: .08em; padding: 1px 5px; border-radius: 3px; border: 1px solid var(--line); color: var(--muted); }
.tag-atardecer { color: #ffb15e; border-color: #7a4e1e; }
.tag-noche { color: #6fa8ff; border-color: #274a7a; }
.tag-interior { color: #ff9e7a; border-color: #7a3a26; }
.tag-abstracto { color: #b98cff; border-color: #4a2e7a; }
.tag-foto { color: #29d3c2; border-color: #1c6b63; }
.tag-arc { color: #ffcf4d; border-color: #7a6320; }
.versionBar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.versionBar button { flex: 1 1 auto; font-size: 10px; padding: 6px 4px; white-space: nowrap; }
/* the primary action gets its own row; JSON / Reset share the one below */
#saveVersion { flex-basis: 100%; }
.savedList { display: flex; flex-direction: column; gap: 5px; }
.savedRow { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 5px 8px; font-size: 11px; }
.savedRow button { padding: 3px 8px; font-size: 10px; }
.savedRow .del { color: var(--accent); }

/* ---- fatal init error ---- */
.fatal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; flex-direction: column; justify-content: center;
  gap: 14px; padding: 8vh 8vw; background: #0a0a0cf2; overflow: auto;
}
.fatal h2 { color: var(--accent); font-size: 15px; margin: 0; }
.fatal pre {
  font-family: var(--mono); font-size: 11px; line-height: 1.6; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 12px; margin: 0; max-height: 45vh; overflow: auto; white-space: pre-wrap;
}
.fatal p { color: var(--muted); font-size: 12px; margin: 0; line-height: 1.6; }
.fatal kbd {
  font-family: var(--mono); font-size: 10px; border: 1px solid var(--line);
  border-radius: 3px; padding: 1px 4px; color: var(--text);
}
.fatal button { align-self: flex-start; }

/* ---- media bin ---- */
.binGroup { margin-bottom: 14px; }
.binGroup > .grpTitle { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent2); margin-bottom: 6px; }
.binList { display: flex; flex-direction: column; gap: 12px; }
.tile {
  display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px; cursor: pointer;
}
.tile:hover { border-color: var(--accent); }
.tile img { width: 64px; height: 40px; object-fit: cover; border-radius: 4px; background: #000; }
.tile .meta { min-width: 0; }
.tile .nm { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { font-size: 10px; color: var(--muted); }

/* ---- stage / monitor ---- */
.stage { display: flex; flex-direction: column; min-width: 0; padding: 16px; gap: 12px; }
.monitor {
  position: relative; flex: 1; min-height: 0; min-width: 0; background: #000;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#gl { width: 100%; height: 100%; object-fit: contain; display: block; }
/* ---- monitor tools (pop-out) ---- */
/* Inside #monitor so they follow it between the edit / storyboard / compose
   slots. Quiet until the monitor is hovered or the button has focus. */
.monTools {
  position: absolute; top: 8px; right: 8px; z-index: var(--z-handle);
  display: flex; gap: 4px;
  opacity: 0; transition: opacity var(--t-base) var(--ease-out);
}
.monitor:hover .monTools, .monTools:focus-within { opacity: 1; }
.monPop {
  background: #0a0a0cd9; border: 1px solid var(--line); color: var(--text);
  font-size: 11px; padding: 4px 8px; border-radius: 5px; backdrop-filter: blur(4px);
}
.monPop:hover { border-color: var(--accent); }
/* compose puts its own interaction layer over the monitor; a button under it
   would look clickable and not be */
#sbCompose .monTools { display: none; }

.monPopped {
  position: absolute; inset: 0; z-index: var(--z-seam);
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; background: #0a0a0cf2; text-align: center; padding: 16px;
  font-size: 12px; color: var(--muted);
}
.monPopped b { color: var(--text); font-weight: 600; }
.monitor.popped .monPopped { display: flex; }

.monMenu {
  position: absolute; top: 38px; right: 8px; z-index: var(--z-popover);
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  padding: 5px; display: flex; flex-direction: column; gap: 3px;
  box-shadow: 0 10px 28px #000000cc; min-width: 190px;
}
.monMenu button { text-align: left; font-size: 11px; padding: 6px 9px; }

.overlay { position: absolute; inset: 0; pointer-events: none; font-family: var(--mono); color: #fff; text-shadow: 0 0 4px rgba(0,0,0,.9); }
.overlay > div { position: absolute; letter-spacing: .1em; }
.ov-rec { top: 16px; left: 18px; display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: clamp(11px,1.4vw,16px); }
.ov-date { top: 16px; right: 18px; font-size: clamp(11px,1.4vw,16px); }
.ov-tc { bottom: 16px; right: 18px; font-size: clamp(11px,1.4vw,16px); color: var(--amber); }
.ov-play { bottom: 16px; left: 18px; font-size: clamp(11px,1.4vw,16px); letter-spacing: .2em; }

.genbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.ctrl { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.ctrl.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.ctrl input[type=range] { width: 120px; accent-color: var(--accent); }
.ctrl input[type=text], .ctrl select { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 5px; padding: 5px 7px; }

/* ---- fx panel ---- */
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.presets button { flex: 1 1 auto; font-size: 11px; padding: 5px 8px; }
.presets button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.fxRow { margin-bottom: 10px; }
.fxRow label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.fxRow input[type=range] { width: 100%; accent-color: var(--accent2); }
.fxRow .val { font-family: var(--mono); color: var(--text); }

/* ---- timeline ---- */
.timelineWrap { height: 210px; background: var(--panel); border-top: 1px solid var(--line); display: flex; flex-direction: column; }
.tlHead { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.tlHead > span { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.tlTools { display: flex; align-items: center; gap: 6px; }
.tlTools button { padding: 3px 9px; }
.tlScroll { flex: 1; overflow-x: auto; overflow-y: hidden; position: relative; }
.tlRuler { position: relative; height: 22px; border-bottom: 1px solid var(--line); background: var(--panel2); }
.tlRuler .tick { position: absolute; top: 0; height: 100%; border-left: 1px solid var(--line); font-size: 9px; color: var(--muted); padding-left: 3px; }
.tlRuler .beat { position: absolute; top: 14px; height: 8px; border-left: 1px solid #333; }
.tlRuler .beat.down { border-color: var(--accent); height: 14px; top: 8px; }
/* detected arrangement boundaries — where the generator "begins again" */
.tlRuler .section { position: absolute; top: 0; height: 100%; border-left: 2px solid var(--amber); opacity: .55; }
.tlTrack { position: relative; height: 130px; background: repeating-linear-gradient(90deg, transparent 0, transparent 39px, #ffffff08 39px, #ffffff08 40px); }
.seg {
  position: absolute; top: 10px; height: 100px; border-radius: 5px; overflow: hidden;
  border: 1px solid var(--line); cursor: grab; background: var(--panel2);
  background-size: cover; background-position: center;
}
.seg .segLabel { position: absolute; left: 0; right: 0; bottom: 0; font-size: 9px; padding: 2px 4px; background: linear-gradient(180deg, transparent, #000d); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg .segIcon { position: absolute; top: 3px; left: 4px; font-size: 10px; background: #000a; padding: 1px 4px; border-radius: 3px; }
.seg.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 12px #ff3b6b66; }
.seg.seq { border-style: dashed; border-color: var(--accent2); }
.seg.multi { border-color: var(--amber); box-shadow: inset 0 0 0 1px #ffcf4d55; }
/* footage this shot points at is gone (rebuilt bin, stale imported JSON) — the
   shot is kept so it can be re-pointed, but it must not read as normal */
.seg.missing {
  background-image: repeating-linear-gradient(45deg, #2a2a34 0 6px, #1c1c24 6px 12px);
  border-color: var(--amber); border-style: dotted;
}
.seg .handle { position: absolute; top: 0; width: 8px; height: 100%; cursor: ew-resize; }
.seg .handle.l { left: 0; } .seg .handle.r { right: 0; }
.seg .handle:hover { background: var(--accent); }
.playhead { position: absolute; top: -22px; bottom: 0; width: 2px; background: var(--amber); pointer-events: none; z-index: var(--z-playhead); box-shadow: 0 0 8px var(--amber); }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: #000c; display: flex; align-items: center; justify-content: center; z-index: var(--z-modal); }
.modalBox { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px; width: min(560px, 90vw); }
.modalBox h3 { color: var(--text); margin-top: 0; }
.progress { height: 10px; background: var(--panel2); border-radius: 5px; overflow: hidden; margin: 10px 0; }
#renderBar { height: 100%; width: 0%; background: var(--accent); transition: width .3s; }
#renderLog { max-height: 180px; overflow: auto; font-family: var(--mono); font-size: 10px; color: var(--muted); background: #000; padding: 8px; border-radius: 6px; white-space: pre-wrap; }
.modalActions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
a.primary { text-decoration: none; display: inline-block; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 6px; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .modeBtn, button, .tab, .tile, .ideaCard { transition-duration: 1ms !important; }
  /* the blinking REC dot is exactly the kind of thing this setting is for —
     stop it outright rather than speeding it up */
  .rec-dot { animation: none !important; }
  #renderBar { transition: none !important; }
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2f2f3a; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }
