/* Design tokens (:root) live in tokens.css — shared with manual.html. */

* { box-sizing: border-box; }

/* inline SVG icons on buttons */
.btn-icon { display: inline-flex; align-items: center; gap: 6px; }
.btn-icon svg { flex: 0 0 auto; display: block; }
/* the display above outranks the UA [hidden] rule — restore it for swapped icons */
.btn-icon svg[hidden] { display: none; }
.btn-icon--lg svg { width: 14px; height: 14px; }

/* dice spin while a random look is rolling */
.btn-icon.rolling svg { animation: dice-roll 0.45s ease; }
@keyframes dice-roll {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* per-axis locks next to the RANDOM dice */
.lock-group { display: inline-flex; gap: 2px; }
.lock-btn { opacity: 0.45; }
.lock-btn:hover { opacity: 0.8; }
.lock-btn.active { opacity: 1; color: var(--accent); }

/* seed of the last roll: copy it, or paste one in to roll it again */
.seed-field { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; }
.seed-input {
  font: inherit; font-size: 10px; font-weight: 700; letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  width: 9ch; padding: 4px 6px; text-align: center; text-transform: uppercase;
  background: var(--panel-2); color: var(--text);
  border: none; border-radius: var(--radius-sm);
  transition: color var(--dur-ui) var(--ease-out), box-shadow var(--dur-ui) var(--ease-out);
}
.seed-input::placeholder { color: var(--muted); letter-spacing: 0; }
.seed-input:focus { outline: none; color: var(--accent-hover); box-shadow: inset 0 0 0 1px var(--line); }
.seed-copy { padding: 5px 6px; opacity: 0.45; }
.seed-copy:hover:not(:disabled) { opacity: 1; }
.seed-copy:disabled { opacity: 0.2; cursor: default; background: transparent; }
.seed-copy .ico-copied { display: none; }
.seed-copy.copied { opacity: 1; color: var(--accent); }
.seed-copy.copied .ico-copy { display: none; }
.seed-copy.copied .ico-copied { display: block; }
.swatch-chip svg { width: 12px; height: 12px; flex: 0 0 auto; display: block; }

html {
  color-scheme: dark;
  scrollbar-width: thin;
  scrollbar-color: var(--line) var(--panel);
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Roboto Mono", ui-monospace, monospace;
  background:
    repeating-linear-gradient(135deg, #0c0c0d 0 2px, transparent 2px 7px),
    var(--black);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: none;
  overflow: hidden;
}

/* ===================== TOP CONTEXT BAR ===================== */
.topbar {
  height: var(--header-h);
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
}
.brand-logo { height: 22px; width: auto; display: block; }
.brand-grid {
  font-size: 10px; color: var(--muted); letter-spacing: 1px;
  border: 1px solid var(--line); padding: 3px 7px;
}

.ctx-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 0 18px;
  overflow-x: auto;
}
.ctx-label {
  font-size: 9px; letter-spacing: 2px; color: var(--muted); font-weight: 700;
  padding-right: 4px; border-right: 1px solid var(--line); margin-right: 4px;
  height: 28px; display: flex; align-items: center;
}
.ctx-controls .field {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  min-width: 132px;
}
.ctx-controls .field > span {
  font-size: 9px; letter-spacing: 2px; color: var(--muted); font-weight: 700;
}

.ctl {
  font: inherit;
  font-size: 12px;
  background: var(--panel-2);
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  padding: 6px 8px;
  width: 100%;
  border-radius: 0;
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%);
  background-position: right 9px center;
  background-size: 7px 7px;
  background-repeat: no-repeat;
  padding-right: 24px;
}
select.ctl option { background: var(--black); }
.ctl:focus { outline: none; border-bottom-color: var(--accent-focus); }
input.ctl { background-image: none; padding-right: 8px; cursor: text; }

/* segmented toggle (MAP) */
.seg { display: inline-flex; border: 1px solid var(--line); width: max-content; border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  font: inherit; font-size: 10px; font-weight: 700; letter-spacing: 1px;
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--panel-2); color: #c8c8cb;
  border: none; padding: 6px 10px; cursor: pointer;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.seg-btn.active { background: var(--accent); color: var(--black); }
.seg-btn:active { transform: scale(0.97); }
.seg-btn svg { display: block; }

/* Tiled pattern collection — inline thumbnail grid (per-cell fill) */
.pattern-prop { min-width: 0; }
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}
.pattern-btn {
  aspect-ratio: 1;
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
  overflow: hidden;
}
.pattern-btn:hover { border-color: var(--text); background: #1a1a1c; }
.pattern-btn.active { border-color: var(--accent); }
.pattern-btn canvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  flex: 0 0 auto;
  pointer-events: none;
}

.export-split {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  margin-left: auto;
  margin-right: 8px;
  align-self: center;
  height: 32px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--dur-ui) var(--ease-out), box-shadow var(--dur-ui) var(--ease-out);
}
.export-split.open {
  border-color: var(--line);
  box-shadow: none;
}

.export-split-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  border: none;
  cursor: pointer;
  border-radius: 0;
  white-space: nowrap;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.export-split-main:hover { background: var(--violet); color: var(--text); }
.export-split-main:active { transform: scale(0.97); }

.export-split-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  background: var(--panel-2);
  color: var(--muted);
  border: none;
  border-left: 1px solid var(--line);
  cursor: pointer;
  border-radius: 0;
  transition: color var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.export-split-caret:hover { color: var(--accent-hover); background: rgba(255,255,255,0.06); }
.export-split-caret:active { transform: scale(0.97); }
.export-split.open .export-split-caret {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}
.export-split.open .export-split-caret svg { transform: rotate(180deg); }

.export-split-menu {
  position: fixed;
  z-index: 70;
  display: none;
  min-width: 248px;
  padding: 0;
  background: var(--black);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.03);
  overflow: hidden;
  transform-origin: top right;
}
.export-split.open .export-split-menu {
  display: block;
  animation: menu-in var(--dur-menu) var(--ease-out);
}

.export-split-menu-inner {
  padding: 8px;
}

.export-split-section + .export-split-divider,
.export-split-divider + .export-split-section {
  margin-top: 0;
}

.export-split-heading {
  padding: 4px 6px 8px;
  font-size: 9px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.export-split-seg {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel-2);
}

.export-split-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.export-split-opt {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0;
  background: transparent;
  border: none;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  letter-spacing: 0.5px;
  white-space: nowrap;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out);
}

.export-split-opt--seg {
  flex: 1;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #c8c8cb;
}
.export-split-opt--seg + .export-split-opt--seg {
  border-left: 1px solid var(--line);
}
.export-split-opt--seg:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}
.export-split-opt--seg.active {
  background: var(--accent);
  color: var(--black);
  font-weight: 800;
}

.export-split-opt--row {
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 6px 8px 6px 10px;
  border: 1px solid transparent;
}
.export-split-opt--row:hover {
  background: var(--panel-2);
  border-color: var(--line);
}
.export-split-opt--row.active {
  background: var(--selected-bg);
  border-color: var(--line);
  color: var(--selected-text);
}

.export-split-opt-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.export-split-opt-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.export-split-opt-hint {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.3px;
  line-height: 1.2;
}
.export-split-opt--row.active .export-split-opt-hint {
  color: var(--muted);
}

.export-split-opt-tag {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.8px;
  padding: 2px 5px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  line-height: 1;
}
.export-split-opt--seg.active .export-split-opt-tag {
  background: rgba(0, 0, 0, 0.18);
  color: var(--black);
}

.export-split-opt-check {
  flex: 0 0 auto;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity var(--dur-press) var(--ease-out), transform var(--dur-press) var(--ease-out);
  color: var(--text);
}
.export-split-opt--row.active .export-split-opt-check {
  opacity: 1;
  transform: scale(1);
}

.export-split-divider {
  height: 1px;
  background: var(--line);
  margin: 8px 0;
}

.export-split-menu::-webkit-scrollbar-track { background: var(--black); border: none; }
.export-split-menu::-webkit-scrollbar-thumb { background: var(--line); border-color: var(--black); }
.export-split-menu { scrollbar-color: var(--line) var(--black); }

/* download RXXR button */
.btn-dl {
  display: none !important;
}
.btn-dl:hover { background: rgba(255,255,255,0.06); color: var(--text); }

.topbar-info-btn {
  align-self: center;
  margin-right: 16px;
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
  font: inherit;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
}
.topbar-info-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}

/* ---- language selector (topbar) ---- */
.lang-select {
  align-self: center;
  margin-right: 8px;
  height: 32px;
  padding: 0 26px 0 10px;
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%237d7d80' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  flex: 0 0 auto;
  -webkit-appearance: none;
  appearance: none;
  transition: color var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out);
}
.lang-select:hover { color: var(--text); border-color: var(--line-hot); }
.lang-select:focus { outline: none; border-color: var(--accent-focus); color: var(--text); }
.lang-select option { background: var(--black); color: var(--text); }

/* ---- inline help markers + popover ---- */
.help-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  margin-left: 5px;
  padding: 0;
  vertical-align: middle;
  font: inherit;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: help;
  flex: 0 0 auto;
  user-select: none;
  opacity: 0;
  transition: color var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out), opacity var(--dur-ui) var(--ease-out);
}
/* keep the ? out of sight until the row is engaged — reveal on hover/focus */
.prop:hover .help-dot,
.prop:focus-within .help-dot,
.slider:hover .help-dot,
.slider:focus-within .help-dot,
.group-head:hover .help-dot,
.group-head:focus-within .help-dot,
.subhead:hover .help-dot,
.subhead:focus-within .help-dot,
.help-dot:hover,
.help-dot:focus-visible,
.help-dot[aria-expanded="true"] { opacity: 1; }
.help-dot:hover,
.help-dot[aria-expanded="true"] {
  color: var(--ink);
  background: var(--accent);
  border-color: var(--accent);
}
.help-dot:focus-visible {
  outline: none;
  border-color: var(--accent-focus);
  color: var(--text);
}

