/* ==========================================================================
   Templates + effects studios (design-studios.js).
   Same chrome as the subtitles / flicker windows: icon header, grey body
   holding white card panels, footer pinned under them. The height is
   DEFINITE, so switching a tab or a template never moves the frame.
     wide project  : gallery | preview over settings
     tall (9:16)   : gallery | settings | full-height preview
     phone         : bottom sheet, preview pinned on top, gallery as a strip
   ========================================================================== */
.modal.modal-lg:has(.design-studio),
.modal:has(.design-studio) {
  display: flex;
  flex-direction: column;
  width: min(1180px, 96vw);
  max-width: min(1180px, 96vw);
  height: min(92vh, 900px);
  max-height: min(92vh, 900px);
  padding: 0;
  overflow: hidden;
}

.design-studio {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  direction: rtl;
  text-align: right;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}

/* .btn and .ds-toggle are display:flex, which beats the browser's [hidden]. */
.design-studio [hidden] {
  display: none !important;
}

/* ── Header ── */
.ds-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px 11px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
}
.ds-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.ds-title-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
}
.ds-title-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ds-title-copy h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}
.ds-title-copy p {
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-3);
}
.ds-header .modal-close {
  flex-shrink: 0;
}

/* ── Body: card panels on the grey sheet ──
   Preview over the gallery on one side, the settings a full-height column
   on the other - settings squeezed under the preview meant scrolling for
   every change. */
.ds-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "stage panel"
    "gallery panel";
  gap: 12px;
  padding: 12px;
  overflow: hidden;
  background: var(--surface-2);
}
.ds-stage,
.ds-gallery,
.ds-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

/* Preview */
.ds-stage {
  grid-area: stage;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
}
.ds-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  border-radius: 6px;
  overflow: hidden;
  background: #0d151d;
}
.ds-preview canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  /* What the window height leaves after ~250px of gallery. */
  max-height: clamp(170px, calc(min(92vh, 900px) - 510px), 310px);
}
.ds-draggable {
  cursor: move;
  touch-action: none;
}
.ds-transport {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.ds-transport .btn {
  flex-shrink: 0;
  padding: 6px 11px;
  font-size: 12px;
}
.ds-transport input[type="range"] {
  flex: 1 1 120px;
  min-width: 0;
  accent-color: var(--accent);
  direction: ltr;
}
.ds-transport output {
  flex-shrink: 0;
  min-width: 64px;
  font-size: 11.5px;
  color: var(--text-3);
  direction: ltr;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.ds-inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}
.ds-inline-field select {
  flex: 1 1 auto;
  max-width: 220px;
}
.ds-preview-status {
  display: block;
  min-height: 15px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--text-3);
}

/* Gallery */
.ds-gallery {
  grid-area: gallery;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  overflow: hidden;
}
.ds-gallery > * {
  flex-shrink: 0;
}
.ds-collection-note {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-3);
}
/* max-content rows: the cards clip their overflow, so auto rows would be
   shrunk to fit the panel and cut every card's name off. */
.ds-card-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 10px;
  margin: 0 -6px;
  padding: 2px 6px 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.ds-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 0 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  text-align: start;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    box-shadow 0.15s;
}
.ds-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}
.ds-card[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}
.ds-card canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  margin-bottom: 5px;
  background: #0d151d;
}
.ds-card strong {
  padding: 0 8px;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ds-card[aria-pressed="true"] strong {
  color: var(--accent);
}
.ds-card > span {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  padding: 0 8px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-3);
}

/* Settings */
.ds-panel {
  grid-area: panel;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.ds-controls {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px 16px;
  align-items: start;
  padding: 12px 14px 16px;
}
.ds-controls > h3:first-child,
.ds-panel-head h3 {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}
/* Template name + tabs, pinned while the settings scroll under them. The
   negative margin covers the panel padding so nothing shows above it. */
.ds-panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: -12px -14px 0;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface);
}
.ds-settings-section {
  display: contents;
}
.ds-wide,
.ds-panel-head,
.ds-help,
.ds-slot,
.ds-timing,
.ds-error,
.ds-background-options,
.ds-controls .ds-section-title {
  grid-column: 1 / -1;
}

