:root {
  color-scheme: dark;
  --bg: #0d0e10;
  --panel: #15171a;
  --panel-2: #1c1f23;
  --panel-3: #24282d;
  --border: #2a2e34;
  --text: #e8eaed;
  --muted: #8b9199;
  --accent: #b8f23a;
  --accent-ink: #11160a;
  --danger: #ff7070;
  --warn: #f5b94a;
  --info: #6bb7ff;
  --radius: 10px;
  --rail-w: 68px;
  --settings-w: 310px;
  --library-w: 380px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); overflow: hidden; }
h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  display: grid;
  grid-template-columns: var(--rail-w) var(--settings-w) minmax(0, 1fr) var(--library-w);
  gap: 10px;
  height: 100vh;
  padding: 10px;
}

/* ---- rail ---- */
.rail {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 0;
  background: var(--panel); border-radius: var(--radius);
}
.logo { margin-bottom: 14px; }
.rail-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 52px; padding: 8px 0; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 11px;
}
.rail-item svg { width: 22px; height: 22px; }
.rail-item:hover { color: var(--text); background: var(--panel-2); }
.rail-item.active { color: var(--accent); }
.rail-spacer { flex: 1; }
.status { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status.ok .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status.down .dot { background: var(--danger); }

/* ---- panels ---- */
.panel { background: var(--panel); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.panel-scroll { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 22px; }
.panel-foot { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.estimate { font-size: 12px; color: var(--muted); text-align: center; min-height: 16px; }
.note { margin: 8px 0 0; font-size: 12px; color: var(--muted); line-height: 1.4; }
.note.warn { color: var(--warn); }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 22px 12px; border: 1.5px dashed var(--border); border-radius: var(--radius);
  background: var(--panel-2); cursor: pointer; color: var(--muted);
}
.drop svg { width: 26px; height: 26px; }
.drop strong { color: var(--text); font-weight: 500; font-size: 13px; }
.drop .hint { font-size: 11px; }
.drop:hover, .drop.over { border-color: var(--accent); color: var(--accent); }

.file-chip { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 8px 8px 12px; background: var(--panel-2); border-radius: 8px; }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted); font-size: 12px; }

.seg { display: flex; padding: 3px; gap: 3px; background: var(--panel-2); border-radius: 8px; }
.seg button { flex: 1; padding: 7px 6px; border: 0; background: transparent; border-radius: 6px; color: var(--muted); }
.seg button:hover:not(:disabled) { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--panel-3); color: var(--accent); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.field label { color: var(--muted); }
.field input[type=number] { width: 90px; padding: 7px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; }
.field input[type=color] { width: 56px; height: 32px; padding: 2px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; }

.primary {
  width: 100%; padding: 13px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 15px;
}
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.primary:disabled { background: var(--panel-3); color: var(--muted); cursor: not-allowed; }
.secondary {
  padding: 8px 14px; border: 1px solid var(--border); background: var(--panel-2); border-radius: 8px; color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-size: 13px;
}
.secondary:hover { background: var(--panel-3); }
.secondary.danger { color: var(--danger); }
.secondary svg { width: 15px; height: 15px; }
.icon-btn { display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); }
.icon-btn:hover:not(:disabled) { background: var(--panel-3); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 16px; height: 16px; }

/* ---- viewport ---- */
.viewport { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.vp-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.vp-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.vp-title h1 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vp-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--panel-3); color: var(--muted); white-space: nowrap; }
.pill.done { background: rgba(184,242,58,.14); color: var(--accent); }
.pill.active { background: rgba(107,183,255,.14); color: var(--info); }
.pill.failed { background: rgba(255,112,112,.14); color: var(--danger); }
.pill.cancelled { background: rgba(245,185,74,.14); color: var(--warn); }

