  :root { color-scheme: dark; --vw: 360px; --ta: 96px; }
  * { box-sizing: border-box; }
  [hidden] { display: none !important; }
  body { margin: 0; padding: 0; font-family: system-ui, sans-serif; background: #111; color: #eee; }

  /* Hides the page's own scroll bar while the Image tab is open.
     The page still scrolls with the mouse wheel or trackpad. */
  html.hide-page-bar { scrollbar-width: none; }
  html.hide-page-bar::-webkit-scrollbar { display: none; }

  /* Page content sits in .page, which provides the side and bottom padding. */
  .page { padding: 0 12px 12px; }

  /* Pinned block: header (tabs + title) and, on the Video tab, the toolbar.
     No negative margins or offsets, so it sits exactly at the top of the window. */
  .sticky-top { position: static; background: #111; padding: 12px 12px 0; }
  body.pin-header .sticky-top {
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 6px 12px -8px rgba(0,0,0,.8);
  }

  header {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    align-items: flex-end;
    border-bottom: 1px solid #333;
    margin-bottom: 10px;
  }
  .title {
    margin: 0 0 6px auto;
    font-family: "Bungee", "Impact", system-ui, sans-serif;
    font-size: 26px;
    letter-spacing: 1px;
    background: linear-gradient(90deg, #f6ad55, #ed64a6, #63b3ed);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    white-space: nowrap;
  }

  .tabs { display: flex; gap: 4px; margin-bottom: -1px; }
  .tab { background: transparent; border: 1px solid transparent; border-bottom: none; border-radius: 10px 10px 0 0; padding: 8px 18px; color: #999; }
  .tab.selected { background: #1a1a1a; border-color: #333; color: #fff; }
  .panel[hidden], .toolbar[hidden] { display: none; }

  .controls-right { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
  .group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  input, textarea, select, button { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid #444; background: #1c1c1c; color: #eee; }
  input[type=number] { width: 80px; }
  #newName { width: 150px; }
  textarea { width: 100%; min-height: var(--ta); resize: vertical; }
  button { cursor: pointer; }
  button:disabled { opacity: .4; cursor: default; }
  .primary { background: #2b6cb0; border-color: #2b6cb0; }
  .ok { background: #2f855a; border-color: #2f855a; }
  .warn { background: #9c4221; border-color: #9c4221; }
  .omit { background: #4a4a4a; border-color: #5a5a5a; }
  .active { outline: 2px solid #fff; outline-offset: 2px; }
  .sizer { display: flex; align-items: center; gap: 6px; }
  .sizer button { padding: 4px 12px; font-size: 18px; line-height: 1; }
  .sizer span { font-size: 13px; color: #aaa; min-width: 70px; text-align: center; }
  .spacer { flex: 1; }

  .toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding-bottom: 10px; }
  .toolbar .controls-right { margin-left: auto; }

  /* video rows */
  .row { display: grid; grid-template-columns: 1fr var(--vw); gap: 12px; background: #1a1a1a; border: 1px solid #333; border-radius: 12px; padding: 12px; margin-bottom: 12px; }
  @media (max-width: 760px) {
    .row { grid-template-columns: 1fr; }
    .out { width: 100%; }
  }
  .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 8px; }
  .badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #333; }
  .gentime { font-size: 12px; color: #9ac; margin-left: 6px; }
  .bar { height: 10px; background: #333; border-radius: 6px; overflow: hidden; margin: 8px 0; }
  .bar > div { height: 100%; width: 0; background: #4299e1; transition: width .4s; }
  .out { width: 100%; border: 1px dashed #444; border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center; min-height: calc(var(--vw) * 0.5625); }
  video { width: 100%; border-radius: 8px; background: #000; }
  .frames { display: flex; gap: 10px 16px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
  .fthumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; background: #000; border: 1px solid #333; }
  .muted { color: #888; font-size: 14px; }
  .err { color: #f88; font-size: 13px; }
  .notice { background: #3d2e10; border: 1px solid #7a5a1a; color: #f6d28b; border-radius: 10px; padding: 8px 12px; font-size: 14px; margin-bottom: 10px; }

  /* Approved clips: the left-hand fields are covered with a light grey mask.
     The mask ignores clicks, so the fields can still be changed if needed.
     The video and the Approve/Redo buttons stay fully visible. */
  .row .fields { position: relative; }
  .row.omitted .fields { opacity: .55; }
  .row.approved .fields::after {
    content: "✓ Approved";
    position: absolute;
    inset: 0;
    background: rgba(170, 170, 170, 0.28);
    border-radius: 8px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 6px;
    box-sizing: border-box;
    pointer-events: none;
    color: #f2f2f2;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .3px;
  }

  /* Approve / Redo / Omit and the take strip sit on one line; the strip wraps below if space is tight. */
  .decide { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; width: 100%; }
  .decide-btns { display: flex; gap: 8px; flex: 0 0 auto; flex-wrap: wrap; justify-content: center; }
  .takes { flex: 1 1 180px; min-width: 0; flex-direction: column; gap: 4px; }
  .takes-nav { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #aaa; justify-content: center; }
  .takes-nav button { padding: 2px 8px; font-size: 13px; line-height: 1.2; }
  .strip { display: flex; gap: 6px; overflow-x: auto; padding: 2px; scrollbar-width: none; -ms-overflow-style: none; }
  .strip::-webkit-scrollbar { display: none; }
  .tile { width: 72px; height: 42px; flex: 0 0 auto; object-fit: cover; border-radius: 6px; border: 2px solid transparent; background: #000; cursor: pointer; }
  .tile:hover { border-color: #777; }

  /* lip-sync audio line under each clip's frames */
  .audio-line { margin-top: 8px; }
  .audio-name { font-size: 12px; color: #9ac; }
  .music-toggle { font-size: 13px; color: #ccc; display: flex; gap: 6px; align-items: center; }

  /* split audio review window: fills the screen width, leaving a small margin */
  .modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    z-index: 50;
  }
  .modal-card {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 14px;
    width: calc(100vw - 24px);
    max-width: none;
    max-height: calc(100vh - 24px);
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .split-form { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
  .split-form input[type=number] { width: 80px; }
  .split-form label { font-size: 13px; color: #aaa; display: flex; gap: 6px; align-items: center; }
  .split-status { font-size: 13px; min-height: 16px; }
  #splitWave {
    width: 100%;
    height: clamp(160px, 42vh, 380px);
    background: #000;
    border-radius: 8px;
    border: 1px solid #333;
    cursor: ew-resize;
    touch-action: none;
  }
  .split-hint { font-size: 13px; min-height: 18px; color: #9ac; }
  .split-note { font-size: 13px; min-height: 16px; color: #f6d28b; }
  .split-list { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; min-height: 160px; max-height: 55vh; overflow: auto; }
  .split-piece {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 6px 8px;
    border-radius: 8px;
    background: #222;
    border: 1px solid #333;
    font-size: 13px;
    cursor: pointer;
  }
  .split-piece:hover { border-color: #555; }
  .split-piece.bad { border-color: #9c4221; }
  .split-piece .sp-clip { min-width: 70px; color: #ddd; }
  .split-piece .sp-time { color: #9ac; }
  .split-piece .sp-note { color: #f6d28b; font-size: 12px; margin-left: auto; }
  .split-buttons { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

  /* image tab */
  .img-layout { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(300px, 2fr); gap: 16px; align-items: start; }
  @media (max-width: 860px) { .img-layout { grid-template-columns: 1fr; } }
  .img-box { background: #1a1a1a; border: 1px solid #333; border-radius: 12px; padding: 12px; margin-bottom: 12px; }
  .img-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
  .thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
  .thumb { position: relative; width: 90px; }
  .thumb img { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; display: block; background: #000; }
  .thumb .x { position: absolute; top: 4px; right: 4px; padding: 0 6px; line-height: 18px; font-size: 14px; border-radius: 6px; background: rgba(0,0,0,.7); border: none; color: #fff; }
  .thumb .n { font-size: 12px; text-align: center; color: #888; margin-top: 2px; }

  /* viewer with zoom and drag-to-pan; scroll bars hidden, scrolling still works.
     Its height is set by JavaScript so the whole Image tab fits the window. */
  .zoombar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
  .zoombar button { padding: 4px 12px; font-size: 16px; line-height: 1; }
  .zoombar span { font-size: 13px; color: #aaa; min-width: 60px; text-align: center; }
  .viewer {
    position: relative;
    border: 1px dashed #444;
    border-radius: 12px;
    height: 60vh;
    min-height: 260px;
    overflow: auto;
    background: #000;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .viewer::-webkit-scrollbar { display: none; }
  .viewer.pannable { cursor: grab; touch-action: none; user-select: none; }
  .viewer.dragging { cursor: grabbing; }
  .viewer img { display: block; margin: 0 auto; width: 100%; height: auto; -webkit-user-drag: none; }
  .viewer .empty { padding: 120px 0; text-align: center; }

  /* prompt used for the selected image */
  .prompt-info {
    margin-top: 8px;
    padding: 8px 10px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 10px;
  }
  .prompt-info[hidden] { display: none; }
  .prompt-text { white-space: pre-wrap; word-wrap: break-word; font-size: 13px; line-height: 1.4; max-height: 72px; overflow-y: auto; }
  .prompt-meta { margin-top: 4px; font-size: 12px; color: #888; }

  /* history strip: full width, fixed height, scrolls sideways inside itself */
  .hist {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 12px;
    padding: 8px;
    height: 118px;
    overflow-x: auto;
    overflow-y: hidden;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    user-select: none;
  }
  .hist::-webkit-scrollbar { display: none; }
  .hist.dragging { cursor: grabbing; }
  .hist .hitem { position: relative; width: 90px; height: 90px; flex: 0 0 auto; }
  .hist .hitem img {
    width: 90px;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    display: block;
    -webkit-user-drag: none;
  }
  .hist .hitem img.active { border-color: #fff; }
  .hist .hdel {
    position: absolute;
    top: 4px;
    right: 4px;
    padding: 0 6px;
    line-height: 18px;
    font-size: 14px;
    border-radius: 6px;
    background: rgba(0,0,0,.7);
    border: none;
    color: #fff;
  }
  .hist .hdel:hover { background: #9c4221; }
  .hist .hint { align-self: center; color: #666; font-size: 13px; padding: 0 8px; }

  /* text tab: a main workspace on the left and a catalogue on the right.
     The left box is three times as wide as the right one. Both boxes share one height. */
  .text-layout {
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 16px;
    height: 480px;                 /* replaced by JavaScript to fill the window */
    min-height: 360px;
  }
  @media (max-width: 760px) {
    .text-layout { grid-template-columns: 1fr; height: auto; }
    .text-box { min-height: 320px; }
    .text-box .box-body { max-height: 60vh; }   /* on narrow screens the box still scrolls, not the page */
  }
  .text-box {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }
  .text-box .box-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }
  .subtabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid #333;
    margin-bottom: 10px;
    flex: 0 0 auto;
  }
  .subtab {
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    padding: 6px 14px;
    color: #999;
    font-size: 14px;
    margin-bottom: -1px;
  }
  .subtab.selected { background: #262626; border-color: #333; color: #fff; }
  .box-placeholder { color: #777; font-size: 14px; }
  .box-title { font-size: 13px; color: #aaa; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .6px; }

  /* News: the box body becomes a column so the text field can fill the box */
  #catalogBox.news-mode .box-body { display: flex; flex-direction: column; overflow: hidden; }
  #catalog-news { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
  #newsText {
    flex: 1 1 auto;
    min-height: 240px;
    resize: none;
    line-height: 1.45;
    font-size: 14px;
  }
  #dazzleBtn {
    flex: 0 0 auto;
    width: 100%;
    padding: 12px;
    font-size: 16px;
    font-weight: 600;
    background: #2b6cb0;
    border-color: #2b6cb0;
  }

  /* Characters catalogue: a large + box, then a scrolling list of character rows */
  .char-add {
    width: 100%;
    height: 84px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #161616;
    border: 2px dashed #444;
    border-radius: 12px;
    color: #ccc;
    font-size: 40px;
    line-height: 1;
  }
  .char-add:hover { border-color: #777; color: #fff; }
  .char-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px;
    margin-bottom: 8px;
    background: #222;
    border: 1px solid #333;
    border-radius: 10px;
    cursor: pointer;
  }
  .char-row:hover { border-color: #555; }
  .char-row.archived { opacity: .45; filter: grayscale(1); }
  .char-thumb {
    width: 52px;
    height: 52px;
    flex: 0 0 auto;
    object-fit: cover;
    border-radius: 8px;
    background: #000;
  }
  .char-phold {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: #888;
    background: #2a2a2a;
  }
  .char-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
  .char-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .char-info .badge { align-self: flex-start; margin-top: 2px; }

  .char-form { display: flex; flex-direction: column; gap: 10px; }
  .char-form input, .char-form textarea { width: 100%; }
  .char-form textarea { min-height: 64px; }
  .char-top { display: flex; gap: 12px; align-items: flex-start; }
  .char-imgbox {
    width: 110px;
    height: 110px;
    flex: 0 0 auto;
    border: 2px dashed #444;
    border-radius: 10px;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    color: #888;
    font-size: 14px;
  }
  .char-imgbox img { width: 100%; height: 100%; object-fit: cover; }
  .char-top-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
  .cf { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #aaa; }
  .char-buttons {
    position: sticky;
    bottom: 0;
    background: #1a1a1a;
    border-top: 1px solid #333;
    padding: 10px 0 0;
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  /* Theatre: main player fills the space; a timeline of approved clips sits below */
  .theatre-stage { position: relative; background: #000; border: 1px solid #333; border-radius: 12px; height: calc(100vh - 220px); min-height: 280px; display: flex; align-items: center; justify-content: center; }
  .theatre-stage video { width: 100%; height: 100%; object-fit: contain; border-radius: 12px; }
  .theatre-empty { position: absolute; }
  .theatre-bar { display: flex; gap: 12px; align-items: center; margin: 12px 0 8px; }
  .theatre-timeline { display: flex; gap: 8px; overflow-x: auto; padding: 8px; background: #1a1a1a; border: 1px solid #333; border-radius: 12px; }
  .theatre-clip { flex: 0 0 auto; width: 150px; background: #222; border: 2px solid #333; border-radius: 8px; padding: 4px; cursor: pointer; text-align: center; user-select: none; }
  .theatre-clip video { width: 100%; height: 84px; object-fit: cover; border-radius: 6px; pointer-events: none; }
  .theatre-clip.picked { border-color: #63b3ed; }
  .theatre-clip .tc-label { font-size: 12px; color: #ccc; margin-top: 4px; }

  /* Info button and project metrics window */
  .info-btn { width: 30px; height: 30px; padding: 0; border-radius: 50%; font-weight: 700; font-family: Georgia, serif; font-style: italic; }
  .metrics-card { width: min(760px, calc(100vw - 24px)); }
  .metrics-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
  .metrics-stat { background: #222; border: 1px solid #333; border-radius: 10px; padding: 8px 10px; }
  .metrics-stat .ms-label { font-size: 12px; color: #888; }
  .metrics-stat .ms-value { font-size: 18px; color: #eee; margin-top: 2px; }
  .metrics-head, .metrics-row { display: grid; grid-template-columns: 1.1fr 1fr 1fr 2fr; gap: 8px; align-items: center; font-size: 13px; }
  .metrics-head { color: #888; padding: 4px 8px; border-bottom: 1px solid #333; }
  .metrics-list { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow: auto; }
  .metrics-row { padding: 6px 8px; background: #222; border: 1px solid #333; border-radius: 8px; }
  .metrics-row.shown { border-color: #63b3ed; }
  .metrics-row .mr-inst b { color: #fff; }
  .metrics-row .mr-inst .muted { font-size: 12px; margin-left: 4px; }
  /* Star rating for the take on screen */
  .stars { display: flex; gap: 2px; align-items: center; justify-content: center; margin: 4px 0; }
  .stars button { background: transparent; border: none; padding: 0 2px; font-size: 20px; line-height: 1; color: #666; cursor: pointer; }
  .stars button.on { color: #f6d28b; }
  .stars button:disabled { opacity: .4; cursor: default; }
  /* Per-GPU time breakdown in the metrics window */
  .gpu-times { display: flex; flex-direction: column; gap: 4px; }
  .gpu-time-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 8px; align-items: center; font-size: 13px; padding: 6px 8px; background: #222; border: 1px solid #333; border-radius: 8px; }
  .gpu-time-row.blank { border-style: dashed; color: #aaa; }
  .gpu-time-head { color: #888; font-size: 12px; padding: 0 8px; }
  .metrics-section-title { font-size: 13px; color: #aaa; margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .6px; }
  /* Saved skit viewer */
  .skit-card { width: min(900px, calc(100vw - 24px)); }
  .skit-body { display: flex; flex-direction: column; gap: 10px; overflow: auto; max-height: 70vh; }
  .skit-bit { background: #222; border: 1px solid #333; border-radius: 10px; padding: 10px 12px; }
  .skit-bit h3 { margin: 0 0 4px; font-size: 16px; }
  .skit-meta { font-size: 12px; color: #9ac; margin-bottom: 6px; }
  .skit-news { font-size: 13px; color: #bbb; margin-bottom: 8px; line-height: 1.4; }
  .skit-beat { display: grid; grid-template-columns: 40px 60px 1fr; gap: 8px; font-size: 13px; padding: 6px 0; border-top: 1px solid #2c2c2c; }
  .skit-beat .sb-dur { color: #9ac; }
  .skit-beat .sb-dia { color: #f6d28b; font-style: italic; margin-top: 3px; }
  /* ===== Video toolbar (final) ===== */
  .toolbar { display: flex; flex-direction: column; gap: 8px; align-items: stretch; padding: 0 0 4px; margin: 0; }
  .tb-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .tb-summary { flex: 1 1 auto; min-width: 0; }

  /* Three cards in a row. Stretch makes them all as tall as the tallest one (Project). */
  .tb-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; align-items: stretch; }
  .tb-card {
    border: 1px solid #f6ad55;
    box-shadow:
        0 0 0 1px rgba(246,173,85,.25),
        0 0 0 2px rgba(237,100,166,.15),
        0 0 0 3px rgba(99,179,237,.10);
}
  .tb-card legend {
    background: linear-gradient(90deg, #f6ad55, #ed64a6, #63b3ed);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
  .tb-card > .tb-row { flex: 0 0 auto; }
  .tb-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
  .tb-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  .tb-field > span { font-size: 11px; color: #888; }
  .tb-field.tb-grow { flex: 1 1 160px; }
  .tb-field.tb-name { flex: 1 1 140px; }
  .tb-field.tb-count { flex: 0 0 80px; }
  .tb-field.tb-end { flex: 0 0 auto; }
  .tb-field select, .tb-field input[type=text] { width: 100%; }
  .tb-field input[type=number] { width: 90px; }
  .tb-field.tb-count input { width: 80px; }
  #newName { width: 100%; }
  #project { max-width: 100%; }
  #runpodUrl { width: 100%; }
  .tb-check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #ccc; padding-bottom: 9px; }
  .tb-runpod { width: 100%; margin-top: 8px; }
  .tb-runpod summary { cursor: pointer; font-size: 13px; color: #aaa; padding: 2px 0; }
  .tb-runpod[open] summary { margin-bottom: 8px; }
  .tb-card .sizer span { min-width: 60px; }

  /* Tighten the space between the toolbar and the first clip */
  .page { padding-top: 0; }
  #rows { margin-top: 0; }
  .plus-slot { display: flex; justify-content: center; align-items: center; height: 22px; margin: 0; }
  .plus-slot .plus-btn { padding: 2px 10px; line-height: 1; }

  .tb-card > .tb-row { flex: 0 0 auto; }

  /* Remove the space between the toolbar and the first clip */
  .toolbar { padding: 0; margin: 0 0 0 0; height: auto; }
  .sticky-top { padding-bottom: 0; }
  .page { padding-top: 0; }
  #videoControls { margin: 0; }
  #rows { margin-top: 0; padding-top: 0; }
  #rows > .plus-slot:first-child { height: 14px; margin: 0; }

  /* Narrow screens: cards stack and size to their contents */
  @media (max-width: 760px) {
    .tb-panels { grid-auto-rows: auto; }
    .tb-card { height: auto; overflow: visible; }
  }

  .toolbar, #videoBar { height: auto !important; min-height: 0 !important; flex: 0 0 auto; }
  .sticky-top { height: auto; min-height: 0; }
  #rows { margin-top: 0 !important; }
  @media (max-width: 760px) {
    .tb-panels { grid-auto-rows: auto; }
    .tb-card { height: auto; }
  }
  /* Collapse empty banner and any spacing above the first clip */
  #banner:empty { display: none; }
  #rows { margin: 0 !important; padding: 0 !important; }
  #rows > .plus-slot:first-child { margin: 0 !important; padding: 0 !important; }
#videoBar {
    display: block;
}

#videoControls {
    flex: none;
}
  
  /* Project, Generation and the Tools/Account wrapper: three equal columns */
  #videoControls { grid-template-columns: repeat(3, 1fr); }
  #videoControls > .tb-card:nth-child(n+3) { width: auto; flex: initial; }

  /* Tools and Account split the third column in half */
  .tb-side { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-width: 0; }
  .tb-side > .tb-card { min-width: 0; height: 100%; }

  #rpBalance { font-size: 20px; color: #eee; }

  /* About window */
  .about-card { width: min(520px, calc(100vw - 24px)); align-items: stretch; }
  .about-hero {
    font-family: "Bungee", "Impact", system-ui, sans-serif;
    font-size: 44px;
    letter-spacing: 2px;
    text-align: center;
    padding: 24px 0 16px;
    background: linear-gradient(90deg, #f6ad55, #ed64a6, #63b3ed);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
  .about-section { border-top: 1px solid #333; padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
  .about-row { display: flex; justify-content: space-between; font-size: 14px; color: #aaa; }
  .about-row b { color: #eee; font-weight: 600; }
  .about-copy { font-size: 12px; color: #888; text-align: center; margin-top: 12px; }

  .about-slogan { font-size: 14px; color: #aaa; text-align: center; font-style: italic; margin: -8px 0 12px; }

  .about-link { color: #63b3ed; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
  .changelog { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid #333; padding-top: 12px; }
  .changelog-head { display: flex; justify-content: space-between; align-items: center; }
  .changelog-body { max-height: 45vh; overflow-y: auto; font-size: 13px; color: #ccc; line-height: 1.5; padding-right: 6px; }
  .changelog-body h4 { margin: 12px 0 4px; font-size: 14px; color: #eee; }
  .changelog-body ul { margin: 0 0 6px; padding-left: 20px; }

  /* Generation group: seed and duration in their own labelled box */
  .gen-group { border: 1px solid #333; border-radius: 10px; background: #161616; padding: 6px 10px 8px; margin-top: 8px; }
  .gen-label { display: block; font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 4px; }
  .gen-row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
  .gen-field { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: #ccc; }
  .gen-field input[type=number] { width: 110px; }
  .gen-inline { display: flex; gap: 8px; align-items: center; }

  /* Clip fields in four columns */
  .clip-cols { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
  .clip-col { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; min-width: 0; }
  .clip-col > label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: #ccc; width: 100%; }
  .clip-col input[type=number] { width: 100%; }
  .clip-col input[type=file] { width: 100%; font-size: 12px; }
  .frame-preview { display: flex; align-items: center; gap: 8px; }
  @media (max-width: 900px) { .clip-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @media (max-width: 560px) { .clip-cols { grid-template-columns: 1fr; } }

  .clip-col:nth-child(4) .frame-preview { min-height: 48px; }

  /* Project metrics: wider window, GPU rows kept on one line */
  .metrics-card { width: min(1000px, calc(100vw - 24px)); }
  .gpu-time-row { grid-template-columns: minmax(220px, 3fr) minmax(90px, 1fr) minmax(70px, 1fr) minmax(110px, 1.5fr); white-space: nowrap; }
  .gpu-time-row b { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .metrics-head, .metrics-row { grid-template-columns: 1.1fr 1fr 1fr 2fr; }
  /* Instance list: GPU column takes most of the width and stays on one line */
  .metrics-head, .metrics-row { grid-template-columns: minmax(90px, 1fr) minmax(70px, .8fr) minmax(70px, .8fr) minmax(0, 3.5fr); }
  .metrics-row > div:last-child, .metrics-head > span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  /* Project metrics: narrower window, fixed-width columns with the GPU name taking the rest */
  .metrics-card { width: min(880px, calc(100vw - 24px)); }
  .metrics-head, .metrics-row { grid-template-columns: 90px 110px 110px minmax(0, 1fr); }

  /* Head row: keep String Together, the × button, and the Approved badge apart */
  .row .head { flex-wrap: wrap; row-gap: 6px; }
  .row .head > span:first-child { flex: 1 1 auto; min-width: 0; }
  .row .head .string-btn { flex: 0 0 auto; }
  .row .head .x-btn { flex: 0 0 auto; }
  .row.approved .fields::after {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    padding: 6px 10px;
    justify-content: flex-end;
    align-items: flex-end;
  }

  /* Remove the Approved overlay: its status already shows in the clip header */
  .row.approved .fields::after { content: none; }

  /* Tighter clips: less padding, smaller prompt box, closer spacing between sections */
  .row { padding: 10px; margin-bottom: 8px; }
  .row textarea { min-height: 64px; }
  .row .head { margin-bottom: 4px; }
  .row .clip-cols { margin-top: 6px; gap: 8px; }
  .row .bar { margin: 6px 0; }
  .frame-preview { min-height: 0; }
  .clip-col:nth-child(4) .frame-preview { min-height: 0; }

  /* Fill the clip's height: the prompt box grows, pushing the fields below it down */
  .row .fields { display: flex; flex-direction: column; }
  .row .fields > textarea { flex: 1 1 auto; min-height: 64px; }
  .row .fields > .bar { margin-top: auto; }

  /* Clip status label: colour matches the decision button */
  .badge.st-approved { background: #2f855a; color: #fff; }
  .badge.st-redo { background: #9c4221; color: #fff; }
  .badge.st-omitted { background: #4a4a4a; color: #eee; }

  /* String Together: grey when off, gold when on */
  .string-btn.ok { background: #d4a93c; border-color: #f0c75e; color: #111; font-weight: 600; }
  .string-btn:disabled { opacity: .4; }

  /* Card titles: solid background so the border doesn't cut through the text */
  .tb-card legend {
    background: #161616;
    color: #f6ad55;
    -webkit-background-clip: border-box;
    background-clip: border-box;
    padding: 0 6px;
    margin-left: 10px;
  }

  /* Card outline: one clean orange line, no pink or blue rings */
  .tb-card { box-shadow: none; }

  .about-cta { font-size: 14px; color: #f6ad55; text-align: center; margin-top: 12px; }

  .chart-toggle { display: flex; gap: 6px; margin: 6px 0 8px; flex-wrap: wrap; }
  .chart-toggle button { padding: 4px 12px; font-size: 13px; }
  .chart-toggle button.on { background: #f6ad55; border-color: #f6ad55; color: #111; font-weight: 600; }
  .chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: #ccc; margin-bottom: 6px; }
  .chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
  .chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
  .chart-wrap { background: #161616; border: 1px solid #333; border-radius: 10px; padding: 8px; }
  .chart-svg { width: 100%; height: 260px; display: block; }

  /* Metrics modal: scrolls as a whole; the instance list gets more room */
  .metrics-card { max-height: calc(100vh - 24px); overflow-y: auto; }
  .metrics-list { max-height: 60vh; }
  .metrics-row { padding: 8px 10px; }

  .chart-legend span { cursor: pointer; user-select: none; }
  .chart-legend span.off { opacity: .35; text-decoration: line-through; }

  #rpTimeLeft { font-size: 20px; color: #eee; }

  #estTime.est-over { color: #ff3b3b; font-weight: 600; }

  /* Project footer: budget and cost per approved minute */
  .proj-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
  .pf-card { background: #161616; border: 1px solid #f6ad55; border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .pf-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: .6px; }
  .pf-value { font-size: 24px; color: #eee; }
  .pf-sub { font-size: 12px; }
  @media (max-width: 560px) { .proj-footer { grid-template-columns: 1fr; } }

  /* Generation card: pin the estimate to the bottom-right so the row doesn't shift */
  .tb-card:has(#estTime) { position: relative; padding-bottom: 28px; }
  .tb-card:has(#estTime) .est-anchor {
    position: absolute;
    right: 12px;
    bottom: 8px;
    text-align: right;
    max-width: 60%;
  }
  .est-anchor .tb-field > span { text-align: right; }

  /* Footage figures: small, right-aligned in the top-right of the Account card */
  .tb-card:has(#fp10) { position: relative; }
  .footage-corner {
    position: absolute;
    top: 8px;
    right: 12px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 12px;
    color: #aaa;
    text-align: right;
  }
  .footage-corner span { white-space: nowrap; }

  /* Characters tab: list | fields | full-size image */
  .char-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) minmax(280px, 1fr);
    gap: 16px;
    height: calc(100vh - 170px);
    min-height: 480px;
  }
  .char-col {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 12px;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
  }
  .char-placeholder {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 20px;
    letter-spacing: .5px;
  }
  .char-form { display: flex; flex-direction: column; gap: 10px; }
  .char-form input, .char-form textarea { width: 100%; }
  .char-form textarea { min-height: 72px; }
  .char-imgbox-full {
    width: 100%;
    height: 100%;
    min-height: 360px;
    flex: 1 1 auto;
    background: #000;
  }
  .char-imgbox-full img { object-fit: contain; }
  @media (max-width: 1000px) {
    .char-layout { grid-template-columns: 1fr; height: auto; }
    .char-col { min-height: 280px; }
    .char-imgbox-full { min-height: 320px; }
  }

  .run-timer { font-size: 12px; color: #f6ad55; font-variant-numeric: tabular-nums; margin-left: 4px; }

  .slot-title { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }
  .slot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .slot-grid.img-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .slot { background: #161616; border: 1px dashed #444; border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: #aaa; min-width: 0; }
  .slot.filled { border-style: solid; border-color: #555; }
  .slot-head { color: #888; }
  .slot-thumb { width: 100%; height: 48px; }
  .slot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 14px; }
  .slot-btns { display: flex; gap: 4px; align-items: center; }
  .slot-pick { font-size: 11px; padding: 3px 6px; border: 1px solid #444; border-radius: 6px; cursor: pointer; background: #1c1c1c; }
  .slot-x { padding: 2px 6px; font-size: 12px; }

  /* Clip layout: prompt | reference images | seed/duration, videos, audio, music */
  .clip-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-top: 6px; align-items: stretch; }
  .cg-prompt { display: flex; min-width: 0; }
  .cg-prompt textarea { flex: 1 1 auto; height: 100%; min-height: 160px; }
  .cg-images, .cg-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .cg-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; align-items: end; }
  .cg-top label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: #ccc; }
  .cg-top input[type=number] { width: 100%; }
  .cg-seed { display: flex; flex-direction: column; gap: 4px; }
  @media (max-width: 1100px) {
    .clip-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .cg-prompt { grid-column: 1 / -1; }
  }
  @media (max-width: 700px) { .clip-grid { grid-template-columns: 1fr; } }

  .slot-grid.three-up { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .slot-grid.three-up .slot { padding: 3px; font-size: 10px; }
  .slot-grid.three-up .slot-btns { flex-direction: column; align-items: stretch; }

  .clip-grid { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr) minmax(0, 1.3fr); }
  .slot-grid.three-up .slot-btns { flex-direction: row; align-items: center; }
  .slot-grid.three-up .slot-pick { flex: 1 1 auto; text-align: center; }
  .slot-grid.three-up .slot-x { flex: 0 0 auto; }
  .slot-grid.three-up .slot:not(:has(.slot-thumb)) { min-height: 96px; justify-content: space-between; }

  .cg-images .cg-top { margin-top: 8px; }
  .clip-grid { align-items: start; }

  .slot-grid.three-up .slot:not(:has(.slot-thumb)) { min-height: 0; justify-content: flex-start; padding: 4px; gap: 4px; }
  .slot-grid.three-up .slot-name { min-height: 12px; }
  .slot-grid.three-up .slot-btns { margin-top: auto; }
  .slot-grid.img-grid .slot { min-height: 0; }

  /* Help window */
  .help-card { width: min(760px, calc(100vw - 24px)); }
  .help-body { overflow-y: auto; max-height: 65vh; display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: #ccc; line-height: 1.5; padding-right: 6px; }
  .help-body h4 { margin: 14px 0 2px; color: #f6ad55; font-size: 15px; }
  .help-body h4:first-child { margin-top: 4px; }
  .help-body ul { margin: 0 0 4px; padding-left: 20px; }
  .help-body li { margin-bottom: 3px; }
  .help-body code { background: #222; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
  .help-table-wrap { overflow-x: auto; flex: 0 0 auto; }
  .help-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .help-table th, .help-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #333; }
  .help-table th { color: #888; font-weight: 600; }
  .help-note { font-size: 12px; color: #888; margin: 4px 0 0; }

  .mention-menu { position: fixed; z-index: 60; background: #1c1c1c; border: 1px solid #444; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.6); padding: 4px; min-width: 200px; max-height: 240px; overflow-y: auto; }
  .mention-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; color: #ddd; }
  .mention-item.on { background: #2b6cb0; color: #fff; }
  .mention-thumb { width: 24px; height: 24px; border-radius: 4px; object-fit: cover; background: #000; }

  .cg-side > .cg-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; align-items: start; }
  .cg-side > .cg-top > .cg-seed,
  .cg-side > .cg-top > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #ccc; min-width: 0; }
  .cg-side > .cg-top input[type=number] { width: 100%; min-width: 0; }
  .cg-side > .cg-top .lock-btn { width: 100%; }
  /* Hosted-only helpers */
  .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: #666; flex: 0 0 auto; }
  .dot.green { background: #48bb78; box-shadow: 0 0 8px #48bb78; }
  .dot.red { background: #f56565; box-shadow: 0 0 8px #f56565; }
  .cap-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #ccc; min-height: 20px; }
  .who { font-size: 13px; color: #aaa; align-self: center; }
  #signoutBtn { padding: 4px 10px; font-size: 13px; align-self: center; }
  .signed-out .needs-auth { display: none !important; }
  .signed-out .needs-auth-off { opacity: .4; pointer-events: none; }
  #signinPanel { padding: 12px 12px 0; }
  .signin-form .tb-card { max-width: 420px; }
  .empty-note { padding: 24px; color: #888; font-size: 14px; }
  .slot-thumb { width: 100%; height: 48px; object-fit: cover; }
  .slot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 14px; }
  .media { position: relative; width: 100%; min-height: 120px; background: #000; border-radius: 8px; overflow: hidden; }
  .media img, .media video { display: block; width: 100%; height: auto; }
  .media.busy img { opacity: .4; }
  .spin { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; width: 40px; height: 40px; border: 4px solid #444; border-top-color: #f6ad55; border-radius: 50%; animation: gt-spin .9s linear infinite; box-sizing: border-box; }
  @keyframes gt-spin { to { transform: rotate(360deg); } }
  .take-strip { display: flex; gap: 6px; overflow-x: auto; width: 100%; }
  .take-strip:empty { display: none; }
  .take-item { position: relative; flex: 0 0 auto; width: 72px; padding: 2px; border: 2px solid transparent; border-radius: 6px; background: #000; cursor: pointer; }
  .take-item.sel { border-color: #fff; }
  .take-item img { display: block; width: 100%; height: 42px; object-fit: cover; border-radius: 4px; background: #111; }
  .take-item .tl { font-size: 10px; color: #ccc; text-align: center; }
  .take-item .ap { position: absolute; top: 3px; left: 3px; background: #2f855a; color: #fff; font-size: 9px; padding: 1px 4px; border-radius: 4px; }
