/* ============================================================
   cf-mobile-v2 — the mobile skin (final).

   Aesthetic: DJ deck meets editor. Deep obsidian black, ice-blue
   lightning accent, Bebas Neue display type, JetBrains Mono for
   timings. No panel overlaps — three stacked regions with clean
   dividers. All widgets you tap are >= 44px tall.
   ============================================================ */

@media (min-width: 721px) {
  body.cfm4-active { all: revert; }
  #cfm4Shell { display: none; }
}

@media (max-width: 720px) {

  /* ── Reset host page ─────────────────────────────────────────── */
  body.cfm4-active {
    margin: 0 !important; padding: 0 !important;
    background: #04060c !important;
    color: #f1f5fb;
    font-family: "Plus Jakarta Sans", system-ui, sans-serif;
    overflow: hidden !important;
    min-height: 100dvh; max-height: 100dvh;
  }
  /* Hide everything except our shell + safety-listed overlays. */
  body.cfm4-active > *:not(#cfm4Shell):not(#auth-loading):not(#settings-modal):not(#cf-paywall-root):not(#cf-trial-offer):not(#cfm4Upsell):not([id^="cf-tr-"]):not([id^="vep-mf-"]):not(.sb-bt-modal):not(.sb-bt-media-modal):not(.sb-bt-feature-modal):not(.sb-bt-toast):not(.sb-bt-log):not(#cfm4Sheet):not(#cfm4Veil):not(#cfm4Toast):not(#cfm4FileHost):not(#cfm4PaneWrap) {
    display: none !important;
  }
  /* Unwrap the desktop app skeleton — but keep tree alive so engine
     keeps working even though we don't visually use it directly. */
  body.cfm4-active .sb-bt-app { all: unset; display: block; }
  body.cfm4-active .sb-bt-toolbar { display: none !important; }
  body.cfm4-active .sb-bt-main { all: unset; display: block; }
  body.cfm4-active .sb-bt-workspace { all: unset; display: block; }
  body.cfm4-active .sb-bt-split-vertical { all: unset; display: block; }

  /* ── Shell scaffold ─────────────────────────────────────────── */
  #cfm4Shell {
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
    background:
      radial-gradient(140% 60% at 50% -10%, rgba(90, 160, 255, 0.20), transparent 60%),
      radial-gradient(90% 50% at 0% 100%, rgba(90, 160, 255, 0.06), transparent 65%),
      #04060c;
    z-index: 1;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* ── Top bar (48px) ──────────────────────────────────────────── */
  .cfm4-top {
    flex: 0 0 auto;
    height: 48px;
    display: grid;
    grid-template-columns: 40px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border-bottom: 1px solid rgba(90, 160, 255, 0.10);
  }
  .cfm4-home {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    border-radius: 12px;
    background: rgba(14, 22, 40, 0.6);
    border: 1px solid rgba(108, 138, 184, 0.18);
    color: #c4d2ea; text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 180ms ease, color 180ms ease;
  }
  .cfm4-home:active { background: rgba(90, 160, 255, 0.18); color: #5aa0ff; }
  .cfm4-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 20px;
    letter-spacing: 0.14em;
    color: #f1f5fb;
  }
  .cfm4-brand-logo {
    display: block;
    width: 22px; height: 22px;
    object-fit: cover;
    border-radius: 6px;
    box-shadow: 0 0 12px rgba(90, 160, 255, 0.45);
  }
  .cfm4-export {
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 15px;
    letter-spacing: 0.1em;
    color: #6c8ab8;
    border: 1px solid rgba(108, 138, 184, 0.18);
    border-radius: 12px;
    background: rgba(14, 22, 40, 0.6);
    padding: 0 12px;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    transition: background 180ms ease, color 180ms ease, border-color 180ms ease;
  }
  .cfm4-export.is-ready {
    color: #04060c;
    background: #5aa0ff;
    border-color: #5aa0ff;
    box-shadow: 0 0 16px rgba(90, 160, 255, 0.45);
  }
  .cfm4-export.is-busy {
    color: #5aa0ff;
    border-color: rgba(90, 160, 255, 0.5);
    background: rgba(90, 160, 255, 0.08);
  }
  .cfm4-export.is-dim { opacity: 0.55; }
  .cfm4-export:active { transform: scale(0.97); }

  /* ── Preview slot ────────────────────────────────────────────── */
  .cfm4-preview {
    flex: 0 0 auto;
    position: relative;
    margin: 10px 12px 0;
    aspect-ratio: 16 / 9;
    max-height: 34dvh;
    border-radius: 18px;
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(90, 160, 255, 0.20);
    box-shadow:
      0 24px 60px -20px rgba(0, 0, 0, 0.8),
      0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  }
  /* Kill inner card styling once reparented */
  .cfm4-preview .sb-bt-player-card {
    all: unset; display: block !important;
    width: 100% !important; height: 100% !important;
    position: relative !important;
  }
  .cfm4-preview .sb-bt-player-body {
    all: unset; display: block !important;
    width: 100% !important; height: 100% !important;
  }
  .cfm4-preview .sb-bt-player-visual {
    all: unset; display: block !important;
    width: 100% !important; height: 100% !important;
    position: relative !important;
  }
  .cfm4-preview .sb-bt-preview {
    width: 100% !important; height: 100% !important;
    aspect-ratio: auto !important;
    max-height: none !important;
    position: relative !important;
    background: #000 !important;
    border-radius: 0 !important;
  }
  .cfm4-preview video,
  .cfm4-preview canvas {
    width: 100% !important; height: 100% !important;
    object-fit: contain !important; background: #000 !important;
  }
  /* Hide desktop rail + resizer + non-essential transport when reparented. */
  .cfm4-preview .sb-bt-resizer,
  .cfm4-preview .sb-bt-player-rail,
  .cfm4-preview .sb-bt-player-top,
  .cfm4-preview .sb-bt-preview-transport,
  .cfm4-preview .sb-bt-agent-feed,
  .cfm4-preview .cf-m-timecode,
  .cfm4-preview .cf-m-empty {
    display: none !important;
  }
  .cfm4-preview .sb-bt-player-empty {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 10px; padding: 20px;
    background: linear-gradient(180deg, #0a0f1e 0%, #04060c 100%);
    color: #c4d2ea;
    border: 0; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    z-index: 6;
  }
  /* When media is loaded, uncover the actual video underneath. */
  .cfm4-preview .sb-bt-player-card--ready .sb-bt-player-empty,
  .cfm4-preview.is-ready .sb-bt-player-empty {
    display: none !important;
  }
  .cfm4-preview .sb-bt-player-empty-icon {
    width: 68px !important; height: 68px !important;
    display: grid; place-items: center;
    border-radius: 50%;
    background: rgba(90, 160, 255, 0.10);
    border: 1.5px solid rgba(90, 160, 255, 0.6);
    color: #5aa0ff;
    font-size: 32px !important; font-weight: 300;
    box-shadow: 0 0 40px -6px rgba(90, 160, 255, 0.5);
  }
  .cfm4-preview .sb-bt-player-empty-title {
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 26px !important; letter-spacing: 0.09em !important;
    color: #f1f5fb !important;
  }
  .cfm4-preview .sb-bt-player-empty-sub {
    font-size: 12px !important; color: #8aa0c2 !important;
  }
  /* Hide the lingering play-overlay circle — on mobile the CTA bar
     already handles play, and the FAB just sits on top of the video. */
  .cfm4-preview .sb-bt-play-fab { display: none !important; }

  /* iOS Safari sometimes renders <video>s with `will-change: opacity` +
     image-rendering hints as fully black even when frames are decoded. Kill
     those hints on mobile and let the layer paint normally. */
  .cfm4-preview .sb-bt-vlayer {
    will-change: auto !important;
    image-rendering: auto !important;
    transition: none !important;
    -webkit-transform: none !important;
    transform: none !important;
  }
  .cfm4-preview .sb-bt-caption-overlay { z-index: 3; }

  /* Corner labels (BPM/time inside preview) */
  .cfm4-time-badge {
    position: absolute;
    top: 10px; right: 12px;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px; letter-spacing: 0.08em;
    color: #f1f5fb;
    background: rgba(4, 6, 12, 0.6);
    backdrop-filter: blur(6px);
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 4;
    pointer-events: none;
  }

  /* ── Phase strip ────────────────────────────────────────────── */
  .cfm4-phase {
    flex: 0 0 auto;
    display: flex; justify-content: center; align-items: center;
    gap: 6px;
    padding: 12px 12px 8px;
  }
  .cfm4-phase-item {
    display: flex; align-items: center; gap: 5px;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 11px; letter-spacing: 0.12em;
    color: #4a5b76;
  }
  .cfm4-phase-item::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%;
    background: #1a2336;
    transition: all 220ms cubic-bezier(.4,.0,.2,1);
  }
  .cfm4-phase-item.is-on { color: #f1f5fb; }
  .cfm4-phase-item.is-on::before {
    background: #5aa0ff;
    box-shadow: 0 0 10px rgba(90, 160, 255, 0.7);
  }
  .cfm4-phase-item.is-done { color: #5aa0ff; }
  .cfm4-phase-item.is-done::before { background: #5aa0ff; opacity: 0.5; }
  .cfm4-phase-sep { color: #283248; font-size: 12px; }

  /* ── Stats row ──────────────────────────────────────────────── */
  .cfm4-stats {
    flex: 0 0 auto;
    display: grid; grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    padding: 0 12px 8px;
  }
  .cfm4-stat {
    background: rgba(14, 22, 40, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    padding: 7px 10px;
    display: flex; flex-direction: column; gap: 2px;
    min-width: 0;
  }
  .cfm4-stat-l {
    font-size: 8px; letter-spacing: 0.2em; color: #4a5b76;
    text-transform: uppercase;
    font-family: "JetBrains Mono", monospace;
  }
  .cfm4-stat-v {
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 18px; letter-spacing: 0.04em; line-height: 1;
    color: #f1f5fb;
  }
  .cfm4-stat.is-live .cfm4-stat-v { color: #5aa0ff; }

  /* ── Duration chips ─────────────────────────────────────────── */
  .cfm4-durs {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 8px 12px 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .cfm4-durs::-webkit-scrollbar { display: none; }
  .cfm4-durs-l {
    flex: 0 0 auto;
    font-family: "JetBrains Mono", monospace;
    font-size: 9px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #6c8ab8;
    padding-right: 2px;
  }
  .cfm4-dchip {
    flex: 0 0 auto;
    height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 0 12px;
    font-family: "JetBrains Mono", monospace;
    font-size: 12px;
    color: #c4d2ea;
    background: rgba(14, 22, 40, 0.6);
    border: 1px solid rgba(108, 138, 184, 0.18);
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
    transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
  }
  .cfm4-dchip.is-on {
    color: #04060c;
    background: #5aa0ff;
    border-color: #5aa0ff;
    font-weight: 700;
  }
  .cfm4-dchip-star {
    font-size: 10px;
    color: #ffd75a;
    line-height: 1;
  }
  .cfm4-dchip.is-on .cfm4-dchip-star { color: #04060c; }
  .cfm4-dchip:active { transform: scale(0.94); }

  /* ── Status strip (mirrors the engine log) ──────────────────── */
  .cfm4-status {
    flex: 0 0 auto;
    margin: 0 12px 8px;
    padding: 7px 10px;
    border-radius: 10px;
    background: rgba(14, 22, 40, 0.5);
    border: 1px solid rgba(108, 138, 184, 0.12);
    font-family: "JetBrains Mono", monospace;
    font-size: 10px;
    letter-spacing: 0.02em;
    line-height: 1.4;
    color: #8aa0c2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 200ms ease, border-color 200ms ease, background 200ms ease;
  }
  .cfm4-status.is-err {
    color: #ff9d9d;
    border-color: rgba(255, 110, 110, 0.35);
    background: rgba(80, 16, 24, 0.35);
  }

  /* ── Export / analyze progress strip ────────────────────────── */
  .cfm4-prog {
    flex: 0 0 auto;
    margin: 8px 12px 0;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(14, 22, 40, 0.75);
    border: 1px solid rgba(90, 160, 255, 0.30);
    box-shadow: 0 0 18px -6px rgba(90, 160, 255, 0.35);
  }
  .cfm4-prog[hidden] { display: none !important; }
  .cfm4-prog-track {
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
  }
  .cfm4-prog-fill {
    display: block;
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #2f7bff, #5aa0ff, #8ec2ff);
    box-shadow: 0 0 10px rgba(90, 160, 255, 0.7);
    transition: width 300ms ease;
  }
  .cfm4-prog.is-indet .cfm4-prog-fill {
    background: linear-gradient(90deg, transparent, #5aa0ff, transparent);
    background-size: 50% 100%;
    background-repeat: no-repeat;
    animation: cfm4Indet 1.2s linear infinite;
    transition: none;
  }
  @keyframes cfm4Indet {
    from { background-position: -60% 0; }
    to   { background-position: 160% 0; }
  }
  .cfm4-prog-label {
    margin-top: 6px;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px;
    letter-spacing: 0.04em;
    color: #8ec2ff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  /* ── Mobile perf: no per-frame color grading on the video layers.
     The desktop's contrast/saturate filter re-renders every frame on the
     GPU — measurable jank on phones. Raw frames are fine at phone size. */
  body.cfm4-active .sb-bt-vlayer,
  body.cfm4-active .sb-bt-vlayer--active {
    filter: none !important;
    image-rendering: auto;
  }

  /* ── Branded empty / home state ─────────────────────────────── */
  .cfm4-empty-vid {
    position: absolute; inset: 0;
    width: 100% !important; height: 100% !important;
    object-fit: cover !important;
    opacity: 0.55;
    pointer-events: none;
  }
  .cfm4-empty-shade {
    position: absolute; inset: 0;
    background:
      radial-gradient(120% 90% at 50% 100%, rgba(4, 6, 12, 0.9), transparent 60%),
      linear-gradient(180deg, rgba(4, 6, 12, 0.55), rgba(4, 6, 12, 0.35) 40%, rgba(4, 6, 12, 0.8));
    pointer-events: none;
  }
  .cfm4-empty-inner {
    position: relative;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 10px;
  }
  .cfm4-empty-logo {
    display: block;
    filter: drop-shadow(0 0 18px rgba(90, 160, 255, 0.55));
    animation: cfm4Float 3.2s ease-in-out infinite;
  }
  @keyframes cfm4Float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-5px); }
  }
  .cfm4-empty-cta {
    margin-top: 4px;
    padding: 10px 22px;
    border-radius: 999px;
    background: linear-gradient(180deg, #5aa0ff, #2f7bff);
    color: #04060c;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 14px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    box-shadow: 0 10px 26px -8px rgba(90, 160, 255, 0.6);
  }

  /* ── Playing states ─────────────────────────────────────────── */
  .cfm4-btn--play.is-playing {
    animation: cfm4Playing 1.6s ease-in-out infinite;
  }
  @keyframes cfm4Playing {
    0%, 100% { box-shadow: 0 10px 26px -8px rgba(90, 160, 255, 0.55); }
    50%      { box-shadow: 0 10px 32px -6px rgba(90, 160, 255, 0.9); }
  }
  body.sb-bt-previewing .cfm4-preview {
    border-color: rgba(90, 160, 255, 0.55);
    box-shadow:
      0 24px 60px -20px rgba(0, 0, 0, 0.8),
      0 0 24px -4px rgba(90, 160, 255, 0.35);
  }
  .cfm4-preview { transition: border-color 300ms ease, box-shadow 300ms ease; }

  /* Smooth phase-strip changes */
  .cfm4-phase-item { transition: color 250ms ease; }
  .cfm4-phase-item::before { transition: background 250ms ease, opacity 250ms ease; }

  /* ── Post-preview upsell banner ─────────────────────────────── */
  #cfm4Upsell {
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(96px + env(safe-area-inset-bottom));
    z-index: 55;
    display: flex; align-items: center; gap: 10px;
    padding: 12px 12px 12px 14px;
    border-radius: 16px;
    background: linear-gradient(165deg, #101b33, #0a1122);
    border: 1px solid rgba(90, 160, 255, 0.4);
    box-shadow: 0 18px 50px -12px rgba(0, 0, 0, 0.8), 0 0 24px -8px rgba(90, 160, 255, 0.5);
    opacity: 0; transform: translateY(14px);
    transition: opacity 260ms ease, transform 260ms ease;
  }
  #cfm4Upsell.is-on { opacity: 1; transform: translateY(0); }
  .cfm4-upsell-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .cfm4-upsell-txt strong { font-size: 13.5px; color: #f1f5fb; }
  .cfm4-upsell-txt span { font-size: 11.5px; color: #8aa0c2; line-height: 1.35; }
  .cfm4-upsell-cta {
    flex: 0 0 auto;
    border: 0; cursor: pointer;
    padding: 10px 16px; border-radius: 11px;
    background: linear-gradient(120deg, #3a6bff, #5aa0ff);
    color: #04122a;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 14px; letter-spacing: 0.1em;
    box-shadow: 0 8px 20px -6px rgba(58, 107, 255, 0.6);
    -webkit-tap-highlight-color: transparent;
  }
  .cfm4-upsell-cta:active { transform: scale(0.96); }
  .cfm4-upsell-x {
    flex: 0 0 auto;
    width: 30px; height: 30px;
    border: 0; border-radius: 9px;
    background: rgba(255, 255, 255, 0.06);
    color: #8aa0c2; font-size: 16px; line-height: 1;
    -webkit-tap-highlight-color: transparent;
  }

  /* ── Export output overlay ──────────────────────────────────── */
  #cfm4Out { position: relative; z-index: 40; }
  #cfm4Out .sb-bt-output {
    position: fixed;
    left: 12px; right: 12px;
    top: calc(env(safe-area-inset-top) + 56px);
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    z-index: 40;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #0a0f1e;
    border: 1px solid rgba(90, 160, 255, 0.35);
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.9);
  }
  #cfm4Out .sb-bt-output[hidden] { display: none !important; }
  #cfm4Out .sb-bt-output video {
    width: 100%;
    border-radius: 12px;
    background: #000;
  }

  /* ── Timeline slot ──────────────────────────────────────────── */
  .cfm4-timeline {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0 12px;
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(14, 22, 40, 0.6), rgba(6, 10, 20, 0.6));
    border: 1px solid rgba(255, 255, 255, 0.04);
    overflow: hidden;
    display: flex; flex-direction: column;
  }
  .cfm4-timeline .sb-bt-timeline-panel {
    all: unset; display: flex !important; flex-direction: column !important;
    width: 100% !important; height: 100% !important; flex: 1 !important;
    min-height: 0 !important; padding: 8px !important;
    box-sizing: border-box;
  }
  /* Waveform + music-icon row is desktop noise on a phone — the user
     already sees the video preview + timeline thumbs; the waveform
     is redundant and the red beat pills clutter the timeline. */
  .cfm4-timeline .sb-bt-waveform,
  .cfm4-timeline .sb-bt-beat-row,
  .cfm4-timeline .sb-bt-track-head,
  .cfm4-timeline .sb-bt-type-pill,
  .cfm4-timeline .sb-bt-type-pill--beat,
  .cfm4-timeline .sb-bt-type-pill--bass,
  .cfm4-timeline .sb-bt-type-pill--snare,
  .cfm4-timeline .sb-bt-type-pill--clap {
    display: none !important;
  }
  /* Single-column track (no left label) once the head is hidden. */
  .cfm4-timeline .sb-bt-track {
    grid-template-columns: 1fr !important;
    border-top: 0 !important;
    min-height: auto !important;
  }
  /* Keep the transitions chips row visible — it lives inside #beatRail
     with position:absolute; top:-26px and needs headroom above the
     Edit lane. Give the Edit lane top padding + let the scroll wrapper
     overflow vertically so chips paint above without clipping. */
  .cfm4-timeline .sb-bt-track--edit {
    padding-top: 32px !important;
  }
  .cfm4-timeline .sb-bt-track--edit .sb-bt-track-scroll {
    overflow-x: auto;
    overflow-y: visible !important;
  }
  .cfm4-timeline #beatRail {
    overflow: visible !important;
  }
  .cfm4-timeline .sb-bt-transitions-row {
    display: block !important;
    z-index: 8;
    pointer-events: none;
  }
  .cfm4-timeline .sb-bt-tx-chip {
    pointer-events: auto;
    font-size: 10px !important;
    padding: 3px 6px !important;
  }
  .cfm4-timeline .sb-bt-tx-chip-play { font-size: 9px !important; }
  .cfm4-timeline .sb-bt-tx-chip-label { font-size: 10px !important; }
  .cfm4-timeline .sb-bt-tx-chip-cls  { font-size: 9px !important; padding: 0 4px !important; }
  .cfm4-timeline .sb-bt-tracks {
    flex: 1 !important; min-height: 0 !important;
    max-height: none !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .cfm4-timeline .sb-bt-tabs,
  .cfm4-timeline .sb-bt-toolbar-tabs {
    overflow-x: auto; scrollbar-width: none;
    gap: 4px !important;
  }
  .cfm4-timeline .sb-bt-tabs::-webkit-scrollbar,
  .cfm4-timeline .sb-bt-toolbar-tabs::-webkit-scrollbar { display: none; }
  .cfm4-timeline .sb-bt-track,
  .cfm4-timeline .sb-bt-beat-row { min-width: max-content; }
  .cfm4-timeline .sb-bt-timeline-empty {
    padding: 20px !important; gap: 6px !important;
  }
  .cfm4-timeline .sb-bt-timeline-empty-title { font-size: 13px !important; }
  .cfm4-timeline .sb-bt-timeline-empty-formats,
  .cfm4-timeline .sb-bt-timeline-empty-hint { font-size: 10px !important; }
  .cfm4-timeline .sb-bt-timeline-empty-plus { font-size: 26px !important; }
  .cfm4-timeline .sb-bt-clips-grid,
  .cfm4-timeline .sb-bt-thumbs {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)) !important;
    gap: 4px !important;
  }

  /* ── Bottom tab bar (Clips / Captions) ──────────────────────── */
  .cfm4-tabs {
    flex: 0 0 auto;
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(90, 160, 255, 0.10);
    background: linear-gradient(180deg, transparent, rgba(4, 6, 12, 0.6) 60%);
  }
  .cfm4-tab {
    position: relative;
    appearance: none; -webkit-appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(14, 22, 40, 0.85);
    color: #cfd9ea;
    -webkit-tap-highlight-color: transparent;
    display: flex; align-items: center; justify-content: center;
    gap: 8px;
    padding: 12px 10px;
    border-radius: 14px;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 15px; letter-spacing: 0.14em;
    text-transform: uppercase;
    line-height: 1;
    transition: transform 120ms ease, background 180ms ease, border-color 180ms ease, color 180ms ease;
  }
  .cfm4-tab-ic { width: 18px; height: 18px; }
  .cfm4-tab.is-on {
    background: rgba(90, 160, 255, 0.12);
    border-color: rgba(90, 160, 255, 0.5);
    color: #5aa0ff;
    box-shadow: 0 0 16px -6px rgba(90, 160, 255, 0.45);
  }
  .cfm4-tab:active { transform: scale(0.97); }
  .cfm4-tab-badge {
    position: absolute; top: 6px; right: 8px;
    min-width: 20px; height: 18px; padding: 0 5px;
    border-radius: 999px;
    background: #5aa0ff; color: #04060c;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px; letter-spacing: 0.02em;
    display: inline-flex; align-items: center; justify-content: center;
    font-style: normal;
  }
  .cfm4-tab-badge[hidden] { display: none; }

  /* ── Slide-up pane container (Clips + Captions bodies) ─────── */
  #cfm4Panes {
    position: fixed; left: 0; right: 0;
    bottom: calc(72px + env(safe-area-inset-bottom));
    z-index: 45;
    pointer-events: none;
  }
  #cfm4Panes .cfm4-pane { pointer-events: auto; }
  .cfm4-pane {
    position: absolute; left: 12px; right: 12px; bottom: 0;
    max-height: 60dvh;
    background: linear-gradient(180deg, #0b1524, #060b18);
    border: 1px solid rgba(90, 160, 255, 0.28);
    border-radius: 20px;
    overflow: hidden;
    display: flex; flex-direction: column;
    box-shadow: 0 -20px 60px -14px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
    animation: cfm4PaneUp 220ms cubic-bezier(.2,.9,.3,1);
  }
  .cfm4-pane[hidden] { display: none !important; }
  @keyframes cfm4PaneUp {
    from { transform: translateY(16px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
  .cfm4-pane-head {
    flex: 0 0 auto;
    display: grid; grid-template-columns: 1fr auto;
    align-items: center; column-gap: 8px;
    padding: 14px 14px 10px;
    border-bottom: 1px solid rgba(90, 160, 255, 0.12);
  }
  .cfm4-pane-t {
    grid-column: 1;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 18px; letter-spacing: 0.10em;
    color: #f1f5fb;
  }
  .cfm4-pane-sub {
    grid-column: 1;
    font-size: 11px; color: #8aa0c2; margin-top: 3px;
  }
  .cfm4-pane-x {
    grid-column: 2; grid-row: 1 / span 2;
    align-self: start;
    width: 30px; height: 30px;
    border-radius: 10px; border: 0;
    background: rgba(255, 255, 255, 0.05);
    color: #cfd9ea; font-size: 20px; line-height: 1;
    -webkit-tap-highlight-color: transparent;
  }
  .cfm4-pane-shuffle {
    grid-column: 2; grid-row: 1 / span 2;
    align-self: center;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px;
    border-radius: 999px; border: 0;
    background: linear-gradient(180deg, #5aa0ff 0%, #2f7bff 100%);
    color: #061224;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 13px; letter-spacing: 0.14em;
    text-transform: uppercase; font-weight: 700;
    box-shadow: 0 6px 18px rgba(47, 123, 255, 0.32);
    -webkit-tap-highlight-color: transparent;
  }
  .cfm4-pane-shuffle svg { display: block; }
  .cfm4-pane-shuffle:active { transform: scale(0.97); }
  .cfm4-pane-body {
    flex: 1 1 auto;
    padding: 12px 14px 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .cfm4-pane-empty {
    padding: 32px 12px;
    text-align: center;
    color: #6c8ab8; font-size: 12px;
  }

  /* ── Clips pane grid ────────────────────────────────────────── */
  .cfm4-clip-actions {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 10px;
  }
  .cfm4-mini {
    appearance: none; border: 1px solid rgba(90, 160, 255, 0.25);
    background: rgba(14, 22, 40, 0.7); color: #cfd9ea;
    padding: 6px 12px; border-radius: 9px;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px; letter-spacing: 0.12em;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
  }
  .cfm4-mini:active { transform: scale(0.96); }
  .cfm4-clip-count {
    margin-left: auto;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px; color: #5aa0ff; letter-spacing: 0.06em;
  }
  .cfm4-clip-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .cfm4-clip {
    position: relative;
    appearance: none; border: 1.5px solid rgba(255, 255, 255, 0.06);
    background: #0a1120; color: #cfd9ea;
    padding: 0; overflow: hidden;
    border-radius: 12px;
    -webkit-tap-highlight-color: transparent;
    aspect-ratio: 9 / 12;
    display: flex; flex-direction: column;
    transition: border-color 180ms ease, transform 120ms ease, opacity 180ms ease;
  }
  .cfm4-clip:not(.is-on) { opacity: 0.4; }
  .cfm4-clip.is-on { border-color: rgba(90, 160, 255, 0.65); box-shadow: 0 0 14px -4px rgba(90, 160, 255, 0.5); }
  .cfm4-clip:active { transform: scale(0.96); }
  .cfm4-clip-thumb {
    display: block; flex: 1 1 auto;
    background: #050912; overflow: hidden;
    position: relative;
  }
  .cfm4-clip-thumb img {
    display: block; width: 100%; height: 100%;
    object-fit: cover;
  }
  .cfm4-clip-meta {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 8px 6px;
    font-family: "JetBrains Mono", monospace;
    font-size: 9px; letter-spacing: 0.06em;
    color: #8aa0c2;
  }
  .cfm4-clip-dur { color: #f1f5fb; }
  .cfm4-clip-tag { color: #5aa0ff; }
  .cfm4-clip-chk {
    position: absolute; top: 6px; right: 6px;
    width: 22px; height: 22px; border-radius: 50%;
    background: rgba(4, 6, 12, 0.7);
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    color: transparent;
    display: grid; place-items: center;
    transition: background 180ms ease, color 180ms ease;
  }
  .cfm4-clip.is-on .cfm4-clip-chk {
    background: #5aa0ff; border-color: #5aa0ff; color: #04060c;
  }

  /* ── Captions pane steps ────────────────────────────────────── */
  .cfm4-cap-steps {
    list-style: none; margin: 0; padding: 0;
    display: flex; flex-direction: column; gap: 8px;
  }
  .cfm4-cap-step {
    display: flex; align-items: center; gap: 12px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(14, 22, 40, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.06);
  }
  .cfm4-cap-num {
    flex: 0 0 28px;
    width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(90, 160, 255, 0.12);
    border: 1px solid rgba(90, 160, 255, 0.35);
    color: #5aa0ff;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 14px; letter-spacing: 0.05em;
  }
  .cfm4-cap-txt { flex: 1 1 auto; min-width: 0; }
  .cfm4-cap-h {
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 14px; letter-spacing: 0.06em; color: #f1f5fb;
  }
  .cfm4-cap-d {
    font-size: 10.5px; color: #8aa0c2; margin-top: 2px;
  }
  .cfm4-cap-btn {
    flex: 0 0 auto;
    appearance: none; border: 1px solid rgba(90, 160, 255, 0.4);
    background: rgba(90, 160, 255, 0.1); color: #5aa0ff;
    padding: 9px 14px; border-radius: 10px;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 13px; letter-spacing: 0.12em;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
    transition: transform 120ms ease, background 180ms ease, color 180ms ease;
  }
  .cfm4-cap-btn:active { transform: scale(0.96); }
  .cfm4-cap-btn.is-on {
    background: #5aa0ff; color: #04060c;
    border-color: #5aa0ff;
  }
  .cfm4-cap-btn--play {
    background: linear-gradient(180deg, #5aa0ff, #2f7bff);
    color: #04060c;
    border: 0;
    box-shadow: 0 8px 22px -8px rgba(90, 160, 255, 0.5);
  }
  .cfm4-cap-status {
    margin-top: 10px;
    padding: 8px 10px;
    background: rgba(14, 22, 40, 0.55);
    border-radius: 10px;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px; letter-spacing: 0.02em;
    color: #8aa0c2;
    min-height: 14px;
  }
  .cfm4-cap-step--full {
    flex-direction: column; align-items: stretch;
    gap: 10px;
  }
  .cfm4-cap-step--full .cfm4-cap-num { align-self: flex-start; }
  .cfm4-cap-tpl-row {
    display: flex; gap: 8px;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 4px 2px 8px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }
  .cfm4-cap-tpl-row::-webkit-scrollbar { display: none; }
  .cfm4-cap-tpl {
    flex: 0 0 auto;
    scroll-snap-align: start;
    appearance: none; border: 2px solid rgba(255, 255, 255, 0.08);
    background: rgba(14, 22, 40, 0.75);
    padding: 0; border-radius: 12px;
    overflow: hidden;
    min-width: 92px; height: 58px;
    display: grid; place-items: center;
    -webkit-tap-highlight-color: transparent;
    transition: transform 120ms ease, border-color 180ms ease;
  }
  .cfm4-cap-tpl:active { transform: scale(0.96); }
  .cfm4-cap-tpl.is-on {
    border-color: #5aa0ff;
    box-shadow: 0 0 0 2px rgba(90, 160, 255, 0.35);
  }
  .cfm4-cap-tpl-sample {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%; height: 100%;
    padding: 8px 12px;
    font-size: 14px;
    text-align: center;
    line-height: 1.05;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }
  .cfm4-cap-tpl-empty {
    padding: 12px; font-size: 11px;
    color: #6c8ab8; text-align: center; width: 100%;
  }

  /* ── Sheet-embedded action row (Analyze / Generate / Preview) ── */
  .cfm4-sheet-actions {
    display: grid; grid-template-columns: 1fr 1fr 1.25fr;
    gap: 8px;
    margin-top: 6px;
  }

  /* ── Btn ─────────────────────────────────────────────────────── */
  .cfm4-btn {
    appearance: none; -webkit-appearance: none;
    border: 0; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    padding: 12px 6px 10px;
    border-radius: 14px;
    background: rgba(14, 22, 40, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: #cfd9ea;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 14px; letter-spacing: 0.14em;
    text-transform: uppercase;
    line-height: 1;
    transition: transform 120ms ease, background 180ms ease, border-color 180ms ease, opacity 200ms ease;
  }
  .cfm4-btn:active:not([disabled]) { transform: scale(0.97); }
  .cfm4-btn.is-dim { opacity: 0.55; }
  .cfm4-btn[disabled] { opacity: 0.4; pointer-events: none; }
  .cfm4-btn-ic { width: 20px; height: 20px; margin-bottom: 2px; }
  .cfm4-btn.is-done {
    background: rgba(90, 160, 255, 0.08);
    border-color: rgba(90, 160, 255, 0.35);
    color: #5aa0ff;
  }
  .cfm4-btn.is-loading::before {
    content: ""; position: absolute; inset: 0;
    border-radius: 14px;
    background: linear-gradient(90deg, transparent, rgba(90, 160, 255, 0.20), transparent);
    background-size: 200% 100%;
    animation: cfm4Shim 1.2s linear infinite;
  }
  @keyframes cfm4Shim { from { background-position: 200% 0; } to { background-position: -200% 0; } }
  .cfm4-btn--play {
    background: linear-gradient(180deg, #5aa0ff, #2f7bff);
    color: #04060c;
    border: 0;
    box-shadow: 0 10px 26px -8px rgba(90, 160, 255, 0.55),
                0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  }
  .cfm4-btn--play[disabled] {
    background: #1a2438; color: #4a5b76; box-shadow: none;
  }
  .cfm4-btn--play.is-dim {
    background: linear-gradient(180deg, #2f4a80, #1e3766);
    color: #7a90b8; box-shadow: none;
    opacity: 1;
  }
  .cfm4-btn.is-pulse {
    animation: cfm4Pulse 1.4s ease-out 3;
  }
  @keyframes cfm4Pulse {
    0%   { box-shadow: 0 10px 26px -8px rgba(90, 160, 255, 0.55), 0 0 0 0   rgba(90, 160, 255, 0.55); }
    70%  { box-shadow: 0 10px 26px -8px rgba(90, 160, 255, 0.55), 0 0 0 14px rgba(90, 160, 255, 0); }
    100% { box-shadow: 0 10px 26px -8px rgba(90, 160, 255, 0.55), 0 0 0 0   rgba(90, 160, 255, 0); }
  }

  /* ── File pick sheet ────────────────────────────────────────── */
  #cfm4Veil {
    position: fixed; inset: 0;
    background: rgba(4, 6, 12, 0.7);
    backdrop-filter: blur(6px);
    z-index: 50;
    opacity: 0; pointer-events: none;
    transition: opacity 240ms ease;
  }
  #cfm4Veil.is-on { opacity: 1; pointer-events: auto; }

  #cfm4Sheet {
    position: fixed; left: 0; right: 0; bottom: 0;
    background: #08111e;
    border-top: 1px solid rgba(90, 160, 255, 0.25);
    border-radius: 24px 24px 0 0;
    z-index: 51;
    padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
    transform: translateY(120%);
    transition: transform 320ms cubic-bezier(.2,.9,.3,1);
    box-shadow: 0 -24px 60px -12px rgba(0, 0, 0, 0.75);
    max-height: 90dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #cfm4Sheet.is-on { transform: translateY(0); }

  /* Sheet-embedded overrides for chips + stats (originally lived in shell). */
  #cfm4Sheet .cfm4-durs {
    margin: 12px 0 8px;
  }
  #cfm4Sheet .cfm4-stats {
    padding: 0;
    margin: 0 0 12px;
  }
  .cfm4-grip {
    width: 40px; height: 4px;
    background: #2a334a; border-radius: 4px;
    margin: -2px auto 14px;
  }
  .cfm4-sheet-h {
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 22px; letter-spacing: 0.09em;
    text-align: center; margin: 0 0 4px; color: #f1f5fb;
  }
  .cfm4-sheet-sub {
    text-align: center; font-size: 11px; color: #6c8ab8;
    margin: 0 0 16px;
  }
  .cfm4-tile {
    display: flex; align-items: center; gap: 14px;
    background: rgba(14, 22, 40, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 14px 14px;
    color: #f1f5fb;
    margin-bottom: 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
  }
  .cfm4-tile:active { transform: scale(0.99); }
  .cfm4-tile.is-on {
    background: rgba(90, 160, 255, 0.08);
    border-color: rgba(90, 160, 255, 0.45);
  }
  /* the actual input sits invisibly inside the label — native tap flow */
  .cfm4-tile input[type="file"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer;
    font-size: 200px; /* keeps hit area full-tile on iOS */
  }
  .cfm4-tile-ic {
    width: 42px; height: 42px; flex: 0 0 42px;
    display: grid; place-items: center;
    border-radius: 12px;
    background: rgba(90, 160, 255, 0.10);
    border: 1px solid rgba(90, 160, 255, 0.35);
    color: #5aa0ff;
  }
  .cfm4-tile.is-on .cfm4-tile-ic { background: #5aa0ff; color: #04060c; }
  .cfm4-tile-body { flex: 1 1 auto; min-width: 0; }
  .cfm4-tile-t {
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 17px; letter-spacing: 0.06em;
    color: #f1f5fb;
  }
  .cfm4-tile-d {
    font-size: 11px; color: #8aa0c2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .cfm4-tile-chk {
    width: 22px; height: 22px; border-radius: 50%;
    border: 1.5px solid #2a334a;
    display: grid; place-items: center;
    color: #04060c; flex: 0 0 22px;
  }
  .cfm4-tile.is-on .cfm4-tile-chk { background: #5aa0ff; border-color: #5aa0ff; }
  .cfm4-sheet-cta {
    appearance: none; border: 0; width: 100%;
    margin-top: 4px;
    padding: 15px;
    border-radius: 14px;
    background: linear-gradient(180deg, #5aa0ff, #2f7bff);
    color: #04060c;
    font-family: "Bebas Neue", "Anton", sans-serif;
    font-size: 16px; letter-spacing: 0.16em;
    cursor: pointer;
    box-shadow: 0 10px 28px -8px rgba(90, 160, 255, 0.5);
  }
  .cfm4-sheet-cta[disabled] {
    background: #1a2438; color: #4a5b76; box-shadow: none; opacity: 0.55;
  }

  /* ── Toast ──────────────────────────────────────────────────── */
  #cfm4Toast {
    position: fixed; left: 50%;
    bottom: calc(96px + env(safe-area-inset-bottom));
    transform: translate(-50%, 10px);
    background: rgba(8, 12, 22, 0.95);
    border: 1px solid rgba(90, 160, 255, 0.35);
    color: #f1f5fb;
    padding: 8px 12px; border-radius: 11px;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px; letter-spacing: 0.04em;
    z-index: 60;
    opacity: 0; pointer-events: none;
    transition: opacity 200ms ease, transform 200ms ease;
    max-width: 84vw; text-align: center;
  }
  #cfm4Toast.is-on { opacity: 1; transform: translate(-50%, 0); }

  /* Modals stay above shell */
  body.cfm4-active #settings-modal,
  body.cfm4-active .sb-bt-modal,
  body.cfm4-active .sb-bt-feature-modal { z-index: 200 !important; }
  body.cfm4-active .sb-bt-media-modal {
    z-index: 200 !important;
    padding: 0 !important;
    align-items: flex-end !important;
  }
  body.cfm4-active .sb-bt-media-modal-panel {
    width: 100% !important; max-width: 100% !important;
    max-height: 92dvh !important;
    border-radius: 22px 22px 0 0 !important;
  }
}