/* Segmented tabs - the subtitles window's control. */
.ds-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.ds-tabs button {
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}
.ds-tabs button:hover {
  color: var(--text);
}
.ds-tabs button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.ds-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin: 0;
}
.ds-field-label {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-2);
}
.ds-field small {
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-3);
}
.ds-field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.ds-field-head output {
  flex-shrink: 0;
  font-size: 11.5px;
  color: var(--text-3);
  direction: ltr;
  font-variant-numeric: tabular-nums;
}
.ds-field input[type="range"] {
  width: 100%;
  min-width: 0;
  margin: 3px 0;
  accent-color: var(--accent);
}
.design-studio select,
.ds-field input[type="text"],
.ds-field input[type="number"] {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background-color: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  outline: none;
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    background-color 0.15s;
}
.design-studio select {
  appearance: none;
  -webkit-appearance: none;
  padding-left: 30px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%236e6e73' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1.5 1.5l4.5 4.5 4.5-4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 11px center;
  background-size: 10px 7px;
  text-overflow: ellipsis;
  cursor: pointer;
}
.design-studio select option {
  background: var(--surface);
  color: var(--text);
}
.design-studio select:hover,
.ds-field input[type="text"]:hover,
.ds-field input[type="number"]:hover {
  border-color: var(--border-strong);
}
.design-studio select:focus,
.ds-field input[type="text"]:focus,
.ds-field input[type="number"]:focus {
  border-color: var(--accent);
  background-color: var(--surface);
  box-shadow: var(--shadow-focus);
}
.ds-field input::placeholder {
  color: var(--text-muted);
}
.ds-field input[type="number"] {
  direction: ltr;
  text-align: right;
}
.ds-field input[type="color"] {
  align-self: flex-start;
  width: 44px;
  height: 32px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  cursor: pointer;
}
.ds-field input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
.ds-field input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 5px;
}
.ds-field input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 5px;
}
.ds-colors {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.ds-colors input[type="color"] {
  align-self: center;
}
.ds-swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.12s;
}
.ds-swatch:hover {
  transform: scale(1.1);
}

.ds-toggle {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  align-self: end;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
}
.ds-toggle:has(input:checked) {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--accent-soft);
  color: var(--text);
}
.ds-toggle input {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 1px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.ds-toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ds-toggle small {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-3);
}

.ds-upload {
  display: flex;
  align-self: end;
  min-width: 0;
}
.ds-upload .btn {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 12px;
}
.ds-controls > .btn {
  justify-self: start;
}

/* One card per template window: number | source, then fit. */
.ds-slot {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  align-items: end;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.ds-slot select {
  background-color: var(--surface);
}
.ds-slot.is-missing {
  border-color: color-mix(in srgb, var(--red) 55%, var(--border));
  background: color-mix(in srgb, var(--red) 6%, var(--surface-2));
}
.ds-slot-number {
  grid-row: 1;
  grid-column: 1;
  align-self: end;
  padding-bottom: 15px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.ds-slot > .ds-field {
  grid-column: 2;
}

/* A picture/video choice: its thumbnail and name; opens the files gallery. */
.ds-source {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 5px 10px 5px 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.ds-source:hover {
  border-color: var(--border-strong);
}
.ds-source.is-empty {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
}
.ds-source-thumb {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 34px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-2);
  color: var(--accent);
}
.ds-source-thumb > img,
.ds-source-thumb > video,
.ds-source-thumb > canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ds-source-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ds-source-change {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* Files gallery (media-picker.js) - the image-layer picker's look, plus: */
.media-picker .ov-thumb-media > video,
.media-picker .ov-thumb-media > canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.mp-thumb-icon {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background: var(--accent-soft);
  color: var(--accent);
}
.ds-source-thumb .mp-thumb-icon {
  background: none;
}
.mp-video-badge {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(10, 16, 24, 0.62);
  color: #fff;
}
.media-picker .ov-thumb {
  position: relative;
}
.media-picker .ov-upload-label {
  padding: 0 8px;
  text-align: center;
  line-height: 1.3;
}
.mp-footer-note {
  min-width: 0;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 840px) {
  .ds-source {
    min-height: 52px;
  }
  .media-picker .overlay-modal-footer .btn {
    min-height: 44px;
  }
}

.ds-timing {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}
.ds-controls .ds-section-title {
  margin: 4px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--divider);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.ds-help {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-3);
}
.ds-error {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--red) 30%, var(--border));
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--red) 8%, var(--surface));
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
}
.ds-error:empty {
  display: none;
}