.help-popover {
  position: absolute;
  z-index: 60;
  max-width: 240px;
  padding: 9px 11px;
  font-size: 11px;
  line-height: 1.45;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line-hot);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.55);
  pointer-events: none;
}
.help-popover::after {
  content: "";
  position: absolute;
  left: var(--arrow-x, 50%);
  width: 8px;
  height: 8px;
  margin-left: -4px;
  background: var(--panel-2);
  border: 1px solid var(--line-hot);
  transform: rotate(45deg);
}
.help-popover[data-placement="below"]::after {
  top: -5px;
  border-right: none;
  border-bottom: none;
}
.help-popover[data-placement="above"]::after {
  bottom: -5px;
  border-left: none;
  border-top: none;
}

.gradient-dropdown .dropdown-label,
.gradient-dropdown .dropdown-option {
  display: flex;
  align-items: center;
  gap: 9px;
}
.gradient-dropdown .dropdown-menu { min-width: 240px; }
.gradient-option-preview {
  width: 72px;
  height: 12px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-sm);
  background-color: var(--panel-2);
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
.gradient-option-preview.is-empty {
  background-color: #171719;
  background-image: linear-gradient(135deg,
    transparent calc(50% - 0.5px), #66666a 50%, transparent calc(50% + 0.5px));
  background-size: 100% 100%;
  background-position: center;
}
.gradient-option-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gradient-dropdown .dropdown-option.active .gradient-option-preview {
  border-color: rgba(0, 0, 0, 0.28);
}

.font-dropdown .dropdown-menu { max-height: 360px; min-width: 280px; }
.font-option-trigger,
.dropdown-option.font-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.font-option-trigger .dropdown-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex: 1;
  min-width: 0;
}
.font-option-name {
  font-family: "Roboto Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--muted);
  flex-shrink: 0;
}
.font-option-sample {
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dropdown-option.active .font-option-name { color: rgba(0, 0, 0, 0.55); }
.dropdown-option.active .font-option-sample { color: var(--black); }
.dropdown-trigger.font-option-trigger:hover .font-option-name,
.dropdown.open .font-option-trigger .font-option-name { color: var(--muted); }

/* ===================== LAYOUT ===================== */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  gap: 0;
  padding: 0;
  align-items: stretch;
  min-height: 0;
}
@media (max-width: 1000px) {
  body { height: auto; overflow: auto; }
  .layout { grid-template-columns: 1fr; }
  .presets { border-right: none; border-bottom: 1px solid var(--line); }
  .props { border-left: none; border-top: 1px solid var(--line); }
  /* Stacked layout: the panels size to content, so the preset scroller has to
     carry its own height instead of collapsing to nothing. */
  .presets { overflow: visible; }
  .presets .preset-scroll { flex: 0 0 auto; overflow: visible; }
  .presets .preset-list { max-height: 60vh; }
  .presets .preset-section-body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 6px;
  }
  .presets .preset-section-body .preset-card { margin-bottom: 0; }
  .preview-col .preview-video { min-height: min(50vh, 420px); }
}

/* ----- left presets panel ----- */
.presets {
  display: flex;
  flex-direction: column;
  background: transparent;
  overflow: hidden;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.presets > .panel-label,
.presets-head > .panel-label {
  padding: 10px 14px 0;
  flex-shrink: 0;
}
.presets-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}
.preset-search-wrap {
  display: none;
  position: relative;
  margin: 0 12px;
}
.preset-search {
  font: inherit;
  font-size: 11px;
  display: block;
  width: 100%;
  padding: 7px 28px 7px 10px;
  background: var(--ink);
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}
.preset-search:focus { outline: none; border-bottom-color: var(--accent-focus); }
.preset-search::placeholder { color: var(--muted); }
.preset-search-clear {
  position: absolute;
  top: 50%;
  right: 2px;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  padding: 0;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
}
.preset-search-clear:hover { color: var(--text); }
.preset-search-clear[hidden] { display: none; }
.preset-filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 12px 4px;
}
.preset-filter {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  padding-bottom: 2px;
  overflow-x: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.preset-filter--sources {
  padding: 4px;
  border-radius: var(--radius);
  background: var(--panel-2);
}
.preset-filter--sources .preset-filter-btn.active {
  color: var(--black);
  background: var(--accent);
}
.preset-filter--categories {
  opacity: 1;
  transition: opacity var(--dur-ui) var(--ease-out);
}
.preset-filter--categories.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}
.preset-filter::-webkit-scrollbar { display: none; }
.preset-filter-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.2px;
  padding: 5px 8px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.preset-filter-btn[hidden] { display: none; }
.preset-filter-btn > svg { flex: 0 0 auto; display: block; }
.preset-filter-btn:hover { color: var(--text); }
.preset-filter-btn:active { transform: scale(0.97); }
.preset-filter-btn:disabled {
  cursor: default;
  opacity: 0.55;
}
.preset-filter-btn.active {
  color: var(--text);
  background: var(--accent-subtle);
}
.preset-empty {
  margin: 0;
  padding: 24px 14px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.preset-empty[hidden] { display: none; }
.preset-card[hidden] { display: none !important; }
/* Footer strip of the presets column: the documents are reachable from the app
   itself, not only from the About dialog. It sits outside .preset-scroll, so it
   stays put while the list scrolls. */
.presets-foot {
  flex: 0 0 auto;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
}
.presets-foot-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.2px;
  color: var(--muted);
  text-decoration: none;
}
.presets-foot-icon { display: flex; color: inherit; }
.presets-foot-link:hover { color: var(--text); }
.presets-foot-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.preset-scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.preset-section {
  margin-bottom: 6px;
}
.preset-section[hidden] {
  display: none !important;
}
.preset-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 0 10px;
  margin-top: 6px;
  border-top: 1px solid var(--line);
}
.preset-section-title {
  font-size: 9px;
  letter-spacing: 2px;
  font-weight: 800;
  color: var(--muted);
}
.preset-section-count {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--muted);
  padding: 2px 6px;
  border: 1px solid var(--line);
  line-height: 1;
}
.preset-section-count[hidden] {
  display: none;
}
.preset-section-body {
  display: flex;
  flex-direction: column;
}
.preset-section-empty {
  margin: 0 0 12px;
  padding: 10px 8px;
  font-size: 10px;
  letter-spacing: 0.4px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.preset-section-empty[hidden] {
  display: none;
}
.preset-section-label {
  display: block;
  font-size: 9px;
  letter-spacing: 2px;
  font-weight: 800;
  color: var(--muted);
  padding: 16px 0 8px;
  margin-top: 4px;
  border-top: 1px solid var(--line);
}
.preset-section-label[hidden] { display: none; }
.preset-card--user {
  position: relative;
}
.preset-card--community {
  position: relative;
}
.preset-card--published::after {
  content: "LIVE";
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 2;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 2px 5px;
  background: rgba(187, 234, 85, 0.18);
  color: var(--accent-hover);
  border: 1px solid rgba(187, 234, 85, 0.35);
}
.preset-card-actions {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(10, 10, 10, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-ui) var(--ease-out);
}
.preset-card:hover .preset-card-actions,
.preset-card-actions:focus-within {
  opacity: 1;
  pointer-events: auto;
}
.preset-action-btn {
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  min-width: 96px;
  padding: 7px 16px;
  border: 1px solid var(--line);
  background: rgba(15, 15, 16, 0.9);
  color: var(--text);
  cursor: pointer;
  transition: background-color var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out);
}
.preset-action-btn:hover {
  background: var(--accent);
  color: var(--ink);
  border-color: var(--accent);
}
.preset-action-btn.preset-publish.is-live {
  color: var(--accent);
  background: var(--accent-subtle);
  border-color: rgba(187, 234, 85, 0.45);
}
.preset-action-btn.preset-publish.is-live:hover {
  color: var(--ink);
  background: var(--accent);
  border-color: var(--accent);
}
.preset-unpublish {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  width: 20px;
  height: 20px;
  padding: 0;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preset-unpublish:hover {
  color: var(--text);
  border-color: var(--text);
}
.preset-community-status {
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 0 0 10px;
  margin: -4px 0 0;
}
.preset-community-status[hidden] { display: none; }
.preset-section--community .preset-section-head {
  padding-bottom: 8px;
}
.preset-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 4;
  width: 20px;
  height: 20px;
  padding: 0;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preset-delete:hover {
  color: var(--text);
  border-color: var(--text);
}
.preset-name-panel { max-height: none; }
.preset-name-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.preset-name-label {
  font-size: 9px;
  letter-spacing: 2px;
  font-weight: 800;
  color: var(--muted);
}
.preset-name-input {
  font: inherit;
  font-size: 12px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  width: 100%;
}
.preset-name-input:focus { outline: none; border-bottom-color: var(--accent-focus); }
.preset-name-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.preset-name-cancel,
.preset-name-save {
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  cursor: pointer;
}
.preset-name-cancel {
  background: transparent;
  color: var(--muted);
}
.preset-name-cancel:hover { color: var(--text); border-color: var(--text); }
.preset-name-save {
  background: var(--selected-bg);
  color: var(--text);
  border-color: transparent;
}
.preset-name-save:hover { background: rgba(255,255,255,0.14); }
.preset-delete-panel { max-height: none; }
.preset-delete-body {
  padding: 16px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.preset-delete-message {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}
.preset-delete-confirm {
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 8px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  background: rgba(255, 80, 80, 0.18);
  color: #ff8888;
}
.preset-delete-confirm:hover { background: rgba(255, 80, 80, 0.32); color: #ffaaaa; }
.preset-publish-panel { max-height: none; }
.preset-publish-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.preset-publish-hint {
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  margin: 0;
}
.preset-publish-category {
  font: inherit;
  font-size: 12px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  width: 100%;
}
.preset-publish-category:focus { outline: none; border-bottom-color: var(--accent-focus); }
.preset-publish-error {
  font-size: 11px;
  color: #ff6b6b;
  margin: 0;
}
.preset-publish-error[hidden] { display: none; }

/* Both classes sit on the same element and `.icon-picker-panel` is declared
   further down the file, so an equal-specificity override here loses on source
   order — hence the doubled selector. */
.icon-picker-panel.project-info-panel {
  width: min(560px, 100%);
  /* Tall enough that the whole dialog fits on a normal desktop screen without
     scrolling. The cover stays pinned and the text scrolls under it only when
     the viewport itself is too short to hold the panel. */
  max-height: min(860px, 92vh);
}
.project-info-cover {
  position: relative;
  flex: 0 0 auto;
  margin: 0;
  line-height: 0;
  background: var(--ink);
}
.project-info-cover-img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}
/* the close button sits on artwork now, not on a flat bar — it carries its own
   backdrop so it stays legible whatever the cover is swapped for */
.project-info-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  color: var(--text);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out);
}
.project-info-close:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: var(--text);
}
.project-info-close:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.project-info-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  overflow-y: auto;
  min-height: 0;
}
.project-info-text {
  margin: 0;
  font-size: 12px;
  line-height: 1.65;
  color: var(--text);
}
.project-info-compat {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.project-info-compat-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--muted);
}
.project-info-compat-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.project-info-compat-icon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  /* rows can wrap to several lines; keep the icon on the first one */
  margin-top: 1px;
  color: var(--muted);
}
.project-info-compat-line {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text);
}
/* OFX hosts do not fit one readable line, so they sit in a grid under their
   row, indented to the text column (icon 14px + row gap 8px). */
