/* The phone editor (static/editor/phone.js), up to 767 px wide as in AutoSubtitles: a start screen, then the
   video, a row of four tools and a word strip, with the panels in a bottom sheet. Wider screens never show it. */
.ed-start, .ed-ptop, .ed-tools, .ed-strip, .ed-jumps, .ed-bigplay, .ed-customise, .ed-export-tiles, .ed-export-edit,
.ed-export-back { display: none; }

@media (max-width: 767px) {
    :root { --ed-phone-bg: #121214; --ed-phone-card: #2c2c2e; --ed-tile: rgba(33, 33, 33, .92); }
    body.ed { grid-template-rows: auto minmax(0, 1fr); background: var(--ed-phone-bg); }
    body.ed:not([data-phone]) .ed-main { visibility: hidden; }

    /* The desktop top bar gives way to the phone's; its export popover and subtitle file menu stay in use. */
    .ed-top, .ed-top-right, .ed-export { display: contents; }
    .ed-top-left, .ed-history, #ed-help, #ed-upgrade, .ed-export-main, .ed-export-more { display: none; }
    #ed-export-menu { position: fixed; top: calc(env(safe-area-inset-top) + 64px); right: 12px; left: auto; z-index: 30; }

    .ed-ptop {
        display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; background: var(--ed-phone-bg);
        padding: calc(env(safe-area-inset-top) + 4px) max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
    }
    .ed-ptop-logo { border-radius: 11px; }
    .ed-ptop-right { display: flex; justify-content: flex-end; gap: 6px; }
    .ed-round { display: grid; place-items: center; width: 52px; height: 52px; padding: 0; border: 0; border-radius: 50%; background: var(--ed-phone-card); color: var(--ed-ink); }
    .ed-round .ed-ic { width: 22px; height: 22px; }
    .ed-done { min-height: 52px; padding: 0 22px; border: 0; border-radius: 26px; background: var(--ed-accent); color: #fff; font-size: 17px; font-weight: 600; }
    .ed-pexport {
        display: inline-flex; align-items: center; gap: 6px; min-height: 52px; padding: 0 16px; border: 0; border-radius: 26px;
        background: var(--ed-accent); color: #fff; font-size: 16px; font-weight: 600;
    }
    .ed-pexport .ed-ic { width: 20px; height: 20px; }
    .ed-round[hidden], .ed-done[hidden], .ed-pexport[hidden] { display: none; }

    /* The sample's note is a card above the video on a phone. A sheet (Styles, Customise, Transcript) needs the
       room, and the note's "Try a style" is what the visitor is doing there, so it steps aside. */
    body[data-source=demo] .ed-stage { gap: 8px; }
    .ed-sample { align-self: stretch; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 10px 12px; border-radius: 16px; text-align: center; }
    .ed-sample p { font-size: 14px; }
    .ed-sample .ed-primary { min-height: 44px; }
    body:is([data-tool=styles], [data-tool=customise], [data-tool=transcript]) .ed-sample { display: none; }

    .ed-main {
        display: flex; flex-direction: column; min-height: 0; background: var(--ed-phone-bg);
        padding-bottom: calc(env(safe-area-inset-bottom) + var(--ed-keyboard, 0px));
    }
    .ed-bottom, .ed-rail, .ed-frame .ed-toolbar, .ed-frame .ed-select { display: none; }
    .ed-stage { flex: 1 1 auto; min-height: 120px; padding: 8px 16px; background: none; }
    .ed-frame canvas { border-radius: 18px; }
    .ed-bigplay {
        position: absolute; top: 50%; left: 50%; z-index: 2; display: grid; place-items: center; width: 72px; height: 72px;
        margin: -36px 0 0 -36px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .5); color: #fff;
    }
    .ed-bigplay .ed-ic { width: 30px; height: 30px; margin-left: 4px; }
    body.is-playing .ed-bigplay { display: none; }
    .ed-status { position: fixed; bottom: calc(env(safe-area-inset-bottom) + 132px); z-index: 26; max-width: calc(100vw - 32px); text-align: center; }
    /* Making captions covers the whole screen, with its steps and Cancel. */
    .ed-busy { position: fixed; inset: 0; z-index: 25; padding: 24px; }

    /* Tools: four tiles, or the Format choices, or the actions on a selected word. */
    .ed-tools { display: block; flex: none; padding: 3px 10px; transition: opacity .2s; }
    .ed-tool-set { display: flex; gap: 6px; }
    .ed-tool-set[hidden] { display: none; }
    .ed-tile {
        display: grid; flex: 1 1 0; place-items: center; align-content: center; gap: 3px; min-width: 44px; height: 56px; padding: 4px;
        border: 0; border-radius: 12px; background: var(--ed-tile); color: var(--ed-ink); font-size: 12px; line-height: 1.1;
    }
    .ed-tile .ed-ic { width: 20px; height: 20px; }
    .ed-tile span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .ed-tile[aria-checked=true] { background: var(--ed-accent); color: #fff; }
    .ed-tile-wrap { position: relative; display: flex; flex: 1 1 0; min-width: 44px; }
    .ed-tile-wrap .ed-tile { width: 100%; }
    .ed-phone-tracks { top: auto; bottom: calc(100% + 8px); left: auto; right: 0; width: 250px; }
    .ed-phone-tracks button { min-height: 44px; font-size: 15px; }
    .ed-translate-add { margin-top: 4px; padding: 0 10px; border: 0; border-top: 1px solid var(--ed-line); border-radius: 0; background: none; text-align: start; }
    body.is-playing .ed-tools { opacity: 0; pointer-events: none; }

    /* The word strip: the triangle marks the playhead in the middle. */
    .ed-strip { position: relative; display: block; flex: none; height: 52px; }
    .ed-strip[hidden] { display: none; }
    .ed-strip-words {
        display: flex; align-items: center; gap: 6px; height: 100%; padding: 0 50%; overflow-x: auto; overflow-y: hidden;
        overscroll-behavior-x: contain; scrollbar-width: none; touch-action: pan-x;
    }
    .ed-strip-words::-webkit-scrollbar { display: none; }
    .ed-chip {
        flex: none; min-width: 44px; height: 44px; padding: 0 10px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .06);
        color: rgba(255, 255, 255, .45); font-size: 17px; white-space: nowrap;
    }
    .ed-chip.is-first { margin-inline-start: 14px; }
    .ed-chip.is-current { color: rgba(255, 255, 255, .75); }
    .ed-chip.is-active { background: rgba(255, 255, 255, .16); color: #fff; font-weight: 600; box-shadow: inset 0 -3px 0 var(--ed-accent); }
    .ed-chip.is-selected { outline: 2px solid var(--ed-accent); outline-offset: -2px; }
    .ed-chip-input { width: auto; min-width: 2ch; background: rgba(255, 255, 255, .16); color: #fff; font-weight: 600; caret-color: var(--ed-accent); outline: 2px solid var(--ed-accent); outline-offset: -2px; }
    .ed-strip-mark {
        position: absolute; top: 0; left: 50%; width: 12px; height: 9px; margin-left: -6px; background: var(--ed-accent);
        clip-path: polygon(0 0, 100% 0, 50% 100%); pointer-events: none;
    }

    /* The bottom sheet holds the panels; the tool row and the strip make room for it. */
    .ed-side { display: none; }
    body[data-tool=styles] .ed-side, body[data-tool=customise] .ed-side, body[data-tool=transcript] .ed-side {
        display: flex; flex: none; flex-direction: column; height: min(50vh, 560px); height: min(50dvh, 560px);
        border: 0; border-radius: 16px 16px 0 0; background: var(--ed-panel); overflow: hidden;
    }
    body[data-tool=styles] .ed-tools, body[data-tool=customise] .ed-tools, body[data-tool=transcript] .ed-tools,
    body[data-tool=styles] .ed-strip, body[data-tool=customise] .ed-strip, body[data-tool=transcript] .ed-strip { display: none; }
    .ed-side .ed-panel { display: flex; flex: 1; flex-direction: column; min-height: 0; border: 0; padding-bottom: 0; }
    .ed-panel > * { flex: none; }
    /* Customise reads Font, Layout, Background, Animation, AI Enhance, as its jump buttons do. */
    #panel-font { order: 1; } #panel-layout { order: 2; } #panel-background { order: 3; } #panel-animate { order: 4; } #panel-ai { order: 5; }
    /* With the keyboard up, the sheet takes the screen so the field being typed in stays in view. */
    body.has-keyboard:is([data-tool=styles], [data-tool=customise], [data-tool=transcript]) .ed-stage { display: none; }
    body.has-keyboard:is([data-tool=styles], [data-tool=customise], [data-tool=transcript]) .ed-side { flex: 1; height: auto; }
    .ed-jumps:not([hidden]) {
        position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 6px; padding: 8px 12px; overflow-x: auto;
        scrollbar-width: none; background: var(--ed-panel); border-bottom: 1px solid var(--ed-line);
    }
    .ed-jumps .ed-pill { flex: none; min-height: 44px; }
    .ed-panel > section { scroll-margin-top: 62px; }
    .ed-jumps .ed-icon-btn { flex: none; width: 44px; height: 44px; }
    .ed-customise { display: inline-flex; min-height: 44px; margin-left: auto; }

    /* Start screen. */
    .ed-start {
        position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; background: var(--ed-phone-bg);
        padding: calc(env(safe-area-inset-top) + 12px) max(20px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 104px) max(20px, env(safe-area-inset-left));
    }
    .ed-start[hidden], .ed-start [hidden] { display: none; }
    .ed-start-top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
    .ed-start-top img { border-radius: 11px; }
    .ed-start-upgrade { min-height: 44px; font-size: 16px; }
    .ed-start-plan { color: var(--ed-upgrade); font-size: 13px; font-weight: 700; letter-spacing: .06em; }
    .ed-start-title { margin: 12px 0 0; font-size: 30px; line-height: 1.15; }
    .ed-start-lead { margin: 0; color: var(--ed-dim); font-size: 15px; }
    .ed-start-upload { gap: 8px; width: 100%; min-height: 56px; margin-top: 8px; border-radius: 14px; font-size: 17px; }
    .ed-start-upload .ed-ic { width: 22px; height: 22px; }
    .ed-start-note { margin: -4px 0 8px; color: var(--ed-dim); font-size: 14px; text-align: center; }
    .ed-start-card {
        position: relative; display: block; flex: none; width: 100%; aspect-ratio: 16 / 10; margin-top: 8px; padding: 0; overflow: hidden;
        border: 0; border-radius: 18px; background: #000; color: #fff; text-align: start;
    }
    .ed-start-card canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
    .ed-start-card::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0, 0, 0, .75), transparent 60%); }
    .ed-start-card-text { position: absolute; right: 120px; bottom: 16px; left: 16px; z-index: 1; display: grid; gap: 2px; }
    .ed-start-card-text small { color: rgba(255, 255, 255, .7); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
    .ed-start-card-text strong { overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
    .ed-start-open {
        position: absolute; right: 16px; bottom: 12px; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 4px;
        min-width: 96px; height: 44px; padding: 0 14px 0 18px; border-radius: 22px; background: var(--ed-accent); color: #fff; font-weight: 600;
    }
    .ed-start-open .ed-ic { width: 16px; height: 16px; transform: rotate(-90deg); }
    .ed-dock {
        position: fixed; right: 0; bottom: 0; left: 0; display: flex; align-items: center; justify-content: center; gap: 32px;
        height: calc(88px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
        background: linear-gradient(to top, var(--ed-phone-bg) 70%, transparent);
    }
    .ed-dock-btn { display: grid; place-items: center; width: 48px; height: 48px; border: 0; border-radius: 50%; background: var(--ed-phone-card); color: var(--ed-ink); }
    .ed-dock-new {
        display: grid; place-items: center; width: 72px; height: 72px; border: 0; border-radius: 50%; background: var(--ed-accent);
        color: #fff; box-shadow: 0 8px 24px rgba(96, 93, 255, .4);
    }
    .ed-dock-new .ed-ic { width: 30px; height: 30px; }
    .ed-phone-settings { width: min(360px, calc(100vw - 32px)); }
    .ed-phone-settings .ed-settings-links { display: grid; gap: 8px; margin-bottom: 16px; }
    .ed-phone-settings .ed-settings-links a { justify-content: center; min-height: 48px; text-decoration: none; }

    /* Export page: the frame as it will be exported, the quality, then Edit and Export. */
    .ed-export-pop {
        position: fixed; inset: 0; z-index: 30; grid-template-rows: auto minmax(0, 1fr); align-content: stretch; width: auto; max-height: none;
        padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px); overflow-y: auto;
        border: 0; border-radius: 0; background: var(--ed-phone-bg); box-shadow: none;
    }
    .ed-export-pop h2 { display: grid; place-items: center; min-height: 52px; font-size: 20px; }
    .ed-export-back { position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 16px; display: grid; }
    /* The frame at its own shape on the page, with rounded corners. */
    .ed-export-preview { place-self: center; width: auto; height: auto; max-width: 100%; max-height: 100%; min-height: 0; border-radius: 18px; }
    .ed-export-quality { display: none; }
    .ed-export-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .ed-export-tile {
        display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; border: 1px solid var(--ed-line);
        border-radius: 12px; background: var(--ed-phone-card); color: var(--ed-ink); font-size: 15px;
    }
    .ed-export-tile[aria-pressed=true] { border-color: #fff; background: #fff; color: #111; }
    .ed-export-tile .ed-ic { width: 16px; height: 16px; color: var(--ed-upgrade); }
    .ed-export-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    /* Remove watermark is a dark row with a round amber bolt. */
    .ed-export-pop .ed-upgrade { justify-content: space-between; padding: 0 12px 0 16px; background: var(--ed-phone-card); color: var(--ed-ink); }
    .ed-export-pop .ed-upgrade .ed-ic { order: 1; width: 30px; height: 30px; padding: 7px; border-radius: 50%; background: var(--ed-upgrade); color: #1a1205; }
    .ed-export-pop .ed-export-wide { min-height: 54px; border-radius: 16px; font-size: 17px; }
    .ed-export-edit { display: inline-flex; background: var(--ed-phone-card); color: var(--ed-ink); }
    .ed-export-dialog, .ed-upgrade-dialog {
        inset: 0; width: 100vw; max-width: none; height: 100vh; height: 100dvh; max-height: none; margin: 0; border: 0; border-radius: 0;
    }
    .ed-export-dialog { padding: calc(env(safe-area-inset-top) + 20px) 20px calc(env(safe-area-inset-bottom) + 20px); }
    .ed-export-dialog[open] { display: grid; align-content: center; gap: 16px; }
    .ed-export-dialog button { min-height: 54px; border-radius: 16px; font-size: 17px; }

    /* The upgrade window slides up as a full sheet, as AutoSubtitles' phone paywall does. */
    .ed-upgrade-dialog { padding: calc(env(safe-area-inset-top) + 68px) 16px calc(env(safe-area-inset-bottom) + 20px); }
    .ed-upgrade-dialog[open] { animation: ed-sheet-up .28s ease-out; }
    .ed-upgrade-close { top: calc(env(safe-area-inset-top) + 8px); right: auto; left: 8px; width: 52px; height: 52px; }
    .ed-upgrade-dialog h2 { padding: 0; font-size: 26px; text-align: center; }
    .ed-upgrade-lead { text-align: center; }
    .ed-periods { display: flex; width: max-content; margin-inline: auto; }
    .ed-upgrade-terms { text-align: center; }
    /* A note that is scrolled to stays clear of the status bar. */
    .ed-upgrade-dialog .ed-upgrade-note { scroll-margin-top: calc(env(safe-area-inset-top) + 16px); }
    .ed-plans { grid-template-columns: 1fr; }
    /* The paid plans lead; the free card is what the visitor has now. */
    .ed-upgrade-dialog .ed-plan-free { display: none; }
    .ed-upgrade-foot { position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom)); margin: 0 -16px; padding: 12px 16px; background: #1f1f1f; }
    .ed-plan .ed-primary, .ed-upgrade-foot .ed-primary { justify-content: center; min-height: 54px; border-radius: 16px; font-size: 17px; }
    .ed-upgrade-foot .ed-primary { width: 100%; }
}
@keyframes ed-sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@media (max-width: 767px) and (prefers-reduced-motion: reduce) {
    .ed-upgrade-dialog[open] { animation: none; }
    .ed-tools { transition: none; }
}
/* The phone keeps the account in Settings (Your account), so the top bar's account stays desktop only. */
@media (max-width: 767px) { :is(.ed-account, .ed-signin) { display: none !important; } }
/* A short screen (a phone held sideways, a low window): the sample's note is one line, so the video keeps its room. */
@media (max-height: 520px) {
    body[data-source=demo] .ed-stage { gap: 4px; }
    .ed-sample { align-self: center; flex-wrap: nowrap; padding: 4px 4px 4px 14px; border-radius: 999px; }
    .ed-sample p span { display: none; }
}
