:root {
  --lime: #bbea55;
  --violet: #4700ff;
  --black: #000000;
  --ink: #0a0a0a;
  --panel: #0f0f10;
  --panel-2: #161617;
  --line: #2a2a2c;
  --line-hot: var(--text);
  --pin: #ffffff;
  --text: #f2f2ef;
  --muted: #7d7d80;
  --header-h: 64px;
  --accent: var(--lime);
  --accent-hover: var(--text);
  --focus: #d4d4d6;
  --accent-focus: var(--focus);
  --accent-subtle: rgba(187,234,85,0.12);
  --selected-bg: rgba(255,255,255,0.09);
  --selected-text: var(--text);
  --selected-border: var(--line-hot);
}

* { 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; }
.btn-icon--lg svg { width: 14px; height: 14px; }
.swatch-chip svg { width: 12px; height: 12px; flex: 0 0 auto; display: block; }

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-beta {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 3px 7px;
  line-height: 1;
}
.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; }
.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;
}
.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 svg { display: block; }

.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);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.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 0.12s, color 0.12s;
}
.export-split-main:hover { background: var(--violet); color: var(--text); }
.export-split-main:active { transform: translateY(1px); }

.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 0.12s, background 0.12s;
}
.export-split-caret:hover { color: var(--accent-hover); background: rgba(255,255,255,0.06); }
.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-caret svg { transition: transform 0.12s; }

.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: 0;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.03);
  overflow: hidden;
}
.export-split.open .export-split-menu {
  display: block;
  animation: export-menu-in 0.14s ease-out;
}
@keyframes export-menu-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.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);
  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 0.1s, color 0.1s;
}

.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 0.1s, transform 0.1s;
  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);
}

/* custom dropdown (replaces native select.ctl) */
.is-enhanced { display: none !important; }
.dropdown { position: relative; display: flex; width: 100%; }
.dropdown-trigger {
  font: inherit; font-size: 12px;
  display: inline-flex; align-items: center; gap: 10px; width: 100%;
  background: var(--panel-2); border: none; border-bottom: 1px solid var(--line);
  color: var(--text);
  padding: 6px 10px; cursor: pointer; border-radius: 0; white-space: nowrap;
}
.dropdown-trigger:hover { border-bottom-color: var(--accent-focus); }
.dropdown.open .dropdown-trigger { border-bottom-color: var(--accent-focus); color: var(--accent-hover); }
.dropdown-label { flex: 1; text-align: left; }
.dropdown-caret { color: var(--muted); font-size: 9px; transition: transform 0.12s; }
.dropdown.open .dropdown-caret { transform: rotate(180deg); }

.dropdown-menu {
  position: fixed; z-index: 60; display: none;
  background: var(--black); border: 1px solid var(--line);
  max-height: 280px; overflow-y: auto;
  overscroll-behavior: contain;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-option {
  display: block; width: 100%; text-align: left;
  font: inherit; font-size: 12px;
  background: transparent; border: none; color: var(--text);
  padding: 8px 12px; cursor: pointer; white-space: nowrap;
}
.dropdown-option:hover { background: var(--panel-2); color: var(--accent-hover); }
.dropdown-option.active { background: var(--text); color: var(--black); font-weight: 700; }

.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); }
}