.project-info-hosts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 3px 16px;
  margin: -3px 0 1px 22px;
}
/* name + version pair: used by the After Effects row and every OFX cell */
.project-info-host {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text);
  white-space: nowrap;
}
.project-info-host b {
  font-weight: 400;
  color: var(--muted);
}
.project-info-links-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.project-info-links {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.project-info-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-decoration: none;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
}
/* the primary action reads primary through colour, not through bulk — it is the
   same cell as the other three */
.project-info-quick-start {
  /* only the family needs resetting off the UA button default — the `font`
     shorthand also reset size and weight, which blew the label up and wrapped it */
  font-family: inherit;
  cursor: pointer;
  color: var(--accent);
  border-color: var(--accent);
}
.project-info-quick-start .project-info-link-icon { color: var(--accent); }
.project-info-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--label);
}
.project-info-link-label {
  line-height: 1;
}
.project-info-link:hover {
  background: rgba(255,255,255,0.08);
  color: var(--accent-hover);
  border-color: var(--text);
}
.project-info-link:hover .project-info-link-icon {
  color: var(--accent-hover);
}
/* The documents are reference, not an action — a line of links under the four
   tiles rather than a fifth tile competing with them. */
.project-info-legal {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin: 8px 0 0;
  font-size: 10px;
  letter-spacing: 0.6px;
  color: var(--muted);
}
.project-info-legal a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.project-info-legal a:hover,
.project-info-legal a:focus-visible {
  color: var(--text);
  border-bottom-color: currentColor;
}
.project-info-legal-sep { color: var(--line-hot); }

/* four labels this long do not survive a full-width panel on a phone */
@media (max-width: 560px) {
  .project-info-links { grid-template-columns: repeat(2, 1fr); }
}
/* versions sit right under the cover, ahead of the intro: a quiet caption
   line, tightened against the paragraph that follows it */
.project-info-version {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 -6px;
  color: var(--muted);
}
.project-info-version-sep { color: var(--line); }

/* ----- quick start ----- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.quick-start {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  /* the tour is non-modal: only the card takes clicks, the app stays usable */
  pointer-events: none;
}
.quick-start[hidden] { display: none; }

/* Nothing behind the tour is dimmed — the ring alone marks the target, so the
   rest of the page keeps showing the change the step just made. */
.quick-start-spotlight {
  position: fixed;
  z-index: 0;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 0 20px 2px var(--accent-subtle);
  pointer-events: none;
  transition:
    left var(--dur-menu) var(--ease-in-out),
    top var(--dur-menu) var(--ease-in-out),
    width var(--dur-menu) var(--ease-in-out),
    height var(--dur-menu) var(--ease-in-out),
    opacity var(--dur-ui) var(--ease-out);
}
.quick-start.is-welcome .quick-start-spotlight,
.quick-start.is-target-missing .quick-start-spotlight {
  opacity: 0;
}

.quick-start-card {
  position: fixed;
  z-index: 1;
  width: min(320px, calc(100vw - 24px));
  padding: 11px 13px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  pointer-events: auto;
  /* no backdrop to separate the card from the page — elevation does it */
  box-shadow: 0 20px 52px rgba(0, 0, 0, 0.7), 0 2px 10px rgba(0, 0, 0, 0.5);
  animation: quick-start-in var(--dur-menu) var(--ease-out);
}
.quick-start.is-welcome .quick-start-card,
.quick-start.is-target-missing .quick-start-card {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
@keyframes quick-start-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.quick-start.is-welcome .quick-start-card { animation: none; }

.quick-start-head {
  min-height: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.quick-start-step {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.6px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.quick-start-step[hidden] { display: none; }
.quick-start-hint {
  padding: 2px 5px;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1.2;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
}
.quick-start-hint[hidden] { display: none; }
.quick-start-skip {
  min-width: 44px;
  min-height: 22px;
  margin-left: auto;
  padding: 0 0 0 10px;
  font: inherit;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.quick-start-skip:hover,
.quick-start-skip:focus-visible { color: var(--text); }

.quick-start-title {
  margin: 0 0 5px;
  font-size: 12px;
  line-height: 1.25;
  letter-spacing: 1.3px;
  font-weight: 800;
  color: var(--text);
  text-transform: uppercase;
}
.quick-start-title:focus { outline: none; }
.quick-start-description {
  min-height: 30px;
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--label);
}

/* Consent line — welcome card only. The links open legal.html in a new tab so
   the tour behind the card is never torn down. */
.quick-start-consent {
  margin: 10px 0 0;
  font-size: 10px;
  line-height: 1.45;
  color: var(--muted);
}
.quick-start-consent[hidden] { display: none; }
.quick-start-consent a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.quick-start-consent a:hover,
.quick-start-consent a:focus-visible { border-bottom-color: currentColor; }
.quick-start-consent a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.quick-start-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
}
.quick-start-button {
  min-width: 82px;
  min-height: 34px;
  padding: 7px 14px;
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  border: 1px solid var(--line-hot);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.quick-start-button[hidden] { display: none; }
.quick-start-button:disabled {
  opacity: 0.35;
  cursor: default;
}
.quick-start-button--secondary {
  color: var(--text);
  background: transparent;
}
.quick-start-button--secondary:hover { background: var(--selected-bg); }
.quick-start-button--primary {
  margin-left: auto;
  color: var(--black);
  background: var(--accent);
  border-color: var(--accent);
}
.quick-start-button--primary:hover { background: var(--text); border-color: var(--text); }
/* still clickable — it cancels the act and jumps to its end state */
.quick-start.is-acting .quick-start-button--primary { opacity: 0.6; }
.quick-start-button:focus-visible,
.quick-start-skip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* a single rail flush with the card's bottom edge, not a marker per step */
.quick-start-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--line);
  overflow: hidden;
}
.quick-start-progress[hidden] { display: none; }
.quick-start-progress > i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width var(--dur-menu) var(--ease-out);
}
.quick-start.is-acting .quick-start-progress > i {
  animation: quick-start-acting 1.1s var(--ease-in-out) infinite;
}
@keyframes quick-start-acting {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@media (max-width: 640px) {
  .quick-start:not(.is-welcome):not(.is-target-missing) .quick-start-card {
    left: 12px !important;
    right: 12px;
    top: auto !important;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    transform: none !important;
  }
  .quick-start-skip,
  .quick-start-button { min-height: 44px; }
  .quick-start-head { min-height: 30px; }
  .quick-start-description { min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .quick-start-card { animation: none; }
  .quick-start-spotlight { transition: none; }
  .quick-start-progress > i { transition: none; }
  .quick-start.is-acting .quick-start-progress > i { animation: none; }
}
.preset-list {
  display: block;
  padding: 0 12px 20px;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
  overscroll-behavior: contain;
  scroll-padding-bottom: 12px;
}
.preset-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  margin-bottom: 10px;
  background: transparent; /* at rest the thumbnail carries the card; fill is hover/active only */
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
.preset-section-body .preset-card:last-child {
  margin-bottom: 0;
}
.preset-card:hover { background: #1a1a1c; }
.preset-card.active {
  background: var(--accent-subtle);
}
.preset-thumb {
  display: block; width: 100%; height: auto; aspect-ratio: 16 / 9;
  background: var(--ink); image-rendering: pixelated;
}
.preset-name {
  font-size: 10px; letter-spacing: 1px; font-weight: 700;
  color: var(--muted); text-align: center;
}
.preset-nickname {
  font-size: 9px;
  letter-spacing: 0.7px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  opacity: 0.9;
}
.preset-card:hover .preset-name,
.preset-card.active .preset-name { color: var(--text); }
.preset-card:hover .preset-nickname,
.preset-card.active .preset-nickname { color: var(--text); }

/* ----- left preview column ----- */
.preview-col {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0;
  min-width: 0;
  min-height: 0;
}

.panel {
  background: transparent;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Without this the head/tool rows' min-content width pushes the whole preview
     column past the viewport on narrow screens. */
  min-width: 0;
}

.preview-video {
  border-bottom: 1px solid var(--line);
}

.panel-label {
  font-size: 10px;
  letter-spacing: 2px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.panel-head h2,
.panel-head .panel-label {
  margin: 0;
}
.panel-head .dim { color: var(--muted); font-weight: 400; letter-spacing: 0; }
.head-tools { display: flex; gap: 0; align-items: center; }
.head-tools .mini svg { width: 12px; height: 12px; }
.tool-group { display: inline-flex; align-items: center; gap: 8px; }
.tool-group-random { gap: 6px; }
.tool-sep {
  width: 1px; align-self: stretch; min-height: 16px;
  background: var(--line); margin: 0 8px; flex: 0 0 auto;
}
.lock-label {
  font-size: 9px; font-weight: 700; letter-spacing: 1px;
  color: var(--muted); text-transform: uppercase;
  margin-right: 2px; user-select: none;
}
.head-tools #resetBtn {
  color: var(--muted);
  background: transparent;
  gap: 5px;
}
.head-tools #resetBtn:hover { color: var(--accent-hover); background: rgba(255,255,255,0.06); }

.mini {
  font: inherit; font-size: 10px; font-weight: 700; letter-spacing: 1px;
  background: var(--panel-2); color: var(--text);
  border: none; padding: 5px 9px; cursor: pointer;
  border-radius: var(--radius-sm); display: inline-flex; align-items: center; gap: 6px;
  transition: color var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.mini:hover { color: var(--accent-hover); background: rgba(255,255,255,0.06); }
.mini.active { color: var(--accent-hover); background: rgba(255,255,255,0.06); }
.mini:active { transform: scale(0.97); }
.mini.chk { cursor: pointer; }
.mini.chk input { accent-color: var(--text); width: 12px; height: 12px; }
.mini.upload { cursor: pointer; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow: hidden;
}
.preview-head { gap: 18px; }

.preview-video .stage { background: var(--ink); padding: 0; }
#videoStage { --stage-bar-h: 54px; }

/* All preview-stage controls — one scale (overrides global .seg-btn) */
#videoStage .seg-btn {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.7px;
  gap: 5px;
  padding: 6px 10px;
  min-height: 32px;
  min-width: 32px;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  color: var(--text);
}
#videoStage .seg-btn svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}
#videoStage .seg-btn:hover {
  color: var(--accent-hover);
  background: rgba(0, 0, 0, 0.88);
}
#videoStage #previewModeSeg .seg-btn {
  padding: 0 12px;
  min-height: 100%;
  min-width: 38px;
}
#videoStage #previewModeSeg .seg-btn svg {
  width: 15px;
  height: 15px;
}
#videoStage #previewModeSeg .seg-btn.active {
  background: transparent;
  color: var(--text);
}
#videoStage #previewModeSeg .seg-btn.active:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
#videoStage #previewModeSeg .seg-btn,
#videoStage #densitySeg .seg-btn,
#videoStage #mapSeg .seg-btn {
  position: relative;
}
#videoStage #previewModeSeg .seg-btn.active::after,
#videoStage #densitySeg .seg-btn.active::after,
#videoStage #mapSeg .seg-btn.active::after {
  content: "";
  position: absolute;
  left: 5px;
  right: 5px;
  bottom: 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 1px 1px 0 0;
  pointer-events: none;
}
#videoStage .seg-btn + .seg-btn {
  border-left-color: rgba(255, 255, 255, 0.12);
}