.ds-background-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.ds-background-options button {
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.ds-background-options button:hover {
  border-color: var(--border-strong);
}
.ds-background-options button[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  color: var(--accent);
}
.ds-background-options canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}
.ds-background-options span {
  padding: 6px 4px;
  font-size: 11.5px;
  font-weight: 600;
  text-align: center;
}

/* ── Footer ── */
.ds-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--divider);
  background: var(--surface);
}
.ds-actions .ds-remove {
  margin-inline-end: auto;
  color: var(--text-3);
}
.ds-actions .ds-remove:hover:not(:disabled) {
  background: color-mix(in srgb, var(--red) 8%, var(--surface));
  color: var(--red);
}
.ds-actions .btn-primary {
  min-width: 160px;
}

.design-studio button:focus-visible,
.design-studio input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.design-studio select:focus-visible {
  outline: none;
}
.ds-card:focus-visible {
  outline-offset: 1px;
}

/* ── Tall (9:16) projects: the preview gets a full-height column ── */
.design-studio[data-shape="tall"] .ds-body {
  grid-template-columns: 330px minmax(0, 1fr) 360px;
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "stage gallery panel";
}
.design-studio[data-shape="tall"] .ds-preview {
  flex: 1 1 0;
}
.design-studio[data-shape="tall"] .ds-preview canvas {
  max-height: 100%;
}
.design-studio[data-shape="tall"] .ds-transport {
  flex-wrap: wrap;
}

@media (max-width: 1100px) {
  .ds-body {
    grid-template-columns: minmax(0, 1fr) 340px;
  }
  .design-studio[data-shape="tall"] .ds-body {
    grid-template-columns: 280px minmax(0, 1fr) 320px;
  }
  .ds-card-grid {
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  }
}

