/* Slate — screen styles.
   Palette: cutting-mat green desk, paper cards, spike-tape yellow for the target, record red for overruns. */

:root {
  --ink: #1b1f2a;
  --ink-2: #4a5163;
  --ink-3: #767d8e;
  --paper: #ffffff;
  --desk: #eceee9;
  --desk-2: #e2e5df;
  --line: #d6dad3;
  --line-2: #c2c7be;
  --mat: #2e5e4e;
  --mat-2: #244b3e;
  --mat-ink: #e8f0ec;
  --mat-grid: rgba(255, 255, 255, 0.09);
  --tape: #f2c230;
  --tape-ink: #5c4500;
  --tape-bg: #fff4cc;
  --signal: #d4343b;
  --signal-bg: #fdeaea;
  --ok: #2b8a57;
  --ok-bg: #e4f4ea;
  --vo: #2f62c9;
  --vo-bg: #e9effc;
  --focus: #2f62c9;
  --shadow-1: 0 1px 2px rgba(27, 31, 42, 0.06), 0 2px 8px rgba(27, 31, 42, 0.05);
  --shadow-2: 0 2px 4px rgba(27, 31, 42, 0.08), 0 12px 32px rgba(27, 31, 42, 0.12);
  --r: 10px;
  --r-sm: 6px;
  --font-display: 'Big Shoulders Display', 'Arial Narrow', 'Helvetica Neue', sans-serif;
  --font-body: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --topbar-h: 60px;
  --header-h: 150px;
  --toolbar-h: 65px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8ebf1;
    --ink-2: #b4bac7;
    --ink-3: #8a91a1;
    --paper: #1c2028;
    --desk: #12151b;
    --desk-2: #181c23;
    --line: #2c323d;
    --line-2: #3a414e;
    --mat: #234a3d;
    --mat-2: #1b3a30;
    --tape-bg: #3a3014;
    --tape-ink: #f5d978;
    --signal-bg: #3a1b1d;
    --ok-bg: #16301f;
    --vo: #7fa6f0;
    --vo-bg: #1b2740;
    --focus: #7fa6f0;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 12px 32px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 400 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.mono { font-family: var(--font-mono); font-feature-settings: 'tnum'; letter-spacing: -0.01em; }
kbd {
  font: 500 11px/1 var(--font-mono);
  padding: 3px 5px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink-2);
  white-space: nowrap;
}
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; }