.stage-idle {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  pointer-events: none;
}
.stage-idle[hidden] { display: none; }
/* idle picker: upload tile + ready-made sample clips, one row of tiles */
.stage-picker {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 100%;
}
.stage-picker-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
}
.stage-picker-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.stage-tile {
  font: inherit;
  padding: 0;
  width: 136px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
  transition: color var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out);
}
.stage-tile:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.68);
}
.stage-tile:active { transform: scale(0.98); }
/* the quick start presses this tile on the user's behalf */
.stage-tile.is-picked {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.68);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.stage-tile-art {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--ink);
}
.stage-tile--upload { border-style: dashed; }
.stage-tile--upload .stage-tile-art { background: transparent; }
#videoStage .stage-tile--upload svg {
  width: 24px;
  height: 24px;
  opacity: 0.7;
}
.stage-tile--upload:hover svg { opacity: 1; color: var(--accent-hover); }
.stage-sample-vid {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.stage-tile-name {
  display: block;
  padding: 5px 0 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}
@media (max-width: 640px) {
  .stage-picker { gap: 10px; }
  .stage-tile { width: 96px; }
}

/* with a source loaded the picker is a hover reveal over the running preview:
   the frame blurs back, the tiles drift up into place */
#videoStage[data-idle="false"] .stage-idle {
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(14px) saturate(0.85);
  -webkit-backdrop-filter: blur(14px) saturate(0.85);
  opacity: 0;
  transition: opacity 260ms var(--ease-out), backdrop-filter 260ms var(--ease-out);
}
#videoStage[data-idle="false"] .stage-idle .stage-picker {
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px) scale(0.985);
  transition: opacity 240ms var(--ease-out) 40ms, transform 320ms var(--ease-out) 40ms;
}
#videoStage[data-idle="false"].is-picker-hover .stage-idle { opacity: 1; }
#videoStage[data-idle="false"].is-picker-hover .stage-idle .stage-picker {
  pointer-events: auto;
  opacity: 1;
  transform: none;
}
/* leaving the frame: no stagger, everything fades out together and faster */
#videoStage[data-idle="false"]:not(.is-picker-hover) .stage-idle,
#videoStage[data-idle="false"]:not(.is-picker-hover) .stage-idle .stage-picker {
  transition-duration: 180ms;
  transition-delay: 0s;
}
@media (prefers-reduced-motion: reduce) {
  #videoStage[data-idle="false"] .stage-idle .stage-picker { transform: none; }
}
/* no hover on touch — the HUD upload and clear buttons cover it there */
@media (hover: none) {
  #videoStage[data-idle="false"] .stage-idle { display: none; }
}
/* the compare split owns the frame: the picker would rise over the divider and
   let the source change mid-comparison */
#videoStage[data-split="on"] .stage-idle { display: none; }

#videoStage[data-idle="true"] #videoCanvas { visibility: hidden; }
#videoStage [hidden] { display: none !important; }

.stage-hud {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.stage-hud > * { pointer-events: auto; }
.stage-hud--top {
  top: 0;
  left: 0;
  right: 0;
  justify-content: space-between;
  align-items: stretch;
  min-height: 38px;
  padding: 0;
  background: rgba(0, 0, 0, 0.52);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.stage-bar {
  --stage-bar-h: 54px;
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--stage-bar-h);
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.52);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.stage-bar-divider {
  width: 1px;
  align-self: stretch;
  margin: 4px 0;
  background: rgba(255, 255, 255, 0.1);
  flex: 0 0 auto;
}
.stage-bar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}
#videoStage .stage-slider {
  flex: 1 1 120px;
  max-width: 180px;
  min-width: 90px;
  gap: 4px;
}
#videoStage .stage-slider span {
  font-size: 9px;
  letter-spacing: 0.7px;
}
#videoStage .stage-slider .tickslider {
  height: 16px;
}
#videoStage .stage-slider .tickslider i { height: 9px; }
#videoStage .stage-slider .tickslider i.lead { height: 16px; }
#videoStage .stage-bar .seg {
  flex: 0 0 auto;
  border-color: rgba(255, 255, 255, 0.1);
}
.stage-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
}
.stage-bar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}
.stage-hud-group {
  display: flex;
  align-items: stretch;
  gap: 0;
}
.stage-hud-group--start {
  flex: 0 0 auto;
}
.stage-hud-group--end {
  min-width: 0;
  flex: 0 1 auto;
  justify-content: flex-end;
  align-items: stretch;
  gap: 0;
  /* No right padding: the last button flushes to the stage edge, mirroring the
     mode seg on the left. Left padding only breathes the file chip off the divider. */
  padding: 0 0 0 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}
.stage-hud-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.1);
  flex: 0 0 auto;
}
.stage-hud-tool {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}
#videoStage .stage-bar-tools .seg {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
}
#videoStage .stage-hud--top #previewModeSeg {
  display: flex;
  align-self: stretch;
  border: none;
  background: transparent;
  overflow: visible;
}
#videoStage .stage-hud--top #previewModeSeg .seg-btn,
#videoStage .stage-bar-tools .seg-btn {
  background: transparent;
  color: var(--muted);
  padding: 5px 7px;
  min-height: 26px;
  min-width: 26px;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out);
}
#videoStage .stage-hud--top #previewModeSeg .seg-btn {
  align-self: stretch;
  min-height: 100%;
  padding: 0 14px;
  border-radius: 0;
}
#videoStage .stage-hud--top #previewModeSeg .seg-btn + .seg-btn {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}
#videoStage .stage-hud--top #previewModeSeg .seg-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
#videoStage .stage-bar-tools .seg-btn svg {
  width: 13px;
  height: 13px;
}
#videoStage .stage-bar-tools .seg-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}
#videoStage #densitySeg .seg-btn.active,
#videoStage #mapSeg .seg-btn.active {
  background: transparent;
  color: var(--text);
}
#videoStage #densitySeg .seg-btn.active:hover,
#videoStage #mapSeg .seg-btn.active:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}
#videoStage .stage-bar-tools .seg-btn + .seg-btn {
  border-left-color: rgba(255, 255, 255, 0.08);
}
#videoStage .stage-hud--top .stage-btn {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.7px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  justify-content: center;
  align-self: stretch;
  min-height: 100%;
  min-width: 26px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 0;
  cursor: pointer;
}
#videoStage .stage-hud--top .stage-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
#videoStage .stage-hud--top .stage-btn--icon {
  padding: 0 10px;
  font-size: 14px;
  line-height: 1;
}
/* One width for every icon button in the end group — the "×" is a text glyph and
   would otherwise sit narrower than the 12px-svg buttons next to it. */
