/*
 * Prism UI — Components
 * ----------------------
 * All values via var(--*) — zero hardcoded colours or sizes.
 * Components: pill-btn, icon-btn, brand-pill, toolbar, tb-pill, tb-play,
 *   settings-panel, setting-row, setting-select, range-input, dropdown,
 *   context-menu, color-picker, timeline, drop-zone, icon-swap, dot-grid.
 *
 * lessons.md applied:
 *   §1  Every hover rule has explicit color declaration
 *   §2  Semantic input+focus compound rules present
 *   §3  No hardcoded accent hex — all via var()
 *   §4  Avatar group z-index first-child-on-top (n/a, no avatars here)
 *   §5  All icon buttons use SVG / Phosphor font — no Unicode chars
 *   §6  Preview padding ≥ 48px, min-height ≥ 160px
 */

/* ═══════════════════════════════════════════════════════════
   PILL BUTTON — the primary CTA (Export, Add Images)
═══════════════════════════════════════════════════════════ */
.pill-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 18px;
  border-radius: var(--radius-btn, var(--radius-full));
  background: var(--fg);
  color: var(--bg);
  border: 0;
  font-family: var(--font-family-active, var(--font-family-base));
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-regular);
  letter-spacing: var(--letter-spacing-tight);
  cursor: pointer;
  transition: var(--transition-btn);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  isolation: isolate;
  white-space: nowrap;
  text-decoration: none;
}

.pill-btn i { font-size: 15px; }

.pill-btn:hover {
  background: color-mix(in srgb, var(--fg) 85%, var(--bg));
  color: var(--bg);
}

.pill-btn:active {
  transform: scale(0.97);
  color: var(--bg);
}

.pill-btn:disabled,
.pill-btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Exporting state — light container with dark sweep fill */
.pill-btn.is-exporting {
  background: var(--surface-soft-hover); /* slightly darker than surface-soft — stays visible on white bg */
  border: 1.5px solid var(--border);     /* anchors the pill shape against the page bg */
  color: var(--fg);
  min-width: 170px;
}

.pill-btn .progress-fill {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  background: var(--fg);
  width: 0%;
  transition: width 0.2s linear;
  z-index: 0;
}

.pill-btn .pill-content {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  mix-blend-mode: difference;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ═══════════════════════════════════════════════════════════
   ICON BUTTON — circular button for settings, tools
═══════════════════════════════════════════════════════════ */
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: var(--transition-btn), border-color var(--dur-normal) var(--ease);
  box-shadow: var(--shadow-sm);
  padding: 0;
  text-decoration: none;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface-soft);
  border-color: var(--border-focus);
  color: var(--fg);
}

.icon-btn:active {
  transform: scale(0.94);
  color: var(--fg);
}

/* Active state — filled black (e.g. settings open) */
.icon-btn.is-active,
.icon-btn[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.icon-btn.is-active:hover,
.icon-btn[aria-pressed="true"]:hover {
  background: color-mix(in srgb, var(--fg) 85%, var(--bg));
  color: var(--bg);
  border-color: transparent;
}

/* Size variants */
.icon-btn--sm {
  width: 32px;
  height: 32px;
  font-size: 14px;
  border-radius: var(--radius-input, var(--radius-xs));  /* square-ish small */
}

/* ═══════════════════════════════════════════════════════════
   BRAND PILL — the logo wordmark chip
═══════════════════════════════════════════════════════════ */
.brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 20px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--fg);
  cursor: default;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--letter-spacing-tight);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   TOOLBAR — floating bottom bar
═══════════════════════════════════════════════════════════ */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-card, var(--shadow));
  padding: var(--toolbar-padding, 10px);
  width: max-content;
  max-width: 100%;
  overflow: hidden;
  transition: background var(--dur-normal) var(--ease),
              border-color var(--dur-normal) var(--ease);
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.toolbar-spacer { flex: 1 1 0; min-width: 8px; }

.toolbar-count {
  font-size: var(--font-size-xs);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════
   TOOLBAR PLAY BUTTON — filled circle
═══════════════════════════════════════════════════════════ */
.tb-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  /* Source uses a muted mid-grey, not solid fg */
  background: var(--fg-soft);
  color: var(--bg);
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: var(--transition-btn);
  flex-shrink: 0;
  padding: 0;
}

.tb-play:hover {
  background: var(--fg-muted);
  color: var(--bg);
}

.tb-play:active {
  transform: scale(0.92);
  color: var(--bg);
}

