:root {
  color-scheme: dark;
  --bg: #101216;
  --panel: #191c22;
  --line: #2c3039;
  --text: #f3f4f7;
  --muted: #a0a6b1;
  --accent: #d7ff64;
  --radius: 16px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, select, summary { cursor: pointer; }
button {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #232730;
  color: var(--text);
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible,
a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #17210b; }
button.ghost { background: transparent; }

.shell { max-width: 1120px; min-height: 100svh; margin: auto; padding: 16px 24px 24px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; margin-bottom: 4px; }
.brand { color: var(--text); font-size: 19px; font-weight: 850; letter-spacing: -.8px; text-decoration: none; }
.brand i { color: var(--accent); font-style: normal; }
.brand small, .heading h1, .heading .eyebrow, .heading .subtitle { display: none; }
.local-badge { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 9px; letter-spacing: .4px; }
.local-badge::before { content: ""; width: 5px; height: 5px; flex: none; border-radius: 50%; background: var(--accent); }
.heading { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-bottom: 12px; }
.project-actions { display: flex; gap: 6px; }
.project-actions button { padding: 9px 12px; font-size: 11px; color: #c6cbd4; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.main-column, .side-column { min-width: 0; }
.preview-panel, .inspector, .timeline-panel, .export-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.preview-panel { background: #14171c; }
.preview-head, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; }
.preview-head { min-height: 38px; padding-top: 10px; padding-bottom: 10px; }
.section-title { margin: 0; font-size: 12px; font-weight: 650; line-height: 1.4; }
.tiny { color: var(--muted); font-size: 9px; letter-spacing: .4px; }
.preview-head .tiny { max-width: 65%; text-align: right; }

/* This is the viewport only. Neither source pixels nor export geometry change. */
.preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(100%, 28.125svh, 292.5px);
  height: auto;
  min-height: 0;
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 6px;
  background: #07090c;
  box-shadow: 0 0 0 1px #ffffff07;
}
.preview canvas { display: block; width: 100%; height: 100%; max-width: 100%; max-height: 100%; object-fit: contain; }
.empty { width: 100%; max-width: 290px; padding: 16px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 38px; height: 38px; margin: 0 auto 14px; border: 1px solid #414b34; border-radius: 12px; background: #20271b; color: var(--accent); font-size: 22px; }
.empty h2 { margin: 0 0 10px; font-size: 17px; line-height: 1.3; letter-spacing: -.4px; font-weight: 550; }
.empty p { margin: 0 0 15px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.empty button { max-width: 100%; padding: 10px; font-size: 11px; }
.empty small { display: block; margin-top: 12px; color: var(--muted); font-size: 9px; line-height: 1.5; }
.transport { padding: 8px 14px; }
.transport-row { display: flex; align-items: center; gap: 10px; }
.play { min-width: 44px; padding: 8px; font-size: 15px; background: #24282f; }
.time { white-space: nowrap; color: #c5c9d2; font-size: 11px; font-variant-numeric: tabular-nums; }
.time b { font-weight: 600; }
.time span { color: var(--muted); }
.transport input { flex: 1; min-width: 24px; }

.timeline-panel { margin-top: 12px; }
.timeline-panel .section-head { padding-top: 6px; padding-bottom: 6px; }
.add-small { min-width: 44px; min-height: 44px; padding: 8px 10px; font-size: 11px; background: transparent; }
.clips { display: block; min-width: 0; padding: 0 14px 12px; overflow: visible; }
.timeline-scroll {
  position: relative;
  min-height: 110px;
  padding: 0 0 12px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: #464d59 transparent;
  -webkit-overflow-scrolling: touch;
}
.timeline-scroll::-webkit-scrollbar { height: 4px; }
.timeline-scroll::-webkit-scrollbar-thumb { border-radius: 4px; background: #464d59; }
.timeline-ruler {
  position: relative;
  height: 28px;
  min-width: 100%;
  background: repeating-linear-gradient(to right, #363c47 0 1px, transparent 1px 32px) bottom left / 100% 5px no-repeat;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}
.timeline-ruler span { position: absolute; top: 3px; padding-left: 4px; color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.timeline-track { position: relative; display: flex; gap: 0; min-width: 100%; height: 76px; isolation: isolate; }
.timeline-clip {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  height: 76px;
  border: 1px solid #414957;
  border-radius: 8px;
  background: linear-gradient(140deg, #2c3540, #232831);
  container-type: inline-size;
}
.timeline-clip.selected { z-index: 2; border-color: var(--accent); background: linear-gradient(140deg, #35452e, #28322a); box-shadow: inset 0 0 0 1px var(--accent); }
.clip-body { display: block; width: 100%; height: 100%; min-height: 44px; min-width: 0; padding: 12px 14px; overflow: hidden; border: 0; border-radius: 7px; background: transparent; color: #e0e4eb; font-size: 11px; line-height: 1.5; text-align: left; white-space: nowrap; text-overflow: ellipsis; user-select: none; -webkit-touch-callout: none; touch-action: pan-y; }
.timeline-clip.selected .clip-body { color: #eef6df; }
.timeline-clip.dragging { z-index: 6; opacity: .9; box-shadow: 0 8px 22px #0008, 0 0 0 1px var(--accent); }
.trim-handle {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  display: none;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: ew-resize;
  touch-action: none;
}
.timeline-clip.selected .trim-handle { display: block; }
.trim-handle.start { left: 0; }
.trim-handle.end { right: 0; }
.trim-handle::before { position: absolute; top: 50%; width: 5px; height: 24px; border-radius: 4px; background: var(--accent); content: ""; transform: translateY(-50%); }
.trim-handle.start::before { left: 1px; }
.trim-handle.end::before { right: 1px; }
.trim-handle:focus-visible { outline-offset: -3px; }
.timeline-playhead { position: absolute; z-index: 5; top: 23px; bottom: 12px; width: 2px; background: #fff; box-shadow: 0 0 3px #0008; transform: translateX(-1px); pointer-events: none; }
.timeline-playhead::before { position: absolute; top: -4px; left: -3px; width: 8px; height: 7px; border-radius: 2px 2px 3px 3px; background: #fff; content: ""; }
.timeline-hint { margin: 9px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.timeline-empty { margin: 0; padding: 14px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
/* Keep tiny clips proportional while separating their 44px touch targets. */
@container (max-width: 87px) {
  .trim-handle.start { top: -6px; bottom: auto; height: 44px; }
  .trim-handle.end { top: auto; bottom: -6px; height: 44px; }
  .trim-handle::before { height: 20px; }
  .clip-body { padding-right: 7px; padding-left: 7px; }
}

.inspector-inner { padding: 0 14px 14px; }
.selected-name { margin: 0 0 14px; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.field-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; color: #bec4ce; font-size: 11px; }
.lut-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-bottom: 14px; }
.lut { min-width: 0; padding: 5px 5px 8px; border-radius: 10px; background: #21252c; font-size: 10px; line-height: 1.3; font-weight: 500; }
.lut .swatch { display: block; height: 44px; margin-bottom: 7px; border-radius: 6px; background: linear-gradient(130deg, #5d7980 0%, #334648 45%, #a7956d 46%, #e4cfa3); }
.lut[data-lut="teal-orange-2"] .swatch { background: linear-gradient(130deg, #235f69 0%, #173f48 45%, #cf8a56 46%, #f0bb86); }
.lut[data-lut="teal-orange-3"] .swatch { background: linear-gradient(130deg, #074953 0%, #12333e 45%, #b46631 46%, #f1ad66); }
.lut.active { border-color: var(--accent); color: var(--accent); }
input[type=range] { width: 100%; height: 44px; margin: 0; accent-color: var(--accent); cursor: pointer; }
input[type=number], select { width: 100%; min-width: 0; min-height: 44px; padding: 10px; border: 1px solid #353b47; border-radius: 9px; background: #12151a; color: var(--text); }
hr { margin: 15px 0; border: 0; border-top: 1px solid var(--line); }
details { margin-top: 10px; border-top: 1px solid var(--line); }
summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 10px 0; color: #c6cbd4; font-size: 11px; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; flex: none; color: var(--muted); font-size: 17px; font-weight: 400; }
details[open] > summary::after { content: "−"; }
.trim-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.trim-fields label { display: grid; gap: 7px; color: var(--muted); font-size: 10px; }
.trim-ranges { display: grid; gap: 0; margin-top: 8px; }
.trim-ranges label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
.trim-ranges span { min-width: 35px; }
.clip-actions { display: flex; gap: 6px; margin-top: 10px; }
.clip-actions button { flex: 1; padding: 9px 5px; font-size: 11px; }
.danger { color: #f3a298; }
.export-panel { margin-top: 12px; padding: 14px; }
.export-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 0 12px; }
.export-settings label { color: var(--muted); font-size: 10px; line-height: 1.5; }
.export-settings select { margin-top: 7px; padding-right: 4px; padding-left: 8px; font-size: 11px; }
.export-button { width: 100%; font-size: 12px; }
.export-panel > .export-button { margin-top: 12px; }
.export-note { margin: 10px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.export-progress { margin-top: 13px; }
.export-progress progress { width: 100%; height: 8px; accent-color: var(--accent); }
.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; font-size: 11px; }
.progress-row button { min-height: 44px; padding: 8px 10px; font-size: 11px; }
.result-actions { display: flex; gap: 8px; margin-top: 12px; }
.result-actions > * { flex: 1; }
.result-actions a { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--accent); font-size: 12px; text-decoration: none; }
.footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 20px; margin-top: 14px; color: var(--muted); font-size: 10px; line-height: 1.6; }
.footer p { margin: 0; }
.footer strong { color: #b6bdc9; font-weight: 500; }
.footer a { color: inherit; }
.status { margin: 0 0 12px; padding: 10px 12px; border: 1px solid #485434; border-radius: 10px; background: #23291d; font-size: 12px; line-height: 1.5; }
.status.error { border-color: #6d3f3f; background: #352121; color: #ffbaba; }
.status, .footer, .tiny, .timeline-hint { overflow-wrap: anywhere; }
.hidden, [hidden] { display: none !important; }
.busy .edit-control { pointer-events: none; opacity: .5; }
.drop-active .preview { outline: 2px dashed var(--accent); outline-offset: -6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (hover: hover) {
  button:not(:disabled):hover { background: #303540; }
  button.primary:not(:disabled):hover { background: #e2ff8f; }
  .clip-body:not(:disabled):hover { background: #ffffff08; }
  .trim-handle:not(:disabled):hover { background: transparent; }
  .trim-handle:not(:disabled):hover::before { background: #ecffb4; }
  summary:hover { color: var(--text); }
}

@media (max-width: 850px) {
  .shell { padding-right: 18px; padding-left: 18px; }
  .workspace { grid-template-columns: minmax(0, 1fr) 280px; gap: 12px; }
}

@media (max-width: 760px) {
  .shell { padding: 10px 12px max(20px, env(safe-area-inset-bottom)); }
  .topbar { margin-bottom: 4px; }
  .heading { margin-bottom: 10px; }
  .project-actions { width: 100%; justify-content: flex-end; }
  .project-actions button { padding-right: 10px; padding-left: 10px; }
  .workspace { display: flex; flex-direction: column; gap: 12px; }
  .main-column, .side-column { width: 100%; }
  .preview-head, .section-head { padding-right: 12px; padding-left: 12px; }
  .preview-head .tiny { font-size: 8px; }
  .transport { padding: 7px 12px; }
  .transport-row { gap: 8px; }
  .time { font-size: 10px; }
  .clips { padding-right: 12px; padding-left: 12px; }
  .inspector-inner { padding-right: 12px; padding-left: 12px; }
  .lut .swatch { height: 45px; }
  .export-panel { padding: 12px; }
  .footer { gap: 9px; }
  .footer p { width: 100%; }
}

@media (max-width: 360px) {
  .shell { padding-right: 8px; padding-left: 8px; }
  .brand { font-size: 18px; }
  .local-badge { font-size: 8px; letter-spacing: 0; }
  .project-actions button { font-size: 10px; }
  .empty { padding: 12px; }
  .empty h2 { font-size: 15px; }
}

@media (max-height: 600px) {
  .empty { padding: 10px; }
  .empty-icon, .empty small { display: none; }
  .empty h2 { font-size: 13px; }
  .empty p { font-size: 10px; }
  .empty button { padding: 8px; font-size: 10px; }
}

@media (max-height: 400px) {
  .empty h2, .empty p { display: none; }
}

/* Editor-first layout: all everyday controls fit before optional settings. */
.shell { padding: 8px 14px max(8px, env(safe-area-inset-bottom)); }
.topbar, .heading, .preview-head, .timeline-hint { display: none; }
.workspace { gap: 8px; }
.preview-panel { padding-top: 6px; }
.preview { width: min(100%, calc(clamp(180px, calc(100svh - 200px), 520px) * .5625)); }
.transport { padding: 2px 10px; }
.transport-row { gap: 8px; }
.timeline-panel { margin-top: 6px; }
.timeline-panel .section-head { padding: 0 10px; }
.clips { padding: 0 10px 5px; }
.timeline-scroll { min-height: 102px; padding-bottom: 16px; }
.timeline-track, .timeline-clip { height: 58px; }
.timeline-playhead { bottom: 16px; }
.inspector-inner { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 12px; padding: 8px; }
.inspector .section-head, .selected-name { display: none; }
.lut-options { grid-column: 1 / -1; gap: 6px; margin: 0 0 3px; }
.lut { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 5px; font-size: 9px; text-align: left; }
.lut .swatch { width: 26px; height: 30px; flex: none; margin: 0; border-radius: 5px; }
.inspector-inner > .field-label { margin: 0; font-size: 10px; }
.inspector-inner > .field-label span { font-size: 9px; }
.inspector-inner > input[type=range] { min-width: 0; }
.inspector-inner > details { grid-column: 1 / -1; }
.clip-actions { grid-column: 1 / -1; gap: 6px; margin-top: 2px; }
.clip-actions button { background: transparent; font-size: 10px; }
.export-panel { display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: start; gap: 8px; margin-top: 6px; padding: 8px; overflow: visible; }
.export-panel > .export-button { grid-column: 1; grid-row: 1; margin: 0; }
.export-panel > .editor-settings { grid-column: 2; grid-row: 1; margin: 0; border: 0; }
.editor-settings > summary { justify-content: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 10px; font-size: 20px; }
.editor-settings > summary::after { display: none; }
.export-progress, .result-actions, .export-panel > .export-note { grid-column: 1 / -1; margin: 0; }
.settings-sheet { position: fixed; z-index: 30; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); left: max(10px, env(safe-area-inset-left)); width: auto; max-width: 520px; max-height: 80svh; margin-left: auto; padding: 14px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid #464d59; border-radius: 18px; background: #1b1e25; box-shadow: 0 0 0 100vmax #0008, 0 14px 60px #0009; }
.settings-close { display: block; min-width: 44px; min-height: 44px; margin-left: auto; padding: 8px 12px; }
.settings-sheet > details { margin-top: 6px; }
.settings-sheet .project-actions { justify-content: flex-start; flex-wrap: wrap; }
.settings-sheet .export-settings { margin-top: 4px; }
.settings-sheet .field-label { margin-bottom: 8px; }
.settings-sheet summary { font-size: 12px; }

@container (max-width: 87px) {
  .trim-handle.start { top: -15px; }
  .trim-handle.end { right: auto; bottom: -15px; left: 0; }
  .trim-handle.end::before { right: auto; left: max(0px, calc(100cqw - 6px)); }
  .clip-body { padding-right: min(7px, 10cqw); padding-left: min(7px, 10cqw); }
}

/* Phone workspace: reserve room for tools, let the preview use the remaining height.
   dvh follows Safari chrome; safe areas protect the island and home indicator. */
@media (max-width: 760px) {
  .shell {
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .workspace { gap: 10px; }
  .preview-panel { padding-top: 8px; border-radius: 20px; background: #0b0d11; }
  .preview {
    width: min(100%, calc(clamp(190px, calc(100svh - 500px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 600px) * .5625));
    width: min(100%, calc(clamp(190px, calc(100dvh - 500px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 600px) * .5625));
    border-radius: 12px;
  }
  .transport { padding: 8px; }
  .transport-row { gap: 10px; }
  .play, .add-small { min-width: 48px; min-height: 48px; border-radius: 14px; font-size: 20px; }
  .time { font-size: 12px; }
  .empty button { min-height: 48px; padding: 12px 16px; font-size: 15px; border-radius: 14px; }
  .timeline-panel { margin-top: 10px; border-radius: 16px; }
  .clips { padding: 4px 10px 6px; }
  .timeline-ruler { height: 32px; }
  .timeline-ruler span { font-size: 11px; }
  .timeline-scroll { min-height: 112px; }
  .timeline-track, .timeline-clip { height: 64px; }
  .timeline-playhead { top: 27px; }
  .clip-body { font-size: 13px; }
  .inspector-inner { padding: 10px; column-gap: 12px; }
  .lut-options { gap: 8px; margin-bottom: 4px; }
  .lut { min-height: 52px; padding: 6px; gap: 6px; font-size: 12px; border-radius: 12px; }
  .lut .swatch { width: 24px; height: 36px; border-radius: 7px; }
  .inspector-inner > .field-label, .inspector-inner > .field-label span { font-size: 12px; }
  .clip-actions { gap: 8px; margin-top: 4px; }
  .clip-actions button { font-size: 12px; border-color: transparent; }
  .export-panel { margin-top: 10px; padding: 8px; grid-template-columns: minmax(0, 1fr) 48px; border-radius: 18px; }
  .export-button { min-height: 48px; border-radius: 12px; font-size: 15px; }
  .editor-settings > summary { width: 48px; height: 48px; border-radius: 12px; }
  .settings-sheet { max-height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px); padding: 16px; border-radius: 24px; }
  .settings-sheet summary, .project-actions button, .result-actions a, .progress-row { font-size: 14px; }
  .settings-sheet input[type=number], .settings-sheet select { font-size: 16px; }
  .settings-sheet label, .export-note { font-size: 12px; }
}

@media (max-width: 380px) {
  .shell { padding-right: max(8px, env(safe-area-inset-right)); padding-left: max(8px, env(safe-area-inset-left)); }
  .lut { font-size: 11px; gap: 4px; }
  .lut .swatch { width: 18px; }
  .transport-row { gap: 6px; }
}

/* A rotated phone keeps a usable preview beside the tools, with safe-area gutters. */
@media (orientation: landscape) and (max-height: 600px) and (min-width: 761px) {
  .shell { padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .workspace { grid-template-columns: minmax(0, 1fr) 300px; }
  .preview { width: min(100%, calc(clamp(160px, calc(100dvh - 210px), 340px) * .5625)); }
  .lut, .clip-actions button { font-size: 12px; }
  .settings-sheet input[type=number], .settings-sheet select { font-size: 16px; }
}

/* Preview-first editing: one timeline, one compact row of editing actions. */
.edit-toolbar { display: grid; grid-template-columns: 1fr 1.25fr .8fr .9fr; gap: 4px; padding: 0 6px 4px; }
.edit-toolbar button { min-width: 0; min-height: 40px; padding: 6px 3px; font-size: 12px; background: transparent; border-color: transparent; }
#split { color: var(--accent); }
.clip-body, .timeline-ruler { touch-action: none; }
.transport-row { justify-content: center; }
.transport .play { min-width: 40px; min-height: 36px; padding: 4px; border: 0; background: transparent; }
.transport { padding: 0 8px; }
.inspector { position: fixed; z-index: 20; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: calc(120px + env(safe-area-inset-bottom)); max-width: 480px; margin: auto; box-shadow: 0 12px 36px #0009; }
.empty p { font-size: 13px; line-height: 1.5; }
@media (max-width: 760px) {
  .shell { padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
  .workspace { gap: 4px; }
  .preview-panel { padding-top: 0; border: 0; border-radius: 12px; }
  .preview { width: 100%; height: max(220px, calc(100svh - 224px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); height: max(220px, calc(100dvh - 224px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); aspect-ratio: auto; border-radius: 12px; }
  .transport { padding: 0 8px; }
  .transport .play { min-height: 36px; min-width: 40px; font-size: 17px; }
  .transport-row { gap: 10px; }
  .timeline-panel { margin-top: 2px; border-radius: 12px; }
  .clips { padding: 0 6px; }
  .timeline-scroll { min-height: 66px; padding-bottom: 12px; }
  .timeline-ruler { height: 22px; }
  .timeline-ruler span { font-size: 10px; }
  .timeline-track, .timeline-clip { height: 32px; }
  .clip-body { min-height: 32px; padding: 3px 12px; font-size: 11px; }
  .timeline-playhead { top: 18px; bottom: 12px; }
  .trim-handle { min-width: 22px; width: 22px; min-height: 32px; }
  .trim-handle::before { width: 3px; height: 18px; }
  .export-panel { margin-top: 0; padding: 3px; border: 0; border-radius: 10px; grid-template-columns: 1fr 40px; gap: 6px; }
  .export-button { min-height: 40px; font-size: 13px; border-radius: 10px; }
  .editor-settings > summary { width: 40px; height: 40px; min-height: 40px; }
  .inspector-inner { padding: 8px; }
  .status { position: relative; margin-bottom: 4px; padding: 6px 10px; font-size: 11px; }
}
@container (max-width: 87px) {
  .trim-handle.start { top: -10px; }
  .trim-handle.end { bottom: -10px; }
}
/* Status messages must not push the editing controls below the screen. */
.status { position: fixed; z-index: 50; top: max(6px, env(safe-area-inset-top)); left: max(6px, env(safe-area-inset-left)); right: max(6px, env(safe-area-inset-right)); max-width: 640px; margin: 0 auto; box-shadow: 0 4px 18px #0006; }

/* Native playback avoids a full video-to-canvas copy when no LUT is active. */
.preview video { display: block; width: 100%; height: 100%; object-fit: contain; }
.edit-toolbar { grid-template-columns: minmax(80px, 1fr) repeat(4, 44px); align-items: center; }
.edit-toolbar button { min-height: 44px; }
.edit-toolbar .icon-button, .edit-toolbar #remove { display: flex; align-items: center; justify-content: center; position: relative; padding: 6px; }
#speed[aria-pressed="true"] { color: var(--accent); background: #d7ff6415; border-color: #d7ff6450; }
.speed-badge { position: absolute; right: 1px; bottom: 1px; font-size: 10px; line-height: 1; }
.timeline-ruler { height: 48px; cursor: ew-resize; }
.timeline-ruler span { top: 25px; }
.timeline-scroll { min-height: 104px; padding-bottom: 12px; }
.timeline-track, .timeline-clip { height: 44px; }
.clip-body { min-height: 44px; }
.timeline-playhead { top: 42px; bottom: 12px; }
.timeline-playhead::before { width: 12px; height: 10px; left: -5px; top: -7px; }
@media (max-width: 760px) {
  .preview { height: max(220px, calc(100svh - 266px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); height: max(220px, calc(100dvh - 266px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); }
  .timeline-ruler { height: 48px; }
  .timeline-ruler span { top: 25px; }
  .timeline-scroll { min-height: 104px; }
  .timeline-track, .timeline-clip, .clip-body { height: 44px; min-height: 44px; }
  .timeline-playhead { top: 42px; }
}

/* Move the playhead without relaying out the timeline on every frame. */
.timeline-playhead { left: 0; will-change: transform; }

/* Fixed sequence viewport. Source pixels remain available behind this crop. */
.sequence-frame { position: relative; flex: none; overflow: hidden; background: #000; outline: 1px solid #ffffff16; }
.preview .sequence-frame video, .preview .sequence-frame canvas { position: absolute; left: 0; top: 0; max-width: none; max-height: none; object-fit: fill; transform-origin: 0 0; pointer-events: none; border-radius: 0; }
.sequence-frame.framing-active { touch-action: none; outline: 1px solid var(--accent); cursor: move; }
.edit-toolbar { grid-template-columns: minmax(70px,1fr) repeat(5,40px); gap: 4px; }
#scale-toggle[aria-pressed="true"] { color: var(--accent); background: #d7ff6415; }
.scale-panel { display: flex; align-items: center; gap: 10px; padding: 6px 10px; }
.scale-panel input { flex: 1; min-width: 0; }
.scale-panel output { min-width: 44px; font-size: 12px; text-align: right; }
.scale-panel button { min-height: 40px; min-width: 40px; padding: 4px; }
@media (max-width: 760px) {
 .scale-editing .preview { height: max(220px, calc(100svh - 318px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); height: max(220px, calc(100dvh - 318px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); }
}
/* Color is a touch-sized popover; outside taps continue to their original target. */
#color-panel { position: fixed; z-index: 60; left: 50%; bottom: max(12px,env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(420px,calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto; box-shadow: 0 10px 50px #000a; }
#color-panel .inspector-inner { display: block; padding: 12px; }
#color-panel .color-close { display: block; margin: 0 0 8px auto; min-width: 44px; min-height: 44px; }
#color-panel .lut-options { display: grid; grid-template-columns: 1fr; gap: 10px; }
#color-panel .lut { min-height: 58px; padding: 10px 14px; gap: 12px; font-size: 15px; touch-action: manipulation; }
#color-panel .lut .swatch { width: 40px; height: 36px; }
#color-panel .field-label { margin-top: 12px; font-size: 14px; }
#color-panel input[type=range] { width: 100%; min-height: 44px; }
/* Keep the decoder composited beneath the opaque color canvas. */
#preview-canvas { z-index: 1; }

/* Only appears when half-speed would repeat missing source frames. */
.source-dialog { box-sizing: border-box; width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 24px 18px 18px; border: 1px solid #383e46; border-radius: 20px; color: var(--text); background: #191d23; }
.source-dialog::backdrop { background: #000a; }
.source-dialog h2 { margin: 8px 40px 16px 0; font-size: 20px; }
.source-dialog p { font-size: 15px; line-height: 1.5; color: #c3c7cd; }
.source-dialog > button:not(.source-close) { display: block; width: 100%; min-height: 48px; margin-top: 12px; white-space: normal; }
.source-dialog .source-close { position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; padding: 0; }
#source-info { overflow-wrap: anywhere; }

.source-dialog .transfer-install{display:block;text-align:center;text-decoration:none;margin-bottom:12px;padding:12px;border-radius:12px}.source-dialog .transfer-state a{display:block;padding:14px;border-radius:12px;text-align:center;text-decoration:none}.source-dialog progress{width:100%}

/* Small project action above the preview; no persistent explanatory banners. */
.project-bar { display: flex; justify-content: flex-end; height: 40px; align-items: center; }
#new-project { min-height: 40px; padding: 6px 10px; border: 0; background: transparent; color: var(--muted); font-size: 12px; touch-action: manipulation; }
#new-project:hover, #new-project:focus-visible { color: var(--text); }
@media (max-width: 760px) {
  .preview { height: max(220px, calc(100svh - 306px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); height: max(220px, calc(100dvh - 306px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); }
}
@media (max-width: 760px) { .scale-editing .preview { height: max(220px, calc(100svh - 358px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); height: max(220px, calc(100dvh - 358px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); } }

/* Three presets per column: swipe sideways while keeping the preview visible. */
#color-panel { width: min(600px, calc(100vw - 16px)); bottom: max(8px, env(safe-area-inset-bottom)); }
#color-panel .inspector-inner { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 6px; padding: 8px; }
#color-panel .color-close { grid-column: 2; grid-row: 1; margin: 0; }
#lut-search { grid-column: 1; grid-row: 1; width: 100%; min-width: 0; min-height: 44px; margin: 0; font-size: 16px; }
#color-panel .lut-options {
  grid-column: 1 / -1; grid-row: 2;
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(3, 44px);
  grid-template-columns: none; grid-auto-columns: 146px; gap: 6px;
  overflow-x: auto; overflow-y: hidden; max-height: none; margin: 0;
  overscroll-behavior-x: contain; touch-action: pan-x;
  scroll-snap-type: x proximity; scrollbar-width: none;
}
#color-panel .lut-options::-webkit-scrollbar { display: none; }
#color-panel .lut { min-height: 44px; height: 44px; min-width: 0; padding: 5px 9px; font-size: 12px; line-height: 1.2; white-space: normal; text-align: left; scroll-snap-align: start; }
#color-panel .lut[hidden] { display: none; }
#color-panel .field-label { grid-column: 1 / -1; grid-row: 3; align-self: center; width: 108px; margin: 0; font-size: 10px; }
#color-panel input[type=range] { grid-column: 1 / -1; grid-row: 3; align-self: center; min-height: 36px; width: calc(100% - 118px); margin: 0 0 0 118px; }