/* ── Phones / small tablets: bottom sheet, one scroller ── */
@media (max-width: 840px), (max-height: 560px) {
  .modal-backdrop:has(.design-studio) {
    align-items: flex-end;
    padding: 0;
  }
  .modal.modal-lg:has(.design-studio),
  .modal:has(.design-studio) {
    width: 100%;
    max-width: 100%;
    height: min(94dvh, 94vh);
    max-height: min(94dvh, 94vh);
    margin: 0;
    padding: 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  .modal.modal-lg:has(.design-studio)::before,
  .modal:has(.design-studio)::before {
    flex: 0 0 auto;
    margin: 8px auto 0;
  }
  .design-studio {
    flex: 1 1 auto;
    height: auto;
  }
  .ds-header {
    padding: 6px 12px 10px;
  }
  .ds-header .modal-close {
    width: 40px;
    height: 40px;
  }
  .ds-title-icon {
    width: 30px;
    height: 30px;
  }
  .ds-title-copy p {
    display: none;
  }

  /* The preview stays pinned while the strip and the settings scroll. */
  .ds-body,
  .design-studio[data-shape="tall"] .ds-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 10px 14px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .ds-body > * {
    flex-shrink: 0;
  }
  .ds-stage {
    position: sticky;
    top: 0;
    z-index: 3;
    margin: 0 -10px;
    padding: 8px 10px;
    border: 0;
    border-bottom: 1px solid var(--divider);
    border-radius: 0;
    background: var(--surface-2);
    box-shadow: 0 8px 14px -12px rgba(10, 22, 40, 0.45);
  }
  .ds-preview canvas {
    max-height: min(30dvh, 280px);
  }
  .design-studio[data-shape="tall"] .ds-preview {
    flex: none;
  }
  .design-studio[data-shape="tall"] .ds-preview canvas {
    max-height: min(36dvh, 340px);
  }
  /* Icon-only transport buttons (their name stays on aria-label). */
  .ds-transport .btn {
    width: 44px;
    min-height: 40px;
    padding: 0;
  }
  .ds-transport .btn > span:not(.ui-icon) {
    display: none;
  }
  .ds-inline-field select {
    max-width: none;
  }

  .ds-gallery {
    gap: 8px;
    overflow: visible;
  }
  .ds-collection-note {
    display: none;
  }
  .ds-card-grid {
    display: flex;
    flex: none;
    gap: 8px;
    margin: 0 -10px;
    padding: 2px 10px 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 10px;
    overscroll-behavior-x: contain;
  }
  .ds-card {
    flex: 0 0 136px;
    scroll-snap-align: start;
  }
  .ds-card > span {
    -webkit-line-clamp: 1;
  }

  .ds-panel {
    overflow: visible;
  }
  .ds-controls {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }
  /* The body is the scroller here and the preview already owns its top. */
  .ds-panel-head {
    position: static;
    margin: 0;
    padding: 0;
    border-bottom: 0;
  }
  .ds-tabs button {
    min-height: 40px;
  }
  .design-studio select,
  .ds-field input[type="text"],
  .ds-field input[type="number"] {
    height: 44px;
    font-size: 16px; /* under 16px iOS zooms the page on focus */
  }
  .ds-toggle {
    align-items: center;
    min-height: 44px;
  }
  .ds-toggle input {
    width: 20px;
    height: 20px;
    margin: 0;
  }
  .ds-upload .btn,
  .ds-controls > .btn {
    min-height: 44px;
  }
  .ds-controls > .btn {
    justify-self: stretch;
  }
  .ds-slot {
    padding: 10px;
  }
  .ds-slot-number {
    padding-bottom: 18px;
  }
  .ds-swatch {
    width: 32px;
    height: 32px;
  }
  .ds-field input[type="color"] {
    width: 52px;
    height: 40px;
  }
  .ds-background-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ds-actions {
    padding: 10px 12px max(12px, env(safe-area-inset-bottom, 12px));
  }
  .ds-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    white-space: normal;
    line-height: 1.25;
    text-align: center;
  }
  .ds-actions .ds-remove {
    margin-inline-end: 0;
  }
  .ds-actions .btn-primary {
    flex-grow: 1.5;
    min-width: 0;
  }
}

/* Landscape phone: too short to pin a preview above anything - put it
   beside the gallery and settings instead. */
@media (max-height: 560px) and (min-width: 600px) {
  .ds-body,
  .design-studio[data-shape="tall"] .ds-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      "gallery stage"
      "panel stage";
    align-items: start;
    padding: 10px;
  }
  .ds-stage {
    align-self: start;
    margin: 0;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
  }
  .ds-preview canvas,
  .design-studio[data-shape="tall"] .ds-preview canvas {
    max-height: max(90px, calc(94dvh - 250px));
  }
}