.icon { display: inline-flex; width: 18px; height: 18px; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--paper); color: var(--ink);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #2c3243; border-color: #2c3243; }
@media (prefers-color-scheme: dark) { .btn-primary:hover { background: #fff; } }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--desk-2); border-color: transparent; }
.btn-danger { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn-danger:hover { background: #b82a30; }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--signal); }
.btn-danger-ghost:hover { background: var(--signal-bg); }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 13px; gap: 6px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-lg { min-height: 48px; padding: 0 20px; font-size: 15px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink-2);
}
.icon-btn:hover:not(:disabled) { background: var(--desk-2); color: var(--ink); }
.icon-btn:disabled { opacity: 0.3; }
.icon-btn.danger:hover:not(:disabled) { background: var(--signal-bg); color: var(--signal); }
.icon-btn-lg { width: 40px; height: 40px; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field, .field-row + .field, .field + .field-row, .field-row + .field-row { margin-top: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-label { font-weight: 600; font-size: 13px; color: var(--ink); }
.field-label .req { color: var(--signal); }
.field-label .opt { font-weight: 400; color: var(--ink-3); margin-left: 6px; font-size: 12px; }
.field-hint { font-size: 12.5px; color: var(--ink-3); }
.field-error { font-size: 12.5px; color: var(--signal); font-weight: 600; }
.input {
  width: 100%; min-height: 40px; padding: 8px 11px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--paper); color: var(--ink);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input::placeholder { color: var(--ink-3); opacity: 0.8; }
.input:hover { border-color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input[aria-invalid] { border-color: var(--signal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 15%, transparent); }
textarea.input { resize: vertical; line-height: 1.5; min-height: 64px; }
textarea.input[rows='1'] { min-height: 40px; }
select.input {
  appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23767d8e' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 18px;
}
.input-title { font-size: 17px; font-weight: 600; }
.input-lg { min-height: 46px; font-size: 16px; }
.input-num { font-family: var(--font-mono); }
.input-suffix { position: relative; display: flex; align-items: center; }
.input-suffix .input { padding-right: 42px; }
.input-suffix > span { position: absolute; right: 11px; font-size: 12px; color: var(--ink-3); pointer-events: none; }
.input-suffix-sm .input { min-height: 34px; padding: 4px 22px 4px 8px; font-size: 13px; }
.input-suffix-sm > span { right: 8px; }
.stack { display: flex; flex-direction: column; }
.stack-xs { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--mat);
  color: var(--mat-ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.topbar-row {
  display: flex; align-items: center; gap: 14px;
  height: var(--topbar-h); padding: 0 16px 0 12px;
}
.brand { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 8px; color: var(--tape); --mark-cut: var(--mat); }
.brand:hover { background: rgba(255, 255, 255, 0.08); }
.slate-mark { display: inline-flex; width: 28px; height: 28px; }
.slate-mark svg { width: 100%; height: 100%; }
.ws-name { display: flex; flex-direction: column; min-width: 0; flex: 0 1 auto; line-height: 1.1; }
.ws-title {
  font: 800 22px/1 var(--font-display); letter-spacing: 0.01em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32vw;
}
.ws-client { font-size: 12px; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32vw; }

.tabs { display: flex; gap: 2px; padding: 3px; background: rgba(0, 0, 0, 0.18); border-radius: 9px; margin-left: 8px; }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px; border: 0; border-radius: 7px;
  background: transparent; color: var(--mat-ink); font-weight: 600; font-size: 14px; opacity: 0.8;
}
.tab:hover { opacity: 1; background: rgba(255, 255, 255, 0.07); }
.tab.active { background: var(--paper); color: var(--ink); opacity: 1; box-shadow: var(--shadow-1); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar .btn { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.16); color: var(--mat-ink); }
.topbar .btn:hover { background: rgba(255, 255, 255, 0.18); }
.topbar .btn-ghost { background: transparent; border-color: transparent; }
.topbar .icon-btn { color: var(--mat-ink); }
.topbar .icon-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

.save-status { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; opacity: 0.85; padding: 0 4px; white-space: nowrap; }
.save-dot { width: 8px; height: 8px; border-radius: 50%; background: #7fd3a5; }
.is-pending .save-dot { background: var(--tape); }
.is-saving .save-dot { background: var(--tape); animation: pulse 0.9s infinite alternate; }
.is-error { opacity: 1; color: #ffd3d5; font-weight: 600; }
.is-error .save-dot { background: #ff6b71; }
@keyframes pulse { to { opacity: 0.3; } }

.backup-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px; border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2); background: transparent; color: var(--mat-ink);
  font-size: 12.5px; font-weight: 600;
}
.backup-chip .icon { width: 15px; height: 15px; }
.backup-chip:hover { background: rgba(255, 255, 255, 0.1); }
.backup-chip.stale { background: var(--tape); border-color: var(--tape); color: var(--tape-ink); }
@media (prefers-color-scheme: dark) { .backup-chip.stale { color: #3b2c00; } }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 230px; padding: 6px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-2);
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: var(--r-sm); background: transparent; text-align: left; font-size: 14px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--desk-2); outline: none; }
.menu-item kbd { margin-left: auto; }

.banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: var(--tape); color: #3b2c00; font-size: 13.5px; font-weight: 500;
}
.banner .btn { background: #fff8; border-color: #0002; color: #3b2c00; }
.banner .icon-btn { margin-left: auto; color: #3b2c00; }

/* ---------- Timeline (signature) ---------- */

.timeline {
  display: grid; grid-template-columns: 200px 1fr; gap: 18px; align-items: center;
  padding: 6px 16px 10px;
  background: var(--mat-2);
  background-image:
    linear-gradient(var(--mat-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--mat-grid) 1px, transparent 1px);
  background-size: 16px 16px;
}
.tl-readout { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.tl-label { width: 100%; font: 600 10.5px/1 var(--font-body); letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.6; }
.tl-numbers strong { font-size: 20px; font-weight: 500; color: #fff; }
.tl-of { font: 400 13px var(--font-mono); opacity: 0.7; }
.tl-pill { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.12); }
.tl-pill-on { background: #7fd3a5; color: #0f3321; }
.tl-pill-under { background: rgba(255, 255, 255, 0.14); }
.tl-pill-over { background: var(--signal); color: #fff; }
.tl-lane { min-width: 0; padding-top: 16px; }
.tl-track {
  position: relative; height: 44px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.tl-block {
  position: absolute; top: 3px; bottom: 3px;
  padding: 0; border: 0; border-radius: 3px;
  background: #f4f2ec center / cover no-repeat;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
  overflow: hidden; transition: transform 0.12s;
  border-right: 2px solid var(--mat-2);
}
.tl-block.has-img::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,.45), transparent 60%); }
.tl-block:hover { transform: translateY(-2px); }
.tl-block.selected { box-shadow: 0 0 0 2px var(--tape), inset 0 0 0 1px rgba(0,0,0,.25); z-index: 2; }
.tl-num {
  position: absolute; left: 5px; top: 50%; transform: translateY(-50%); z-index: 1;
  font: 800 17px/1 var(--font-display); color: var(--ink);
}
.tl-block.has-img .tl-num { color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.tl-overflow {
  position: absolute; top: 0; bottom: 0; pointer-events: none; z-index: 3;
  background: repeating-linear-gradient(-45deg, rgba(212, 52, 59, 0.55) 0 6px, rgba(212, 52, 59, 0.2) 6px 12px);
  border-radius: 0 4px 4px 0;
}
.tl-target { position: absolute; top: -16px; bottom: -4px; width: 0; z-index: 4; pointer-events: none; }
.tl-target::before { content: ''; position: absolute; top: 12px; bottom: 0; left: -1.5px; width: 3px; background: var(--tape); border-radius: 2px; }
.tl-target span {
  position: absolute; top: -2px; right: -2px; white-space: nowrap;
  font: 700 10px/1 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 3px 3px 0 3px; background: var(--tape); color: #3b2c00;
}
.tl-empty { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12.5px; opacity: 0.6; }
.tl-ruler { position: relative; height: 14px; margin-top: 3px; }
.tl-tick { position: absolute; top: 0; transform: translateX(-50%); font: 400 10px/1 var(--font-mono); opacity: 0.55; }
.tl-tick::before { content: ''; position: absolute; left: 50%; top: -3px; width: 1px; height: 3px; background: currentColor; }
.tl-tick:first-child { transform: none; }

/* ---------- Views ---------- */

.view { outline: none; }
.panel {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px 22px; box-shadow: var(--shadow-1);
}
.panel + .panel { margin-top: 18px; }
.panel-head { margin-bottom: 16px; }
.panel-head h2 { font: 800 24px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.01em; }
.panel-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.panel-sub { margin-top: 5px; font-size: 13px; color: var(--ink-3); }
.panel-stat { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; padding-top: 4px; }
.panel-stat.over { color: var(--signal); font-weight: 600; }
.panel-foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* Script tab */
.script-layout {
  display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px; align-items: start;
  max-width: 1400px; margin: 0 auto; padding: 20px;
}
.brief { position: sticky; top: calc(var(--header-h) + 20px); max-height: calc(100vh - var(--header-h) - 40px); overflow: auto; }
.script-text {
  min-height: 300px; font-size: 16px; line-height: 1.7; padding: 16px 18px;
  font-family: var(--font-mono); font-size: 14.5px;
}

.beats-empty { padding: 18px; border: 1.5px dashed var(--line-2); border-radius: var(--r-sm); color: var(--ink-3); font-size: 14px; text-align: center; }
.beat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.beat {
  display: grid; grid-template-columns: 112px 1fr; gap: 14px;
  padding: 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--paper);
}
.beat:focus-within { border-color: var(--line-2); box-shadow: var(--shadow-1); }
.beat-rail { display: flex; flex-direction: column; gap: 6px; }
.beat-no { font: 800 34px/0.9 var(--font-display); color: var(--mat); }
.beat-tc { font-size: 11px; color: var(--ink-3); }
.beat-tools { display: flex; gap: 0; margin-top: 2px; margin-left: -6px; }
.beat-tools .icon-btn { width: 30px; height: 30px; }
.beat-label {
  width: 100%; border: 0; border-bottom: 1.5px solid transparent; background: transparent; padding: 2px 0 4px;
  font-weight: 700; font-size: 15px; margin-bottom: 8px;
}
.beat-label:hover { border-bottom-color: var(--line); }
.beat-label:focus { outline: none; border-bottom-color: var(--focus); }
.beat-label::placeholder { color: var(--ink-3); font-weight: 500; }
.beat-lanes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.lane { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.lane-tag {
  display: inline-flex; align-items: center; gap: 5px; align-self: flex-start;
  font: 700 10.5px/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase;
  padding: 4px 7px 4px 5px; border-radius: 4px;
}
.lane-tag .icon { width: 13px; height: 13px; }
.lane-video .lane-tag { background: var(--desk-2); color: var(--ink-2); }
.lane-audio .lane-tag { background: var(--vo-bg); color: var(--vo); }
.lane-super .lane-tag { background: var(--tape-bg); color: var(--tape-ink); }
.lane-video .input { border-left: 3px solid var(--line-2); }
.lane-audio .input { border-left: 3px solid var(--vo); }
.lane-super .input { border-left: 3px solid var(--tape); }
.lane-super .input { font-weight: 600; }
.lane-input { font-size: 14px; }
.lane-fit { font-size: 12px; font-weight: 600; }
.lane-fit.ok { color: var(--ok); }
.lane-fit.bad { color: var(--signal); }
.lane-boxed + .lane-boxed, .field + .lane-boxed, .field-row + .lane-boxed, .lane-boxed + .ed-group { margin-top: 16px; }

/* Storyboard tab */
.board { position: relative; }
.board-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--desk);
  position: sticky; top: var(--header-h); z-index: 10; min-height: var(--toolbar-h);
}
.toolbar-hint { margin-left: auto; font-size: 12.5px; color: var(--ink-3); display: inline-flex; align-items: center; gap: 4px; }
.toolbar-count { font-size: 12.5px; color: var(--ink-2); padding-left: 10px; border-left: 1px solid var(--line-2); }
.board-layout { display: grid; grid-template-columns: minmax(0, 1fr); }
.board-layout.editing { grid-template-columns: minmax(0, 1fr) minmax(360px, 430px); }
.board-scroll { padding: 20px; min-width: 0; }

.frame-grid {
  --card-min: 240px;
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr)); gap: 18px;
}
.frame-card {
  position: relative; display: flex; flex-direction: column;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-1); cursor: pointer; overflow: hidden;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
.frame-card:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
.frame-card.selected { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink), var(--shadow-2); }
.frame-card:focus-visible { outline-offset: 3px; }
.frame-card.dragging { opacity: 0.35; transform: scale(0.97); }
.frame-card.drop-before::before, .frame-card.drop-after::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 4px; background: var(--focus); border-radius: 2px; z-index: 5;
}
.frame-card.drop-before::before { left: -11px; }
.frame-card.drop-after::after { right: -11px; }
.frame-card.drop-target, .ed-media.drop-target { box-shadow: 0 0 0 3px var(--focus); }

.card-media { position: relative; background: var(--desk-2); overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-noimg {
  position: absolute; inset: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px dashed var(--line-2); border-radius: var(--r-sm); color: var(--ink-3); font-size: 12px; text-align: center;
}
.card-noimg .icon { width: 26px; height: 26px; }
.frame-no {
  position: absolute; left: 0; top: 0;
  font: 800 26px/1 var(--font-display);
  padding: 6px 10px 5px 9px; background: var(--paper); color: var(--ink);
  border-bottom-right-radius: 8px;
}
.frame-card.selected .frame-no { background: var(--ink); color: var(--paper); }
.card-body { padding: 10px 12px 4px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-meta { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-3); }
.card-dur { color: var(--ink); font-weight: 500; background: var(--desk-2); padding: 1px 6px; border-radius: 4px; }
.card-action {
  font-size: 14px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-action.is-empty { color: var(--ink-3); font-style: italic; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 10px;
  background: var(--desk-2); color: var(--ink-2);
}
.chip .icon { width: 12px; height: 12px; }
.chip-vo { background: var(--vo-bg); color: var(--vo); }
.chip-super { background: var(--tape-bg); color: var(--tape-ink); }
.chip-warn { background: var(--tape); color: #3b2c00; }
.chip-danger { background: var(--signal-bg); color: var(--signal); }
.card-actions { display: flex; align-items: center; padding: 4px 6px 6px; }
.card-actions .icon-btn { width: 32px; height: 32px; }
.card-actions-gap { flex: 1; }
.grip { cursor: grab; touch-action: none; }
.grip:active { cursor: grabbing; }

.frame-add button {
  width: 100%; height: 100%; min-height: 180px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed var(--line-2); border-radius: var(--r); background: transparent; color: var(--ink-3); font-weight: 600;
}
.frame-add button:hover { border-color: var(--ink-3); color: var(--ink); background: var(--paper); }
.frame-add .icon { width: 26px; height: 26px; }

.board-empty {
  grid-column: 1 / -1; max-width: 560px; margin: 40px auto; text-align: center;
  padding: 40px 28px; border: 2px dashed var(--line-2); border-radius: 14px; background: var(--paper);
}
.board-empty h2 { font: 800 34px/1 var(--font-display); text-transform: uppercase; }
.board-empty p { margin: 10px 0 20px; color: var(--ink-2); }
.board-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.drop-veil {
  position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: 0;
  display: grid; place-items: center; background: color-mix(in srgb, var(--mat) 82%, transparent);
  transition: opacity 0.12s;
}
.drop-veil > div {
  display: flex; flex-direction: column; align-items: center; gap: 6px; color: #fff;
  padding: 40px 56px; border: 3px dashed rgba(255, 255, 255, 0.6); border-radius: 18px;
}
.drop-veil .icon { width: 40px; height: 40px; }
.drop-veil strong { font: 800 32px/1 var(--font-display); text-transform: uppercase; }
.board.file-over .drop-veil { opacity: 1; }

/* Frame editor */
.editor {
  position: sticky; top: calc(var(--header-h) + var(--toolbar-h));
  height: calc(100vh - var(--header-h) - var(--toolbar-h));
  display: flex; flex-direction: column;
  background: var(--paper); border-left: 1px solid var(--line);
}
.ed-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.ed-title { display: flex; align-items: baseline; gap: 8px; }
.ed-eyebrow { font: 700 11px/1 var(--font-body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); }
.ed-no { font: 800 34px/0.9 var(--font-display); }
.ed-of { font-size: 12px; color: var(--ink-3); }
.ed-nav { display: flex; gap: 2px; }
.ed-scroll { flex: 1; overflow: auto; padding: 16px 18px 24px; overscroll-behavior: contain; }
.ed-media { position: relative; border-radius: var(--r-sm); overflow: hidden; background: var(--desk-2); max-height: 320px; margin: 0 auto; }
.ed-media img { width: 100%; height: 100%; object-fit: contain; background: #111; }
.ed-media-add {
  position: absolute; inset: 0; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 2px dashed var(--line-2); border-radius: var(--r-sm); background: transparent; color: var(--ink-2);
}
.ed-media-add:hover { border-color: var(--ink-3); background: var(--desk); }
.ed-media-add .icon { width: 28px; height: 28px; }
.ed-media-add span { font-size: 12px; color: var(--ink-3); }
.ed-media-actions { display: flex; gap: 6px; margin-top: 8px; }
.ed-media + .field, .ed-media-actions + .field { margin-top: 18px; }
.duration-ctl { display: flex; align-items: center; gap: 4px; }
.duration-ctl .input-suffix { flex: 1; }
.nudge { width: 34px; height: 40px; border: 1px solid var(--line-2); font-size: 18px; font-weight: 600; flex: none; }
.ed-group { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px 14px; margin: 18px 0 0; }
.ed-group legend { display: inline-flex; align-items: center; gap: 6px; padding: 0 6px; font-weight: 700; font-size: 13px; }
.ed-group legend .icon { width: 16px; height: 16px; color: var(--ink-3); }
.ed-group + .field { margin-top: 18px; }
.input-other { margin-top: 0; }
.ed-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------- Library ---------- */

.library { max-width: 1180px; margin: 0 auto; padding: 32px 20px 60px; }
.lib-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.lib-brand { display: flex; align-items: center; gap: 14px; }
.lib-mark { width: 56px; height: 56px; padding: 10px; border-radius: 14px; background: var(--mat); color: var(--tape); --mark-cut: var(--mat); }
.lib-title { font: 800 52px/0.85 var(--font-display); text-transform: uppercase; letter-spacing: 0.01em; }
.lib-tag { color: var(--ink-2); margin-top: 4px; }
.lib-actions { display: flex; gap: 8px; }
.lib-notice {
  display: flex; gap: 12px; align-items: flex-start; margin: 26px 0 30px; padding: 14px 16px;
  background: var(--tape-bg); border: 1px solid color-mix(in srgb, var(--tape) 70%, transparent); border-radius: var(--r);
  font-size: 14px; color: var(--ink);
}
.lib-notice .icon { color: var(--tape-ink); margin-top: 1px; }
.lib-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.lib-section-head h2 { font: 800 26px/1 var(--font-display); text-transform: uppercase; }
.project-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.project-card { display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-1); overflow: hidden; transition: box-shadow 0.15s, transform 0.15s; }
.project-card:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
.project-open { display: flex; flex-direction: column; gap: 4px; padding: 18px 18px 14px; border: 0; background: transparent; text-align: left; flex: 1; }
.project-aspect { width: 30px; max-height: 40px; border: 2px solid var(--mat); border-radius: 3px; margin-bottom: 10px; background: color-mix(in srgb, var(--mat) 12%, transparent); }
.project-title { font: 800 26px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.01em; }
.project-client { color: var(--ink-2); font-size: 14px; }
.project-stats { margin-top: 10px; font-size: 12.5px; color: var(--ink-2); }
.project-stats .over { color: var(--signal); font-weight: 600; }
.project-edited { font-size: 12px; color: var(--ink-3); }
.project-foot { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 18px; border-top: 1px solid var(--line); background: var(--desk); }
.backup-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ok); font-weight: 600; }
.backup-tag .icon { width: 14px; height: 14px; }
.backup-tag.stale { color: var(--tape-ink); }
.project-tools { display: flex; }
.lib-empty { text-align: center; padding: 56px 24px; border: 2px dashed var(--line-2); border-radius: 14px; background: var(--paper); }
.lib-empty h2 { font: 800 34px/1 var(--font-display); text-transform: uppercase; }
.lib-empty p { margin: 10px auto 22px; max-width: 460px; color: var(--ink-2); }
.lib-empty-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ---------- Dialogs ---------- */

.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow-2);
}
.dialog::backdrop { background: rgba(18, 22, 28, 0.5); backdrop-filter: blur(2px); }
.dialog-sm { width: min(440px, calc(100vw - 32px)); }
.dialog-print { width: min(640px, calc(100vw - 32px)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 0 22px; }
.dialog-head h2 { font: 800 26px/1 var(--font-display); text-transform: uppercase; }
.dialog-body { padding: 16px 22px 4px; }
.dialog-text { color: var(--ink-2); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; padding: 18px 22px 20px; }
.dialog-actions .spacer { flex: 1; }

.choices { display: grid; gap: 8px; }
.choices-2 { grid-template-columns: 1fr 1fr; }
.choices-fieldset { border: 0; padding: 0; margin: 18px 0 0; }
.choices-fieldset legend { margin-bottom: 8px; padding: 0; }
.choice {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--r); cursor: pointer;
}
.choice:hover { border-color: var(--line-2); }
.choice:has(input:checked) { border-color: var(--ink); background: var(--desk); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:focus-visible) { outline: 2.5px solid var(--focus); outline-offset: 2px; }
.choice-text { display: flex; flex-direction: column; gap: 2px; }
.choice-text strong { font-size: 14.5px; }
.choice-text span { font-size: 12.5px; color: var(--ink-3); }
.choice-doc { flex: none; position: relative; width: 34px; height: 34px; }
.choice-doc::before, .choice-doc::after { content: ''; position: absolute; border: 1.5px solid var(--ink-2); border-radius: 2px; background: var(--paper); }
.doc-script::before { width: 22px; height: 30px; left: 6px; top: 2px; }
.doc-board::before { width: 32px; height: 23px; left: 1px; top: 6px; }
.doc-pack::before { width: 18px; height: 25px; left: 1px; top: 1px; }
.doc-pack::after { width: 24px; height: 17px; left: 9px; top: 15px; }
.print-dialog { display: flex; flex-direction: column; gap: 14px; }
.print-opt { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.print-opt-label { font-weight: 600; font-size: 13px; }
.print-opt.check { gap: 8px; cursor: pointer; }
.print-opt.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.seg { display: inline-flex; padding: 3px; background: var(--desk-2); border-radius: 8px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg input:checked + span { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-1); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); }
.print-note { font-size: 13px; color: var(--ink-2); padding: 10px 12px; background: var(--desk); border-radius: var(--r-sm); }
.print-note.warn { background: var(--tape-bg); color: var(--tape-ink); }
.print-tips { font-size: 13px; color: var(--ink-2); }
.print-tips summary { cursor: pointer; font-weight: 600; }
.print-tips ul { margin: 8px 0 0; padding-left: 18px; }

.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0 0 12px; align-items: center; }
.shortcut-list dt { text-align: right; }
.shortcut-list dd { margin: 0; font-size: 14px; color: var(--ink-2); }

/* ---------- Generate image ---------- */

.btn-generate { border-color: color-mix(in srgb, var(--vo) 45%, var(--line-2)); color: var(--vo); }
.btn-generate:hover { background: var(--vo-bg); border-color: var(--vo); }
.ed-media-actions { flex-wrap: wrap; }
.dialog-gen { width: min(680px, calc(100vw - 32px)); }
.dialog-gen .dialog-body { padding-bottom: 0; }
.gen { display: flex; flex-direction: column; gap: 14px; }
.gen-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.gen-row .field-label { min-width: 56px; }
.gen-prompt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gen-prompt { font-size: 13.5px; line-height: 1.55; min-height: 190px; }
.gen-note { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.gen-note .icon { width: 16px; height: 16px; color: var(--ink-3); flex: none; }
.gen-error { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-sm); background: var(--signal-bg); color: var(--signal); font-size: 13.5px; font-weight: 600; }
.gen-unavailable { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0 4px; }
.gen-unavailable .icon { width: 22px; height: 22px; color: var(--ink-3); margin-top: 2px; }
.gen-unavailable p { margin-top: 4px; color: var(--ink-2); }
.gen-busy { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 36px 12px; text-align: center; color: var(--ink-2); }
.gen-busy strong { font: 800 24px/1 var(--font-display); text-transform: uppercase; color: var(--ink); }
.gen-spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--vo); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.gen-preview { max-height: 46vh; margin: 0 auto; max-width: 100%; border-radius: var(--r-sm); overflow: hidden; background: var(--desk-2); }
.gen-preview img { width: 100%; height: 100%; object-fit: contain; }
.gen-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 18px 0 20px; }

