/* Caption editor: dark, full screen, no page scroll. Desktop: preview, timeline and player on the left,
   one panel and an icon rail on the right. Phone held upright: preview, timeline, rail, then the panel.
   Phone held sideways: the desktop layout with a narrow side. */
:root {
    --ed-bar: #171717;
    --ed-stage: #262626;
    --ed-panel: #171717;
    --ed-card: #212121;
    --ed-field: #2b2b2b;
    --ed-line: #2f2f2f;
    --ed-ink: #f2f3f5;
    --ed-dim: #a3a3a3;
    --ed-faint: #737373;
    --ed-accent: #605dff;
    --ed-block: #570df8;
    --ed-head: #60a5fa;
    --ed-drag: #c026d3;
    --ed-active: #3b82f6;
    --ed-upgrade: #f5a524;
    --ed-focus: #8f8cff;
    --ed-radius: 8px;
    --ed-top-h: 56px;
    --ed-side-w: 385px;
    --ed-rail-w: 94px;
    --ed-hit: 36px;
    color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body.ed {
    margin: 0;
    background: var(--ed-bar);
    color: var(--ed-ink);
    font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Hebrew", "Noto Sans Arabic", sans-serif;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--ed-top-h) minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 2px solid var(--ed-focus); outline-offset: 2px; }
.ed-ic { width: 18px; height: 18px; flex: none; }
.ed-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Top bar */
.ed-top {
    display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 12px;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    background: var(--ed-bar); border-bottom: 1px solid var(--ed-line);
}
.ed-top-left, .ed-top-right, .ed-history, .ed-export { display: flex; align-items: center; gap: 6px; }
.ed-brand { position: relative; }
/* The account: Sign in for a visitor, the initials and a menu once signed in. Plan buttons hide for Pro and up. */
.ed-account { position: relative; }
.ed-signin { text-decoration: none; }
:is(.ed-account, .ed-signin, [data-upgrade="plans"])[hidden] { display: none !important; }
.ed-avatar-btn { display: grid; place-items: center; width: var(--ed-hit); height: var(--ed-hit); padding: 0; border: 0; border-radius: 999px; background: none; }
.ed-avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 999px; background: var(--ed-accent); color: #fff; font-size: 12px; font-weight: 700; }
.ed-account-menu { min-width: 230px; }
.ed-account-head { display: grid; gap: 2px; margin-bottom: 4px; padding: 8px 10px 10px; border-bottom: 1px solid var(--ed-line); }
.ed-account-head strong { overflow-wrap: anywhere; }
.ed-account-head > span { color: var(--ed-dim); font-size: 12px; overflow-wrap: anywhere; }
.ed-account-head .ed-account-plan { justify-self: start; margin-top: 6px; padding: 2px 8px; border-radius: 999px; background: var(--ed-card); color: var(--ed-ink); font-weight: 600; }
.ed-account-head .ed-account-plan.is-paid { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.ed-brand-btn { display: flex; align-items: center; gap: 2px; min-height: var(--ed-hit); padding: 0 4px; border: 0; background: none; border-radius: var(--ed-radius); }
.ed-brand-btn img { border-radius: 6px; }
.ed-brand-btn .ed-ic { width: 14px; height: 14px; color: var(--ed-dim); }
.ed-ghost, .ed-primary {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--ed-hit); padding: 0 10px;
    border: 0; border-radius: var(--ed-radius); background: none; color: var(--ed-dim);
}
.ed-ghost:hover { background: var(--ed-card); color: var(--ed-ink); }
.ed-primary { padding: 0 14px; background: var(--ed-accent); color: #fff; font-weight: 600; }
.ed-icon-btn {
    display: inline-grid; place-items: center; width: var(--ed-hit); height: var(--ed-hit); padding: 0;
    border: 0; border-radius: var(--ed-radius); background: none; color: var(--ed-dim);
}
.ed-icon-btn:not(:disabled):hover { background: var(--ed-card); color: var(--ed-ink); }
.ed-history { background: #222; border-radius: var(--ed-radius); gap: 0; }
.ed-upgrade {
    display: inline-flex; align-items: center; gap: 6px; min-height: var(--ed-hit); padding: 0 14px;
    border-radius: var(--ed-radius); background: var(--ed-upgrade); color: #1a1205; font-weight: 600; text-decoration: none;
}
.ed-export { position: relative; gap: 0; }
.ed-export-main, .ed-export-more {
    display: inline-flex; align-items: center; gap: 6px; min-height: var(--ed-hit); border: 0;
    background: var(--ed-accent); color: #fff; font-weight: 600;
}
.ed-export-main { padding: 0 14px; border-radius: var(--ed-radius) 0 0 var(--ed-radius); }
.ed-export-more { padding: 0 8px; border-radius: 0 var(--ed-radius) var(--ed-radius) 0; border-left: 1px solid rgba(255, 255, 255, .25); }
.ed-export-main:disabled { opacity: .6; }

/* Main grid */
.ed-main {
    display: grid; min-height: 0;
    grid-template-columns: minmax(0, 1fr) calc(var(--ed-side-w) + var(--ed-rail-w));
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "stage side" "bottom side";
}
.ed-stage { grid-area: stage; position: relative; display: flex; min-width: 0; min-height: 0; padding: 20px; background: var(--ed-stage); }
.ed-frame { position: relative; display: flex; flex: 1; min-width: 0; min-height: 0; align-items: center; justify-content: center; }
.ed-frame video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.ed-frame canvas { display: block; max-width: 100%; max-height: 100%; background: #000; touch-action: none; }
.ed-busy {
    position: absolute; inset: 0; z-index: 6; display: grid; place-content: safe center; justify-items: center; gap: 10px;
    overflow-y: auto; background: rgba(10, 10, 10, .55); backdrop-filter: blur(6px); color: #fff; text-align: center;
}
.ed-busy[hidden] { display: none; }
.ed-busy small { color: rgba(255, 255, 255, .7); }
.ed-busy-cancel { min-width: 96px; min-height: 44px; border: 1px solid rgba(255, 255, 255, .4); color: #fff; }
.ed-busy-cancel:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.ed-busy-bars { display: flex; align-items: center; gap: 4px; height: 28px; }
.ed-busy-bars i { width: 4px; height: 100%; border-radius: 2px; background: #fff; animation: ed-bar 1s ease-in-out infinite; }
.ed-busy-bars i:nth-child(2) { animation-delay: .15s; }
.ed-busy-bars i:nth-child(3) { animation-delay: .3s; }
.ed-busy-bars i:nth-child(4) { animation-delay: .45s; }
.ed-busy-bars i:nth-child(5) { animation-delay: .6s; }
@keyframes ed-bar { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }
.ed-busy-steps { display: flex; gap: 6px; }
.ed-busy-steps i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, .3); }
.ed-busy-steps i.is-done { background: #fff; }
.ed-status {
    position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); margin: 0; padding: 8px 14px;
    border-radius: 999px; background: rgba(0, 0, 0, .75); color: var(--ed-ink); font-size: 13px;
}
/* The sample says it is one, in the flow above the video, with the way to the visitor's own, so it never covers the
   video. On the sample the top bar leads with Upload video, and Export goes plain (2026-11-17-first-visit-clarity.md). */
body[data-source=demo] .ed-stage { flex-direction: column; gap: 12px; }
.ed-sample {
    display: flex; flex: none; align-self: center; align-items: center; gap: 14px; max-width: 100%; padding: 6px 6px 6px 16px;
    border: 1px solid rgba(255, 255, 255, .12); border-radius: 999px; background: rgba(23, 23, 23, .94);
}
.ed-sample[hidden] { display: none; }
.ed-sample p { margin: 0; color: var(--ed-dim); font-size: 13px; }
.ed-sample strong { color: var(--ed-ink); }
.ed-sample .ed-primary { flex: none; border-radius: 999px; }
body[data-source=demo] #ed-new { background: var(--ed-accent); color: #fff; font-weight: 600; }
body[data-source=demo] :is(.ed-export-main, .ed-export-more) { background: var(--ed-card); color: var(--ed-ink); }
.ed-drop {
    position: absolute; inset: 12px; display: grid; place-content: center; justify-items: center; gap: 8px; z-index: 5;
    border: 2px dashed var(--ed-accent); border-radius: 12px; background: rgba(23, 23, 23, .86); font-size: 16px;
}
.ed-drop[hidden], .ed-status[hidden] { display: none; }
.ed-drop .ed-ic { width: 32px; height: 32px; color: var(--ed-accent); }

/* Timeline, seek bar and player row */
.ed-bottom { grid-area: bottom; min-width: 0; border-top: 1px solid var(--ed-line); background: var(--ed-bar); padding-bottom: env(safe-area-inset-bottom); }
.ed-timeline { display: flex; align-items: stretch; gap: 4px; padding: 6px 8px 0 12px; }
.ed-track { position: relative; flex: 1; min-width: 0; height: 76px; overflow: hidden; cursor: grab; touch-action: none; user-select: none; }
.ed-track.is-scrubbing { cursor: grabbing; }
.ed-tl-content { position: absolute; top: 0; bottom: 0; left: 0; will-change: transform; }
/* The wave has its own lane under the caption blocks. */
.ed-wave { position: absolute; left: 0; right: 0; bottom: 2px; width: 100%; height: 18px; pointer-events: none; }
.ed-ruler {
    position: relative; height: 18px; font: 10px ui-monospace, Menlo, Consolas, monospace; color: var(--ed-faint);
    background-image: radial-gradient(circle, #555 1px, transparent 1.5px);
    background-size: var(--tick, 20px) 6px; background-repeat: repeat-x; background-position: 0 12px;
}
.ed-ruler span { position: absolute; top: 0; padding-left: 3px; border-left: 1px solid #444; line-height: 10px; }
.ed-blocks { position: absolute; top: 20px; bottom: 22px; left: 0; right: 0; }
.ed-block {
    position: absolute; top: 0; bottom: 0; min-width: 2px; padding: 0 6px; overflow: hidden;
    border: 0; border-radius: 2px; background: var(--ed-block); color: #fff; font-size: 11px;
    text-align: start; white-space: nowrap; text-overflow: ellipsis; cursor: grab;
}
.ed-block.is-selected { box-shadow: inset 0 0 0 2px #fff; }
/* A block moves with its body and changes its start or end at the caption's first or last edge. */
.ed-block:is([data-grip="start"], [data-grip="end"]), .ed-track:is([data-drag="start"], [data-drag="end"]) { cursor: ew-resize; }
.ed-track[data-drag="move"], .ed-track[data-drag="move"] .ed-block { cursor: grabbing; }
.ed-drag-label {
    position: absolute; top: 0; z-index: 2; transform: translateX(-50%); padding: 1px 8px; border-radius: 999px;
    background: var(--ed-drag); color: #fff; font: 600 10px/16px ui-monospace, Menlo, Consolas, monospace;
    white-space: pre; pointer-events: none;
}
.ed-drag-label[hidden] { display: none; }
.ed-playhead { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: var(--ed-head); pointer-events: none; }
.ed-zoom { display: flex; flex-direction: column; justify-content: center; }
.ed-zoom .ed-icon-btn { width: 28px; height: 28px; }
.ed-seek {
    display: block; width: calc(100% - 24px); height: 16px; margin: 4px 12px 0; padding: 0;
    -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer;
}
.ed-seek::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--ed-active) var(--fill, 0%), #3a3a3a var(--fill, 0%)); }
.ed-seek::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--ed-active) var(--fill, 0%), #3a3a3a var(--fill, 0%)); }
.ed-seek::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: #fff; border: 0; }
.ed-seek::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 0; }
.ed-transport { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; padding: 2px 12px 8px; }
.ed-transport-left, .ed-transport-mid, .ed-transport-right { display: flex; align-items: center; gap: 4px; min-width: 0; }
.ed-transport-right { justify-content: flex-end; }
.ed-volume { width: 90px; accent-color: #fff; }
.ed-play {
    display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%;
    background: #fff; color: #111;
}
.ed-play .ed-ic { width: 18px; height: 18px; }
.ed-time-readout { min-width: 0; margin-left: 6px; font: 13px ui-monospace, Menlo, Consolas, monospace; color: var(--ed-dim); white-space: nowrap; }
.ed-speed { min-width: 44px; height: var(--ed-hit); border: 0; border-radius: var(--ed-radius); background: #222; color: var(--ed-dim); }

/* Right side */
.ed-side { grid-area: side; display: grid; grid-template-columns: minmax(0, 1fr) var(--ed-rail-w); min-height: 0; border-left: 1px solid var(--ed-line); background: var(--ed-panel); }
.ed-panel { min-width: 0; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); }
.ed-rail { display: flex; flex-direction: column; gap: 4px; padding: 8px 6px; border-left: 1px solid var(--ed-line); background: var(--ed-bar); }
.ed-rail [role=tab] {
    display: grid; justify-items: center; gap: 3px; min-height: 56px; padding: 6px 2px;
    border: 0; border-radius: var(--ed-radius); background: none; color: var(--ed-dim); font-size: 11px; line-height: 1.1; white-space: nowrap;
}
.ed-rail [role=tab]:hover { color: var(--ed-ink); }
.ed-rail [aria-selected=true] { background: #262626; color: var(--ed-ink); }

@media (max-width: 1279px) { :root { --ed-side-w: 320px; --ed-rail-w: 82px; } }

/* Touch screens: every control at least 44 px. */
@media (pointer: coarse) {
    :root { --ed-hit: 44px; }
    .ed-play { width: 44px; height: 44px; }
    #ed-new, .ed-upgrade, .ed-export-more { min-width: 44px; justify-content: center; }
    .ed-transport button { flex: none; }
    .ed-zoom { flex-direction: row; align-items: center; }
    .ed-zoom .ed-icon-btn { width: 44px; height: 44px; }
    .ed-track { height: 64px; }
    .ed-ruler { height: 14px; background-position: 0 9px; }
    .ed-track { height: 80px; }
    .ed-blocks { top: 16px; bottom: 20px; }
    .ed-wave { height: 16px; }
    .ed-transport .ed-keys-wrap { display: none; }
    .ed-seek { height: 44px; }
}
/* On a phone the timeline drag seeks, so the thin seek bar is left out. */
@media (pointer: coarse) and (max-width: 899px), (pointer: coarse) and (max-height: 520px) {
    .ed-seek { display: none; }
}

/* Phone held upright. */
@media (max-width: 899px) and (min-height: 521px) {
    :root { --ed-top-h: 52px; }
    .ed-main {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(160px, 32vh) auto auto minmax(0, 1fr);
        grid-template-areas: "stage" "bottom" "rail" "side";
    }
    .ed-stage { padding: 8px; }
    .ed-side { display: contents; }
    .ed-panel { grid-area: side; border-top: 1px solid var(--ed-line); background: var(--ed-panel); }
    .ed-rail {
        grid-area: rail; flex-direction: row; overflow-x: auto; padding: 6px; border: 0; border-top: 1px solid var(--ed-line); scrollbar-width: none;
        mask-image: linear-gradient(to right, #000 85%, transparent);
    }
    .ed-rail [role=tab] { flex: none; min-width: 76px; min-height: 52px; }
    .ed-volume { display: none; }
    .ed-transport { grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px; padding: 0 8px 6px; }
    .ed-transport-mid { justify-content: center; }
    .ed-time-readout { margin-left: 2px; font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 420px) and (min-height: 521px) {
    .ed-top { gap: 4px; padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
    .ed-top-right { gap: 4px; }
    .ed-upgrade { padding: 0 10px; }
    .ed-upgrade span { display: none; }
    .ed-export-main { padding: 0 12px; }
    .ed-export-main .ed-ic { display: none; }
}

/* Phone held sideways, or any short window: keep the panel beside the preview. */
@media (max-height: 520px) {
    :root { --ed-top-h: 48px; --ed-side-w: 250px; --ed-rail-w: 64px; }
    .ed-stage { padding: 6px; }
    .ed-new-label, .ed-volume, .ed-upgrade span { display: none; }
    .ed-rail { overflow-y: auto; scrollbar-width: none; }
    .ed-rail [role=tab] { min-height: 48px; font-size: 10px; }
    .ed-transport { grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px; padding: 0 8px 4px; }
    .ed-transport-mid { justify-content: center; }
    .ed-time-readout { margin-left: 2px; font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
}
@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; }
    .ed-busy-bars i { animation-duration: 3s; }
}