.stage {
  flex: 1; min-height: 0; display: grid; place-items: center; padding: 20px; position: relative;
  background:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / 48px 48px,
    radial-gradient(ellipse at 50% 40%, #1d2127, #0f1114 70%);
}
.media {
  position: relative; width: min(100%, calc((100vh - 220px) * var(--ar, 1.7778))); max-height: 100%;
  aspect-ratio: var(--ar, 16 / 9);
  border-radius: 6px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.45);
  background: var(--media-bg, #fff);
}
.media.checker {
  background: repeating-conic-gradient(#3a3f46 0% 25%, #2b2f35 0% 50%) 0 0 / 20px 20px;
}
.media img, .media video { display: block; width: 100%; height: 100%; object-fit: contain; }
.media .overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(13,14,16,.62); backdrop-filter: blur(2px); color: var(--text);
}
.progress { width: min(320px, 70%); height: 6px; background: var(--panel-3); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }
.progress.indeterminate > i { width: 40%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.overlay .big { font-size: 18px; font-weight: 600; }
.overlay .sub { color: var(--muted); font-size: 13px; }

.empty { text-align: center; color: var(--muted); display: grid; gap: 10px; justify-items: center; max-width: 340px; }
.empty svg { width: 44px; height: 44px; opacity: .6; }
.empty strong { color: var(--text); font-size: 16px; font-weight: 600; }
.error-box { max-width: min(640px, 100%); padding: 16px; border: 1px solid rgba(255,112,112,.4); border-radius: var(--radius); background: rgba(255,112,112,.06); text-align: left; display: grid; gap: 10px; }
.error-box strong { color: var(--danger); }
.error-box pre { margin: 0; max-height: 220px; overflow: auto; font-size: 12px; white-space: pre-wrap; color: #f0b8b8; }

.vp-bottom { display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--border); }
.vp-bottom .seg { width: 170px; flex: none; }
.vp-bottom input[type=range] { flex: 1; accent-color: var(--accent); min-width: 80px; }
.vp-bottom .frame-label { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.chips-info { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.chip-info { padding: 3px 9px; background: var(--panel-2); border-radius: 6px; font-size: 12px; color: var(--muted); }

/* ---- library ---- */
.lib-head { padding: 14px 14px 10px; display: grid; gap: 10px; }
.search { display: flex; align-items: center; gap: 8px; padding: 0 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; }
.search svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; padding: 9px 0; background: transparent; border: 0; outline: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { padding: 4px 11px; border: 1px solid var(--border); background: transparent; border-radius: 999px; color: var(--muted); font-size: 12px; }
.chips button[aria-checked="true"] { background: var(--panel-3); color: var(--accent); border-color: transparent; }
.grid-wrap { flex: 1; overflow-y: auto; padding: 0 14px 14px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.card { position: relative; border-radius: 8px; background: var(--panel-2); border: 2px solid transparent; overflow: hidden; cursor: pointer; text-align: left; padding: 0; display: block; width: 100%; }
.card:hover { border-color: var(--panel-3); }
.card.selected { border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 16 / 9; background: repeating-conic-gradient(#2b2f35 0% 25%, #24282d 0% 50%) 0 0 / 14px 14px; display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { color: var(--muted); font-size: 12px; text-align: center; padding: 6px; }
.badges { position: absolute; left: 6px; top: 6px; display: flex; gap: 4px; }
.badge { padding: 2px 6px; border-radius: 4px; background: rgba(13,14,16,.78); font-size: 10px; font-weight: 600; color: var(--text); }
.badge.state-failed { color: var(--danger); }
.badge.state-cancelled { color: var(--warn); }
.badge.state-active { color: var(--info); }
.card-meta { padding: 7px 9px 9px; display: grid; gap: 2px; }
.card-meta .name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta .when { font-size: 11px; color: var(--muted); }
.card .del { position: absolute; right: 4px; top: 4px; background: rgba(13,14,16,.78); opacity: 0; }
.card:hover .del, .card:focus-within .del { opacity: 1; }
.card .dl { position: absolute; right: 34px; top: 4px; background: rgba(13,14,16,.78); opacity: 0; text-decoration: none; }
.card:hover .dl, .card:focus-within .dl { opacity: 1; }
.icon-btn { text-decoration: none; }
.empty-lib { text-align: center; color: var(--muted); padding: 40px 10px; line-height: 1.5; }
.lib-foot { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.lib-foot .count { margin-left: 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(560px, 90vw); padding: 11px 16px; background: var(--panel-3); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); z-index: 10; }
.toast.error { border-color: rgba(255,112,112,.5); }

/* ---- narrower screens ---- */
@media (max-width: 1360px) { :root { --library-w: 320px; --settings-w: 290px; } }
@media (max-width: 1100px) {
  body { overflow: auto; }
  .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); grid-template-rows: auto auto auto; height: auto; min-height: 100vh; }
  .rail { grid-row: 1 / span 3; position: sticky; top: 10px; align-self: start; }
  .viewport { order: 1; min-height: 520px; }
  .settings { order: 2; }
  .library { order: 3; min-height: 480px; }
  .media { width: min(100%, calc(60vh * var(--ar, 1.7778))); }
  .panel-scroll { overflow: visible; }
}
@media (max-width: 640px) {
  :root { font-size: 15px; }
  .app { grid-template-columns: minmax(0, 1fr); padding: 8px; gap: 8px; }
  .rail { grid-row: auto; flex-direction: row; justify-content: space-between; padding: 6px 12px; position: static; width: 100%; }
  .logo { margin: 0; }
  .rail-spacer { display: none; }
  .vp-top { flex-direction: column; align-items: flex-start; }
  .vp-bottom { flex-wrap: wrap; }
  .chips-info { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { .progress.indeterminate > i { animation: none; width: 100%; } * { transition: none !important; } }

/* ---- studio shell: top bar, collapsible sections (used by every studio page) ---- */
.status-label small { display: block; font-size: 9px; opacity: .7; }
.status { text-align: center; }
.logo { display: block; }
.topbar { display: flex; align-items: center; gap: 16px; min-width: 0; padding: 0 4px; }
.brand { display: grid; line-height: 1.15; flex: none; }
.brand strong { font-size: 20px; letter-spacing: -.01em; }
.brand span { font-size: 11px; color: var(--muted); }
.crumb { display: flex; gap: 8px; margin: 0 auto; min-width: 0; }
.crumb-pill { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border); color: var(--text); text-decoration: none; min-width: 0; white-space: nowrap; }
.crumb-pill:hover { background: var(--panel-2); }
.crumb-pill strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.crumb-pill svg { width: 14px; height: 14px; color: var(--muted); flex: none; }
.crumb-k { color: var(--muted); font-size: 12px; }
.crumb-sep { width: 1px; height: 14px; background: var(--border); }
.top-right { display: flex; align-items: center; gap: 10px; flex: none; }
.top-right .icon-btn { position: relative; width: 36px; height: 36px; background: var(--panel); border-radius: 10px; }
.bell-dot { position: absolute; right: 7px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-3); font-weight: 650; }

.sec { border-bottom: 1px solid var(--border); padding-bottom: 14px; }
.sec:last-child { border-bottom: 0; }
.sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 2px 0 10px; font-size: 13px; font-weight: 600; color: var(--text); }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::before { content: ""; width: 7px; height: 7px; border-right: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; margin: 0 4px 2px 2px; }
.sec[open] > summary::before { transform: rotate(45deg); }
.sec > summary:hover { color: var(--accent); }
.page-body { overflow-y: auto; padding: 4px 4px 24px; display: grid; gap: 16px; align-content: start; min-height: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--muted); }
.page-head .grow { flex: 1; }
.text-input { padding: 9px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; min-width: 220px; }

/* ---- render queue ---- */
.queue { margin: 0 14px 10px; padding: 10px 12px; background: var(--panel-2); border-radius: 10px; display: grid; gap: 8px; max-height: 42%; overflow-y: auto; flex: none; }
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.q-head h2 { margin: 0; }
.q-count { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 6px; }
.q-head .secondary { padding: 5px 10px; font-size: 12px; }
.q-note { margin: 0; font-size: 12px; color: var(--warn); }
.q-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.q-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel); border-radius: 8px; font-size: 12px; }
.q-row.running { box-shadow: inset 2px 0 0 var(--accent); }
.q-pos { color: var(--muted); font-variant-numeric: tabular-nums; }
.q-row.running .q-pos { color: var(--accent); }
.q-name { display: grid; min-width: 0; }
.q-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-name small { color: var(--muted); font-size: 11px; }
.q-bar { height: 3px; border-radius: 99px; background: var(--panel-3); overflow: hidden; margin-top: 3px; }
.q-bar i { display: block; height: 100%; background: var(--accent); }
.q-tools { display: flex; gap: 0; }
.q-tools .icon-btn { width: 24px; height: 24px; }
.q-tools .icon-btn svg { width: 14px; height: 14px; }