.tb-play:disabled,
.tb-play[aria-disabled="true"] {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════
   TOOLBAR PILL CONTROL — label + value capsule
   (used for fps, duration, fit mode controls)
═══════════════════════════════════════════════════════════ */
.tb-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  height: 38px;
  padding: 0 18px;
  background: var(--surface-soft);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--dur-normal) var(--ease),
              border-color var(--dur-normal) var(--ease);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
  color: var(--fg);
}

.tb-pill:hover {
  background: var(--surface-soft-hover);
  color: var(--fg);
}

.tb-pill.is-focused,
.tb-pill:focus-within {
  background: var(--surface);
  border-color: var(--fg);
  color: var(--fg);
}

.tb-pill__label {
  color: var(--fg-muted);
  font-size: var(--font-size-base);
}

.tb-pill__value {
  color: var(--fg);
  font-size: var(--font-size-base);
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-weight-medium);
}

.tb-pill__caret {
  color: var(--fg-soft);
  font-size: 10px;
  margin-left: -6px;
}

.tb-pill__suffix {
  color: var(--fg-muted);
  font-size: var(--font-size-base);
  margin-left: -8px;
}

/* Inline input inside tb-pill (for number drag inputs) */
.tb-pill input[type="number"],
.tb-pill input[type="text"] {
  background: transparent;
  border: 0;
  outline: none;
  font-family: inherit;
  font-size: var(--font-size-base);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-weight-medium);
  padding: 0;
  margin: 0;
  text-align: right;
  cursor: ns-resize;
  width: 36px;
}

.tb-pill input[type="number"]:focus,
.tb-pill input[type="text"]:focus {
  cursor: text;
}

/* ═══════════════════════════════════════════════════════════
   TOOLBAR FIT / BG BUTTONS — small iconographic circles
═══════════════════════════════════════════════════════════ */
.tb-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface-soft);
  border: 0;
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: var(--transition-btn);
  padding: 0;
  flex-shrink: 0;
  text-decoration: none;
}

.tb-icon:hover {
  background: var(--surface-soft-hover);
  color: var(--fg);
}

.tb-icon:active {
  transform: scale(0.92);
  color: var(--fg);
}

/* Swatch circle inside bg button */
.tb-icon .swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--current-bg, #000);
  box-shadow: rgba(0,0,0,0.15) 0 0 0 1px inset;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   SETTINGS PANEL — floating card
═══════════════════════════════════════════════════════════ */
.settings-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card, var(--radius));
  box-shadow: var(--shadow-card, var(--shadow));
  padding: 16px;
  width: 280px;
  max-width: calc(100vw - 40px);
}

.settings-title {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  color: var(--fg-muted);
  margin: 0 0 12px;
  font-weight: var(--font-weight-medium);
}

/* ═══════════════════════════════════════════════════════════
   SETTING ROW — label + control pair
═══════════════════════════════════════════════════════════ */
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-row + .setting-row {
  margin-top: 12px;
}

.setting-row.inline {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-row label {
  font-size: var(--font-size-sm);
  color: var(--fg);
}

.setting-row .row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-sm);
}

.setting-row .row-head .val {
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════
   SETTING SELECT — custom styled <select>
═══════════════════════════════════════════════════════════ */
.setting-select {
  position: relative;
  flex: 0 0 auto;
  min-width: 130px;
}

.setting-select select {
  width: 100%;
  height: 30px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input, var(--radius-xs));
  background: var(--surface);
  font-family: inherit;
  font-size: var(--font-size-sm);
  color: var(--fg);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: border-color var(--dur-normal) var(--ease),
              background var(--dur-normal) var(--ease);
}

.setting-select select:hover {
  border-color: var(--border-focus);
}

.setting-select select:focus {
  border-color: var(--fg);
}

.setting-select__caret {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--fg-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
}

/* ═══════════════════════════════════════════════════════════
   RANGE INPUT — custom slider
═══════════════════════════════════════════════════════════ */
input[type="range"].range-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"].range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--fg);
  border-radius: 50%;
  cursor: grab;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-normal) var(--ease);
}

input[type="range"].range-input:hover::-webkit-slider-thumb {
  transform: scale(1.15);
}

input[type="range"].range-input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--fg);
  border-radius: 50%;
  cursor: grab;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ═══════════════════════════════════════════════════════════
   DROPDOWN — animated panel (scale + fade)