#videoStage .stage-hud--top .stage-hud-group--end .stage-btn {
  flex: 0 0 auto;
  min-width: 38px;
  padding: 0;
}
#videoStage .stage-bar .stage-btn {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.7px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  min-height: 32px;
  min-width: 32px;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: none;
  cursor: pointer;
}
#videoStage .stage-bar .stage-btn svg,
#videoStage .stage-hud--top .stage-btn svg {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
}
#videoStage .stage-bar .stage-btn-icon {
  display: none;
}
#videoStage .stage-bar .stage-btn.is-playing .stage-btn-icon--pause { display: block; }
#videoStage .stage-bar .stage-btn:not(.is-playing) .stage-btn-icon--play { display: block; }
#videoStage .stage-bar .stage-btn:hover {
  color: var(--accent-hover);
  background: rgba(255, 255, 255, 0.12);
}
#videoStage .stage-bar .stage-btn--icon {
  padding: 6px 8px;
  font-size: 16px;
  line-height: 1;
}
.preview-media-chip {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
  min-height: 0;
  /* block, not inline-flex: flex containers don't ellipsize their own text */
  display: block;
  line-height: 34px;
  align-self: center;
}
.preview-media-chip[hidden],
.stage-btn[hidden] { display: none; }

/* These rows crowd whenever their own panel gets narrow — which happens on a
   phone and equally on a 1024px desktop, where the middle column is ~360px.
   So they key off the panel width (container query), not the viewport. */
.preview-video { container: preview / inline-size; }
.preview-glyphs { container: glyphs / inline-size; }

@container glyphs (max-width: 720px) {
  /* The atlas toolbar is wider than the panel: let it stack. */
  .atlas-head { flex-wrap: wrap; row-gap: 8px; }
  .atlas-head .head-tools {
    flex: 1 1 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    row-gap: 6px;
  }
  .atlas-head .tool-group { flex-wrap: wrap; }
  .atlas-head .atlas-preset-bar { flex: 1 1 auto; justify-content: flex-end; }
}

@container preview (max-width: 720px) {
  #videoStage .stage-hud--top { min-height: 36px; }
  #videoStage .stage-hud-group--end { padding: 0 0 0 6px; }
  #videoStage .stage-bar-tools .stage-hud-divider { display: none; }
  #videoStage #previewModeSeg .seg-btn { padding: 0 10px; min-width: 36px; }
  .stage-bar { gap: 8px; padding: 8px 10px; --stage-bar-h: 50px; }
  #videoStage .stage-slider { min-width: 72px; max-width: 120px; }
  #videoStage .stage-bar .stage-btn-label { display: none; }
  .preview-media-chip { max-width: 100px; }
}

@container preview (max-width: 560px) {
  /* No room left for the file name next to the tool buttons. */
  #videoStage .preview-media-chip { display: none; }
  /* Sliders and tool segs no longer fit on one line — stack them. */
  .stage-bar { flex-wrap: wrap; row-gap: 6px; --stage-bar-h: auto; }
  .stage-bar .stage-bar-divider { display: none; }
  .stage-bar-tools { order: 2; flex: 0 1 auto; margin-left: auto; }
  .stage-bar-controls { order: 3; flex: 1 1 100%; }
  #videoStage .stage-slider { flex: 1 1 40%; max-width: none; }
}

#videoStage .stage-bar .stage-btn--icon-only {
  padding: 6px;
  min-width: 0;
  background: transparent !important;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: var(--muted);
  transition: color var(--dur-ui) var(--ease-out);
}
#videoStage .stage-bar .stage-btn--icon-only svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}
#videoStage .stage-bar .stage-btn--icon-only:hover {
  background: transparent !important;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: var(--text);
}
#videoStage .stage-hud--top .stage-btn--upload { display: none; }
#videoStage[data-preview-mode="media"] .stage-hud--top .stage-btn--upload { display: inline-flex; }
#videoStage .stage-hud--top .stage-btn--flip { display: none; }
#videoStage[data-preview-mode="camera"] .stage-hud--top .stage-btn--flip { display: inline-flex; }
#videoStage[data-preview-mode="media"][data-media-type="image"] #playBtn { display: none; }
#videoStage .stage-hud--top .stage-btn--compare[aria-pressed="true"],
#videoStage .stage-hud--top .stage-btn--overlay[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

/* before / after compare split: original media left of the handle, glyphs right */
.stage-split {
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: ew-resize;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.stage-split-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  margin-left: -1px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.stage-split-grip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.92);
  color: #fff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out);
}
.stage-split-grip svg { width: 16px; height: 16px; display: block; }
.stage-split:hover .stage-split-grip,
.stage-split.is-dragging .stage-split-grip {
  background: rgba(0, 0, 0, 0.88);
  transform: translate(-50%, -50%) scale(1.08);
}
.stage-split-label {
  position: absolute;
  bottom: calc(var(--stage-bar-h, 54px) + 10px);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.86);
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 8px;
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  transition: opacity var(--dur-ui) var(--ease-out);
}
.stage-split-label--a { left: 12px; }
.stage-split-label--b { right: 12px; }
.stage-split[data-edge="start"] .stage-split-label--a,
.stage-split[data-edge="end"] .stage-split-label--b { opacity: 0; }

.stage-btn {
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--text);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.stage-btn svg {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  display: block;
}
.stage-btn:hover { color: var(--accent-hover); background: rgba(0, 0, 0, 0.88); }
.stage-btn--icon {
  padding: 7px 9px;
  font-size: 14px;
  line-height: 1;
}

.stage-btn-icon--play { display: none; }
.stage-btn.is-playing .stage-btn-icon--pause { display: block; }
.stage-btn.is-playing .stage-btn-icon--play { display: none; }
.stage-btn:not(.is-playing) .stage-btn-icon--pause { display: none; }
.stage-btn:not(.is-playing) .stage-btn-icon--play { display: block; }

.stage canvas { display: block; max-width: 100%; max-height: 100%; }

#videoCanvas { width: 100%; height: 100%; object-fit: contain; image-rendering: auto; }
#srcVideo, #srcImage, #threeCanvas { display: none; }

/* glyph atlas stage: atlas + overlay stacked, capped so it doesn't grow huge */
.preview-glyphs .panel-head {
  border-bottom: none;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.atlas-head {
  gap: 10px;
}
.atlas-head .panel-label {
  flex-shrink: 0;
}
.atlas-head .head-tools {
  flex-shrink: 0;
}
.atlas-preset-bar {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.atlas-preset-ghost {
  color: var(--muted);
  background: transparent;
  gap: 5px;
  padding: 5px 0;
  white-space: nowrap;
}
.atlas-preset-ghost:hover {
  color: var(--text);
  background: transparent;
}
.atlas-preset-bar[data-mode="idle"] .atlas-preset-work { display: none; }
.atlas-preset-bar:not([data-mode="idle"]) .atlas-preset-ghost { display: none; }
.atlas-preset-work {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.atlas-preset-chip {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--text);
  padding: 5px 8px;
  background: var(--selected-bg);
  max-width: min(160px, 36vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.atlas-preset-chip:hover { color: var(--accent-hover); }
.atlas-preset-chip:active { transform: scale(0.97); }
.atlas-preset-chip[hidden] { display: none; }
.atlas-preset-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 6px 8px;
  background: var(--ink);
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.atlas-preset-input:focus { outline: none; border-bottom-color: var(--accent-focus); }
.atlas-preset-input::placeholder { color: var(--muted); font-weight: 600; }
.atlas-preset-input[hidden] { display: none; }
.atlas-preset-save { flex-shrink: 0; }
.atlas-preset-bar[data-dirty="true"] .atlas-preset-save,
.atlas-preset-bar[data-mode="naming"] .atlas-preset-save {
  color: var(--accent-hover);
}
.atlas-preset-cancel {
  flex-shrink: 0;
  color: var(--muted);
  background: transparent;
  padding: 5px 7px;
  font-size: 16px;
  line-height: 1;
}
.atlas-preset-cancel:hover { color: var(--text); background: transparent; }
.atlas-preset-cancel[hidden] { display: none; }
.atlas-preset-delete {
  flex-shrink: 0;
  color: #ff6b6b;
}
.atlas-preset-delete:hover {
  color: #ff8888;
  background: rgba(255, 80, 80, 0.12);
}
.atlas-preset-delete[hidden] { display: none; }
.atlas-preset-save[hidden] { display: none; }

.preview-glyphs .stage {
  padding: 14px; display: flex; align-items: center; justify-content: center;
}
.atlas-frame {
  position: relative; width: 100%; max-width: 760px; max-height: 100%;
  margin: auto;
}
#atlasCanvas {
  display: block; width: 100%; height: auto; image-rendering: pixelated;
}
#overlayCanvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; image-rendering: pixelated;
}
#glyphStage { cursor: grab; touch-action: none; }
#glyphStage.is-cell-dragging { cursor: grabbing; }

/* per-cell CLEAR / HIDE floating over the selected cell of the atlas */
.cell-hud {
  position: absolute;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 6px;
  pointer-events: none;
  z-index: 2;
}
/* one pill so the pair reads as a single cell toolbar instead of two chips */
.cell-hud-group {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(10,10,10,0.86);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.45);
  opacity: 0;
  transform: translateY(3px);
  transition: opacity var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out);
}
.cell-hud-btn {
  /* hit-testable only while the pill is actually revealed (see below) — an
     invisible pill must not stand between the pointer and the atlas cell */
  pointer-events: none;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out),
              transform var(--dur-press) var(--ease-out);
}
.cell-hud-btn svg { width: 13px; height: 13px; display: block; }
.cell-hud-btn svg[hidden] { display: none; }
.cell-hud-btn:hover { background: var(--selected-bg); color: var(--text); }
.cell-hud-btn:active { transform: scale(0.94); }
/* clearing a cell is the destructive half of the pair — flag it on hover */
.cell-hud-btn[data-cell-action="clear"]:hover { background: rgba(255, 80, 80, 0.14); color: #ff8888; }
/* hide is a toggle: lit while the cell is hidden */
.cell-hud-btn.active { color: var(--accent); }
.cell-hud-btn.active:hover { color: var(--accent-hover); }
.cell-hud-btn:focus-visible { outline: 1px solid var(--accent-focus); outline-offset: -1px; }
/* revealed while the pointer is over the selected cell (is-cell-hovered is set
   from the stage pointermove); a hidden cell keeps its toggle visible so the way
   back is always in reach, and touch devices get no hover at all */
.cell-hud.is-cell-hovered .cell-hud-group,
.cell-hud.is-hidden-cell .cell-hud-group,
.cell-hud-group:focus-within { opacity: 1; transform: none; }
.cell-hud.is-cell-hovered .cell-hud-btn,
.cell-hud.is-hidden-cell .cell-hud-btn,
.cell-hud-group:focus-within .cell-hud-btn { pointer-events: auto; }
#glyphStage.is-cell-dragging .cell-hud { opacity: 0; }
#glyphStage.is-cell-dragging .cell-hud-btn { pointer-events: none; }
@media (hover: none) {
  .cell-hud-group { opacity: 1; transform: none; }
  .cell-hud-btn { pointer-events: auto; }
}

.atlas-view-toggles {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
  flex-shrink: 0;
}
.view-toggle {
  color: var(--muted);
  background: transparent;
  padding: 5px;
}
.view-toggle:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.view-toggle.active { color: var(--accent); background: transparent; }
.view-toggle.active:hover { color: var(--accent-hover); background: rgba(255,255,255,0.06); }

.checker {
  background-image:
    linear-gradient(45deg, #1a1a1b 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a1b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a1b 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a1b 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-color: #0d0d0e;
}

/* ===================== RIGHT PROPERTIES PANEL ===================== */
.props {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: transparent;
  overflow-y: auto;
  min-height: 0;
  min-width: 0;
  padding-bottom: 20px;
  scroll-padding-bottom: 16px;
  border-left: 1px solid var(--line);
}
/* ----- collapsible groups (AE-style) ----- */
.group { border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: none; }
/* selected group: brighter head so the active section is obvious */
.group.selected .group-head {
  color: var(--text);
}
.group.selected .group-head .chev { color: var(--text); }
/* open group body reads as a card, a hair lifted off the black head */
.group:not(.collapsed) .group-body { background: var(--panel); }

.group-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 14px;
  background: var(--black);
  border: none;
  color: var(--label);
  font: inherit;
  font-size: 10px;
  letter-spacing: 1.4px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
  transition: color var(--dur-ui) var(--ease-out), box-shadow var(--dur-ui) var(--ease-out);
}
.group-head:hover { color: var(--accent-hover); }
.group-head .group-name { flex: 1; }
.group-head .chev {
  color: var(--muted); font-size: 10px; width: 10px;
  transform: rotate(0deg);
}
.group.collapsed .chev { transform: rotate(-90deg); }
.group-head .badge { letter-spacing: 1px; }

/* on/off switch in a group head */
.switch {
  position: relative; width: 30px; height: 16px; flex: 0 0 auto;
  border: none; border-radius: 999px; background: var(--panel-2); cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--muted); transition: left var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out);
}
.switch[aria-checked="true"] { background: rgba(255,255,255,0.1); }
.switch[aria-checked="true"]::after { left: 16px; background: var(--text); }
.switch:focus { outline: none; box-shadow: 0 0 0 1px var(--accent-focus); }

