:root {
  --bg: #0f0d0b; --panel: #17140f; --panel-2: #1e1a15; --line: #2c2620; --line-2: #3a332b;
  --ink: #f1ebe2; --muted: #a39a8e; --faint: #6f675d; --accent: #d1ad68; --accent-ink: #17120a;
  --danger: #e2735f; --ok: #7cc48c; --warn: #e3b55b;
  --radius: 10px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Cormorant Garamond", "Bodoni MT", Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--ui); display: flex; flex-direction: column; }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
.spacer { flex: 1; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel-2); color: var(--ink); font-weight: 560; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #51473b; background: #25201a; }
.btn:focus-visible, .icon-btn:focus-visible, .mode button:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.small { min-height: 30px; padding: 0 11px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--ink); cursor: pointer; }
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* top bar */
.topbar { flex: none; height: 54px; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-weight: 650; letter-spacing: .01em; }
.brand-mark { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 50% 50%, #fff 0 4px, var(--accent) 4.5px 7px, transparent 7.5px); box-shadow: 0 0 0 2px rgba(209,173,104,.25); }
.crumb { display: flex; align-items: center; gap: 8px; color: var(--faint); min-width: 0; flex: 1; }
.title-input { min-width: 0; width: min(420px, 100%); padding: 6px 8px; border: 1px solid transparent; border-radius: 6px; background: transparent; font-weight: 560; }
.title-input:hover { border-color: var(--line-2); }
.title-input:focus { outline: none; border-color: var(--accent); background: var(--bg); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.save-state { color: var(--faint); font-size: 12.5px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 12px; color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.pill[data-state="ready"]::before { background: var(--ok); }
.pill[data-state="busy"]::before, .pill[data-state="loading"]::before { background: var(--warn); animation: blink 1.2s ease-in-out infinite; }
.pill[data-state="error"]::before, .pill[data-state="unavailable"]::before, .pill[data-state="offline"]::before { background: var(--danger); }
@keyframes blink { 50% { opacity: .35; } }
.mode { display: inline-flex; padding: 3px; border: 1px solid var(--line-2); border-radius: 9px; }
.mode button { padding: 4px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.mode button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

main { flex: 1; min-height: 0; }

/* library */
.library { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; overflow: auto; height: 100%; }
.lib-head h1 { margin: 0 0 4px; font: 500 34px/1.1 var(--serif); }
.lib-head p { margin: 0 0 20px; }
.drop { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 30px 20px; border: 1.5px dashed var(--line-2); border-radius: 14px; background: var(--panel); cursor: pointer; text-align: center; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: #1c1813; }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.drop-icon { width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--accent); position: relative; margin-bottom: 4px; }
.drop-icon::before, .drop-icon::after { content: ""; position: absolute; left: 50%; top: 50%; background: var(--accent); transform: translate(-50%, -50%); }
.drop-icon::before { width: 14px; height: 1.5px; } .drop-icon::after { width: 1.5px; height: 14px; }
.drop-title { font-weight: 600; }
.upload-progress { width: min(320px, 80%); height: 4px; border-radius: 2px; background: var(--line-2); overflow: hidden; margin-top: 8px; }
.upload-progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.grid { list-style: none; margin: 24px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { position: relative; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); overflow: hidden; }
.card a { display: block; color: inherit; text-decoration: none; }
.card a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 12px; }
.card .poster { aspect-ratio: 16 / 9; background: #000 center / cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 12.5px; }
.card .meta { padding: 10px 12px 12px; }
.card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 26px; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card .sub.err { color: var(--danger); }
.card .del { position: absolute; right: 6px; bottom: 9px; width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--faint); cursor: pointer; }
.card .del:hover { color: var(--danger); background: var(--panel-2); }

/* editor */
.editor { height: 100%; }
.workspace { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 360px; }
.stage-col { min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 14px 14px 10px; gap: 10px; }
.stage-wrap { flex: 1; min-height: 160px; display: grid; place-items: center; position: relative; }
.stage { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: var(--ar, 16 / 9); max-width: 100%; max-height: 100%; width: 100%; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: default; touch-action: none; }
.stage.marking canvas { cursor: crosshair; }
.marking-bar { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; padding: 6px 6px 6px 14px; border-radius: 10px; background: rgba(15,13,11,.88); border: 1px solid var(--line-2); font-size: 13px; max-width: calc(100% - 20px); backdrop-filter: blur(6px); }
.marking-actions { display: flex; gap: 6px; flex: none; }
.stage-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; background: rgba(0,0,0,.72); color: var(--muted); }
.preview-host { width: 100%; max-height: 100%; display: grid; place-items: center; }
.preview-host interactive-video { width: 100%; }

.transport { flex: none; display: flex; align-items: center; gap: 4px; }
.timecode { font-variant-numeric: tabular-nums; font-weight: 600; margin: 0 8px 0 6px; }
.keys { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.timeline { flex: none; position: relative; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); user-select: none; cursor: pointer; max-height: 190px; overflow-y: auto; overflow-x: hidden; }
.ruler { position: sticky; top: 0; z-index: 2; height: 22px; border-bottom: 1px solid var(--line); background: var(--panel); margin-left: 120px; }
.tick { position: absolute; top: 0; height: 100%; border-left: 1px solid var(--line-2); padding-left: 4px; font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; line-height: 22px; }
.lanes { position: relative; }
.lane { display: flex; height: 26px; border-bottom: 1px solid var(--line); }
.lane:last-child { border-bottom: 0; }
.lane.sel { background: rgba(209,173,104,.06); }
.lane-name { flex: none; width: 120px; padding: 0 8px; display: flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; overflow: hidden; border-right: 1px solid var(--line); }
.lane-name i { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.lane-name span { overflow: hidden; text-overflow: ellipsis; }
.lane-track { position: relative; flex: 1; }
.run { position: absolute; top: 8px; height: 10px; border-radius: 3px; opacity: .85; }
.run.pending { opacity: .25; }
.mk { position: absolute; top: 7px; width: 10px; height: 10px; margin-left: -5px; transform: rotate(45deg); border: 1.5px solid #fff; border-radius: 2px; }
.lanes-empty { padding: 8px 12px 9px 132px; color: var(--faint); font-size: 12px; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; pointer-events: none; z-index: 3; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }

/* sidebar */
.side { min-height: 0; overflow: auto; border-left: 1px solid var(--line); background: var(--panel); padding: 14px 14px 32px; }
.side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.side-head h2 { margin: 0; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.objects { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.obj { width: 100%; display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid transparent; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; }
.obj:hover { background: var(--panel-2); }
.obj[aria-current="true"] { background: var(--panel-2); border-color: var(--line-2); }
.obj:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.obj i { width: 12px; height: 12px; border-radius: 50%; }
.obj .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.obj .state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.obj .state.err { color: var(--danger); }
.obj .bar { grid-column: 2 / 4; height: 3px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.obj .bar span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .25s; }
.empty { margin: 4px 0 0; font-size: 13px; }

.detail { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button { flex: 1; padding: 7px 0; border: 1px solid var(--line-2); border-radius: 7px; background: transparent; color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--panel-2); color: var(--ink); border-color: #51473b; }
.panel { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { font-size: 12px; color: var(--muted); font-weight: 550; padding: 0; }
.field input, .field textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--bg); }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 60px; }
.two { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }
.details { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.detail-row { display: grid; grid-template-columns: 0.8fr 1.4fr 28px; gap: 6px; }
.detail-row input { padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--bg); min-width: 0; }
.detail-row input:focus { outline: none; border-color: var(--accent); }
.x { width: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--faint); cursor: pointer; }
.x:hover { color: var(--danger); background: var(--panel-2); }
.image-row { display: flex; gap: 10px; align-items: center; }
.thumb { flex: none; width: 72px; height: 72px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg) center / contain no-repeat; }
.image-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.marks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.mark-row { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }
.mark-row button { padding: 3px 8px; border: 1px solid var(--line-2); border-radius: 6px; background: transparent; cursor: pointer; font-size: 12px; }
.mark-row button:hover { border-color: var(--accent); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.job-line { margin: 0; font-size: 12.5px; color: var(--muted); min-height: 1.2em; }

dialog { border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 0; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog h2 { margin: 0; font: 500 26px/1.1 var(--serif); }
.dialog p { margin: 0; }
.dialog textarea, .dialog input { font: 12.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .editor { height: auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .stage-wrap { min-height: 0; }
  .keys { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ------------------------------------------------------------------ */
/* Analytics (M4)                                                      */
/* Chart tokens: text never wears a data colour; product colours come  */
/* from each product; single-series charts use --viz-1 (validated).    */
/* ------------------------------------------------------------------ */
:root {
  --viz-surface: var(--panel);
  --viz-1: #3987e5;               /* categorical slot 1, dark step */
  --viz-wash: rgba(57,135,229,.10);
  --viz-grid: #2c2620;            /* one step off the surface */
  --viz-axis: #6f675d;
  --ramp-1: #184f95; --ramp-2: #256abf; --ramp-3: #3987e5; --ramp-4: #6da7ec; /* ordinal, validated */
}
.analytics { height: 100%; overflow: auto; padding: 16px 20px 48px; position: relative; }
.an-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 16px; }
.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line-2); border-radius: 9px; }
.seg button { padding: 5px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.badge { padding: 4px 10px; border-radius: 999px; border: 1px solid #6b5426; background: #2a2114; color: #f0d29a; font-size: 12px; font-weight: 600; }
.an-body { transition: opacity .2s; }
.an-body.loading { opacity: .55; }
.an-empty { max-width: 640px; padding: 40px 0; }
.an-empty h2 { margin: 0 0 6px; font: 500 26px/1.15 var(--serif); }
.an-empty code { font-size: 12px; background: var(--panel-2); padding: 1px 6px; border-radius: 5px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { border: 1px solid var(--line); border-radius: 12px; background: var(--viz-surface); padding: 12px 14px 10px; min-width: 0; }
.kpi .label { font-size: 12.5px; color: var(--muted); }
.kpi .value { font-size: 30px; font-weight: 650; line-height: 1.15; margin-top: 2px; letter-spacing: -.01em; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi svg { display: block; width: 100%; height: 28px; margin-top: 6px; }
.an-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 1100px) { .an-grid { grid-template-columns: 1fr; } }
.chart-card { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--viz-surface); padding: 14px 16px 10px; min-width: 0; }
.chart-card figcaption h3 { margin: 0; font-size: 14px; font-weight: 650; }
.chart-card figcaption p { margin: 2px 0 8px; font-size: 12.5px; color: var(--muted); }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font: 11px var(--ui); font-variant-numeric: tabular-nums; }
.chart .strong { fill: var(--ink); font-weight: 650; }
.chart .grid { stroke: var(--viz-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:focus { outline: none; }
.chart .hit:focus-visible + .focus-ring, .chart .bar-hit:focus-visible { outline: 2px solid var(--accent); }
.chart .xhair { stroke: var(--muted); stroke-width: 1; }
details { margin-top: 6px; }
details summary { cursor: pointer; font-size: 12.5px; color: var(--muted); width: max-content; }
details summary:hover { color: var(--ink); }
.table-wrap { overflow-x: auto; }
.an-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.an-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.an-table td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.an-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.an-table th.num { text-align: right; }
.an-table .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; }
.an-table .rate { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; width: 100%; }
.an-table .meter { width: 72px; height: 6px; border-radius: 3px; background: #23303f; overflow: hidden; flex: none; }
.an-table .meter span { display: block; height: 100%; border-radius: 3px; background: var(--viz-1); }
.an-tip { position: fixed; z-index: 20; pointer-events: none; min-width: 120px; padding: 8px 10px; border-radius: 8px; background: #0b0a08; border: 1px solid var(--line-2); box-shadow: 0 10px 30px rgba(0,0,0,.45); font-size: 12.5px; }
.an-tip .t { color: var(--muted); margin-bottom: 4px; }
.an-tip .row { display: flex; align-items: center; gap: 8px; }
.an-tip .row b { font-size: 14px; font-variant-numeric: tabular-nums; }
.an-tip .key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.an-tip .name { color: var(--muted); }

/* ------------------------------------------------------------------ */
/* Accounts (M5)                                                       */
/* ------------------------------------------------------------------ */
.auth { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: min(400px, 100%); border: 1px solid var(--line); border-radius: 14px; background: var(--panel); padding: 26px 24px 20px; }
.auth-card h1 { margin: 0 0 4px; font: 500 30px/1.1 var(--serif); }
.auth-card > p { margin: 0 0 16px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card .btn.primary { min-height: 40px; margin-top: 4px; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin: 16px 0 0; font-size: 13px; }
.auth-links a { color: var(--accent); }
.ok { color: var(--ok); font-size: 13px; margin: 0; }
.account { display: flex; align-items: center; gap: 8px; padding-left: 10px; border-left: 1px solid var(--line-2); }
.account-email { color: var(--muted); font-size: 12.5px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Publish dialog (M5) */
.pub-progress { display: flex; flex-direction: column; gap: 6px; }
.pub-progress .bar { height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.pub-progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; min-width: 0; padding: 7px 9px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--bg); font: 12.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; }
#pub-live { display: flex; flex-direction: column; gap: 12px; }
#pub-live:not([hidden]) { display: flex; }