═══════════════════════════════════════════════════════════ */
.dropdown {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card, var(--radius));
  box-shadow: var(--shadow-card, var(--shadow));
  padding: 6px;
  z-index: var(--z-dropdown);

  /* Animation */
  transform-origin: left top;
  transform: scale(var(--dropdown-pre-scale, 0.97));
  opacity: 0;
  pointer-events: none;
  transition: transform var(--dropdown-open-dur, 250ms) var(--ease-dropdown),
              opacity   var(--dropdown-open-dur, 250ms) var(--ease-dropdown);
  will-change: transform, opacity;
}

/* Origin variants */
.dropdown[data-origin="top-right"]    { transform-origin: right top; }
.dropdown[data-origin="top-center"]   { transform-origin: center top; }
.dropdown[data-origin="bottom-left"]  { transform-origin: left bottom; }
.dropdown[data-origin="bottom-center"]{ transform-origin: center bottom; }
.dropdown[data-origin="bottom-right"] { transform-origin: right bottom; }

.dropdown.is-open {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

.dropdown.is-closing {
  transform: scale(var(--dropdown-closing-scale, 0.99));
  opacity: 0;
  pointer-events: none;
  transition: transform var(--dropdown-close-dur, 150ms) var(--ease-dropdown),
              opacity   var(--dropdown-close-dur, 150ms) var(--ease-dropdown);
}

@media (prefers-reduced-motion: reduce) {
  .dropdown { transition: none !important; }
}

/* ═══════════════════════════════════════════════════════════
   CONTEXT MENU — right-click menu
═══════════════════════════════════════════════════════════ */
.context-menu {
  min-width: 196px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-card, var(--shadow));
  padding: 4px;
  font-size: var(--font-size-sm);
  user-select: none;
}

.context-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.cm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-2xs, 6px);
  cursor: pointer;
  color: var(--fg);
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
  text-decoration: none;
}

.cm-row i {
  font-size: 14px;
  color: var(--fg-muted);
  transition: color var(--dur-fast) var(--ease);
  flex-shrink: 0;
}

.cm-row:hover {
  background: var(--surface-soft);
  color: var(--fg);
}

.cm-row.danger:hover {
  background: var(--color-danger-bg, #fee2e2);
  color: var(--color-danger, #b91c1c);
  border-color: var(--color-danger-border, #fca5a5);
}

.cm-row.danger:hover i {
  color: var(--color-danger, #b91c1c);
}

/* Duration inline input inside context menu */
.cm-dur {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 10px;
}

.cm-dur label {
  flex: 1;
  font-size: var(--font-size-sm);
  color: var(--fg);
}

.cm-dur input {
  width: 56px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-2xs, 6px);
  font-family: inherit;
  font-size: var(--font-size-sm);
  text-align: right;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  color: var(--fg);
  outline: none;
  transition: var(--transition-border);
}

/* lessons.md §2 — explicit focus style, no glow mismatch */
.cm-dur input:focus {
  border-color: var(--fg);
  color: var(--fg);
}

.cm-dur .suffix {
  color: var(--fg-muted);
  font-size: var(--font-size-xs);
}

.cm-reset {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--fg-muted);
  padding: 2px 4px;
  font-size: var(--font-size-xs);
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease),
              color var(--dur-normal) var(--ease);
}

.cm-reset.is-visible { opacity: 1; }
.cm-reset:hover {
  color: var(--fg);
}

/* ═══════════════════════════════════════════════════════════
   SEGMENTED CONTROL — e.g. Color / Image mode switcher
═══════════════════════════════════════════════════════════ */
.seg-control {
  position: relative;
  display: flex;
  background: var(--surface-soft);
  border-radius: var(--radius-xs, 8px);
  padding: 3px;
}

.seg-control__btn {
  flex: 1;
  height: 26px;
  background: transparent;
  border: 0;
  border-radius: 5px;
  font-size: var(--font-size-sm);
  font-family: inherit;
  font-weight: var(--font-weight-medium);
  color: var(--fg-muted);
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: color var(--dur-medium) var(--ease);
}

.seg-control__btn.is-active {
  color: var(--fg);
}

.seg-control__btn:hover:not(.is-active) {
  color: var(--fg);
}

.seg-control__indicator {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  background: var(--surface);
  border-radius: 5px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.22s var(--ease);
  pointer-events: none;
}

/* When second tab active, slide indicator right */
.seg-control[data-active="1"] .seg-control__indicator {
  transform: translateX(calc(100%));
}

/* ═══════════════════════════════════════════════════════════
   COLOR PICKER — saturation/value square + hue slider
═══════════════════════════════════════════════════════════ */
.color-picker {
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-card, var(--shadow));
  padding: 12px;
  --hue: 0;
  --cur-color: #000;
}

