:root {
  --bg: #16171d;
  --bg-2: #1d1f27;
  --panel: #23252f;
  --panel-2: #2b2e3a;
  --line: #363a48;
  --text: #eceef4;
  --muted: #9aa0b4;
  --accent: #ff6a3d;
  --accent-2: #ff8a63;
  --accent-ink: #1b0d07;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --danger: #ff4d5e;
  --focus: #7aa7ff;
  --line-strong: #4a4f63;
  --hover: #343848;
  /* One scale for corners, control heights and icon sizes so everything lines up. */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --control-h-sm: 30px;
  --control-h: 36px;
  --control-h-lg: 44px;
  --icon-xs: 14px;
  --icon-sm: 16px;
  --icon: 18px;
  --icon-lg: 20px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, 'Helvetica Neue', sans-serif;
  color-scheme: dark;
}

/* Display font for the landing page and sign-in screens (self-hosted for the CSP). */
@font-face { font-family: 'Fredoka'; src: url('/fonts/fredoka.woff2') format('woff2'); font-weight: 600; font-display: swap; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); }
h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
p { margin: 0 0 0.8em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Controls ---------- */
button, .btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
button:hover, .btn:hover { background: var(--hover); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.danger { background: transparent; border-color: rgba(255, 77, 94, 0.5); color: var(--danger); }
button.danger:hover { background: rgba(255, 77, 94, 0.12); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--panel-2); }
button.icon { width: var(--control-h); padding: 0; }
button.sm { height: var(--control-h-sm); padding: 0 10px; font-size: 13px; }
button.icon.sm { width: var(--control-h-sm); padding: 0; }
button.active, button[aria-pressed='true'] { background: rgba(255, 106, 61, 0.18); border-color: var(--accent); color: var(--accent-2); }
button svg, .btn svg { width: var(--icon); height: var(--icon); flex: none; }
button.sm svg { width: var(--icon-sm); height: var(--icon-sm); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  min-width: 0;
}
input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='color']), select { height: var(--control-h); padding-top: 0; padding-bottom: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; }
input[type='checkbox'] { width: 16px; height: 16px; accent-color: var(--accent); }
input[type='range'] { accent-color: var(--accent); padding: 0; background: none; border: 0; }
input[type='color'] { padding: 2px; width: 44px; height: var(--control-h); }
textarea { width: 100%; min-height: 120px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.field input, label.field select { width: 100%; }
label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.slider-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.slider-row input[type='range'] { grid-column: 1 / -1; width: 100%; }
.slider-row output { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.admin { background: rgba(255, 106, 61, 0.15); color: var(--accent-2); border-color: rgba(255, 106, 61, 0.4); }
.badge.ok { background: rgba(62, 207, 142, 0.12); color: var(--ok); border-color: rgba(62, 207, 142, 0.35); }
.badge.off { background: rgba(255, 77, 94, 0.12); color: var(--danger); border-color: rgba(255, 77, 94, 0.35); }
.meter { height: 6px; background: var(--bg-2); border-radius: 99px; overflow: hidden; min-width: 60px; }
.meter > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.meter.warn > i { background: var(--warn); }
.meter.full > i { background: var(--danger); }

.boot { display: grid; place-items: center; height: 100vh; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Top navigation ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 18px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.topbar nav { display: flex; gap: 4px; margin-left: 12px; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: var(--radius); }
.topbar nav a:hover, .topbar nav a.current { color: var(--text); background: var(--panel-2); }
.usermenu { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 6px; z-index: 50;
}
.menu button, .menu a { width: 100%; justify-content: flex-start; border: 0; background: transparent; height: var(--control-h); padding: 0 10px; color: var(--text); }
.menu button:hover, .menu a:hover { background: var(--panel-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .menu-head { padding: 6px 10px 8px; font-size: 12px; color: var(--muted); }

.page { max-width: 1180px; margin: 0 auto; padding: 28px 18px 60px; }

/* ---------- Auth (sign in, sign up, password screens): a clapperboard card on a film set ---------- */
.auth-wrap {
  --set-yellow: #f5c542;
  position: relative; overflow: hidden;
  min-height: 100vh; display: grid; place-items: center; padding: 40px 16px;
  background: var(--bg);
}
.auth-strip {
  position: absolute; left: -80px; right: -80px; height: 132px; padding: 8px 0 8px 30px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: #0e0f13; pointer-events: none;
}
.auth-strip.robot { top: 6vh; transform: rotate(-4deg); }
.auth-strip.ball { bottom: 5vh; transform: rotate(3deg); padding-left: 60px; }
.auth-strip > i { height: 10px; border-radius: 3px; background: repeating-linear-gradient(90deg, #2a2b34 0 14px, transparent 14px 34px); }
.auth-frames { display: flex; gap: 12px; }
.auth-frame { position: relative; flex: none; width: 140px; height: 86px; border-radius: 6px; background: #2d6a5f; }
.auth-frame span { position: absolute; bottom: 8px; width: 20px; height: 30px; border-radius: 4px; background: var(--set-yellow); }
.auth-strip.ball .auth-frame { background: #3b4f8a; }
.auth-strip.ball .auth-frame span { bottom: auto; width: 22px; height: 22px; border-radius: 50%; background: #ff8a66; }

.auth-stage { position: relative; z-index: 1; width: 100%; max-width: 460px; display: flex; flex-direction: column; align-items: center; }
/* The BotBuilders robot peeks over the card in a spotlight. Its outlines are black, so the spotlight keeps it readable. */
.auth-robot { position: relative; display: block; height: 184px; overflow: hidden; margin-bottom: -10px; padding: 6px 36px 0; }
.auth-robot::before {
  content: ''; position: absolute; inset: 6px 0 -40px; border-radius: 50% 50% 0 0;
  /* Opaque, so the film strip behind doesn't show through the robot. */
  background: linear-gradient(rgba(245, 197, 66, 0.16), rgba(245, 197, 66, 0.16)), var(--bg);
}
.auth-robot img { position: relative; display: block; height: 310px; width: auto; }
.auth-robot:focus-visible { outline-offset: -2px; border-radius: 12px; }

.auth-card { position: relative; z-index: 2; width: 100%; border-radius: 22px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6); overflow: hidden; }
.auth-clapper { height: 40px; background: repeating-linear-gradient(-45deg, #f5f5f7 0 20px, #16171d 20px 40px); }
.auth-slate { display: flex; justify-content: space-between; gap: 12px; padding: 11px 28px; border-bottom: 1px solid var(--line); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.auth-slate span { white-space: nowrap; }
/* The scene always shows in full; the site name gives way if there isn't room. */
.auth-slate span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.auth-slate span:last-child { flex-shrink: 0; }
.auth-body { padding: 24px 28px 28px; }
.auth-body h1 { margin: 0 0 18px; text-align: center; font-family: 'Fredoka', var(--font); font-weight: 600; font-size: 30px; line-height: 1.15; color: #f5f5f7; }
.auth-sub { margin: -8px 0 18px; text-align: center; color: var(--muted); font-size: 15px; }
.auth-card form > * + * { margin-top: 16px; }
.auth-card .form-error:empty { display: none; }
.auth-card label.field > span { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; color: #c9cbd6; margin-bottom: 6px; }
.auth-card label.field input:not([type='checkbox']):not([type='radio']) { height: 52px; border-radius: 14px; border-width: 1.5px; border-color: var(--line-strong); padding: 0 16px; font-size: 17px; }
.auth-card label.field input:not([type='checkbox']):not([type='radio']):focus { border-color: var(--set-yellow); }
.auth-card button.primary { width: 100%; height: 56px; gap: 10px; border-radius: 16px; font-size: 17px; font-weight: 700; background: var(--set-yellow); border-color: var(--set-yellow); color: #16171d; }
.auth-card button.primary:hover { background: #ffd35c; }
.auth-play { width: 0; height: 0; border-style: solid; border-width: 7px 0 7px 12px; border-color: transparent transparent transparent currentColor; }
.auth-back { width: 100%; }
.auth-card a { color: var(--set-yellow); }
.auth-forgot { font-weight: 600; }

.auth-kind { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; }
.auth-kind button { height: 46px; border: 0; border-radius: 12px; background: transparent; color: #c9cbd6; font-size: 15px; font-weight: 600; }
.auth-kind button:hover { background: var(--panel-2); }
.auth-kind button[aria-pressed='true'] { background: #f5f5f7; color: #16171d; font-weight: 700; }

.auth-tip { display: flex; gap: 12px; align-items: flex-start; background: #2e2a1a; border: 1px solid #4d4322; border-radius: 14px; padding: 13px 16px; font-size: 14px; line-height: 1.45; color: #e9dcb0; }
.auth-tip svg { width: 20px; height: 20px; flex: none; margin-top: 1px; color: var(--set-yellow); }
.auth-tip b { color: #f5f5f7; }
.auth-foot { margin: 16px 0 0; text-align: center; font-size: 15px; color: #c9cbd6; }
.auth-card form .auth-foot { margin-top: 16px; }
.auth-credit { position: relative; margin: 20px 0 0; padding: 6px 14px; border-radius: 999px; background: var(--bg); text-align: center; font-size: 14px; color: var(--muted); }
.auth-credit a { color: #c9cbd6; }

@media (max-height: 880px) {
  .auth-wrap { padding: 24px 16px; }
  .auth-robot { height: 142px; }
  .auth-robot img { height: 222px; }
  .auth-body { padding-top: 20px; padding-bottom: 22px; }
  .auth-body h1 { margin-bottom: 14px; }
  .auth-card form > * + * { margin-top: 12px; }
}

@media (max-width: 520px) {
  .auth-body { padding: 20px 20px 24px; }
  .auth-slate { padding: 10px 20px; font-size: 11px; }
  .auth-slate span:first-child { display: none; }
  .auth-body h1 { font-size: 26px; }
  .auth-robot { height: 150px; }
  .auth-robot img { height: 250px; }
  .auth-strip.ball { display: none; }
}
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; }

/* ---------- Projects ---------- */
.proj-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.proj-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; display: flex; flex-direction: column; transition: border-color 0.15s, transform 0.15s; }
.proj-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.proj-thumb { aspect-ratio: 16 / 9; background: #0e0f13 center/cover no-repeat; display: grid; place-items: center; color: var(--muted); cursor: pointer; position: relative; }
.proj-thumb img { width: 100%; height: 100%; object-fit: cover; }
.proj-thumb .shared { position: absolute; top: 8px; left: 8px; }
.proj-thumb .expires { position: absolute; top: 8px; right: 8px; }
.proj-body { padding: 10px 12px 12px; display: flex; gap: 6px; align-items: flex-start; }
.proj-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-new { border: 2px dashed var(--line); background: transparent; border-radius: var(--radius-lg); min-height: 180px; display: grid; place-items: center; color: var(--muted); cursor: pointer; font-size: 15px; }
.proj-new:hover { border-color: var(--accent); color: var(--accent-2); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.class-block { border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.class-block > summary { list-style: none; cursor: pointer; }
.class-block > summary::-webkit-details-marker { display: none; }
.class-head { display: flex; align-items: center; gap: 14px; padding: 10px 12px; background: var(--bg-2); }
.class-head .badge { margin-left: 4px; vertical-align: 1px; }
.class-head .user-cell { display: flex; flex-direction: column; }
.class-block[open] > .class-head { border-bottom: 1px solid var(--line); }
.class-block .table-wrap { border: 0; border-radius: 0; }
.link-cell code { font-size: 12px; word-break: break-all; color: var(--muted); }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 16px; }
.plan-card { display: flex; flex-direction: column; gap: 12px; }
.plan-card.current { border-color: var(--accent); }
.plan-card h2 { margin: 0; }
.plan-price { font-size: 20px; font-weight: 600; }
.plan-features { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; flex: 1; font-size: 13px; }
.plan-features li { display: flex; gap: 8px; align-items: flex-start; }
.plan-features svg { width: var(--icon-sm); height: var(--icon-sm); flex: none; color: var(--ok); margin-top: 1px; }
.storage-line { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.storage-line .meter { width: 140px; }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(5, 6, 10, 0.6); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade 0.12s; }
.modal { width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.modal.wide { max-width: 760px; }
.modal header { display: flex; align-items: center; padding: 16px 18px 0; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 16px 18px; }
.modal .body > * + * { margin-top: 12px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 16px; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; background: #2f3342; border: 1px solid var(--line); padding: 10px 16px; border-radius: var(--radius-lg); box-shadow: var(--shadow); pointer-events: auto; animation: fade 0.15s; max-width: 90vw; }
.toast.error { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }

/* ---------- Tables (admin) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg-2); position: sticky; top: 0; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
tbody tr:last-child td { border-bottom: 0; }
td .user-cell { display: flex; flex-direction: column; }
td .user-cell b { font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); height: 40px; }
.tabs button.current { color: var(--text); border-bottom-color: var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 12px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type='search'] { width: 260px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Editor ---------- */
.editor { position: fixed; inset: 0; display: grid; grid-template-rows: 52px minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); background: #0f1014; }
.ed-top { position: relative; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: var(--bg-2); border-bottom: 1px solid var(--line); min-width: 0; }
.ed-title { font-weight: 600; font-size: 15px; background: transparent; border: 1px solid transparent; padding: 5px 8px; width: 260px; max-width: 30vw; }
.ed-title:hover { border-color: var(--line); }
.ed-title:focus { background: var(--bg-2); }
.sync { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; background: transparent; border: 0; height: 28px; padding: 0 8px; }
.sync:disabled { opacity: 1; cursor: default; }
.sync.error { color: var(--danger); cursor: pointer; }
.sync.error:hover { background: rgba(255, 77, 94, 0.1); }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.sync.busy i { background: var(--warn); animation: pulse 1s infinite; }
.sync.error i { background: var(--danger); }
/* Save status sits in the middle of the bar when there is room for it. */
@media (min-width: 1100px) { .ed-top .sync { position: absolute; left: 50%; transform: translateX(-50%); } }
@keyframes pulse { 50% { opacity: 0.3; } }
/* --side-w, --side-h and --tl-h are set when someone drags a border (see Editor.initSplitters). */
.ed-main { display: grid; grid-template-columns: minmax(0, 1fr) min(var(--side-w, 330px), max(240px, calc(100vw - 380px))); min-height: 0; min-width: 0; }
.stage-wrap { position: relative; display: grid; place-items: center; min-height: 0; min-width: 0; padding: 14px; overflow: hidden; }
.stage { position: relative; max-width: 100%; max-height: 100%; box-shadow: 0 0 0 1px var(--line), var(--shadow); background: #000; }
.stage canvas { display: block; width: 100%; height: 100%; }
.stage .overlay { position: absolute; inset: 0; pointer-events: none; }
.stage.picking { cursor: crosshair; }
.stage-badge { position: absolute; top: 10px; left: 10px; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: var(--radius-sm); background: rgba(0, 0, 0, 0.6); pointer-events: none; }
.stage-badge.live { background: var(--danger); color: #fff; }
.stage-counter { position: absolute; top: 10px; right: 10px; font-size: 12px; padding: 3px 8px; border-radius: var(--radius-sm); background: rgba(0, 0, 0, 0.6); font-variant-numeric: tabular-nums; pointer-events: none; }
.stage-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; }
.stage-msg > div { max-width: 360px; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash 0.25s; }
@keyframes flash { from { opacity: 0.7; } to { opacity: 0; } }
.bulk-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 10px; background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius); }
th.check-col, td.check-col { width: 36px; padding-right: 0; }

/* AI tools: face blur status chip and the manual "blur an area" box */
.stage-ai { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; max-width: calc(100% - 180px); font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: rgba(15, 16, 20, 0.72); border: 1px solid rgba(255, 255, 255, 0.14); pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-ai svg { width: var(--icon-xs); height: var(--icon-xs); flex: none; color: var(--accent-2); }
.stage.blurring { cursor: crosshair; touch-action: none; user-select: none; }
.blur-box { position: absolute; border: 2px dashed #fff; background: rgba(255, 255, 255, 0.18); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5); pointer-events: none; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); background: rgba(245, 185, 66, 0.1); border: 1px solid rgba(245, 185, 66, 0.45); font-size: 13px; }
.notice > svg { width: var(--icon-sm); height: var(--icon-sm); flex: none; margin-top: 2px; color: var(--warn); }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 120px; font-weight: 800; color: #fff; text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6); pointer-events: none; }

.side { position: relative; background: var(--bg-2); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.side-tabs { display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); border-bottom: 1px solid var(--line); }
.side-tabs button { border: 0; border-radius: 0; background: transparent; height: 46px; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); padding: 0; min-width: 0; }
.side-tabs button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.side-tabs button:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.side-tabs button svg { width: var(--icon); height: var(--icon); }
.side-tabs button.current { color: var(--accent-2); box-shadow: inset 0 -2px 0 var(--accent); }
.side-body { overflow-y: auto; padding: 14px; flex: 1; }
.side-body section + section { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.side-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.side-body .stack > * + * { margin-top: 10px; }
/* A wider side panel shows more at once instead of making things bigger:
   the grids below add columns, and everything else stops at a comfortable width. */
.side-body .stack > :not(.trans-grid, .style-grid, .sticker-results, .sfx-group, .scene-grid) { max-width: 440px; }
.side-body select, .side-body input[type='number'] { width: 100%; }
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; height: var(--control-h-sm); background: transparent; font-size: 12px; padding: 0 6px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.current { background: rgba(255, 106, 61, 0.18); color: var(--accent-2); }
.track { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.track + .track { margin-top: 8px; }
.track-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch { width: 24px; height: 24px; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.bg-thumb { width: 100%; aspect-ratio: 16/9; border-radius: var(--radius); border: 1px solid var(--line); background: #000 center/cover no-repeat; }

.ed-bottom { position: relative; background: var(--bg-2); border-top: 1px solid var(--line); min-width: 0; }
.transport { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; padding: 8px 12px; }
.tp-left, .tp-center, .tp-right { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tp-right { justify-content: flex-end; gap: 10px; }
.transport .time { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); white-space: nowrap; }
.transport .time b { color: var(--text); font-weight: 600; }
.live-btn { height: var(--control-h-lg); }
.capture-btn { height: var(--control-h-lg); min-width: 132px; border-radius: 99px; font-size: 15px; background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 700; box-shadow: 0 4px 14px rgba(255, 77, 94, 0.3); }
.capture-btn:hover:not(:disabled) { background: #ff6b79; }
.capture-btn:disabled { background: var(--panel-2); border-color: var(--line); color: var(--muted); box-shadow: none; opacity: 1; }
.capture-btn svg { width: var(--icon-lg); height: var(--icon-lg); }
.play-btn { width: var(--control-h-lg); height: var(--control-h-lg); padding: 0; border-radius: 50%; background: var(--text); border-color: var(--text); color: var(--bg); }
.play-btn:hover:not(:disabled) { background: #fff; }
.play-btn svg { width: var(--icon-lg); height: var(--icon-lg); }
.fps-chip { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.fps-chip input { width: 64px; }
.zoom { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.zoom svg { width: var(--icon-sm); height: var(--icon-sm); }
.zoom input { width: 90px; }
@media (max-width: 1180px) and (min-width: 901px) { .zoom { display: none; } }

.timeline { position: relative; overflow-x: auto; overflow-y: auto; max-height: 34vh; padding: 6px 10px 10px 0; user-select: none; }
.tl-tracks { position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: repeat(3, auto); column-gap: 8px; width: max-content; min-width: 100%; }
/* Track names; they stay at the left edge (covering the tracks) while the timeline scrolls. */
.tl-label { grid-column: 1; position: sticky; left: 0; z-index: 4; width: 128px; display: flex; align-items: flex-start; gap: 6px; padding: 4px 8px 0 12px; background: var(--bg-2); border-right: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 600; line-height: 20px; white-space: nowrap; }
.tl-label.frames { padding-top: 21px; }
.tl-label svg { width: var(--icon-xs); height: var(--icon-xs); flex: none; margin-top: 3px; }
.tl-label span { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) { .tl-label { width: 36px; padding-left: 11px; } .tl-label span { display: none; } }
.tl-frames { display: flex; gap: 0; min-height: 86px; align-items: stretch; position: relative; }
.tl-frame { position: relative; flex: none; height: 80px; padding: 0 2px; cursor: pointer; }
.tl-frame:hover .img { border-color: var(--line-strong); }
.tl-frame .img:has(img:not([src])) { background: linear-gradient(90deg, #1b1d25 0%, #262935 50%, #1b1d25 100%) 0 0 / 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.tl-frame .img { height: 62px; border-radius: var(--radius-sm); background: #000 center/cover no-repeat; border: 2px solid transparent; position: relative; overflow: hidden; flex: 1; min-width: 0; }
.tl-frame .img img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.tl-frame .num { font-size: 11px; color: var(--muted); text-align: center; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tl-frame .hold { position: absolute; right: 4px; bottom: 4px; background: rgba(0, 0, 0, 0.75); color: #fff; font-size: 11px; font-weight: 700; padding: 0 5px; border-radius: 4px; }
.tl-frame.selected .img { border-color: var(--focus); }
.tl-frame.current .img { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 106, 61, 0.35); }
.tl-frame.selected.current .img { border-color: var(--accent); }
.tl-frame.dragging { opacity: 0.35; }
/* A capture still being face-blurred: AI skeleton tile with a colour wave */
.tl-pending { position: relative; flex: none; height: 80px; padding: 0 2px; cursor: progress; }
.tl-pending .img { position: relative; height: 62px; border-radius: var(--radius-sm); overflow: hidden; display: grid; place-items: center; background: #1b1d25; border: 2px solid rgba(255, 138, 99, 0.35); }
.tl-pending .ai-wave { position: absolute; inset: 0; background: linear-gradient(110deg, transparent 20%, rgba(255, 106, 61, 0.35) 38%, rgba(160, 120, 255, 0.45) 50%, rgba(122, 167, 255, 0.35) 62%, transparent 80%) 0 0 / 250% 100% no-repeat; animation: ai-wave 1.4s ease-in-out infinite; }
.tl-pending .img svg { position: relative; width: 20px; height: 20px; color: #fff; filter: drop-shadow(0 0 6px rgba(160, 120, 255, 0.9)); animation: ai-pulse 1.4s ease-in-out infinite; }
.tl-pending .num { font-size: 11px; color: var(--accent-2); text-align: center; margin-top: 2px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes ai-wave { from { background-position: 150% 0; } to { background-position: -150% 0; } }
@keyframes ai-pulse { 50% { transform: scale(0.8) rotate(20deg); opacity: 0.6; } }
.tl-insert { position: absolute; top: 0; width: 3px; height: 62px; background: var(--danger); border-radius: 2px; box-shadow: 0 0 8px var(--danger); pointer-events: none; z-index: 2; }
.tl-insert span { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff; display: grid; place-items: center; }
.tl-insert svg { width: 13px; height: 13px; }
.tl-drop { position: absolute; top: -2px; width: 3px; height: 66px; background: var(--focus); border-radius: 2px; pointer-events: none; }
.tl-live { flex: none; width: 70px; height: 62px; margin: 0 2px; border-radius: var(--radius-sm); border: 2px dashed var(--danger); display: grid; place-items: center; color: var(--danger); font-size: 11px; font-weight: 700; cursor: pointer; }
.tl-audio { position: relative; height: 22px; margin-top: 4px; }
.tl-clip { position: absolute; top: 0; height: 20px; border-radius: var(--radius-sm); background: rgba(122, 167, 255, 0.25); border: 1px solid rgba(122, 167, 255, 0.6); font-size: 11px; line-height: 18px; padding: 0 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: grab; }
.tl-clip.muted { opacity: 0.4; }
.tl-playhead { grid-column: 2; grid-row: 1 / -1; position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); pointer-events: none; }
.tl-empty { color: var(--muted); padding: 22px 6px; font-size: 13px; max-width: min(440px, 70vw); }
.sel-bar { display: flex; gap: 6px; align-items: center; min-height: 36px; padding: 0 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); overflow-x: auto; white-space: nowrap; }
.sel-hint { color: var(--muted); }
.sel-count { color: var(--text); font-weight: 600; margin-right: 6px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; }
.stepper output { min-width: 22px; text-align: center; color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.danger-text { color: var(--danger) !important; }

.loading-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(15, 16, 20, 0.85); z-index: 30; }
.progress { width: 240px; height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }

.ctx-menu { position: fixed; z-index: 150; }

@media (max-width: 900px) {
  .ed-main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(120px, 1fr) min(var(--side-h, 34vh), 70vh); }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .ed-title { width: 140px; }
  .ed-top .badge { display: none; }
  .hide-sm { display: none !important; }
  .transport { gap: 4px; }
  .transport .time { min-width: 0; }
  .capture-btn { min-width: 0; }
}

/* ---------- Share / player page ---------- */
.player-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 14px; }
.player-page .stage { width: min(960px, 100%); }
.player-controls { display: flex; gap: 8px; align-items: center; width: min(960px, 100%); }
.player-controls input[type='range'] { flex: 1; }

/* Floating view toggles over the stage */
.stage-tools { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.stage-tool { height: var(--control-h-sm); padding: 0 10px; font-size: 12px; border-radius: 99px; background: rgba(15, 16, 20, 0.72); border-color: rgba(255, 255, 255, 0.14); backdrop-filter: blur(6px); }
.stage-tool svg { width: var(--icon-sm); height: var(--icon-sm); }
.stage-tool:hover { background: rgba(15, 16, 20, 0.9); }
.stage-tool.on { background: rgba(255, 106, 61, 0.9); border-color: var(--accent); color: var(--accent-ink); }
.toast-action { color: var(--accent-2); font-weight: 700; }

@media (max-width: 900px) {
  .transport { grid-template-columns: auto 1fr; grid-template-areas: 'left right' 'center center'; row-gap: 6px; }
  .tp-left { grid-area: left; }
  .tp-center { grid-area: center; justify-content: center; }
  .tp-right { grid-area: right; }
  .stage-tool span { display: none; }
  .stage-tool { width: var(--control-h-sm); padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ---------- Transitions, text & stickers ---------- */
.tl-row { display: flex; height: 62px; }
.tl-trans { flex: none; height: 62px; margin-right: -4px; border-radius: var(--radius-sm) 0 0 var(--radius-sm); display: grid; place-items: center; color: #fff; background: repeating-linear-gradient(135deg, rgba(160, 120, 255, 0.55) 0 6px, rgba(160, 120, 255, 0.3) 6px 12px); border: 2px solid rgba(160, 120, 255, 0.8); border-right: 0; position: relative; z-index: 1; }
.tl-trans svg { width: 16px; height: 16px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)); }
.tl-frame:has(.tl-trans) .img { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.tl-frame .card-tag { position: absolute; left: 4px; top: 4px; width: 18px; height: 18px; border-radius: 4px; background: rgba(0, 0, 0, 0.7); color: #fff; display: grid; place-items: center; }
.tl-frame .card-tag svg { width: 12px; height: 12px; }
.tl-overlays { position: relative; margin-top: 4px; }
.tl-ov { position: absolute; height: 20px; display: flex; align-items: center; gap: 4px; padding: 0 12px 0 5px; border-radius: var(--radius-sm); font-size: 11px; line-height: 18px; overflow: hidden; white-space: nowrap; cursor: grab; background: rgba(255, 106, 61, 0.22); border: 1px solid rgba(255, 106, 61, 0.6); }
.tl-ov.sticker, .tl-ov.image { background: rgba(62, 207, 142, 0.2); border-color: rgba(62, 207, 142, 0.6); }
.tl-ov.selected { box-shadow: 0 0 0 2px var(--focus); }
.tl-ov svg { width: 12px; height: 12px; flex: none; }
.tl-ov span { overflow: hidden; text-overflow: ellipsis; }
.tl-ov-edge { position: absolute; right: 0; top: 0; bottom: 0; width: 9px; cursor: ew-resize; background: rgba(255, 255, 255, 0.18); }
.tl-ov-edge:hover { background: rgba(255, 255, 255, 0.4); }

.ov-box { position: absolute; border: 2px dashed #fff; outline: 1px solid rgba(0, 0, 0, 0.55); border-radius: 4px; pointer-events: none; transform-origin: center; }
.ov-handle { position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5); pointer-events: auto; touch-action: none; }
.ov-resize { right: -9px; bottom: -9px; cursor: nwse-resize; }
.ov-rotate { left: 50%; top: -30px; margin-left: -8px; cursor: grab; }
.ov-rotate::after { content: ''; position: absolute; left: 5px; top: 14px; width: 2px; height: 14px; background: #fff; }
.stage:not(.blurring):not(.picking) canvas { touch-action: none; }

.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.style-btn { height: var(--control-h-lg); background: var(--panel); }
.text-input { font-family: inherit; font-size: 15px; min-height: 56px; }
.font-list { max-height: 208px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); padding: 4px; }
.font-item { width: 100%; height: auto; min-height: 38px; padding: 4px 10px; justify-content: space-between; border: 0; background: transparent; border-radius: var(--radius-sm); }
.font-item + .font-item { margin-top: 2px; }
.font-item.current { background: rgba(255, 106, 61, 0.18); color: var(--accent-2); }
.font-name { overflow: hidden; text-overflow: ellipsis; }

.sticker-group + .sticker-group { margin-top: 12px; }
.sticker-group h4, .sfx-group h4 { margin: 0 0 6px; font-size: 12px; color: var(--text); }
.sticker-group p { margin: -2px 0 6px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; }
.sticker-btn { height: auto; aspect-ratio: 1; padding: 6px; background: var(--panel); border-color: transparent; }
.sticker-btn:hover { border-color: var(--line); background: var(--panel-2); }
.sticker-btn svg { width: 100%; height: 100%; }
.sticker-results { max-height: 46vh; overflow-y: auto; padding-right: 2px; }

.trans-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.trans-btn { height: auto; flex-direction: column; padding: 5px 5px 4px; gap: 4px; font-size: 11px; background: var(--panel); }
.trans-btn canvas { width: 100%; height: auto; border-radius: var(--radius-sm); display: block; }
.trans-btn span { white-space: normal; line-height: 1.2; }
.trans-btn.current { border-color: var(--accent); background: rgba(255, 106, 61, 0.18); color: var(--accent-2); }

.sfx-group + .sfx-group { margin-top: 12px; }
.sfx-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px; }
.sfx { display: flex; min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.sfx-play { flex: 1; min-width: 0; height: var(--control-h-sm); justify-content: flex-start; gap: 5px; padding: 0 6px; border: 0; border-radius: 0; background: transparent; font-size: 12px; }
.sfx-play span { overflow: hidden; text-overflow: ellipsis; }
.sfx-play svg { width: var(--icon-xs); height: var(--icon-xs); color: var(--accent-2); }
.sfx-play.playing { color: var(--accent-2); }
.sfx-add.icon.sm { width: var(--control-h-sm); height: var(--control-h-sm); border: 0; border-left: 1px solid var(--line); border-radius: 0; background: transparent; }
.sfx-add:hover, .sfx-play:hover { background: var(--panel-2); }

.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; max-height: 50vh; overflow-y: auto; }
.scene-btn { height: auto; flex-direction: column; align-items: stretch; padding: 4px; gap: 3px; font-size: 11px; background: var(--panel); }
.scene-btn img { width: 100%; border-radius: var(--radius-sm); display: block; object-fit: cover; }
.scene-btn.current { border-color: var(--accent); background: rgba(255, 106, 61, 0.18); color: var(--accent-2); }

.card-dialog { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card-dialog .scene-grid { max-height: 220px; }
.card-preview { width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); background: #000; display: block; }
.swatch-btn { width: 26px; height: 26px; padding: 0; border-radius: var(--radius-sm); border: 1px solid var(--line); }
@media (max-width: 700px) { .card-dialog { grid-template-columns: 1fr; } }

/* ---------- Resizable borders ---------- */
.editor.tl-sized .timeline { height: min(var(--tl-h), 60vh); max-height: none; }
.splitter { position: absolute; z-index: 6; touch-action: none; }
.splitter::after { content: ''; position: absolute; background: var(--accent); border-radius: 2px; opacity: 0; transition: opacity 0.15s; }
.splitter:hover::after, .splitter:focus-visible::after, .splitter.dragging::after { opacity: 1; }
.splitter:focus-visible { outline: none; }
.split-side { top: 0; bottom: 0; left: -5px; width: 10px; cursor: col-resize; }
.split-side::after { top: 0; bottom: 0; left: 4px; width: 3px; }
.split-bottom { left: 0; right: 0; top: -5px; height: 10px; cursor: row-resize; }
.split-bottom::after { left: 0; right: 0; top: 4px; height: 3px; }
.editor.resizing, .editor.resizing * { user-select: none; }
.editor.resizing .stage-wrap, .editor.resizing .side-body, .editor.resizing .timeline { pointer-events: none; }
@media (max-width: 900px) {
  .split-side { top: -5px; bottom: auto; left: 0; right: 0; width: auto; height: 10px; cursor: row-resize; }
  .split-side::after { top: 4px; bottom: auto; left: 0; right: 0; width: auto; height: 3px; }
}
