/* A control-room look: deep navy desk, signal blue for what is selected,
   tally-light red for the playhead and anything recording. */
:root {
  color-scheme: dark;
  --desk: #0d1220;
  --panel: #161c2d;
  --raised: #222a42;
  --raised-hi: #2c3655;
  --line: #2b3552;
  --ink: #eef1f8;
  --muted: #98a2bd;
  --signal: #4470ff;
  --signal-deep: #2b54e0;
  --tally: #ff473b;
  --flash: #ffd400;
  --label-w: 168px;
  --ease: 140ms ease-out;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr); /* wide content (a zoomed timeline) scrolls instead of widening the page */
  background: var(--desk);
  color: var(--ink);
  font: 14px/1.4 "Archivo", system-ui, sans-serif;
  overflow: hidden;
}

.ic { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }

/* Controls */
button, select, input, textarea { font: inherit; color: inherit; }
button, .menu summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 12px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
}
button:hover, .menu summary:hover, .menu[open] summary { background: var(--raised-hi); border-color: #46527a; }
button:active { transform: translateY(1px); }
button.primary { background: var(--signal-deep); border-color: var(--signal-deep); color: #fff; font-weight: 700; }
button.primary:hover { background: #2448c4; border-color: #2448c4; }
button.danger { color: #ff8a80; }
button.danger:hover { background: #4a1f24; border-color: #7a2c30; }
button.icon { padding: 7px; }
button.active { color: var(--tally); }
button:disabled { opacity: 0.4; cursor: default; background: var(--raised); border-color: var(--line); transform: none; }
:focus-visible { outline: 2px solid var(--flash); outline-offset: 2px; }

select, input[type="text"], input[type="number"], input:not([type]), textarea {
  padding: 7px 9px;
  background: #0f1525;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  transition: border-color var(--ease);
}
select:hover, input:hover, textarea:hover { border-color: #46527a; }
::placeholder { color: #6f7994; }
input[type="range"] { accent-color: var(--signal); }
input[type="checkbox"] { accent-color: var(--signal); width: 16px; height: 16px; }

/* Top bar */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
/* The wordmark is itself a little name bar, like the graphics the app makes. */
.bar h1 { margin: 0 10px 0 0; font-size: 19px; line-height: 1; }
.bar h1 span {
  display: block;
  padding: 6px 10px 5px;
  background: #fff;
  border-left: 6px solid var(--signal);
  color: #0d1220;
  font-weight: 800;
  font-stretch: 68%;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.bar .spacer { flex: 1; }
/* On a computer the More group is invisible and its controls sit in the bar in this order. */
.more { display: contents; }
.bar .pair { order: 1; }
.more > .inline, .more > .spacer, #install, #still, #export { order: 2; }
#moreBtn, .rail, .sheet-close { display: none; }
.bar .lead { border-color: #46527a; }
.pair { display: inline-flex; }
.pair button:first-child { border-radius: 6px 0 0 6px; }
.pair button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.inline { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.bar button, .bar .inline { white-space: nowrap; }
/* On mid-size screens the menus' own wording is enough; drop their little names to fit the bar. */
@media (min-width: 1366px) and (max-width: 1600px) {
  .bar .inline .lab { display: none; }
  #install .lab { display: none; }
  #install { padding: 7px; }
}

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary .ic:last-child { width: 0.8em; margin-left: -2px; opacity: 0.7; }
.menu > div {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 5;
  display: grid;
  gap: 2px;
  width: max-content;
  padding: 6px;
  background: var(--raised);
  border: 1px solid #46527a;
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
}
.menu > div button { justify-content: flex-start; background: transparent; border-color: transparent; }
.menu > div button:hover { background: var(--raised-hi); }

/* Work area */
main {
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr) 300px;
  min-height: 0;
}
aside { background: var(--panel); overflow-y: auto; padding: 16px 14px; scrollbar-width: thin; }
aside h2, .card h2, dialog h2 { margin: 0 0 12px; font-size: 18px; font-weight: 700; font-stretch: 78%; letter-spacing: 0.01em; }
.add { border-right: 1px solid var(--line); }
.add h2:not(:first-of-type) { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); }

/* Graphic presets: each card previews the real look on a stand-in video frame. */
.add button[data-add] {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 0 12px 8px;
  overflow: hidden;
  background: var(--raised);
  text-align: left;
  font-size: 13px;
}
.add button[data-add]:hover { border-color: var(--signal); transform: translateY(-1px); }
.add button[data-add]:hover .thumb { filter: brightness(1.12); }
.thumb {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  height: 52px;
  margin: 0 -12px 7px;
  padding: 0 12px;
  background: #2c3446;
  line-height: 1;
  transition: filter var(--ease);
}
/* Previews follow the brand kit's colors and typefaces (set by renderBrand). */
.thumb b, .thumb i, .thumb em { font-style: normal; white-space: nowrap; }
.t-headline b { padding: 2px 5px; line-height: 1.2; background: var(--b-accent); color: var(--b-dark); font: 800 12px var(--b-head), sans-serif; letter-spacing: -0.02em; }
.t-label b, .t-credit b { padding: 2px 5px; background: var(--b-dark); color: var(--b-light); font: 700 9px var(--b-body), monospace; }
.t-label b { letter-spacing: 0.04em; text-transform: uppercase; }
.t-lower b { padding: 2px 5px; line-height: 1.2; background: var(--b-accent); color: var(--b-dark); font: 800 11px var(--b-head), sans-serif; }
.t-lower i { padding: 2px 5px; background: var(--b-dark); color: var(--b-light); font: 700 8px var(--b-body), monospace; }
.t-lower i em, .t-quote i { color: var(--b-accent); }
.t-quote { padding: 0 10px; }
.t-quote span { padding: 4px 7px 5px; background: var(--b-dark); border-top: 2px solid var(--b-accent); }
.t-quote i { display: block; margin-bottom: 3px; font: 700 7px var(--b-body), monospace; text-transform: uppercase; }
.t-quote b { color: var(--b-light); font: 800 11px var(--b-head), sans-serif; }
.t-quote b em { padding: 0 2px; background: var(--b-accent); color: var(--b-dark); }
.t-credit { justify-content: flex-end; padding-bottom: 7px; }
.t-cover { justify-content: flex-end; align-items: stretch; padding: 0; }
.t-cover b { height: 70%; background: linear-gradient(rgba(17, 17, 17, 0), #111 75%); }
.t-text b { color: #fff; font: 800 13px var(--b-head), sans-serif; text-shadow: 0 1px 4px #000; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 14px; }
.tile { flex-direction: column; gap: 5px; padding: 10px 0 8px; font-size: 12px; }
.tile .ic { width: 20px; height: 20px; color: var(--signal); }
.tile:hover .ic { color: #fff; }
.add button.plain { width: 100%; margin-bottom: 8px; }

/* Saved styles, layouts, fonts */
.lib { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin-bottom: 8px; }
.lib p { margin: 0; font-size: 13px; color: var(--muted); }
.lib-row { display: flex; gap: 4px; align-items: center; }
.lib-row input { flex: 1; width: 0; min-width: 0; padding: 5px 7px; font-size: 13px; }
.lib-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-row button { padding: 5px 9px; font-size: 13px; }
.lib-row button.icon { padding: 6px; color: var(--muted); }
.lib-row button.icon:hover { color: #ff8a80; }

/* Stage */
.stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 40%, #1b2338, var(--desk) 75%);
  overflow: hidden;
}
.wrap { position: relative; touch-action: none; user-select: none; box-shadow: 0 0 0 1px #33405f, 0 24px 60px rgba(0, 0, 0, 0.55); }
.wrap canvas { display: block; width: 100%; height: 100%; background: #000; }
.sel {
  position: absolute;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1.5px var(--signal), 0 0 18px rgba(68, 112, 255, 0.55);
  pointer-events: none;
}
.sel .grip {
  position: absolute;
  top: 50%;
  right: -8px;
  width: 13px;
  height: 30px;
  margin-top: -15px;
  background: #fff;
  border: 2px solid var(--signal);
  border-radius: 4px;
  cursor: ew-resize;
  pointer-events: auto;
}
/* Covers also resize from the bottom edge. */
.sel .vgrip {
  position: absolute;
  left: 50%;
  bottom: -8px;
  display: none;
  width: 30px;
  height: 13px;
  margin-left: -15px;
  background: #fff;
  border: 2px solid var(--signal);
  border-radius: 4px;
  cursor: ns-resize;
  pointer-events: auto;
}
.sel.tall .vgrip { display: block; }
/* The rest of a clip's picture, dimmed around the frame while reframing. */
.stage { position: relative; }
.ghost { position: absolute; z-index: 0; opacity: 0.3; pointer-events: none; }
.wrap { z-index: 1; }
.rail { position: relative; z-index: 2; }
/* Platform safe zones: shaded areas the app's own buttons and captions cover. */
.safe { position: absolute; inset: 0; pointer-events: none; }
.safe div { position: absolute; background: rgba(255, 71, 59, 0.16); outline: 1px dashed rgba(255, 140, 130, 0.8); outline-offset: -1px; }
.safe div::after { content: attr(data-label); position: absolute; left: 4px; top: 3px; padding: 1px 5px; background: rgba(13, 18, 32, 0.8); border-radius: 3px; color: #ffb4ad; font-size: 10px; font-weight: 600; white-space: nowrap; }
.guide { position: absolute; z-index: 1; background: var(--flash); box-shadow: 0 0 4px rgba(255, 212, 0, 0.8); pointer-events: none; }
.guide.v { top: 0; bottom: 0; width: 1px; margin-left: -0.5px; }
.guide.h { left: 0; right: 0; height: 1px; margin-top: -0.5px; }
/* Nine spots to place a graphic: a small grid in the panel, and on a phone, over the video. */
.place { display: grid; grid-template-columns: repeat(3, 30px); gap: 3px; margin-top: 5px; }
.place button { position: relative; width: 30px; height: 24px; padding: 0; border-radius: 4px; }
.place button i, .place-over button i { position: absolute; width: 10px; height: 6px; background: var(--muted); border-radius: 1px; }
.place button:hover i, .place-over button:hover i { background: var(--ink); }
.p-top i { top: 4px; } .p-middle i { top: calc(50% - 3px); } .p-bottom i { bottom: 4px; }
.p-left i { left: 4px; } .p-center i { left: calc(50% - 5px); } .p-right i { right: 4px; }
.place-over { position: absolute; inset: 0; z-index: 2; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 2px; padding: 2px; background: rgba(13, 18, 32, 0.45); }
.place-over[hidden] { display: none; }
.place-over button { position: relative; padding: 0; background: rgba(34, 42, 66, 0.55); border: 1px dashed rgba(255, 255, 255, 0.35); border-radius: 4px; }
.place-over button i { width: 40%; height: 14%; background: rgba(255, 255, 255, 0.85); }
.place-over .p-top i { top: 10%; } .place-over .p-middle i { top: 43%; } .place-over .p-bottom i { bottom: 10%; }
.place-over .p-left i { left: 8%; } .place-over .p-center i { left: 30%; } .place-over .p-right i { right: 8%; }
.empty {
  position: absolute;
  top: 9%;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 86%;
  padding: 18px 22px;
  background: rgba(13, 18, 32, 0.86);
  border: 1px dashed #5a6790;
  border-radius: 10px;
  text-align: center;
  backdrop-filter: blur(6px);
}
.empty > .ic { width: 30px; height: 30px; color: var(--signal); }
.empty p { margin: 6px 0 12px; }
body.dropping .wrap { outline: 3px dashed var(--flash); outline-offset: 6px; }

/* Inspector */
.hint { margin: 0; color: var(--muted); }
#noSel .ic { display: block; width: 26px; height: 26px; margin-bottom: 8px; color: var(--signal); }
.f { display: block; margin-bottom: 15px; font-size: 13px; color: var(--muted); }
.f > textarea, .f > input, .f > select { display: block; width: 100%; margin-top: 5px; }
.f textarea { resize: vertical; }
.f input[type="range"] { padding: 0; }
.f small { display: block; margin-top: 5px; font-size: 12px; color: #7d88a6; }
textarea:disabled { background: transparent; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 15px; font-size: 13px; }
.seg { display: flex; margin-top: 5px; }
.seg button { flex: 1; border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button[aria-pressed="true"] { position: relative; background: var(--signal); border-color: var(--signal); color: #fff; }
/* Color presets as small chips, then one round swatch per color with its name beside it. */
.looks { display: flex; gap: 6px; margin: 6px 0 8px; }
.looks button { width: 38px; height: 28px; padding: 0; font-size: 12px; font-weight: 800; border-color: #46527a; }
.looks button:hover { transform: translateY(-1px); border-color: #fff; }
.colors { display: flex; flex-wrap: wrap; gap: 6px; }
.colors label {
  display: inline-flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  background: #0f1525;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
}
.colors label:hover { border-color: #46527a; }
.colors input { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; -webkit-appearance: none; appearance: none; }
.colors input::-webkit-color-swatch-wrapper { padding: 0; }
.colors input::-webkit-color-swatch { border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 50%; }
.colors input::-moz-color-swatch { border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 50%; }
.times { display: flex; gap: 10px; }
.times label { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }

/* Number fields with − and + either side. */
.num { display: flex; margin-top: 5px; }
.num > button { width: 36px; padding: 0; font-size: 17px; line-height: 1; }
.num > button:first-child { border-radius: 6px 0 0 6px; }
.num > button:last-child { border-radius: 0 6px 6px 0; }
.num-box { display: flex; flex: 1; min-width: 0; align-items: center; background: #0f1525; border: 1px solid var(--line); border-width: 1px 0; color: var(--muted); }
.num-box input { flex: 1; width: 0; min-width: 0; padding: 7px 0 7px 10px; background: none; border: 0; border-radius: 0; text-align: center; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.num-box input::-webkit-inner-spin-button, .num-box input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num-box i { width: 22px; font-style: normal; font-size: 13px; }
.num-box:has(> i) input { padding-left: 22px; }
.num-box:focus-within { outline: 2px solid var(--flash); outline-offset: -1px; }
.num-box input:focus-visible { outline: none; }

/* Timing & animation: always open on a computer, folded away on a phone. */
/* Framing controls for a clip. */
.framing .keep { display: block; margin: 4px 0 8px; font-size: 12px; color: #7d88a6; }
.key-row, .zoom-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.key-row > button { width: 38px; height: 36px; padding: 0; }
#keyHere.on { color: var(--flash); border-color: var(--flash); }
#keyMove { flex: 1; margin: 0; }
#keyMove button { gap: 5px; font-size: 12px; }
.zoom-row .num { flex: 1; margin: 0; }
.zoom-row .w { font-size: 13px; }
#resetFrame { width: 38px; height: 36px; padding: 0; }

/* Shape tiles for export and cover images. */
.shape-pick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 4px 0 6px; }
.shape-pick button { flex-direction: column; justify-content: flex-end; gap: 8px; height: 104px; padding: 10px 4px 8px; font-size: 12px; line-height: 1.2; text-align: center; }
.shape-pick button i { display: block; flex: none; border: 2px solid var(--muted); border-radius: 3px; }
.shape-pick button[aria-pressed="true"] { background: #1d2a55; border-color: var(--signal); box-shadow: 0 0 0 1px var(--signal); color: var(--ink); }
.shape-pick button[aria-pressed="true"] i { border-color: var(--signal); background: rgba(68, 112, 255, 0.25); }

/* Cover image picker. */
.cover-dlg { width: min(560px, 94vw); }
.cover-view { display: grid; place-items: center; margin-bottom: 10px; padding: 8px; background: #0a0e19; border-radius: 8px; }
#coverPreview { display: block; width: auto; max-width: 100%; max-height: 42vh; border-radius: 3px; }
#coverTime { width: 100%; accent-color: var(--signal); }
.cover-strip { display: flex; gap: 4px; margin: 8px 0 12px; overflow-x: auto; scrollbar-width: none; }
.cover-strip button { flex: none; padding: 0; overflow: hidden; border-radius: 4px; }
.cover-strip canvas { display: block; height: 64px; width: auto; }
.cover-mark { position: absolute; bottom: 0; width: 8px; height: 8px; margin-left: -4px; background: var(--flash); border-radius: 2px; transform: rotate(45deg); pointer-events: none; }

/* Auto captions. */
#captionDlg .seg button[aria-pressed="true"] { background: var(--signal); border-color: var(--signal); color: #fff; }
#captionDlg .num { margin-top: 5px; }
.cap-status { margin: 4px 0 6px; }
.model-store { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; padding: 8px 10px; background: #0f1525; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; color: var(--muted); }
.model-store span { flex: 1; }
.model-store button { padding: 5px 10px; font-size: 12px; }
.cap-status p { margin: 0 0 8px; font-size: 13px; color: var(--ink); }
#capBar i { background: var(--signal); box-shadow: none; }
#capBar.busy i { width: 35% !important; animation: busy 1.2s ease-in-out infinite alternate; }
@keyframes busy { from { margin-left: 0; } to { margin-left: 65%; } }

/* Transcript: a panel beside the video on a computer, a sheet below it on a phone. */
.transcript {
  position: fixed;
  inset: 64px 12px 12px auto;
  z-index: 9;
  display: none;
  flex-direction: column;
  width: min(440px, calc(100vw - 24px));
  height: auto;
  max-height: none;
  margin: 0;
  padding: 16px 16px 8px;
}
.transcript[open] { display: flex; }
.tr-head { display: flex; align-items: center; gap: 10px; }
.tr-head h2 { margin: 0; }
.tr-head span { flex: 1; color: var(--muted); font-size: 13px; }
.transcript .hint { margin: 8px 0 10px; font-size: 12px; }
.transcript .hint .ic { width: 1em; height: 1em; }
.tr-lines { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.tr-line { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; gap: 6px; align-items: start; padding: 6px; border-radius: 8px; }
.tr-line.now { background: #1d2a55; box-shadow: inset 3px 0 0 var(--signal); }
.tr-time { padding: 6px 4px; font-size: 12px; font-variant-numeric: tabular-nums; }
.tr-line textarea { width: 100%; min-height: 34px; padding: 6px 8px; resize: none; overflow: hidden; line-height: 1.35; }
.tr-tools { display: flex; gap: 2px; }
.tr-tools button { width: 32px; height: 34px; padding: 0; }

/* Keyboard shortcut list. */
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 4px 0 8px; font-size: 13px; }
.keys dt { white-space: nowrap; color: var(--ink); }
.keys dd { margin: 0; color: var(--muted); }
kbd { display: inline-block; min-width: 20px; padding: 1px 6px; background: var(--raised); border: 1px solid #46527a; border-bottom-width: 2px; border-radius: 5px; color: var(--ink); font: 600 12px/1.5 Archivo, sans-serif; text-align: center; }
.in-menu, .chip-name { display: none; }

/* Phone-only pieces. */
.fi, .caps-ic, .chips, .brand-dots, .edit-tabs { display: none; }
.mark { margin: -8px 0 15px; padding: 4px 10px; font-size: 12px; }
.times input, .times select { width: 100%; }
button.wide, select.wide { display: flex; width: 100%; margin-top: 8px; }
select.wide { display: block; }
#replaceImage { margin: 0 0 15px; }
.here { display: flex; gap: 6px; margin-top: 8px; }
.here button { flex: 1; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 15px; border-top: 1px solid var(--line); }
.actions button { flex: 1 1 calc(50% - 3px); font-size: 13px; white-space: nowrap; }

/* Timeline */
.timeline { background: var(--panel); border-top: 1px solid var(--line); }
.transport { display: flex; align-items: center; gap: 10px; padding: 10px 16px 8px; }
#play {
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--ink);
  border-color: var(--ink);
  border-radius: 50%;
  color: var(--desk);
}
#play:hover { background: #fff; transform: scale(1.06); }
.tl-zoom { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.tl-zoom input { width: 140px; accent-color: var(--signal); }
#play .ic { width: 18px; height: 18px; }
/* Timecode readout, like the counter on a tape deck. */
.timecode {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  background: #0a0e19;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.timecode b { font-size: 19px; font-weight: 700; font-stretch: 85%; }
.timecode span { color: var(--muted); font-size: 13px; }
.timecode span::before { content: "of "; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); }

.tracks { position: relative; max-height: 208px; overflow: auto; padding: 0 16px 12px; scrollbar-width: thin; overscroll-behavior-x: contain; }
.row { --rh: 30px; display: grid; grid-template-columns: var(--label-w) var(--lane-w, minmax(0, 1fr)); align-items: center; width: max-content; min-width: 100%; height: var(--rh); }
.row > span { padding-right: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); cursor: pointer; }
/* Layer names stay pinned on the left while a zoomed timeline scrolls under them,
   each filling its row (and the margin beside it) so nothing shows through. */
.row > span { position: sticky; left: -16px; z-index: 3; align-self: stretch; margin-left: -16px; padding-left: 16px; line-height: var(--rh); background: var(--panel); }
.row > span .ic { margin-right: 7px; color: #6f7ca3; }
.row > span:hover { color: var(--ink); }
/* Layer names double as drag handles for reordering. */
.row[data-id] > span { touch-action: pan-y; user-select: none; -webkit-touch-callout: none; }
.row.dragging { position: relative; z-index: 2; background: var(--raised); border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }
.row.dragging > span { color: var(--ink); cursor: grabbing; }
.row.drop-before { box-shadow: inset 0 2px 0 var(--flash); }
.row.drop-after { box-shadow: inset 0 -2px 0 var(--flash); }
.row.on > span { color: var(--ink); font-weight: 700; }
.row.on > span .ic { color: var(--signal); }
.row.video { --rh: 36px; }
.lane { position: relative; height: 100%; border-top: 1px solid #202842; overflow: hidden; }
.ruler-row { --rh: 24px; }
.ruler { position: relative; height: 100%; cursor: pointer; touch-action: pan-y; }
.ruler i { position: absolute; bottom: 0; padding: 0 0 2px 5px; border-left: 1px solid #46527a; font-style: normal; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none; }

.clip {
  position: absolute;
  top: 4px;
  bottom: 4px;
  min-width: 6px;
  background: linear-gradient(#56628c, #485480);
  border-radius: 4px;
  cursor: grab;
  touch-action: pan-y;
  transition: filter var(--ease);
}
.clip:hover, .vclip:hover, .cue:hover { filter: brightness(1.18); }
.clip:active { cursor: grabbing; }
.row.on .clip { background: linear-gradient(#5a82ff, var(--signal-deep)); box-shadow: 0 0 12px rgba(68, 112, 255, 0.45); }
.cue { position: absolute; top: 7px; bottom: 7px; min-width: 2px; background: #56628c; border-right: 1px solid var(--panel); border-radius: 2px; cursor: pointer; touch-action: pan-y; }
/* Grips on the selected layer's lines, once they're wide enough to grab. */
.row.on .cue::before, .row.on .cue::after { content: ""; position: absolute; top: 3px; bottom: 3px; width: 2px; background: rgba(255, 255, 255, 0.85); border-radius: 1px; }
.row.on .cue::before { left: 2px; }
.row.on .cue::after { right: 2px; }
.row.on .cue { background: var(--signal); }

/* Video clips carry a strip of sprocket holes along both edges. */
.vclip {
  position: absolute;
  top: 2px;
  bottom: 2px;
  padding: 0 16px;
  overflow: hidden;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.3) 0 4px, transparent 4px 10px) 0 3px / 100% 3px no-repeat,
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.3) 0 4px, transparent 4px 10px) 0 calc(100% - 3px) / 100% 3px no-repeat,
    #2f3a5c;
  border-left: 2px solid var(--panel);
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  line-height: 32px;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  touch-action: pan-y;
}
.vclip.on {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.45) 0 4px, transparent 4px 10px) 0 3px / 100% 3px no-repeat,
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.45) 0 4px, transparent 4px 10px) 0 calc(100% - 3px) / 100% 3px no-repeat,
    var(--signal-deep);
}

/* Framing keyframes on a video clip: yellow diamonds jump, white ones glide. */
.vclip .kf { position: absolute; top: 50%; z-index: 1; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; background: var(--flash); border: 1.5px solid #0d1220; transform: rotate(45deg); cursor: pointer; }
.vclip .kf.glide { background: #fff; }
.vclip .kf.on { box-shadow: 0 0 0 2px var(--tally); }
.vclip .kf::before { content: ""; position: absolute; inset: -6px; }
.vclip .kf { touch-action: pan-y; }
.vclip .kf.dragging { box-shadow: 0 0 0 2px var(--tally); cursor: grabbing; }
/* The time shown above a keyframe while it's dragged. */
.key-tip {
  position: fixed;
  z-index: 12;
  padding: 4px 8px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  color: #0d1220;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px));
  pointer-events: none;
}

/* Trim handles: a wide grab area with a slim white grip drawn inside it. */
.clip::before, .clip::after, .vclip::before, .vclip::after {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 10px;
  max-width: 33%;
  cursor: ew-resize;
  opacity: 0.7;
}
.vclip::before, .vclip::after { top: 9px; bottom: 9px; }
.clip::before, .vclip::before { left: 0; background: linear-gradient(to right, transparent 3px, #fff 3px 6px, transparent 6px); }
.clip::after, .vclip::after { right: 0; background: linear-gradient(to left, transparent 3px, #fff 3px 6px, transparent 6px); }
.clip:hover::before, .clip:hover::after, .vclip:hover::before, .vclip:hover::after, .row.on .clip::before, .row.on .clip::after, .vclip.on::before, .vclip.on::after { opacity: 1; }

.lanes { position: absolute; top: 0; bottom: 0; left: calc(16px + var(--label-w)); width: var(--lane-w); z-index: 2; pointer-events: none; }
.playhead { position: absolute; top: 4px; bottom: 0; width: 2px; margin-left: -1px; background: var(--tally); box-shadow: 0 0 8px rgba(255, 71, 59, 0.7); }
.playhead::before { content: ""; position: absolute; top: -4px; left: -5px; width: 12px; height: 12px; background: var(--tally); border-radius: 3px 3px 6px 6px; }
.no-rows { margin: 0; padding: 8px 0; color: var(--muted); font-size: 13px; }

/* Dialogs, export, toast */
dialog, .card {
  width: min(430px, 92vw);
  max-height: 92dvh;
  overflow-y: auto;
  padding: 24px;
  background: var(--panel);
  border: 1px solid #46527a;
  border-radius: 12px;
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop, .modal { background: rgba(6, 9, 17, 0.72); }
dialog[open] { animation: rise 180ms ease-out; }
dialog h2 { margin-bottom: 8px; }
dialog .hint { margin-bottom: 18px; }
dialog .lib { margin-top: 6px; }
dialog form.lib-row { margin-top: 6px; }
dialog form.lib-row input { padding: 7px 9px; font-size: 14px; }
.logo-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.logo-row img { max-width: 96px; max-height: 48px; border-radius: 4px; background: repeating-conic-gradient(#39435f 0 25%, #252d47 0 50%) 0 0 / 12px 12px; }
dialog .actions { position: sticky; bottom: -24px; z-index: 2; justify-content: flex-end; margin: 0 -24px -24px; padding: 12px 24px 24px; background: var(--panel); }
.dlg-close { float: right; margin: -6px -6px 0 0; }
dialog .actions button { flex: none; padding: 8px 20px; }

.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 10; }
.card p { margin: 0 0 14px; color: var(--muted); }
.progress { height: 8px; margin-bottom: 8px; background: #0a0e19; border-radius: 4px; overflow: hidden; }
.progress i { display: block; width: 0; height: 100%; background: var(--tally); box-shadow: 0 0 10px var(--tally); }
.toast button { pointer-events: auto; margin-left: 12px; padding: 4px 12px; background: var(--signal-deep); border-color: var(--signal-deep); color: #fff; font-size: 13px; font-weight: 700; }
.toast {
  pointer-events: none;
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  max-width: min(520px, 90vw);
  padding: 11px 18px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  color: #0d1220;
  font-weight: 500;
  z-index: 11;
  animation: toast 200ms ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 10px); } }

video.src { position: fixed; left: -10px; top: -10px; width: 2px; height: 2px; opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Narrower windows (a MacBook browser not at full width, and phones): less-used top bar controls
   fold into the More menu, so Export never falls off the edge. */
@media (max-width: 1365px) {
  .bar { position: relative; }
  .bar h1 { margin-right: auto; }
  #moreBtn { display: inline-flex; order: 3; }
  #export { order: 4; padding: 7px 14px; }
  .more {
    position: absolute;
    top: calc(100% + 4px);
    right: 8px;
    z-index: 6;
    display: none;
    width: min(300px, calc(100vw - 16px));
    max-height: 70dvh;
    overflow-y: auto;
    padding: 8px;
    background: var(--raised);
    border: 1px solid #46527a;
    border-radius: 10px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  }
  .more.open { display: grid; gap: 4px; }
  .more > .spacer { display: none; }
  .more .in-menu { display: inline; }
  .more > button, .more summary { justify-content: flex-start; width: 100%; background: transparent; border-color: transparent; }
  .more .inline { justify-content: space-between; padding: 4px 12px; font-size: 14px; }
  .more .inline select { width: 60%; }
  .more .menu > div { position: static; width: auto; margin: 2px 0 4px 14px; box-shadow: none; }

}

/* Phones and small tablets: the video on top, the timeline under it, and one panel at a time below. */
@media (max-width: 900px) {
  :root { --label-w: 92px; }
  body {
    height: 100dvh;
    overflow-y: auto; /* only scrolls when the screen is too short to fit everything, like a phone on its side */
    grid-template-rows: auto minmax(200px, 1fr) auto auto;
    grid-template-areas: "bar" "stage" "timeline" "panel";
  }
  main { display: contents; }
  .bar { grid-area: bar; position: relative; gap: 6px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  .bar h1 { margin-right: auto; font-size: 16px; }
  .bar .lbl { display: none; }
  .stage { grid-area: stage; grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px; padding: 6px; }
  .timeline { grid-area: timeline; }
  .transport { padding: 6px 12px; }
  #play { width: 36px; height: 36px; }
  .tracks { max-height: 15dvh; padding: 0 12px 6px; }
  .lanes { left: calc(12px + var(--label-w)); }
  .row > span { left: -12px; margin-left: -12px; padding-left: 12px; }
  .transport { gap: 6px; }
  #play, #mute { flex: none; }
  .timecode { flex: none; gap: 5px; padding: 4px 8px; white-space: nowrap; }
  .timecode b { font-size: 16px; }
  .timecode span { font-size: 11px; }
  .tl-zoom { gap: 2px; }
  .tl-zoom button { width: 34px; height: 34px; padding: 0; }
  .tl-zoom input { width: 60px; }

  /* Rails of tools in the space beside a tall video. */
  .rail { display: grid; grid-auto-rows: 40px; grid-template-columns: 46px; align-content: center; gap: 4px; max-height: 100%; overflow-y: auto; scrollbar-width: none; }
  #addRail { grid-template-columns: 46px 46px; }
  .rail > div { display: contents; }
  .rail > div[hidden] { display: none; }
  .rail button { flex-direction: column; gap: 2px; padding: 0; background: #1c2338; font-size: 10px; font-weight: 600; color: var(--muted); }
  .rail button .ic { width: 19px; height: 19px; color: var(--ink); }
  #addRail .ic { color: var(--signal); }
  .rail button.danger .ic { color: #ff8a80; }
  #wrap { grid-column: 2; }

  /* The full Add panel slides up as a sheet from the More button. */
  .add {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 8;
    max-height: 75dvh;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    border-top: 1px solid #46527a;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.6);
    transform: translateY(105%);
    transition: transform 200ms ease-out;
  }
  body.sheet-add .add { transform: none; }
  .sheet-close { display: inline-flex; float: right; margin: -4px -2px 0 0; }
  .add button[data-add] { display: none; } /* already on the rail */

  /* The editing panel: one group of settings at a time, picked from the tab strip under it. */
  .inspector { grid-area: panel; display: flex; flex-direction: column; max-height: 42dvh; padding: 0; overflow: hidden; border: 0; border-top: 1px solid var(--line); }
  .inspector { height: 230px; }
  .inspector > form, .inspector > .hint { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; }
  .inspector .hint { font-size: 13px; }
  #props, #clipProps { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-content: start; align-items: center; }
  #props[hidden], #clipProps[hidden] { display: none; }
  #propTitle, #textLabel, .inspector .f small, .inspector .actions, .inspector .w { display: none; }
  .inspector .w.mini { display: block; margin-bottom: 4px; font-size: 11px; color: var(--muted); }
  .inspector[data-tab="text"] #props [data-group]:not([data-group="text"]),
  .inspector[data-tab="style"] #props [data-group]:not([data-group="style"]),
  .inspector[data-tab="color"] #props [data-group]:not([data-group="color"]),
  .inspector[data-tab="timing"] #props [data-group]:not([data-group="timing"]) { display: none; }
  .inspector h2 { grid-column: 1 / -1; margin: 0; font-size: 15px; }
  .inspector .f, .inspector .check, #replaceImage { margin: 0; font-size: 12px; }
  .inspector .f > textarea, .inspector .f > input, .inspector .f > select { margin-top: 3px; }
  .inspector textarea { height: 3.4em; resize: none; }
  [data-k="text"], [data-k="sub"], [data-k="offset"] { min-width: 0; }
  #props [data-group="text"], #props .f:has(.colors), #props .f:has([data-chips]), #props [data-group="timing"], #replaceImage { grid-column: 1 / -1; }
  .mark { justify-self: start; width: 44px; height: 44px; padding: 0; }
  .mark .ic { width: 20px; height: 20px; }

  /* Icons stand in for the field names. */
  .fi { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 24px; color: #6f7ca3; }
  svg.fi { height: 20px; }
  .fi-size { font-weight: 800; font-size: 17px; line-height: 1; }
  .fi-size small { font-size: 10px; }
  .f.cued { display: flex; align-items: center; gap: 6px; }
  .f.cued .num { flex: 1; margin: 0; }
  .f.cued input[type="range"] { flex: 1; min-width: 0; margin: 0; }
  .num > button { width: 38px; }
  .num-box input { padding: 9px 0 9px 8px; }
  .num-box:has(> i) input { padding-left: 4px; }
  .num-box i { width: 16px; }
  .inspector .seg { margin: 0; }
  .inspector .seg button { width: 44px; height: 44px; padding: 0; flex: none; }

  /* All capitals as a toggle button. */
  .caps { justify-self: start; min-height: 0; }
  .caps input { position: absolute; opacity: 0; pointer-events: none; }
  .caps-ic { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; background: var(--raised); border: 1px solid var(--line); border-radius: 6px; font-size: 13px; font-weight: 800; }
  .caps:has(input:checked) .caps-ic { background: var(--signal); border-color: var(--signal); color: #fff; }
  .caps:has(input:focus-visible) .caps-ic { outline: 2px solid var(--flash); }

  /* Menus shown as chips. */
  select[data-chips] { display: none !important; }
  .chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  .chips button { flex: none; height: 40px; padding: 0 13px; font-size: 16px; }
  .chips button.icon { width: 44px; height: 44px; padding: 0; }
  .chips button.icon .ic { width: 20px; height: 20px; }
  [data-chips="anim"] + .chips { gap: 4px; }
  [data-chips="anim"] + .chips button.icon { width: 40px; }
  .chips button.on { background: var(--signal); border-color: var(--signal); color: #fff; }
  [data-chips="font"] + .chips button.on { background: #1d2a55; border-color: var(--signal); box-shadow: 0 0 0 1px var(--signal); color: var(--ink); }

  /* Colors: tap a target, then a brand dot. */
  .looks { margin: 0 0 10px; }
  .looks button { width: 46px; height: 38px; }
  .colors label.on { border-color: var(--signal); box-shadow: 0 0 0 1px var(--signal); }
  .brand-dots { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
  .brand-dots button { width: 34px; height: 34px; padding: 0; border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 50%; }
  .brand-dots button.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--signal); }
  .brand-dots .any { background: conic-gradient(#ff473b, #ffd400, #3ddc84, #4470ff, #c86bff, #ff473b); }

  /* Timing: two rows of motion icons, then speed and whole-video. */
  #timing { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
  #timing > .f, #timing .times { display: contents; }
  #timing .span-times { display: flex; grid-column: 1 / -1; order: 0; }
  #timing .here { grid-column: 1 / -1; order: 0; margin: 0; }
  #timing .here button { height: 40px; }
  #timing .span-times label { flex-direction: row; align-items: center; gap: 6px; font-size: 12px; }
  #timing label.move { grid-column: 1 / -1; display: flex; flex-direction: row; align-items: center; gap: 6px; order: 1; }
  #timing [data-k="speed"] + .chips { order: 2; }
  #timing [data-k="speed"] + .chips button { width: 52px; font-weight: 700; font-size: 18px; }
  #whole { order: 3; width: 44px; height: 44px; margin: 0; padding: 0; }

  .safe div::after { left: 2px; top: 2px; padding: 0 3px; font-size: 8px; opacity: 0.85; }

  /* Clip framing on a phone. */
  #clipProps .framing { grid-column: 1 / -1; }
  .inspector .f small.keep { display: block; margin: 0 0 6px; }
  .key-row > button, #resetFrame { width: 44px; height: 44px; }
  #keyMove button { height: 44px; }
  .vclip .kf { width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; }

  .transcript { inset: auto 0 0 0; width: 100%; height: 62dvh; border-radius: 14px 14px 0 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .tr-line { grid-template-columns: 54px minmax(0, 1fr); }
  .tr-tools { grid-column: 2; justify-content: flex-end; }
  .tr-tools button { width: 40px; height: 36px; }

  .place-f { display: none !important; } /* on a phone, Place on the rail puts the spots on the video */

  /* Fingers need at least 44px. */
  .bar button, .bar .pair button, #play, #mute, .tl-zoom button { min-width: 44px; min-height: 44px; }
  #export { padding: 0 14px; }
  .bar h1 { font-size: 14px; }
  .bar h1 span { padding: 5px 8px 4px; }
  .tl-zoom input { display: none; } /* − / + and pinching are enough on a phone */
  #keysBtn { display: none; }
  .inspector .f small.chip-name { display: block; margin-top: -2px; font-size: 11px; color: var(--muted); }
  .fi-txt { width: 30px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
  #timing [data-k="speed"] + .chips + .chip-name { order: 2; grid-column: 1 / -1; }
  #timing label.move { flex-wrap: wrap; }
  #timing label.move .chip-name { flex-basis: 100%; padding-left: 36px; }

  /* The tab strip. */
  .edit-tabs { display: flex; flex: none; padding: 0 6px max(0px, env(safe-area-inset-bottom)); background: var(--desk); border-top: 1px solid var(--line); }
  .edit-tabs[hidden] { display: none; }
  .edit-tabs button { flex: 1; flex-direction: column; gap: 2px; height: 50px; padding: 0; background: none; border: 0; border-top: 2px solid transparent; border-radius: 0; color: var(--muted); font-size: 11px; font-weight: 600; }
  .edit-tabs button .ic { width: 21px; height: 21px; }
  .edit-tabs .aa { font: 600 19px/22px "Newsreader", serif; }
  .edit-tabs button.on { color: var(--ink); border-top-color: var(--signal); }
  .edit-tabs button.on .ic, .edit-tabs button.on .aa { color: var(--signal); }
  .edit-tabs button:active { transform: none; }

  /* iPhone zooms the page into any field with text smaller than 16px. */
  input, select, textarea { font-size: 16px; }
  .toast { bottom: calc(64px + env(safe-area-inset-bottom)); }
  .card .actions button, dialog .actions button { flex: 1 1 100%; }
}

/* Fingers need bigger handles than a mouse pointer. */
@media (pointer: coarse) {
  button, summary { touch-action: manipulation; }
  .row { --rh: 38px; }
  .row.video { --rh: 42px; }
  .clip::before, .clip::after, .vclip::before, .vclip::after { width: 18px; opacity: 1; }
  .clip::before, .vclip::before { background: linear-gradient(to right, transparent 4px, #fff 4px 8px, transparent 8px); }
  .clip::after, .vclip::after { background: linear-gradient(to left, transparent 4px, #fff 4px 8px, transparent 8px); }
  .sel .grip { right: -11px; width: 18px; height: 38px; margin-top: -19px; }
  .sel .vgrip { bottom: -11px; width: 38px; height: 18px; margin-left: -19px; }
}
