/* Layout: library · stage · inspector over a scene timeline.
   Two looks from Nour's palette: Night (dark, default) and Day (light), switched by [data-ui]. */
:root {
  --bg: #0b0e12;
  --panel: #11151b;
  --card: #161b22;
  --raised: #1d242e;
  --hover: #232b37;
  --line: rgba(238, 242, 246, 0.08);
  --line2: rgba(238, 242, 246, 0.16);
  --fg: #eef2f6;
  --muted: rgba(238, 242, 246, 0.64);
  --faint: rgba(238, 242, 246, 0.4);
  --accent: #b8ff5c;
  --accent-hover: #c8ff7c;
  --accent-text: #b8ff5c;
  --accent-soft: rgba(184, 255, 92, 0.12);
  --accent-line: rgba(184, 255, 92, 0.4);
  --ink: #10281a;
  --mint: #5ce1a9;
  --danger: #ff7b72;
  --scrim: rgba(5, 7, 9, 0.72);
  --chip-dark: rgba(15, 18, 22, 0.86);
  --stage-bg: radial-gradient(ellipse at 50% 40%, #141a21 0%, #0b0e12 70%);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 40px rgba(0, 0, 0, 0.45);
  --f-ui: 'IBM Plex Sans Arabic', 'Figtree', system-ui, sans-serif;
  --f-lat: 'Figtree', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --f-mono: 'JetBrains Mono', 'Cascadia Code', Menlo, monospace;
  --r1: 8px;
  --r2: 14px;
  --r3: 22px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}
:root[data-ui='light'] {
  --bg: #eef2f6;
  --panel: #ffffff;
  --card: #f5f7fa;
  --raised: #e9edf2;
  --hover: #e1e7ee;
  --line: rgba(16, 24, 32, 0.09);
  --line2: rgba(16, 24, 32, 0.17);
  --fg: #101820;
  --muted: #3a4450;
  --faint: rgba(16, 24, 32, 0.45);
  --accent: #b8ff5c;
  --accent-hover: #a6f23f;
  --accent-text: #3f7d10;
  --accent-soft: rgba(63, 125, 16, 0.1);
  --accent-line: rgba(63, 125, 16, 0.45);
  --ink: #10281a;
  --mint: #0f7a58;
  --danger: #c4332b;
  --scrim: rgba(16, 24, 32, 0.45);
  --chip-dark: rgba(15, 18, 22, 0.82);
  --stage-bg: radial-gradient(ellipse at 50% 40%, #f7f9fb 0%, #e3e9ef 75%);
  --shadow: 0 1px 2px rgba(16, 24, 32, 0.06), 0 18px 40px rgba(16, 24, 32, 0.14);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 14px/1.5 var(--f-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mono { font-family: var(--f-mono); }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
::selection { background: var(--accent); color: var(--ink); }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 352px;
  grid-template-rows: 60px minmax(0, 1fr) auto;
  grid-template-areas: 'top top top' 'side stage insp' 'side tl insp';
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ------------------------------------------------ top bar */
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 14px;
  border-bottom: 1px solid var(--line); background: var(--panel); min-width: 0;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent-text); }
.brand-icon { width: 36px; height: 36px; border-radius: 9px; flex: none; display: block; box-shadow: 0 0 0 1px var(--line); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; color: var(--fg); }
.brand-text strong { font-weight: 700; font-size: 15px; }
.brand-text span { font: 400 11px var(--f-mono); color: var(--muted); direction: ltr; text-align: right; }
.top-mid { flex: 1; display: flex; justify-content: center; min-width: 0; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 99px; color: var(--muted);
  font: 500 12.5px var(--f-ui); display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.seg button .ar { width: 10px; border: 1.5px solid currentColor; border-radius: 2px; display: inline-block; }
.seg button.on { background: var(--raised); color: var(--fg); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.seg button:hover:not(.on) { color: var(--fg); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; border-radius: 99px; padding: 8px 16px;
  border: 1px solid var(--line2); background: var(--card); font-weight: 600; font-size: 13.5px; color: var(--fg);
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease), transform 0.16s var(--ease);
  white-space: nowrap; justify-content: center;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--ink); border-color: transparent; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.btn.big { padding: 12px 22px; font-size: 15px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--muted); padding: 0;
}
.icon-btn:hover { background: var(--card); color: var(--fg); border-color: var(--line); }
.icon-btn[disabled] { opacity: 0.35; pointer-events: none; }
.icon-btn.sm { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.icon-btn.on { color: var(--accent-text); }
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 50; min-width: 230px;
  background: var(--panel); border: 1px solid var(--line2); border-radius: var(--r2); padding: 6px; box-shadow: var(--shadow);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; border: 0; background: transparent; padding: 9px 12px; border-radius: var(--r1); color: var(--fg); }
.menu button:hover { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ------------------------------------------------ panels */
.panel { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.side { grid-area: side; border-inline-end: 1px solid var(--line); }
.inspector { grid-area: insp; border-inline-start: 1px solid var(--line); overflow-y: auto; padding: 12px 14px 40px; }
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 9px 4px 11px; color: var(--muted); font-weight: 600; font-size: 13px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabs button svg { width: 18px; height: 18px; }
.tabs button.on { color: var(--fg); border-bottom-color: var(--accent-text); }
.tabs button:hover:not(.on) { color: var(--fg); }
.tab-body { flex: 1; overflow-y: auto; padding: 12px; min-height: 0; }

.search {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 9px 14px; outline: none; color: var(--fg);
}
.search:focus { border-color: var(--line2); }
.cats { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 8px; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cat {
  border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 99px; padding: 5px 11px;
  font-size: 12.5px; white-space: nowrap;
}
.cat:hover { color: var(--fg); }
.cat.on { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-line); font-weight: 600; }
.cat small { font: 400 10.5px var(--f-mono); opacity: 0.7; margin-inline-start: 4px; }
.count-note { color: var(--faint); font-size: 12px; margin: 2px 2px 10px; }

.tpl-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tpl {
  position: relative; border-radius: var(--r2); overflow: hidden; background: var(--card); border: 1px solid var(--line);
  padding: 0; text-align: start; display: flex; flex-direction: column; cursor: pointer;
  transition: border-color 0.16s var(--ease), transform 0.16s var(--ease);
}
.tpl:hover { border-color: var(--accent-line); transform: translateY(-2px); }
.tpl canvas { width: 100%; display: block; background: #000; }
.tpl .meta { padding: 7px 9px 8px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tpl .name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl .num { font: 400 10.5px var(--f-mono); color: var(--faint); }
.tpl .acts {
  position: absolute; inset: 8px 8px auto 8px; display: flex; gap: 6px; justify-content: flex-start; opacity: 0;
  transition: opacity 0.16s var(--ease);
}
.tpl:hover .acts, .tpl:focus-within .acts { opacity: 1; }
.tpl .acts button {
  border: 0; border-radius: 99px; padding: 5px 10px; font-size: 11.5px; font-weight: 700;
  background: var(--accent); color: var(--ink); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.tpl .acts button.alt { background: var(--chip-dark); color: #fff; }
.tpl.picked { border-color: var(--accent-text); box-shadow: 0 0 0 2px var(--accent-text); }
.tpl .pick-badge {
  position: absolute; top: 8px; inset-inline-end: 8px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--ink); font: 700 13px var(--f-mono); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

/* add-element panel */
.group-title { font-weight: 700; font-size: 12.5px; color: var(--muted); margin: 16px 2px 8px; display: flex; align-items: center; gap: 8px; }
.group-title::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.group-title:first-child { margin-top: 2px; }
.add-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.add-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 12px 6px;
  border-radius: var(--r2); border: 1px solid var(--line); background: var(--card); font-size: 12px; color: var(--muted);
  min-height: 74px; text-align: center;
}
.add-btn:hover { color: var(--fg); border-color: var(--accent-line); background: var(--raised); }
.add-btn svg { width: 22px; height: 22px; color: var(--accent-text); }
.add-btn .glyph { font: 800 20px var(--f-lat); color: var(--accent-text); line-height: 1; }
.add-btn canvas { filter: var(--glyph-filter, none); }
:root[data-ui='light'] .add-btn canvas, :root[data-ui='light'] .icon-pick canvas { filter: brightness(0.55) saturate(1.4); }
.icon-pick { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.icon-pick button { aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; color: var(--muted); padding: 0; }
.icon-pick button:hover, .icon-pick button.on { border-color: var(--accent-line); background: var(--accent-soft); }

/* style panel */
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.theme-card { border-radius: var(--r2); border: 1px solid var(--line); padding: 0; overflow: hidden; background: var(--card); text-align: start; }
.theme-card.on { border-color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent-text); }
.theme-card .sw { height: 54px; display: flex; align-items: flex-end; gap: 4px; padding: 8px; }
.theme-card .sw i { width: 14px; height: 14px; border-radius: 50%; display: block; border: 1px solid rgba(255, 255, 255, 0.15); }
.theme-card .sw b { font: 800 20px var(--f-lat); margin-inline-start: auto; line-height: 1; }
.theme-card .lab { padding: 6px 9px 7px; font-size: 12.5px; font-weight: 600; display: flex; justify-content: space-between; color: var(--fg); }
.theme-card .lab small { color: var(--faint); font: 400 10.5px var(--f-mono); }
.badge { font: 600 10px var(--f-ui); color: var(--accent-text); background: var(--accent-soft); border-radius: 99px; padding: 1px 7px; }

/* galleries (backgrounds, transitions, cameras, sounds) */
.gal-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.gal-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.gal-item {
  border: 1px solid var(--line); border-radius: var(--r1); padding: 0; overflow: hidden; background: var(--card); position: relative; text-align: start;
  transition: border-color 0.14s var(--ease);
}
.gal-item:hover { border-color: var(--accent-line); }
.gal-item.on { border-color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent-text); }
.gal-item img, .gal-item canvas { width: 100%; display: block; aspect-ratio: 4 / 5; object-fit: cover; background: #000; }
.gal-item.wide img, .gal-item.wide canvas { aspect-ratio: 4 / 3; }
.gal-item span {
  position: absolute; inset: auto 0 0 0; font-size: 10.5px; padding: 12px 5px 3px; background: linear-gradient(transparent, rgba(0, 0, 0, 0.82)); color: #fff;
  text-align: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip-list { display: flex; flex-wrap: wrap; gap: 5px; }
.chip-list button {
  border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 99px; padding: 5px 10px; font-size: 12px;
}
.chip-list button:hover { color: var(--fg); border-color: var(--line2); }
.chip-list button.on { color: var(--ink); background: var(--accent); border-color: transparent; font-weight: 600; }

/* ------------------------------------------------ fields */
.sec { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.sec:first-of-type { border-top: 0; }
.sec > summary {
  list-style: none; cursor: pointer; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: space-between;
  padding: 2px 0 10px; color: var(--fg);
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: '▾'; color: var(--faint); transition: transform 0.2s var(--ease); }
.sec:not([open]) > summary::after { transform: rotate(90deg); }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > label, .field > .lab { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.field .val { font: 500 11.5px var(--f-mono); color: var(--fg); direction: ltr; }
.hint { font-size: 11.5px; color: var(--faint); line-height: 1.6; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.input, .select, .textarea {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: var(--r1); padding: 8px 10px; outline: none; color: var(--fg);
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent-line); background: var(--panel); }
.textarea { resize: vertical; min-height: 64px; line-height: 1.6; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: 14px 52%, 9px 52%; background-size: 5px 5px; background-repeat: no-repeat; }
input[type='range'] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; }
input[type='range']::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--raised); }
input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--fg); margin-top: -6px; border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--line2); }
input[type='range']::-moz-range-track { height: 4px; border-radius: 4px; background: var(--raised); }
input[type='range']::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--fg); border: 3px solid var(--panel); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips button { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 99px; padding: 5px 10px; font-size: 12px; }
.chips button.on { color: var(--ink); background: var(--accent); border-color: transparent; font-weight: 600; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line2); padding: 0; }
.swatches button.on { box-shadow: 0 0 0 2px var(--accent-text); }
.swatches input[type='color'] { width: 30px; height: 30px; border: 0; padding: 0; background: transparent; border-radius: 50%; cursor: pointer; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; cursor: pointer; }
.toggle input { appearance: none; width: 34px; height: 20px; border-radius: 99px; background: var(--raised); position: relative; cursor: pointer; transition: background 0.16s; flex: none; margin: 0; }
.toggle input::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: inset-inline-start 0.16s var(--ease), background 0.16s; }
.toggle input:checked { background: var(--accent-soft); }
.toggle input:checked::after { inset-inline-start: 17px; background: var(--accent-text); }
.preset-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.preset-grid button {
  border: 1px solid var(--line); background: var(--card); border-radius: var(--r1); padding: 7px 4px; font-size: 11.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.preset-grid button:hover { color: var(--fg); border-color: var(--line2); }
.preset-grid button.on { color: var(--ink); background: var(--accent); border-color: transparent; font-weight: 600; }

.insp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.insp-head h3 { margin: 0; font-size: 15px; font-weight: 700; flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.insp-head h3 small { font: 400 11px var(--f-mono); color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.itabs { display: flex; gap: 3px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 12px; position: sticky; top: -12px; z-index: 3; }
.itabs button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 7px 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.itabs button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }
.tip { background: var(--card); border: 1px dashed var(--line2); border-radius: var(--r2); padding: 10px 12px; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; line-height: 1.7; }
.tip b { color: var(--accent-text); font-weight: 600; }
.layers { display: grid; gap: 4px; }
.layer {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--r1); background: var(--card); border: 1px solid transparent;
  font-size: 12.5px; cursor: pointer;
}
.layer:hover { border-color: var(--line2); }
.layer.on { border-color: var(--accent-text); }
.layer .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer .ty { font: 400 10.5px var(--f-mono); color: var(--faint); }
.layer.hidden-el .nm { opacity: 0.4; text-decoration: line-through; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.quick-texts { display: grid; gap: 8px; margin-bottom: 14px; }
.qt { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: start; }
.qt .textarea { min-height: 40px; padding: 7px 10px; }
.qt button { margin-top: 4px; }
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.big-actions .btn { padding: 10px 8px; font-size: 12.5px; }

/* sound editor */
.snd-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 7px 8px; border-radius: var(--r1); background: var(--card); margin-bottom: 5px; border: 1px solid transparent; }
.snd-row.muted { opacity: 0.45; }
.snd-row .t { font: 500 11px var(--f-mono); color: var(--faint); direction: ltr; min-width: 40px; }
.snd-row .what { min-width: 0; display: grid; gap: 4px; }
.snd-row .what b { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snd-row .what .select { padding: 4px 8px; font-size: 12px; }
.snd-row .acts { display: flex; gap: 2px; }
.snd-play { width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--accent); color: var(--ink); display: grid; place-items: center; padding: 0; }
.snd-play svg { width: 12px; height: 12px; fill: currentColor; stroke: none; }
.snd-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
.snd-grid button { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: var(--r1); padding: 6px 8px; font-size: 11.5px; color: var(--muted); text-align: start; min-width: 0; }
.snd-grid button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snd-grid button:hover { color: var(--fg); border-color: var(--line2); }
.snd-grid button.on { border-color: var(--accent-text); color: var(--fg); }
.snd-grid button i { width: 18px; height: 18px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; flex: none; font-style: normal; font-size: 9px; }

/* ------------------------------------------------ stage */
.stage-wrap { grid-area: stage; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--stage-bg); }
.stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 18px; position: relative; }
.stage-inner { position: relative; box-shadow: var(--shadow); border-radius: 6px; }
.stage-inner canvas { display: block; width: 100%; height: 100%; border-radius: 6px; background: #000; }
.overlay { position: absolute; inset: 0; touch-action: none; }
.sel { position: absolute; top: 0; left: 0; border: 1.5px solid var(--accent); border-radius: 3px; pointer-events: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45); }
.sel .h { position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid #10281a; border-radius: 50%; pointer-events: auto; }
.sel .h.br { right: -8px; bottom: -8px; cursor: nwse-resize; }
.sel .h.tl { left: -8px; top: -8px; cursor: nwse-resize; }
.sel .h.rot { left: 50%; top: -34px; margin-left: -7px; cursor: grab; background: var(--accent); }
.sel .stem { position: absolute; left: 50%; top: -22px; width: 1.5px; height: 22px; background: var(--accent); }
.hov { position: absolute; top: 0; left: 0; border: 1px dashed rgba(184, 255, 92, 0.75); border-radius: 3px; pointer-events: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); }
.guide { position: absolute; background: #ff4fa3; pointer-events: none; }
.guide.v { width: 1px; top: 0; bottom: 0; }
.guide.h { height: 1px; left: 0; right: 0; }
.inline-edit {
  position: absolute; z-index: 5; background: rgba(15, 18, 22, 0.94); color: #fff; border: 1.5px solid var(--accent);
  border-radius: 8px; padding: 8px 10px; resize: none; outline: none; text-align: center; line-height: 1.5; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
/* floating quick toolbar above the selection */
.qbar {
  position: absolute; z-index: 6; display: flex; gap: 2px; padding: 4px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--line2); box-shadow: var(--shadow); transform: translate(-50%, -100%); white-space: nowrap;
}
.qbar button { height: 32px; min-width: 32px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; color: var(--fg); display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.qbar button:hover { background: var(--hover); }
.qbar button svg { width: 16px; height: 16px; }
.qbar .sep { width: 1px; background: var(--line); margin: 4px 2px; }
.qbar .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line2); }
.stage-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  font-size: 12px; padding: 5px 12px; border-radius: 99px; pointer-events: none; white-space: nowrap; box-shadow: var(--shadow);
}
.transport { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.play { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: var(--ink); display: grid; place-items: center; flex: none; }
.play svg { fill: currentColor; stroke: none; width: 16px; height: 16px; }
.play .i-pause { display: none; }
.playing .play .i-pause { display: block; }
.playing .play .i-play { display: none; }
.time { font-size: 12px; color: var(--muted); min-width: 120px; direction: ltr; text-align: center; }
.scrub { flex: 1; min-width: 60px; direction: ltr; }
.chip-btn { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 99px; padding: 6px 11px; font-size: 12px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.chip-btn svg { width: 14px; height: 14px; }
.chip-btn.on { color: var(--accent-text); border-color: var(--accent-line); background: var(--accent-soft); }

/* ------------------------------------------------ timeline */
.timeline { grid-area: tl; border-top: 1px solid var(--line); background: var(--panel); padding: 10px 14px 12px; min-width: 0; }
.tl-row { display: flex; align-items: stretch; overflow-x: auto; padding-bottom: 4px; }
.tl-card { position: relative; flex: none; width: 120px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); padding: 0; overflow: hidden; text-align: start; cursor: pointer; }
.tl-card.on { border-color: var(--accent-text); }
.tl-card canvas { display: block; width: 100%; height: 72px; object-fit: cover; background: #000; }
.tl-card .info { display: flex; justify-content: space-between; align-items: center; padding: 4px 7px 5px; font-size: 11px; gap: 4px; color: var(--fg); }
.tl-card .info .n { font: 600 10.5px var(--f-mono); color: var(--faint); }
.tl-card .info .d { font: 500 10.5px var(--f-mono); color: var(--muted); direction: ltr; }
.tl-card .x { position: absolute; top: 4px; inset-inline-start: 4px; display: none; gap: 3px; }
.tl-card:hover .x, .tl-card.on .x { display: flex; }
.tl-card .x button { width: 22px; height: 22px; border-radius: 6px; border: 0; background: var(--chip-dark); color: #fff; display: grid; place-items: center; padding: 0; }
.tl-card .x button svg { width: 13px; height: 13px; }
.tl-card.drag-over { border-color: var(--mint); }
.tr-chip {
  flex: none; align-self: center; margin: 0 4px; border: 1px dashed var(--line2); background: transparent; color: var(--muted); border-radius: 99px;
  padding: 3px 7px; font-size: 10.5px; white-space: nowrap; max-width: 78px; overflow: hidden; text-overflow: ellipsis;
}
.tr-chip:hover { color: var(--accent-text); border-color: var(--accent-line); }
.tl-add { flex: none; width: 92px; margin-inline-start: 8px; border-radius: 10px; border: 1.5px dashed var(--line2); background: transparent; color: var(--muted); display: grid; place-items: center; font-size: 12px; gap: 4px; padding: 10px 4px; }
.tl-add:hover { color: var(--accent-text); border-color: var(--accent-line); }
.tl-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; color: var(--muted); gap: 8px; }
.tl-head b { color: var(--fg); font-weight: 600; }
.pop { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line2); border-radius: var(--r2); padding: 10px; width: 320px; max-height: 70vh; overflow-y: auto; box-shadow: var(--shadow); color: var(--fg); }

/* ------------------------------------------------ modals */
.modal { position: fixed; inset: 0; z-index: 100; background: var(--scrim); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(6px); }
.modal-card { width: min(560px, 100%); max-height: 92vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line2); border-radius: var(--r3); color: var(--fg); box-shadow: var(--shadow); }
.modal-card.wide { width: min(1100px, 100%); }
.modal-card.mid { width: min(860px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 8px; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.modal-body { padding: 8px 18px 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: space-between; align-items: center; padding: 12px 18px 16px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }
.bar { height: 8px; border-radius: 99px; background: var(--raised); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.2s linear; }
.exp-stats { display: flex; justify-content: space-between; font: 400 12px var(--f-mono); color: var(--muted); margin: 8px 0 14px; direction: ltr; }
.exp-video { width: 100%; border-radius: var(--r2); background: #000; max-height: 50vh; display: block; margin-bottom: 12px; }
.note { font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.steps { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--faint); }
.steps span { display: inline-flex; align-items: center; gap: 6px; }
.steps span b { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--raised); color: var(--muted); font: 700 11px var(--f-mono); }
.steps span.on { color: var(--fg); }
.steps span.on b { background: var(--accent); color: var(--ink); }
.steps i { width: 18px; height: 1px; background: var(--line2); }
.aspect-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.aspect-card { border: 1.5px solid var(--line); border-radius: var(--r2); background: var(--card); padding: 18px 10px 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--fg); }
.aspect-card:hover { border-color: var(--accent-line); }
.aspect-card.on { border-color: var(--accent-text); background: var(--accent-soft); }
.aspect-card .shape { border: 2px solid currentColor; border-radius: 6px; opacity: 0.85; }
.aspect-card b { font-size: 14px; }
.aspect-card small { color: var(--muted); font: 400 11px var(--f-mono); }
.story-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 16px; }
.story-card { border: 1.5px solid var(--line); border-radius: var(--r2); background: var(--card); padding: 12px; text-align: start; color: var(--fg); display: grid; gap: 4px; }
.story-card:hover { border-color: var(--accent-line); }
.story-card b { font-size: 14px; }
.story-card small { color: var(--muted); font-size: 12px; line-height: 1.5; }
.pv-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
.pv-canvas { width: 100%; border-radius: var(--r2); background: #000; display: block; box-shadow: var(--shadow); }
.pv-side { display: grid; gap: 10px; }
.pv-side h3 { margin: 0; font-size: 18px; }
.pv-side .cat-name { color: var(--accent-text); font-size: 12px; font-weight: 600; }
.pv-nav { display: flex; gap: 8px; }
.poster-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 18px; align-items: start; }
.kbd { font: 500 11px var(--f-mono); background: var(--raised); border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; direction: ltr; display: inline-block; }
.help-list { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-size: 13px; align-items: center; }
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel); color: var(--fg); border: 1px solid var(--line2); border-radius: 99px; padding: 10px 18px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s var(--ease), transform 0.2s var(--ease); z-index: 200; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------ responsive */
@media (max-width: 1240px) {
  .app { grid-template-columns: 300px minmax(0, 1fr) 316px; }
  .brand-text span { display: none; }
}
@media (max-width: 920px) {
  body { overflow: auto; }
  .app {
    height: auto; min-height: 100%;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas: 'top' 'stage' 'tl' 'side' 'insp';
  }
  .topbar { flex-wrap: wrap; padding: 10px max(16px, env(safe-area-inset-left, 0px)) 10px max(16px, env(safe-area-inset-right, 0px)); gap: 8px; }
  .top-mid { order: 3; flex-basis: 100%; overflow-x: auto; justify-content: flex-start; }
  .top-actions { flex-wrap: wrap; }
  .top-actions .lbl { display: none; }
  .stage { flex: none; height: min(64vh, 640px); padding: 10px; }
  .transport { flex-wrap: wrap; padding-inline: max(16px, env(safe-area-inset-left, 0px)); }
  .scrub { order: 5; flex-basis: 100%; }
  .side, .inspector { border: 0; border-top: 1px solid var(--line); }
  .inspector { overflow: visible; padding-inline: max(16px, env(safe-area-inset-left, 0px)); }
  .tab-body { overflow: visible; max-height: none; }
  .timeline { padding-inline: max(16px, env(safe-area-inset-left, 0px)); }
  .tpl-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .tpl .acts { opacity: 1; }
  .pv-wrap, .poster-wrap { grid-template-columns: 1fr; }
  .aspect-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .itabs { top: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* watermark box (export + poster dialogs) */
.wm-box { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 4px 0 12px; background: var(--card); }
.wm-head { display: flex; align-items: center; gap: 10px; }
.wm-head > svg { width: 18px; height: 18px; flex: none; stroke: var(--accent-text, var(--accent)); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.wm-head > div { flex: 1; display: grid; gap: 2px; min-width: 0; }
.wm-head b { font-size: 13px; }
.wm-head b.mono { font-family: var(--f-mono); text-align: right; }
.wm-head small, .wm-msg { color: var(--muted); font-size: 11.5px; }
.wm-form { display: flex; gap: 8px; margin-top: 10px; }
.wm-form .input { flex: 1; min-width: 0; }
.wm-msg { display: block; margin-top: 6px; min-height: 1em; }
.wm-msg.bad { color: var(--danger); }
.wm-box > .toggle { margin: 0 0 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
