:root {
  --ink: #131217;
  --panel: #1c1b22;
  --panel-2: #24232b;
  --line: #312f39;
  --line-2: #3e3c48;
  --text: #ece9e2;
  --muted: #9a97a3;
  --amber: #f5b942;
  --amber-2: #ffd27a;
  --teal: #3dd6c3;
  --rose: #ff6b81;
  --green: #7ad67a;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --radius: 12px;
  --font-display: "Bricolage Grotesque", "Nunito", system-ui, sans-serif;
  --font-body: "Nunito", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--ink); color: var(--text); font: 14px/1.4 var(--font-body); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 8px; padding: 6px 12px; transition: background .15s, border-color .15s, transform .05s; }
button:hover { background: #2d2c35; border-color: #4a4856; }
button:active { transform: translateY(1px); }
button.primary { background: var(--teal); color: #0b1f1c; border-color: transparent; font-weight: 800; }
button.primary:hover { background: #5ee6d4; }
button.accent { background: var(--amber); color: #2a1d00; border-color: transparent; font-weight: 800; }
button.accent:hover { background: var(--amber-2); }
button.ghost { background: transparent; }
button.danger { color: var(--rose); }
button.icon { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; font-size: 15px; }
button.tiny { padding: 2px 8px; font-size: 12px; border-radius: 6px; }
button:disabled { opacity: .45; cursor: default; }
input[type=text], input[type=number], select, textarea { background: #15141a; border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 8px; width: 100%; min-width: 0; }
input[type=text]:focus, input[type=number]:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(61,214,195,.18); }
input[type=range] { width: 100%; accent-color: var(--amber); }
input[type=color] { width: 32px; height: 28px; padding: 0; border: 1px solid var(--line-2); border-radius: 6px; background: none; cursor: pointer; }
textarea { resize: vertical; min-height: 56px; }
label.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
label.chk.small { font-size: 12px; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row > .fixed { flex: 0 0 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span.lbl { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.section h3 { margin: 0 0 10px; font: 700 15px var(--font-display); letter-spacing: .01em; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section h3 .right { display: inline-flex; gap: 6px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line-2); font-size: 11px; color: var(--muted); }
.badge.warn { background: rgba(255,107,129,.15); border-color: rgba(255,107,129,.5); color: var(--rose); }
.badge.ok { background: rgba(122,214,122,.12); border-color: rgba(122,214,122,.45); color: var(--green); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line-2); font-size: 12px; cursor: pointer; }
.chip.on { background: rgba(245,185,66,.18); border-color: var(--amber); color: var(--amber-2); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.4); }
.swatch.on { border-color: var(--amber); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 196px 1fr 340px; grid-template-rows: 56px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 14px; background: linear-gradient(180deg, #1f1e25, #19181f); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { width: 14px; height: 14px; border-radius: 4px; background: linear-gradient(135deg, var(--amber), var(--rose)); display: inline-block; transform: rotate(12deg); }
.brand-name { font: 800 20px var(--font-display); letter-spacing: -.02em; }
.brand-sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; }
.title-input { background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 6px 10px; width: 220px; font-weight: 700; }
.title-input:hover, .title-input:focus { border-color: var(--line-2); background: #15141a; outline: none; }
.transport { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.transport .time { font-variant-numeric: tabular-nums; min-width: 128px; text-align: center; color: var(--muted); }
.actions { display: flex; gap: 6px; }

.scenes-panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.scene-card { position: relative; border: 2px solid transparent; border-radius: 10px; background: var(--panel-2); padding: 6px; cursor: pointer; transition: border-color .15s; }
.scene-card:hover { border-color: var(--line-2); }
.scene-card.active { border-color: var(--amber); }
.scene-card canvas { width: 100%; border-radius: 6px; display: block; background: #000; aspect-ratio: 16 / 9; }
.scene-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 5px; font-size: 12px; }
.scene-card .meta b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.scene-card .num { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 99px; }
.scene-card .tools { display: none; position: absolute; top: 8px; right: 8px; gap: 3px; }
.scene-card:hover .tools, .scene-card.active .tools { display: flex; }
.scene-card .tools button { width: 24px; height: 24px; padding: 0; font-size: 12px; border-radius: 6px; background: rgba(0,0,0,.6); border-color: transparent; }
.add-scene { border: 1px dashed var(--line-2); border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); background: transparent; }
.add-scene:hover { color: var(--amber); border-color: var(--amber); }

.center { display: grid; grid-template-rows: 1fr 210px; min-width: 0; min-height: 0; background: radial-gradient(1200px 600px at 50% 0%, #1b1a21, var(--ink)); }
.stage-wrap { position: relative; display: grid; place-items: center; padding: 14px; min-height: 0; overflow: hidden; }
#stage { max-width: 100%; max-height: 100%; border-radius: 6px; box-shadow: var(--shadow); background: #000; cursor: default; }
#stage.pick { cursor: crosshair; }
.stage-hint { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); background: rgba(0,0,0,.4); padding: 3px 10px; border-radius: 99px; pointer-events: none; }

/* ---------- timeline ---------- */
.timeline { border-top: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tl-scenes { display: flex; height: 26px; border-bottom: 1px solid var(--line); position: relative; cursor: pointer; }
.tl-scene { position: relative; height: 100%; border-right: 1px solid var(--ink); background: #2a2932; font-size: 11px; padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.tl-scene.active { background: rgba(245,185,66,.18); color: var(--amber-2); }
.tl-body { position: relative; flex: 1; overflow: auto; }
.tl-ruler { position: sticky; top: 0; height: 18px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 10px; color: var(--muted); z-index: 2; }
.tl-ruler span { position: absolute; top: 2px; transform: translateX(-50%); }
.tl-ruler i { position: absolute; top: 12px; width: 1px; height: 6px; background: var(--line-2); }
.tl-track { position: relative; height: 30px; border-bottom: 1px solid var(--line); }
.tl-track .tl-label { position: sticky; left: 0; display: inline-block; width: 110px; height: 100%; padding: 6px 8px; font-size: 11px; color: var(--muted); background: var(--panel); border-right: 1px solid var(--line); z-index: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-seg { position: absolute; top: 4px; height: 22px; border-radius: 6px; font-size: 11px; line-height: 22px; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: grab; border: 1px solid rgba(255,255,255,.15); user-select: none; }
.tl-seg.action { background: linear-gradient(180deg, #3b6ea5, #2d5684); }
.tl-seg.dialog { background: linear-gradient(180deg, #b7832b, #8c6420); }
.tl-seg.dialog.overlap { background: linear-gradient(180deg, #c0392b, #8e2a1f); }
.tl-seg.caption { background: linear-gradient(180deg, #6a4b9a, #4f3775); }
.tl-seg.selected { outline: 2px solid var(--amber); }
.tl-seg .grip { position: absolute; right: 0; top: 0; width: 8px; height: 100%; cursor: ew-resize; }
.tl-playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--rose); z-index: 3; pointer-events: none; }
.tl-playhead::before { content: ""; position: absolute; top: 0; left: -5px; border: 6px solid transparent; border-top-color: var(--rose); }
.tl-scrub { position: absolute; left: 110px; right: 0; top: 0; height: 18px; cursor: pointer; z-index: 2; }

/* ---------- inspector ---------- */
.inspector { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 10px 4px; font-weight: 700; color: var(--muted); font-size: 13px; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--amber-2); border-bottom-color: var(--amber); }
.tab-body { overflow-y: auto; flex: 1; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { border: 1px solid var(--line-2); border-radius: 10px; padding: 8px; background: var(--panel-2); }
.item.selected { border-color: var(--amber); }
.item .head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.item .head b { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.char-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.char-cell { border: 2px solid transparent; border-radius: 10px; background: var(--panel-2); padding: 4px; text-align: center; cursor: pointer; font-size: 10px; color: var(--muted); }
.char-cell:hover { border-color: var(--line-2); }
.char-cell.on { border-color: var(--amber); color: var(--amber-2); }
.char-cell canvas { width: 100%; aspect-ratio: 2 / 3; display: block; border-radius: 6px; background: linear-gradient(#2b3a4a, #1f2a33); }
.preview-canvas { width: 100%; aspect-ratio: 16 / 10; display: block; border-radius: 10px; background: linear-gradient(#93c9ec, #e8f4fb 70%, #5f9e46 70%); }
.actor-pos { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: end; }
.level { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.level > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--amber), var(--rose)); width: 0; transition: width .05s; }
.progress { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--amber)); width: 0; transition: width .2s; }
.note { font-size: 12px; color: var(--muted); background: rgba(255,255,255,.04); border-left: 3px solid var(--teal); padding: 6px 10px; border-radius: 0 8px 8px 0; margin: 8px 0; }
.note.warn { border-left-color: var(--rose); }
kbd { font-family: inherit; font-size: 11px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 5px; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(3px); }
.modal-card { width: min(560px, 92vw); max-height: 86vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow); padding: 18px 20px; }
.modal-card h2 { margin: 0 0 10px; font: 800 22px var(--font-display); letter-spacing: -.01em; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #2a2932; border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; max-width: 80vw; }
.toast.error { border-color: var(--rose); }

@media (max-width: 1100px) {
  .app { grid-template-columns: 150px 1fr 300px; }
  .brand-sub, .title-input { display: none; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .app { display: flex; flex-direction: column; height: auto; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px; gap: 8px; }
  .transport { margin-left: 0; }
  .scenes-panel { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .scene-card { min-width: 150px; }
  .center { grid-template-rows: auto 200px; }
  .inspector { max-height: 60vh; }
}