.sv-square {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius-xs, 8px);
  overflow: hidden;
  cursor: crosshair;
  user-select: none;
  touch-action: none;
  background:
    linear-gradient(to bottom, transparent, #000),
    linear-gradient(to right, #fff, hsl(var(--hue), 100%, 50%));
  box-shadow: rgba(0,0,0,0.08) 0 0 0 1px inset;
}

.sv-dot {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cur-color, #000);
  border: 2px solid #fff;
  box-shadow: rgba(0,0,0,0.3) 0 0 0 1px, rgba(0,0,0,0.25) 0 1px 3px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  left: 0;
  top: 0;
}

.hue-slider {
  position: relative;
  height: 12px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  margin-top: 12px;
  background: linear-gradient(to right,
    #ff0000 0%, #ffff00 17%, #00ff00 33%,
    #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
  box-shadow: rgba(0,0,0,0.08) 0 0 0 1px inset;
}

.hue-handle {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: hsl(var(--hue), 100%, 50%);
  border: 2px solid #fff;
  box-shadow: rgba(0,0,0,0.3) 0 0 0 1px, rgba(0,0,0,0.25) 0 1px 3px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  left: 0;
}

/* Colour controls row: eyedropper + hex input */
.color-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

.eyedrop-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-input, var(--radius-xs));
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  padding: 0;
  transition: background var(--dur-normal) var(--ease),
              border-color var(--dur-normal) var(--ease),
              transform var(--dur-fast) var(--ease);
}

.eyedrop-btn:hover {
  background: var(--surface-soft);
  border-color: var(--border-focus);
  color: var(--fg);
}

.eyedrop-btn:active {
  transform: scale(0.92);
  color: var(--fg);
}

.eyedrop-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.hex-input-wrap {
  flex: 1;
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 8px 0 10px;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-input, var(--radius-xs));
  background: var(--surface);
  transition: var(--transition-border);
  font-variant-numeric: tabular-nums;
}

.hex-input-wrap:focus-within {
  border-color: var(--fg);
}

.hex-input-wrap__prefix {
  font-size: var(--font-size-sm);
  color: var(--fg-soft);
  font-weight: var(--font-weight-medium);
  flex-shrink: 0;
}

.hex-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  color: var(--fg);
  outline: none;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
}

/* Colour swatches grid */
.color-swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  margin-top: 12px;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-2xs, 6px);
  border: 1px solid rgba(0,0,0,0.08);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s var(--ease);
  background: currentColor;
}

.color-swatch:hover {
  transform: scale(1.14);
}

.color-swatch.is-active {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

/* Image drop zone (inside color picker / bg popover) */
.img-drop-zone {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius-xs, 8px);
  border: 1.5px dashed var(--border-strong, var(--border));
  background: var(--surface-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  font-size: var(--font-size-sm);
  color: var(--fg-muted);
  cursor: pointer;
  transition: border-color var(--dur-normal) var(--ease),
              background var(--dur-normal) var(--ease),
              color var(--dur-normal) var(--ease);
  text-align: center;
  padding: 12px;
}

.img-drop-zone:hover,
.img-drop-zone.drag-over {
  border-color: var(--fg);
  background: var(--surface);
  color: var(--fg);
}

.img-drop-zone i { font-size: 22px; }

.img-drop-zone .sub {
  font-size: var(--font-size-xs);
  color: var(--fg-soft);
}

/* Image preview + actions */
.img-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius-xs, 8px);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--border);
  background: var(--surface-soft);
}

.img-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.img-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.img-action-btn {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: inherit;
  font-size: var(--font-size-base);
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--dur-normal) var(--ease),
              border-color var(--dur-normal) var(--ease),
              color var(--dur-normal) var(--ease),
              transform var(--dur-fast) var(--ease);
}

.img-action-btn:hover {
  background: var(--surface-soft);
  border-color: var(--border-focus);
  color: var(--fg);
}

.img-action-btn:active {
  transform: scale(0.98);
  color: var(--fg);
}