/* colour overrides stay editable like SIZE + OFFSET; each tile shows its own
   on/off state via the .active class + eye toggle, so no group-level gating */
.global-overrides { margin-top: 12px; }

/* spread the fill colour across cells as a dark → bright glyph-colour ramp */
/* each colour tile carries its own spread row — SPREAD, the ramp-shape anchor
   and CLEAR sit with the colour they act on, so glyph fill and backdrop are
   configured separately instead of through a shared target switch */
.global-ramp-block {
  display: flex;
  align-items: stretch;
  gap: 6px;
  /* tight to the colour bar it belongs to; the air that separates FILL from
     BACKDROP lives between the tiles instead (.global-overrides .swatch-colors) */
  margin-top: 6px;
}
.global-ramp-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  transition: color var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.global-ramp-btn:hover { color: var(--text); border-color: var(--accent); }
.global-ramp-btn:active { background: rgba(255, 255, 255, 0.06); transform: scale(0.98); }
/* lit while the 12 cells still hold exactly this ramp — the check is the plain
   read of "this spread is what's on the atlas right now" */
.global-ramp-on { flex: 0 0 auto; margin-left: auto; color: var(--accent); opacity: 0; }
.is-spread .global-ramp-btn {
  border-color: var(--accent);
  background: var(--selected-bg);
  color: var(--text);
}
.is-spread .global-ramp-on { opacity: 1; }
.global-ramp-preview {
  flex: 0 0 auto;
  width: 52px;
  height: 12px;
  background: linear-gradient(90deg, #1a1a1a, #e6e6e6);
}
.global-ramp-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* where the picked colour itself sits: the icons draw the ramp's own shape —
   rising to the last cell, or peaking in the middle */
.global-ramp-mode { flex: 0 0 auto; }
.global-ramp-mode .seg-btn { padding: 3px 8px; }
.global-ramp-mode .seg-btn svg { display: block; width: 14px; height: 14px; }
.global-ramp-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  transition: color var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out);
}
.global-ramp-clear:hover { color: var(--text); border-color: var(--accent); }
.global-ramp-clear:active { background: rgba(255, 255, 255, 0.06); }
/* nothing per-cell to clear for this target */
.global-ramp-clear:disabled { opacity: 0.35; cursor: default; }
.global-ramp-clear:disabled:hover { color: var(--muted); border-color: var(--line); }
.global-ramp-clear svg { flex: 0 0 auto; }