/* ── Timeline: effects lane, template badge, clip grips ── */
.tl-clip-head {
  display: flex;
  flex-direction: row;
  direction: ltr;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
}
.tl-clip.has-speed .tl-clip-head {
  padding-right: 34px;
}
.tl-clip-template-badge {
  position: static;
  z-index: 6;
  flex: none;
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: 76px;
  height: 14px;
  padding: 0 5px;
  border: 1px solid #c2ece970;
  border-radius: 7px;
  background: #13383bcc;
  color: #e1f4f1;
  font-family: inherit;
  font-size: 9px;
  font-weight: 500;
  line-height: 1;
  cursor: default;
  pointer-events: none;
  overflow: hidden;
  direction: ltr;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}
.tl-clip-template-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.track-row.effects,
.track-row.effects .track-label,
.track-row.effects .track-content {
  height: 36px;
  min-height: 36px;
}
.track-row.effects {
  margin-bottom: 1px;
}
.track-content.effects {
  position: relative;
  background: var(--surface-2);
}
.ds-track-open {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font: inherit;
  padding: 0;
}
.tl-effect-empty {
  position: absolute;
  inset: 4px auto 4px 8px;
  border: 1px dashed var(--border, #bccbd8);
  border-radius: 4px;
  color: var(--text-3, #71839a);
  background: transparent;
  font-size: 10px;
  padding: 2px 12px;
  cursor: pointer;
}
.tl-effect-block {
  position: absolute;
  top: 3px;
  height: 30px;
  background: #e8eaf6;
  border: 1px solid #9baad0;
  border-radius: 4px;
  color: #405582;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 9px;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  touch-action: none;
  direction: rtl;
}
.tl-effect-block.is-selected {
  outline: 2px solid #687fb3;
  outline-offset: -1px;
}
.tl-effect-name {
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-effect-block small {
  font-size: 8px;
  opacity: 0.7;
  white-space: nowrap;
  margin-inline-start: auto;
}
.tl-effect-block .tl-trim {
  pointer-events: auto;
  opacity: 0.65;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 5px;
  background: #687fb345;
  cursor: ew-resize;
}
.tl-effect-block .left {
  left: 0;
}
.tl-effect-block .right {
  right: 0;
}
.track-row.effects.is-empty .track-label-body {
  color: var(--text-3);
}

/* Native timeline labels and persistent video edge grips. */
.track-row.effects .ds-track-open {
  font: inherit;
  font-weight: inherit;
  color: inherit;
}
.track-row.effects .track-label {
  color: var(--text-2);
}
.tl-effect-block {
  top: 4px;
  height: 28px;
  border-radius: var(--r-xs);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  color: var(--text-2);
}
.tl-effect-block.is-selected {
  outline-color: var(--accent);
}
.track-content.video .tl-clip > .tl-trim {
  opacity: 1;
  cursor: ew-resize;
  pointer-events: auto;
  top: 0;
  bottom: 0;
  width: 14px;
  background: transparent;
  box-shadow: none;
  z-index: 8;
}
.track-content.video .tl-clip > .tl-trim.left {
  left: 0;
}
.track-content.video .tl-clip > .tl-trim.right {
  right: 0;
}
.track-content.video .tl-clip > .tl-trim::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  height: auto;
  border-radius: 0;
  box-shadow: none;
  background: var(--accent);
  pointer-events: none;
  transition: background 0.1s;
}
.track-content.video .tl-clip > .tl-trim.left::before {
  left: 0;
}
.track-content.video .tl-clip > .tl-trim.right::before {
  right: 0;
}
.track-content.video .tl-clip > .tl-trim:hover::before {
  width: 3px;
  height: auto;
  background: #7ef6ff;
}
.tl-clip.is-trimming,
.tl-clip.is-trimming > .tl-trim {
  transition: none;
}
.tl-clip.has-template .tl-clip-title {
  flex: 0 1 auto;
  width: auto;
  min-width: 0;
  padding-left: 0;
}
.tl-clip.has-template.has-speed .tl-clip-title {
  padding-inline-end: 0;
}

@media (pointer: coarse) {
  .track-content.video .tl-clip > .tl-trim {
    width: 18px;
  }
}