/* ---------- Command palette ---------- */

.palette {
  width: min(620px, calc(100vw - 32px)); margin-top: 12vh; padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow-2);
}
.palette::backdrop { background: rgba(18, 22, 28, 0.45); }
.palette-search { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.palette-search .icon { color: var(--ink-3); }
.palette-input { flex: 1; height: 56px; border: 0; background: transparent; font-size: 17px; outline: none; }
.palette-list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14.5px; }
.palette-item .icon { color: var(--ink-3); }
.palette-item.active { background: var(--ink); color: var(--paper); }
.palette-item.active .icon, .palette-item.active .palette-group { color: inherit; opacity: 0.75; }
.palette-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-group { font: 400 12px var(--font-mono); color: var(--ink-3); }
.palette-empty { padding: 18px; text-align: center; color: var(--ink-3); }

/* ---------- Player ---------- */

.player {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  background: #0d0f12; color: #e9ecf1; outline: none;
}
.player-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; font-size: 14px; }
.player-top strong { font: 800 20px/1 var(--font-display); text-transform: uppercase; margin-right: 10px; }
.player-no { opacity: 0.6; font-size: 13px; }
.player-top-right { display: flex; align-items: center; gap: 14px; }
.player-clock { font-size: 15px; }
.player-over { background: var(--signal); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 10px; }
.player-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px 16px; }
.player-frame { position: relative; max-width: 100%; max-height: 100%; height: 100%; background: #000; overflow: hidden; border-radius: 4px; }
.player-media, .player-media img { width: 100%; height: 100%; }
.player-media img { object-fit: cover; }
.player-blank { width: 100%; height: 100%; display: grid; place-items: center; padding: 10%; background: #1c2028; }
.player-blank p { font-size: clamp(16px, 2.4vw, 26px); text-align: center; opacity: 0.85; }
.player-super {
  position: absolute; left: 6%; right: 6%; top: 8%; text-align: center; white-space: pre-line;
  font: 800 clamp(18px, 3.6vw, 44px)/1.05 var(--font-display); text-transform: uppercase; color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}
.player-vo {
  position: absolute; left: 8%; right: 8%; bottom: 6%; text-align: center;
  font-size: clamp(13px, 1.6vw, 19px); font-style: italic; color: #fff;
  background: rgba(0, 0, 0, 0.55); padding: 6px 12px; border-radius: 4px;
}
.player-bottom { padding: 8px 16px 18px; }
.player-segs { display: flex; gap: 3px; height: 8px; }
.player-seg { flex-basis: 0; position: relative; padding: 0; border: 0; border-radius: 2px; background: rgba(255, 255, 255, 0.18); overflow: hidden; }
.player-seg.current { background: rgba(255, 255, 255, 0.3); }
.player-seg-fill { position: absolute; inset: 0; background: var(--tape); transform-origin: left; transform: scaleX(0); }
.player-controls { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 12px; position: relative; }
.player-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.1); color: #fff; }
.player-btn:hover { background: rgba(255, 255, 255, 0.2); }
.player-play { width: 56px; height: 56px; background: #fff; color: #0d0f12; }
.player-play:hover { background: var(--tape); }
.player-play .icon { width: 24px; height: 24px; }
.player-hint { position: absolute; right: 0; font-size: 12px; opacity: 0.55; }
.player-hint kbd { background: transparent; color: inherit; border-color: rgba(255, 255, 255, 0.3); }

/* ---------- Toasts ---------- */

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(560px, calc(100vw - 24px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  padding: 10px 8px 10px 14px; border-radius: 10px; background: var(--ink); color: var(--paper);
  box-shadow: var(--shadow-2); font-size: 14px; animation: toast-in 0.18s ease-out;
}
.toast.leaving { opacity: 0; transform: translateY(6px); transition: 0.18s; }
.toast-success .icon:first-child { color: #7fd3a5; }
.toast-error { background: var(--signal); color: #fff; }
.toast-msg { flex: 1; }
.toast-action { border: 0; background: rgba(255, 255, 255, 0.16); color: inherit; font-weight: 700; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.toast-action:hover { background: rgba(255, 255, 255, 0.28); }
.toast-close { border: 0; background: transparent; color: inherit; opacity: 0.7; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.booting, .fatal { max-width: 560px; margin: 18vh auto; padding: 0 20px; text-align: center; color: var(--ink-2); }
.fatal h1 { font: 800 36px/1 var(--font-display); text-transform: uppercase; color: var(--ink); margin-bottom: 14px; }
.fatal p + p { margin-top: 10px; }

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .beat-lanes { grid-template-columns: 1fr; }
  .toolbar-hint { display: none; }
  .toolbar-count { margin-left: auto; }
}

@media (max-width: 1000px) {
  .script-layout { grid-template-columns: 1fr; }
  .brief { position: static; max-height: none; }
  .timeline { grid-template-columns: 1fr; gap: 4px; }
  .tl-readout { flex-wrap: nowrap; }
  .tl-label { width: auto; }
  .board-layout.editing { grid-template-columns: minmax(0, 1fr); }
  .editor {
    position: fixed; z-index: 50; top: 0; right: 0; bottom: 0; height: auto;
    width: min(460px, 100vw); box-shadow: var(--shadow-2); border-left: 1px solid var(--line);
    animation: sheet-in 0.2s ease-out;
  }
  @keyframes sheet-in { from { transform: translateX(30px); opacity: 0; } }
}

@media (max-width: 900px) {
  .hide-sm, .save-text { display: none; }
  .topbar-row { gap: 10px; }
  .ws-title, .ws-client { max-width: 24vw; }
  .topbar-actions { gap: 4px; }
}

@media (max-width: 760px) {
  .hide-sm { display: none; }
  .topbar-row { gap: 8px; padding: 0 8px; }
  .ws-name { display: none; }
  .tabs { margin-left: 0; }
  .tab { padding: 0 10px; }
  .save-text { display: none; }
  .field-row { grid-template-columns: 1fr; }
  .choices-2 { grid-template-columns: 1fr; }
  .beat { grid-template-columns: 1fr; }
  .beat-rail { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .script-layout, .board-scroll { padding: 12px; }
  .board-toolbar { padding: 10px 12px; }
  .lib-title { font-size: 40px; }
  .player-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media screen { #print-root { display: none; } }