/* shape picker — single-row Lucide icons */
.shape-prop { margin-top: 6px; }
.shape-seg { display: flex; width: 100%; }
.shape-seg .seg-btn {
  flex: 1;
  justify-content: center;
  padding: 6px 0;
}
.shape-seg .seg-btn svg { width: 14px; height: 14px; }
.shape-style-prop,
.shape-stroke-prop { margin-top: 6px; }
.shape-style-prop.disabled,
.shape-stroke-prop.disabled {
  pointer-events: none;
}
.shape-style-prop.disabled > span,
.shape-stroke-prop.disabled > span {
  color: #565658;
}
.shape-stroke-prop.disabled > span b {
  color: #565658;
}
.shape-style-prop.disabled .seg-btn {
  color: #565658;
  background: #1a1a1c;
}
.shape-style-prop.disabled .seg-btn.active {
  background: #252527;
  color: #565658;
}
.shape-stroke-prop.disabled .tickslider {
  cursor: default;
}
.shape-stroke-prop.disabled .tickslider i {
  background: #1a1a1c;
}
.shape-stroke-prop.disabled .tickslider i.on {
  background: #353537;
}
.shape-stroke-prop.disabled .tickslider i.lead {
  background: linear-gradient(#565658, #565658) center / 3px 100% no-repeat;
}
.shape-style-seg,
.pattern-edge-seg { display: flex; width: 100%; }
.shape-style-seg .seg-btn,
.pattern-edge-seg .seg-btn {
  flex: 1;
  justify-content: center;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 6px 0;
}

.pattern-edge-prop { margin-top: 10px; }
.pattern-edge-prop.disabled { pointer-events: none; }
.pattern-edge-prop.disabled > span { color: #565658; }
.pattern-edge-prop.disabled .seg-btn { color: #565658; background: #1a1a1c; }
.pattern-edge-prop.disabled .seg-btn.active { background: #252527; color: #565658; }

.group-body {
  padding: var(--sp-3);
  display: grid;
  overflow: hidden;
  min-width: 0;
}
.group.collapsed .group-body { display: none; }

/* ----- CELL sub-sections: micro-label + hairline divider ----- */
.subhead {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  letter-spacing: 1.4px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: var(--sp-1);
}
.prop-divider {
  height: 1px;
  background: var(--line);
  margin: var(--sp-3) calc(var(--sp-3) * -1);
}
.prop-divider:first-child { display: none; }

.props-foot { padding: 14px; margin-top: auto; }

.badge {
  background: var(--selected-bg); color: var(--text); font-weight: 800;
  padding: 2px 8px; font-size: 11px; letter-spacing: 1px;
  border: none;
  border-radius: var(--radius-sm);
}

.prop { display: flex; flex-direction: column; gap: 7px; margin-bottom: var(--sp-3); }
.prop:last-child { margin-bottom: 0; }
.prop > span { font-size: 10px; letter-spacing: 0.6px; color: var(--label); font-weight: 700; }
.prop.inline { flex-direction: row; align-items: center; justify-content: space-between; }
.prop.inline > span { font-size: 11px; color: var(--text); }
.prop.two { flex-direction: row; gap: 12px; }
.prop.two .slider,
.prop.two > label { flex: 1; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.prop.two > label > span { font-size: 10px; letter-spacing: 0.6px; color: var(--label); font-weight: 700; }

.prop input[type="text"] {
  font: inherit; font-size: 18px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px; width: 100%; border-radius: var(--radius);
}
.prop input[type="text"]:focus { outline: none; border-color: var(--accent-focus); }

.row { display: flex; align-items: center; gap: 10px; }
.row input[type="checkbox"] { accent-color: var(--text); width: 15px; height: 15px; }
.hint { font-size: 9px; color: var(--muted); letter-spacing: 0.5px; }

.swatch {
  width: 44px; height: 26px; padding: 0;
  border: 1px solid var(--line); background: none; cursor: pointer; border-radius: var(--radius);
}

/* ----- cell editor ----- */
.cell-editor {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: stretch;
  margin-bottom: 16px;
  background: var(--panel-2);
  border-radius: var(--radius);
  overflow: hidden;
}
/* explicit display above overrides the UA [hidden] rule, so restore it */
.cell-editor[hidden] { display: none; }
/* same fix for the per-cell image/icon row — .cell-swatch-panel sets display:flex */
.cell-media[hidden] { display: none; }
/* per-cell CLEAR / HIDE, sitting under the cell field */
.cell-actions {
  display: flex;
  gap: 8px;
  margin: -8px 0 16px;
}
.cell-actions[hidden] { display: none; }
.cell-actions .mini { flex: 1 1 0; justify-content: center; }
/* a hidden cell keeps its editor usable, just visibly inert */
.group-body.cell-is-hidden .cell-editor,
.group-body.cell-is-hidden .cell-swatch-panel { opacity: 0.5; }
.cell-nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.cell-nav-btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}
.cell-nav-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}
.cell-nav-btn:active { background: rgba(255, 255, 255, 0.1); transform: scale(0.94); }
.cell-editor-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 8px 4px;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}
.cell-editor-index {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1.4px;
  color: var(--muted);
  line-height: 1;
  user-select: none;
}
.glyph-input {
  font: inherit;
  font-weight: 700;
  font-size: 32px;
  line-height: 1;
  text-align: center;
  background: transparent;
  border: none;
  color: var(--text);
  width: 100%;
  min-width: 0;
  height: auto;
  padding: 0;
  border-radius: 0;
}
.glyph-input::placeholder { color: #3a3a3d; }
.glyph-input:focus {
  outline: none;
}

/* SINGLE / ALL 12 glyph-entry mode toggle */
.cell-mode-seg {
  display: flex;
  width: 100%;
  margin-bottom: 10px;
}
.cell-mode-seg .seg-btn {
  flex: 1;
  justify-content: center;
  padding: 7px 0;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.4px;
}

/* ALL 12 — one field for the whole ramp */
.ramp-editor { margin-bottom: 16px; }
.ramp-input {
  font: inherit;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 6px;
  line-height: 1;
  text-align: center;
  width: 100%;
  background: var(--panel-2);
  border: none;
  color: var(--text);
  padding: 16px 6px;
  border-radius: var(--radius);
}
.ramp-input::placeholder { color: #3a3a3d; letter-spacing: 6px; }
.ramp-input:focus { outline: none; }
.ramp-hint {
  display: block;
  margin-top: 6px;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  user-select: none;
}

/* ----- swatch tiles ----- */
.swatch-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch-grid.two { grid-template-columns: repeat(2, 1fr); }
.swatch-grid.four { grid-template-columns: repeat(2, 1fr); }

.swatch-tile { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.swatch-box {
  position: relative;
  height: 46px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  overflow: hidden;
  display: block;
  background-size: cover;
  background-position: center;
}
button.swatch-box {
  font: inherit;
  width: 100%;
  padding: 0;
  text-align: inherit;
}
.swatch-tile:not(.swatch-tile--color):hover .swatch-box {
  box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.04);
}
.swatch-tile:not(.swatch-tile--color).active .swatch-box {
  box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.08);
}
.swatch-tile:not(.swatch-tile--color):hover .upload-box {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: none;
}
.swatch-tile:not(.swatch-tile--color).active .upload-box {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}
.swatch-box input[type="color"] {
  position: absolute; inset: -4px;
  width: calc(100% + 8px); height: calc(100% + 8px);
  padding: 0; border: none; background: none; cursor: pointer;
}
/* transparent state: show checker until a colour is chosen */
.swatch-box.checker {
  background-image:
    linear-gradient(45deg, #1f1f20 25%, transparent 25%),
    linear-gradient(-45deg, #1f1f20 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1f1f20 75%),
    linear-gradient(-45deg, transparent 75%, #1f1f20 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-color: #0d0d0e;
}
.swatch-tile:not(.active) .swatch-box.checker input[type="color"] { opacity: 0; }

.upload-box {
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2);
}
.upload-glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.upload-glyph svg { display: block; }
.swatch-tile.active .upload-glyph { display: none; }

.swatch-cap {
  font-size: 9px; letter-spacing: 1.5px; font-weight: 700;
  color: var(--muted); text-align: center;
}
.swatch-tile.active .swatch-cap { color: var(--text); }

.swatch-chip {
  font: inherit; font-size: 9px; font-weight: 800; letter-spacing: 1px;
  background: transparent; color: var(--text);
  border: none; border-radius: var(--radius-sm); padding: 4px 6px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.swatch-chip-row { display: flex; gap: 2px; justify-content: center; min-width: 0; }
.swatch-chip:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.swatch-chip:active { transform: scale(0.96); }
.swatch-tile.active .swatch-chip {
  color: var(--text);
  background: rgba(255,255,255,0.08);
}
.swatch-tile:not(.active) .swatch-chip { visibility: hidden; }

/* icon-only chips in the cell color/media clusters.
   text spans stay in the DOM for i18n + screen readers, hidden visually;
   the existing title / data-i18n-title tooltips carry discoverability */
.cell-swatch-panel .swatch-chip {
  padding: 0;
  width: 24px;
  gap: 0;
}
.cell-swatch-panel .swatch-chip > span[data-i18n] {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.cell-swatch-panel .swatch-chip svg { width: 13px; height: 13px; }

/* ----- cell color rows (GLYPH / FILL) ----- */
.cell-swatch-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.swatch-colors {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.swatch-tile--color { gap: 0; }
.swatch-color-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: stretch;
  gap: 8px;
  height: 36px;
  padding: 0;
  background: var(--panel-2);
  border-radius: var(--radius);
  border: none;
  overflow: hidden;
}
.swatch-color-actions {
  display: flex;
  align-self: stretch;
}
.swatch-color-actions .swatch-chip + .swatch-chip {
  border-left: 1px solid var(--line);
}
.swatch-tile--color:hover .swatch-color-row {
  box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.04);
}
.swatch-tile--color.active .swatch-color-row {
  box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.08);
}
.swatch-box--compact {
  width: 36px;
  height: 100%;
  flex: 0 0 auto;
}
.swatch-color-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding-right: 4px;
}
.swatch-tile--color .swatch-cap {
  text-align: left;
  font-size: 8px;
  letter-spacing: 1.2px;
}
.swatch-hex {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.swatch-hex--inherit { color: var(--muted); }
.swatch-hex--empty {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
}
.swatch-tile--color .swatch-box {
  border: none;
}
.swatch-tile--color:hover .swatch-box,
.swatch-tile--color.active .swatch-box {
  border: none;
}
.swatch-tile--color .swatch-chip {
  align-self: stretch;
  visibility: visible;
  min-width: 0;
  padding: 0;
  font-size: 8px;
  border-left: none;
}
.swatch-tile--color:not(.active) .swatch-chip {
  display: none;
}
.swatch-tile--color .swatch-box input[type="color"] {
  inset: 0;
  width: 100%;
  height: 100%;
}
.swatch-tile--color .swatch-box.checker input[type="color"] { opacity: 1; }
.swatch-tile--color:not(.active) .swatch-box.checker input[type="color"] { opacity: 0; }
.cell-swatch-panel .swatch-grid { gap: 6px; }
.cell-swatch-panel .swatch-grid .swatch-tile { gap: 4px; }
.cell-swatch-panel .swatch-grid .swatch-box { height: 36px; }
.cell-swatch-panel .swatch-grid .swatch-cap { font-size: 8px; letter-spacing: 1.2px; }
.cell-swatch-panel .swatch-grid .swatch-chip { padding: 3px 0; align-self: center; }

/* compact native gradient control, kept inside CELL → COLOR */
.gradient-control {
  display: grid;
  gap: 7px;
  margin: -4px 0 14px;
}
.gradient-preset-prop { margin: 0; }
.gradient-preset-line {
  display: flex;
  align-items: stretch;
  gap: 4px;
  min-width: 0;
}
.gradient-preset-line .dropdown { flex: 1; min-width: 0; }
.gradient-gen-btn { flex: none; width: 30px; padding: 0; }

/* inline gradient editor: the ramp the atlas actually draws, with a draggable
   marker per stop sitting along the bottom edge */
.gradient-stops-row {
  display: grid;
  gap: 6px;
  min-width: 0;
}
/* An author `display` beats the UA `[hidden] { display: none }`, so the editor
   row stayed on screen with an empty bar while the preset was "none". */
.gradient-stops-row[hidden] { display: none; }
.gradient-actions {
  display: flex;
  justify-content: flex-end;
  gap: 2px;
}
.gradient-actions .swatch-chip[hidden] { display: none; }
/* .swatch-chip svg is display:block, which would beat [hidden] on the inactive
   blend icon and show both at once. */
.gradient-actions .swatch-chip svg[hidden] { display: none; }
.gradient-actions .swatch-chip[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}
.swatch-chip--danger:hover { color: #ff8888; }
.gradient-stops-bar {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-sm);
  background-color: var(--panel-2);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  touch-action: none;
}
.gradient-stop {
  position: absolute;
  bottom: 0;
  left: 0;
  transform: translateX(-50%);
  width: 14px;
  height: 18px;
  box-sizing: border-box;
  border: 1px solid rgba(0, 0, 0, 0.65);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55);
  border-radius: var(--radius-sm);
  cursor: ew-resize;
}
.gradient-stop:hover { box-shadow: 0 0 0 1px #fff; }
.gradient-stop input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
}
.swatch-box.has-gradient {
  background-size: 100% 100%;
  background-position: center;
}
.swatch-box.has-gradient input[type="color"] { opacity: 0 !important; }

.swatch-vis {
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 0;
  font: inherit;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
}
.swatch-vis:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}
.swatch-vis[aria-pressed="true"] { color: var(--text); }
.swatch-vis-icon { display: block; }
.swatch-vis-icon--off { display: none; }
.swatch-vis[aria-pressed="false"] .swatch-vis-icon--on { display: none; }
.swatch-vis[aria-pressed="false"] .swatch-vis-icon--off { display: block; }

/* each tile is now a colour bar plus its own spread row — 6px binds the pair,
   so the tiles need real air between them or the four rows read as one mass */
.global-overrides .swatch-colors { gap: 18px; }

.slider { display: flex; flex-direction: column; gap: 7px; }
.slider span { font-size: 10px; letter-spacing: 0.6px; color: var(--label); font-weight: 700; }
.slider b { color: var(--text); }
/* label left, value right on one clean baseline */
.slider > span { display: flex; align-items: center; gap: 6px; }
.slider > span > span:first-child { flex: 1; letter-spacing: 0.6px; }
.slider > span > b { letter-spacing: 0.5px; }

/* ----- C4 tick slider ----- */
.tickslider {
  display: flex; align-items: center; gap: 2px;
  width: 100%; height: 22px; cursor: pointer; touch-action: none;
}
.tickslider i { flex: 1; height: 13px; background: #1d1d1f; display: block; transition: background var(--dur-press) var(--ease-out); }
.tickslider i.on { background: var(--muted); }
.tickslider.modified i.on { background: var(--accent); }
.tickslider i.lead {
  background: linear-gradient(var(--pin), var(--pin)) center / 3px 100% no-repeat;
  height: 22px;
}
.tickslider:hover i:not(.on):not(.lead) { background: #262628; }

.cellnav { display: flex; gap: 8px; }
.cellnav .mini { flex: 1; justify-content: center; }

.btn-ghost {
  font: inherit; font-size: 11px; font-weight: 800; letter-spacing: 1px;
  width: 100%; background: transparent; color: var(--violet);
  border: none; padding: 10px; cursor: pointer; border-radius: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.btn-ghost svg { width: 14px; height: 14px; flex: 0 0 auto; display: block; }
.btn-ghost:hover { background: var(--violet); color: var(--text); }
.btn-ghost:active { transform: scale(0.98); }

/* ===================== CUSTOM SCROLLBARS ===================== */
/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line) var(--panel);
}

/* WebKit / Blink */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track {
  background: var(--panel);
  border-left: 1px solid var(--line);
}
*::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 2px solid var(--panel);
  background-clip: padding-box;
  border-radius: 0;
  min-height: 32px;
}
*::-webkit-scrollbar-thumb:hover { background: #444448; }
*::-webkit-scrollbar-thumb:active { background: #5a5a5e; }
*::-webkit-scrollbar-corner { background: var(--panel); }

/* dark popovers / menus on black track */
.export-split-menu,
.cpick,
.icon-picker-grid {
  scrollbar-color: var(--line) var(--black);
}
.export-split-menu::-webkit-scrollbar-track,
.cpick::-webkit-scrollbar-track,
.icon-picker-grid::-webkit-scrollbar-track {
  background: var(--black);
  border-left: 1px solid var(--line);
}
.export-split-menu::-webkit-scrollbar-thumb,
.cpick::-webkit-scrollbar-thumb,
.icon-picker-grid::-webkit-scrollbar-thumb {
  border-color: var(--black);
}

/* horizontal-only bars (top context bar) sit on the panel, not pure black */
.ctx-controls {
  scrollbar-color: var(--line) var(--panel);
}
.ctx-controls::-webkit-scrollbar-track { background: var(--panel); border: none; border-top: 1px solid var(--line); }
.ctx-controls::-webkit-scrollbar-thumb { border-color: var(--panel); }

/* preset list + props panel scrollbars use neutral thumb on panel track */
.preset-list::-webkit-scrollbar-thumb,
.props::-webkit-scrollbar-thumb { border-color: var(--panel); }
.preset-list:hover::-webkit-scrollbar-thumb,
.props:hover::-webkit-scrollbar-thumb { background: #444448; }
.preset-list,
.props { scrollbar-color: var(--line) var(--panel); }

/* ===================== CUSTOM COLOR PICKER ===================== */
/* native color inputs become a passive swatch fill; clicks open the popover */
input[type="color"].is-cpick { pointer-events: none; }

.cpick {
  position: fixed; z-index: 200; display: none;
  width: 232px; padding: 12px;
  background: var(--black);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  user-select: none; touch-action: none;
  transform-origin: top left;
}
.cpick.open { display: block; animation: menu-in var(--dur-menu) var(--ease-out); }

.cpick-sv {
  position: relative; width: 100%; height: 140px;
  margin-bottom: 12px; cursor: crosshair;
  border: 1px solid var(--line);
}
.cpick-sv-thumb {
  position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6); pointer-events: none;
}

.cpick-hue {
  position: relative; width: 100%; height: 14px; margin-bottom: 12px;
  cursor: pointer; border: 1px solid var(--line);
  background: linear-gradient(to right,
    #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%,
    #0000ff 67%, #ff00ff 83%, #ff0000 100%);
}
.cpick-hue-thumb {
  position: absolute; top: -2px; bottom: -2px; width: 6px; margin-left: -3px;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.cpick-foot { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cpick-hash { color: var(--muted); font: 700 13px/1 "Roboto Mono", monospace; }
.cpick-hex {
  flex: 1; min-width: 0;
  font: 700 13px "Roboto Mono", monospace; letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 7px 8px; border-radius: var(--radius);
}
.cpick-hex:focus { outline: none; border-color: var(--accent-focus); }
.cpick-preview {
  width: 30px; height: 30px; flex: 0 0 auto; border: 1px solid var(--line);
}
.cpick-pick {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
}
.cpick-pick:hover { color: var(--text); border-color: var(--text); }
.cpick-pick.active { color: var(--accent-hover); border-color: var(--accent); }

.cpick-pick-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  cursor: crosshair;
  background: transparent;
}
.cpick-pick-overlay[hidden] { display: none; }
.cpick-pick-loupe {
  position: fixed;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}
body.is-eyedropper-active { cursor: crosshair !important; }

.cpick-swatches { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.cpick-sw {
  height: 16px; padding: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.cpick-sw:hover { border-color: var(--text); transform: scale(1.12); }

/* ----- icon picker (Iconify) ----- */
.icon-picker {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  padding: 16px;
  animation: modal-fade-in var(--dur-menu) var(--ease-out);
}
.icon-picker[hidden] { display: none; }
.icon-picker-panel {
  width: min(360px, 100%);
  max-height: min(480px, 90vh);
  display: flex;
  flex-direction: column;
  background: var(--black);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  /* modals scale from center (transform-origin default), not from a trigger */
  animation: modal-pop-in var(--dur-menu) var(--ease-out);
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}
.icon-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.icon-picker-title {
  font-size: 10px;
  letter-spacing: 2px;
  font-weight: 800;
  color: var(--muted);
}
.icon-picker-close {
  font: inherit;
  font-size: 20px;
  line-height: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}
.icon-picker-close:hover { color: var(--text); }
.icon-picker-search {
  font: inherit;
  font-size: 12px;
  margin: 10px 12px 0;
  padding: 8px 10px;
  background: var(--panel-2);
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  width: calc(100% - 24px);
}
.icon-picker-search:focus { outline: none; border-bottom-color: var(--accent-focus); }
.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 10px 12px 12px;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
}
.icon-picker-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid transparent;
  cursor: pointer;
  padding: 6px;
}
.icon-picker-item:hover { border-color: var(--text); background: #1a1a1c; }
/* Set fetched, icon not in it — kept in place so the grid does not reflow. */
.icon-picker-item.is-missing { opacity: 0.25; cursor: default; }
.icon-picker-item.is-missing:hover { border-color: transparent; background: var(--panel-2); }
.icon-picker-item img {
  width: 20px;
  height: 20px;
  display: block;
  pointer-events: none;
}
/* Licence of the hovered icon. Iconify sets differ — CC BY wants attribution,
   CC BY-SA follows the finished work — so the tile grid stays clean and the
   name lands here, legible, instead of inside a 40px square. */
.icon-picker-note {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 7px 12px 8px;
  font-size: 10px;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Licence card for the icon in the selected cell. Fixed-positioned off the
   chip, so the scrolling properties column cannot clip it. */
.lic-pop {
  position: fixed;
  z-index: 60;
  width: 216px;
  max-width: calc(100vw - 16px);
  padding: 10px 12px 11px;
  background: var(--black);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}
.lic-pop[hidden] { display: none; }
.lic-pop-set {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lic-pop-name { margin-top: 3px; font-size: 11px; color: var(--text); }
.lic-pop-name a { color: var(--text); text-underline-offset: 2px; }
.lic-pop-note { margin-top: 6px; font-size: 10px; line-height: 1.35; color: var(--muted); }
.icon-picker-empty {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
}

/* ===================== REDUCED MOTION ===================== */
/* Gentle, not zero: keep color/opacity fades that aid comprehension;
   drop movement (press scale, menu scale/translate). Caret rotations
   stay — they are meaningful open/closed state indicators, not decoration. */
@media (prefers-reduced-motion: reduce) {
  .seg-btn:active,
  .preset-filter-btn:active,
  .export-split-main:active,
  .export-split-caret:active,
  .mini:active,
  .global-ramp-btn:active,
  .atlas-preset-chip:active,
  .cell-nav-btn:active,
  .cell-hud-btn:active,
  .swatch-chip:active,
  .btn-ghost:active { transform: none; }

  .cell-hud-group { transform: none; }

  .export-split.open .export-split-menu,
  .dropdown.open .dropdown-menu,
  .cpick.open,
  .icon-picker-panel { animation: reduced-fade-in var(--dur-menu) var(--ease-out); }
}
@keyframes reduced-fade-in { from { opacity: 0; } to { opacity: 1; } }