/* ----- 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-filter {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  margin: 0 12px;
  padding-bottom: 2px;
  overflow-x: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.preset-filter::-webkit-scrollbar { display: none; }
.preset-filter-btn {
  flex: 0 0 auto;
  font: inherit;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.2px;
  padding: 5px 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.preset-filter-btn:hover { color: var(--text); }
.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; }
.preset-scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.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-publish {
  position: absolute;
  top: 4px;
  right: 28px;
  z-index: 2;
  width: 20px;
  height: 20px;
  padding: 0;
  font: inherit;
  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-publish:hover {
  color: var(--accent-hover);
  border-color: var(--accent-hover);
}
.preset-publish.is-live {
  color: var(--accent-hover);
  border-color: rgba(187, 234, 85, 0.45);
}
.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: 8px 0 12px;
  margin: 0;
}
.preset-community-status[hidden] { display: none; }
.preset-section-label--community {
  margin-top: 0;
  border-top: none;
  padding-top: 8px;
}
.preset-delete {
  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-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; }

.project-info-panel { max-height: none; width: min(420px, 100%); }
.project-info-body {
  padding: 16px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.project-info-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.project-info-logo {
  height: 48px;
  width: auto;
  display: block;
}
.project-info-text {
  margin: 0;
  max-width: 34ch;
  font-size: 12px;
  line-height: 1.65;
  color: var(--text);
}
.project-info-compat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  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: center;
  gap: 8px;
}
.project-info-compat-icon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.project-info-compat-line {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text);
}
.project-info-links-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.project-info-links {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.project-info-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 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);
}
.project-info-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.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);
}

.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: var(--panel-2);
  border: none;
  cursor: pointer;
}
.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: 104px;
  background: var(--ink); image-rendering: pixelated;
}
.preset-name {
  font-size: 10px; letter-spacing: 1px; font-weight: 700;
  color: var(--muted); text-align: center;
}
.preset-card:hover .preset-name,
.preset-card.active .preset-name { 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;
}

.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: 8px; align-items: center; }
.head-tools .mini svg { width: 12px; height: 12px; }
.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: 0; display: inline-flex; align-items: center; gap: 6px;
}
.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.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;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.stage-idle[hidden] { display: none; }
.stage-idle-btn {
  pointer-events: auto;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 32px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--muted);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
#videoStage .stage-idle-btn svg {
  width: 28px;
  height: 28px;
  opacity: 0.65;
}
#videoStage .stage-idle-btn span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}
.stage-idle-btn:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(0, 0, 0, 0.72);
}
.stage-idle-btn:hover svg { opacity: 1; color: var(--accent-hover); }

#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;
  padding: 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 0.12s, color 0.12s;
}
#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;
}
#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;
  display: inline-flex;
  align-items: center;
  align-self: stretch;
}
.preview-media-chip[hidden],
.stage-btn[hidden] { display: none; }

@media (max-width: 720px) {
  #videoStage .stage-hud--top { min-height: 36px; }
  #videoStage .stage-hud-group--end { padding: 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; }
}

#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 0.12s;
}
#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; }

.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.72);
  color: var(--text);
  border: none;
  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;
}
.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;
}
.atlas-preset-chip:hover { color: var(--accent-hover); }
.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: pointer; }

.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;
  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.selected .group-head { color: var(--text); }

.group-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 14px;
  background: var(--black);
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  letter-spacing: 2px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}
.group-head:hover { color: var(--accent-hover); }
.group-head .group-name { flex: 1; }
.group-head .chev {
  color: var(--muted); font-size: 10px; width: 10px;
  transition: transform 0.12s; 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; background: var(--panel-2); cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; background: var(--muted); transition: left 0.12s, background 0.12s;
}
.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); }

/* the GLOBAL switch only gates the colour overrides; SIZE + OFFSET stay editable */
.group.disabled .global-overrides { opacity: 0.35; pointer-events: none; }
.global-overrides { margin-top: 4px; }

/* 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 { display: flex; width: 100%; }
.shape-style-seg .seg-btn {
  flex: 1;
  justify-content: center;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 6px 0;
}

.group-body {
  padding: 14px;
  display: grid;
  overflow: hidden;
}
.group.collapsed .group-body { 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: 1px solid var(--line);
}

.prop { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.prop:last-child { margin-bottom: 0; }
.prop > span { font-size: 10px; letter-spacing: 1px; color: var(--muted); 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: 1px; color: var(--muted); 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: 0;
}
.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: 0;
}

/* ----- cell editor ----- */
.cell-editor {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: stretch;
  margin-bottom: 16px;
  background: var(--panel-2);
  overflow: hidden;
}
.cell-nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s, color 0.12s;
}
.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); }
.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;
}

/* ----- 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;
  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; padding: 4px 6px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.swatch-chip:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.swatch-tile.active .swatch-chip {
  color: var(--text);
  background: rgba(255,255,255,0.08);
}
.swatch-tile:not(.active) .swatch-chip { visibility: hidden; }

/* ----- 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: 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 6px;
  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 5px; font-size: 8px; }

.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; }

.global-overrides .swatch-colors { gap: 6px; }

.slider { display: flex; flex-direction: column; gap: 7px; }
.slider span { font-size: 10px; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.slider b { color: var(--text); }

/* ----- 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; }
.tickslider 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;
}
.btn-ghost svg { width: 14px; height: 14px; flex: 0 0 auto; display: block; }
.btn-ghost:hover { background: var(--violet); color: var(--text); }

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

/* WebKit / Blink */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track {
  background: var(--black);
  border-left: 1px solid var(--line);
}
::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 3px solid var(--black); /* inset the thumb so it reads as a slim bar */
  background-clip: padding-box;
  min-height: 32px;
}
::-webkit-scrollbar-thumb:hover { background: #3c3c40; }
::-webkit-scrollbar-thumb:active { background: #3c3c40; }
::-webkit-scrollbar-corner { background: var(--black); }

/* horizontal-only bars (top context bar) sit on the panel, not pure black */
.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 { scrollbar-color: var(--line) var(--panel); }
.props { scrollbar-color: var(--line) var(--panel); }

/* dropdown menus */
.dropdown-menu::-webkit-scrollbar-track { background: var(--black); border: none; }
.dropdown-menu::-webkit-scrollbar-thumb { background: var(--line); border-color: var(--black); }
.dropdown-menu { scrollbar-color: var(--line) var(--black); }

/* ===================== 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);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  user-select: none; touch-action: none;
}
.cpick.open { display: block; }

.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: 0;
}
.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-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: 0;
}
.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;
}
.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);
  overflow: hidden;
}
.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; }
.icon-picker-item img {
  width: 20px;
  height: 20px;
  display: block;
  pointer-events: none;
}
.icon-picker-empty {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
}
