:root {
  --bg: #0f1216;
  --panel: #171b21;
  --tile: #2f313d;
  --line: #262c35;
  --text: #e8ecf1;
  --dim: #8a94a3;
  --accent: #ecc332;
  --on-accent: #1b1500;
  --danger: #ef6a6a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
  padding-top: var(--safe-t);
}
button {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; cursor: pointer;
}
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
input[type=text], input[type=number] {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-width: 0; flex: 1; user-select: text; -webkit-user-select: text;
}
input[type=color] { width: 42px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 2px; }
.spacer { flex: 1; }

.bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.bar h1 { margin: 0; font-size: 19px; letter-spacing: .2px; font-weight: 800; }
.logo { border-radius: 7px; display: block; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.stage { position: relative; flex: 1; min-height: 120px; background: #000; overflow: hidden; }
.stage canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.empty {
  position: absolute; inset: 0; margin: auto; width: 220px; height: 120px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: transparent; border: 2px dashed var(--line); color: var(--dim); border-radius: 16px;
}
.empty .plus { font-size: 34px; color: var(--accent); line-height: 1; }
.empty[hidden] { display: none; }

/* on-canvas rectangle editor */
#ov { position: absolute; pointer-events: none; }
#ov[hidden] { display: none; }
#ovBox {
  position: absolute; border: 2px solid var(--accent);
  pointer-events: auto; touch-action: none; cursor: move;
}
#ov.dim #ovBox { box-shadow: 0 0 0 9999px rgba(0,0,0,.4); }
#ovBox i { position: absolute; width: 26px; height: 26px; background: var(--accent); border-radius: 50%; border: 3px solid #fff; touch-action: none; }
#ovBox i[data-h=tl] { left: -14px; top: -14px; cursor: nwse-resize; }
#ovBox i[data-h=tr] { right: -14px; top: -14px; cursor: nesw-resize; }
#ovBox i[data-h=bl] { left: -14px; bottom: -14px; cursor: nesw-resize; }
#ovBox i[data-h=br] { right: -14px; bottom: -14px; cursor: nwse-resize; }

.transport { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.round { width: 44px; height: 44px; border-radius: 50%; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.round.sm { width: 36px; height: 36px; }
.round svg, .tools i svg { display: block; }
.time { font-variant-numeric: tabular-nums; color: var(--dim); white-space: nowrap; font-size: 13px; }
.zoom { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 13px; }
.zoom input { width: 90px; accent-color: var(--accent); }

.tl-box { position: relative; background: var(--panel); border-block: 1px solid var(--line); flex: none; }
#tlWrap { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain; }
#tlWrap::-webkit-scrollbar { display: none; }
#timeline { display: flex; width: max-content; }
.spacer-x { flex: none; }
#content { flex: none; position: relative; padding-bottom: 8px; }
#ruler { position: relative; height: 24px; color: var(--dim); font-size: 11px; }
#ruler span { position: absolute; top: 4px; padding-left: 4px; border-left: 1px solid var(--line); height: 20px; }
#track { display: flex; height: 64px; margin-top: 2px; }
.lane { position: relative; height: 24px; margin-top: 5px; }
.lane[hidden] { display: none; }
.item { position: absolute; top: 0; height: 100%; border-radius: 6px; padding: 3px 8px; font-size: 11px; overflow: hidden; white-space: nowrap; cursor: pointer; border: 1px solid transparent; }
.item.pip { background: #5b3b8c; border-color: #8a63c7; }
.item.audio { background: #1f6b57; border-color: #3aa88a; }
.item.sel { border-color: #fff; }
.clip {
  flex: none; height: 100%; overflow: hidden; position: relative;
  background: hsl(var(--h) 45% 32%);
  border: 1px solid hsl(var(--h) 55% 50%);
  border-radius: 8px;
  padding: 6px 8px; font-size: 12px; cursor: pointer;
}
.clip + .clip { margin-left: 2px; }
.clip.cur { background: hsl(var(--h) 50% 38%); border-color: #fff; }
.clip .n { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip .d { display: block; color: rgba(255,255,255,.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.playhead {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px;
  background: #fff; box-shadow: 0 0 6px rgba(0,0,0,.6); pointer-events: none;
}

.tools {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px calc(8px + var(--safe-b));
  scrollbar-width: none; flex: none;
}
.tools::-webkit-scrollbar { display: none; }
.tools button { flex: none; min-width: 66px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 6px 8px; }
.tools button.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.tools i { font-style: normal; display: flex; height: 24px; align-items: center; }

/* tool panel replaces timeline + quick tools while open */
.panel { flex: none; max-height: 44dvh; display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.panel[hidden] { display: none; }
.panel > header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; }
.panel h2 { margin: 0; font-size: 16px; }
#panelBody { overflow-y: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }
body.panel-open .tl-box, body.panel-open .tools { display: none; }
.sec { display: flex; flex-direction: column; gap: 8px; }
.sec h3 { margin: 0; font-size: 12px; color: var(--dim); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 12px; border-radius: 999px; font-size: 13px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row .act { flex: 1; }
.act { padding: 10px 14px; }
.hint { margin: 0; color: var(--dim); font-size: 13px; }
.lbl { color: var(--dim); font-size: 12px; margin-bottom: -4px; }
.sl { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--dim); }
.sl b { color: var(--text); font-weight: 600; }
.sl input { width: 100%; accent-color: var(--accent); }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dim); }
.sw { width: 32px; height: 32px; border-radius: 50%; padding: 0; border: 2px solid var(--line); }
.sw.on { border-color: #fff; }
.tgt span { color: var(--dim); font-size: 13px; }
.tgt input { max-width: 110px; }

/* tools grid sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; z-index: 8; }
.sheet[hidden] { display: none; }
.sheet-card { width: 100%; max-height: 82dvh; overflow-y: auto; background: #25262f; border-radius: 18px 18px 0 0; padding: 8px 12px calc(14px + var(--safe-b)); }
.sheet-card > header { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 8px; }
.sheet-card h2 { margin: 0; font-size: 16px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  background: var(--tile); border: 0; border-radius: 10px; min-height: 92px; padding: 10px 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-size: 13px; text-align: center; color: #fff;
}
.tile .ic { color: var(--accent); display: flex; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; }
.overlay[hidden] { display: none; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(380px, 100%); }
.card h2 { margin: 0 0 6px; font-size: 17px; }
.card p { margin: 0 0 14px; color: var(--dim); word-break: break-word; }
.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-bottom: 16px; }
#ovBar { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.card .row { justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translate(-50%, 20px);
  background: #000; border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; text-align: center; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  #track { height: 76px; }
  .panel { max-height: 38dvh; }
}