/* Danger variant (Remove button) */
.img-action-btn.danger:hover {
  background: var(--color-danger-bg, #fee2e2);
  border-color: var(--color-danger-border, #fca5a5);
  color: var(--color-danger, #b91c1c);
}

/* ═══════════════════════════════════════════════════════════
   TIMELINE — scrollable row of slide thumbnails
═══════════════════════════════════════════════════════════ */
.timeline {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  padding: 4px 70px 4px 2px;
  min-height: 60px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  -webkit-mask-image: linear-gradient(to right,
    #000 0, #000 calc(100% - 80px),
    rgba(0,0,0,0.15) calc(100% - 30px),
    transparent calc(100% - 4px));
}

.timeline::-webkit-scrollbar { height: 5px; }
.timeline::-webkit-scrollbar-track { background: transparent; }
.timeline::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.timeline::-webkit-scrollbar-thumb:hover { background: var(--fg-soft); }

/* Slide thumbnail */
.tl-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--border) 60%, transparent); /* ~60% opacity resting stroke */
  cursor: grab;
  background: var(--surface-soft);
  transition: border-color var(--dur-normal) var(--ease),
              transform var(--dur-normal) var(--ease),
              box-shadow var(--dur-normal) var(--ease);
}

.tl-thumb:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.tl-thumb:active { cursor: grabbing; }

.tl-thumb.is-active { border-color: var(--fg); }

.tl-thumb.is-dragging { opacity: 0.3; }
.tl-thumb.is-drop-target { transform: translateX(4px); }

.tl-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.tl-thumb__dur {
  position: absolute;
  bottom: 2px;
  left: 2px;
  font-size: 9px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(4px);
  pointer-events: none;
}

.tl-thumb__remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity var(--dur-normal) var(--ease),
              transform var(--dur-normal) var(--ease),
              background var(--dur-normal) var(--ease);
  padding: 0;
  font-size: 10px;
}

.tl-thumb:hover .tl-thumb__remove {
  opacity: 1;
  transform: scale(1);
}

.tl-thumb__remove:hover {
  background: rgba(220, 38, 38, 0.9);
}

/* Add slide button */
.tl-add {
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border-radius: 10px;
  border: 1.5px dashed var(--border);
  background: transparent;   /* no fill — works correctly on any seed/theme bg */
  color: var(--fg-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: border-color var(--dur-normal) var(--ease),
              color var(--dur-normal) var(--ease),
              transform var(--dur-normal) var(--ease),
              background var(--dur-normal) var(--ease);
  font-family: inherit;
  padding: 0;
}

.tl-add:hover {
  border-color: var(--fg-muted);
  color: var(--fg);
  background: var(--surface-soft);
  transform: translateY(-2px);
}

.tl-add:active {
  transform: scale(0.95);
}

/* ═══════════════════════════════════════════════════════════
   ICON SWAP — animated A↔B icon transition
═══════════════════════════════════════════════════════════ */
.icon-swap {
  position: relative;
  display: inline-grid;
}

.icon-swap__icon {
  grid-area: 1 / 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity   var(--icon-swap-dur, 200ms) var(--ease-inout),
              filter    var(--icon-swap-dur, 200ms) var(--ease-inout),
              transform var(--icon-swap-dur, 200ms) var(--ease-inout);
  will-change: opacity, filter, transform;
}

.icon-swap[data-state="a"] .icon-swap__icon[data-icon="a"],
.icon-swap[data-state="b"] .icon-swap__icon[data-icon="b"] {
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
}

.icon-swap[data-state="a"] .icon-swap__icon[data-icon="b"],
.icon-swap[data-state="b"] .icon-swap__icon[data-icon="a"] {
  opacity: 0;
  filter: blur(var(--icon-swap-blur, 2px));
  transform: scale(var(--icon-swap-start-scale, 0.25));
}

@media (prefers-reduced-motion: reduce) {
  .icon-swap__icon { transition: none !important; }
}

/* ═══════════════════════════════════════════════════════════
   DOT GRID — canvas background pattern
═══════════════════════════════════════════════════════════ */
.dot-grid {
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: 0 0;
}

/* Drag-over indicator */
.dot-grid.drag-over::before {
  content: '';
  position: absolute;
  inset: 16px;
  border: 2px dashed var(--fg);
  border-radius: 24px;
  pointer-events: none;
  z-index: 2;
}

/* ═══════════════════════════════════════════════════════════
   UTILITY
═══════════════════════════════════════════════════════════ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .settings-panel {
    right: 12px;
    width: calc(100vw - 24px);
    max-width: 320px;
  }
  .pill-btn { min-width: 0; padding: 0 16px; }
}

@media (max-width: 420px) {
  .tb-pill__label { display: none; }
  .tb-pill { gap: 6px; padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
