:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e1e4e8;
  --border-strong: #c9ced6;
  --text: #1c2026;
  --muted: #69717c;
  --accent: #d0402f;
  --accent-hover: #b53424;
  --accent-soft: #fdecea;
  --highlight: rgba(208, 64, 47, 0.22);
  --edited: #e8a317;
  --edited-soft: #fff7e3;
  --edited-border: #f1d48f;
  --edited-text: #8a5a00;
  --success: #1f7a43;
  --success-soft: #e8f5ee;
  --success-border: #b3dec4;
  --success-text: #176134;
  --danger: #b42318;
  --danger-hover: #912018;
  --danger-soft: #fdeceb;
  --danger-border: #f4b4ad;
  --danger-text: #b42318;
  --field: #ffffff;
  --inverse: #1c2026;
  --on-inverse: #ffffff;
  --backdrop: rgba(16, 24, 40, 0.45);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.18);
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}
/* Set on <html> by the inline script in index.html: the saved choice, otherwise the system setting. */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1f232b;
  --border: #2b303a;
  --border-strong: #3d4450;
  --text: #e6e8eb;
  --muted: #9aa2ad;
  --accent-hover: #e25a49;
  --accent-soft: rgba(208, 64, 47, 0.18);
  --highlight: rgba(208, 64, 47, 0.5);
  --edited-soft: rgba(232, 163, 23, 0.14);
  --edited-border: rgba(232, 163, 23, 0.45);
  --edited-text: #f0b94a;
  --success: #2a8f52;
  --success-soft: rgba(42, 143, 82, 0.16);
  --success-border: rgba(42, 143, 82, 0.45);
  --success-text: #5cc984;
  --danger: #d9453a;
  --danger-hover: #b8352b;
  --danger-soft: rgba(217, 69, 58, 0.16);
  --danger-border: rgba(217, 69, 58, 0.5);
  --danger-text: #f2746b;
  --field: #12151a;
  --inverse: #e6e8eb;
  --on-inverse: #12151a;
  --backdrop: rgba(0, 0, 0, 0.6);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
body.busy { cursor: progress; }
body.busy main { opacity: 0.55; pointer-events: none; transition: opacity 0.2s; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }

/* ---------- icons & buttons ---------- */
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-xl { width: 44px; height: 44px; stroke-width: 1.5; color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font: inherit; font-size: 0.9rem; font-weight: 500;
  padding: 0.5rem 0.9rem; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .menu-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--muted); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  cursor: pointer; transition: all 0.15s; text-decoration: none;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger-border); background: var(--danger-soft); }
.icon-btn.danger.active { color: #fff; background: var(--danger); border-color: var(--danger); }
.icon-btn.reset { color: var(--edited); border-color: var(--edited-border); background: var(--edited-soft); }

.pill { font-size: 0.78rem; font-weight: 600; padding: 0.2rem 0.65rem; border-radius: 999px; }
.pill-warn { background: var(--edited-soft); color: var(--edited-text); border: 1px solid var(--edited-border); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.7rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  display: flex; align-items: center; background: none; border: 0; padding: 0.2rem; margin: -0.2rem; border-radius: 8px; color: inherit; font: inherit; cursor: default;
  /* Same geometry as .github/assets/logo.svg: a 39×19 box, a 6-unit gap, then "Editor". */
  --logo-h: 1.45rem; gap: calc(var(--logo-h) * 6 / 19);
}
.brand[title] { cursor: pointer; }
.brand[title]:hover h1 { color: var(--accent); }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.brand h1 { margin: 0; line-height: 0; }
.brand .wordmark { height: var(--logo-h); width: calc(var(--logo-h) * 52.2 / 19); fill: currentColor; display: block; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  height: var(--logo-h); width: calc(var(--logo-h) * 39 / 19);
  background: var(--accent); color: #fff; font-weight: 800; font-size: calc(var(--logo-h) * 12 / 19); letter-spacing: 0.05em; line-height: 1;
}
/* Taller than the file buttons, so the bar keeps its height when a file loads. */
.brand-wrap { position: relative; display: flex; align-items: center; min-height: 2.4rem; }
.brand.attention .logo { animation: logo-pulse 1.6s ease-out 3; }
@keyframes logo-pulse { 0% { box-shadow: 0 0 0 0 rgba(208, 64, 47, 0.55); } 100% { box-shadow: 0 0 0 12px rgba(208, 64, 47, 0); } }

/* Points at the logo after a download. */
.callout {
  position: absolute; top: calc(100% + 12px); left: -0.25rem; z-index: 20;
  display: flex; align-items: center; white-space: nowrap;
  padding: 0.3rem 0.3rem 0.3rem 0.4rem; border-radius: 8px;
  background: var(--inverse); color: var(--on-inverse); font-size: 0.8rem; box-shadow: var(--shadow-lg);
  animation: callout-in 0.25s ease-out, callout-nudge 1.2s ease-in-out 0.3s 3;
}
.callout::before {
  content: ""; position: absolute; top: -5px; left: 1.1rem;
  width: 10px; height: 10px; background: var(--inverse); transform: rotate(45deg); border-radius: 2px;
}
.callout-text { padding: 0.15rem 0.15rem 0.15rem 0.35rem; }
.callout-close { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; padding: 0; background: none; border: 0; color: inherit; opacity: 0.7; border-radius: 5px; cursor: pointer; }
.callout-close .icon { width: 14px; height: 14px; stroke-width: 2.5; }
.callout-close:hover { opacity: 1; background: rgba(128, 128, 128, 0.25); }
@keyframes callout-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes callout-nudge { 50% { transform: translateY(-5px); } }
@media (prefers-reduced-motion: reduce) { .callout, .brand.attention .logo { animation: none; } }
.file-info { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.topbar-end { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-left: auto; }
.file-chip { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 600; padding: 0.35rem 0.7rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.file-chip .muted { font-weight: 400; font-size: 0.85rem; }

main { padding: 1.5rem; max-width: 1440px; margin: 0 auto; }

/* ---------- import ---------- */
.tagline {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  margin: 2.5rem auto 0; text-align: center; line-height: 1.2; letter-spacing: -0.02em;
}
.tagline-q { font-size: clamp(1.8rem, 4.5vw, 2.6rem); font-weight: 800; }
.tagline-a { font-size: clamp(1.05rem, 2.4vw, 1.35rem); font-weight: 500; color: var(--muted); letter-spacing: -0.01em; }
/* Echoes the red box of the logo. */
.skp-tag {
  display: inline-block; padding: 0 0.3em; background: var(--accent); color: #fff;
  font-size: 0.85em; letter-spacing: 0.02em; transform: rotate(-3deg); vertical-align: 0.05em;
}
.tagline .hl {
  color: var(--text); font-weight: 700;
  background: linear-gradient(transparent 60%, var(--highlight) 60%, var(--highlight) 92%, transparent 92%);
}
.tagline .grad {
  font-weight: 800; background: linear-gradient(90deg, var(--accent), #f0a020);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

#drop-zone {
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  max-width: 52rem; padding: 4rem 1.5rem; margin: 2rem auto 0;
  border: 2px dashed var(--border-strong); border-radius: 16px; background: var(--surface);
  cursor: pointer; text-align: center; transition: all 0.2s;
}
#drop-zone strong { font-size: 1.15rem; margin-top: 0.5rem; }
#drop-zone span { color: var(--muted); }
#drop-zone small { color: var(--muted); margin-top: 1rem; }
#drop-zone.over, #drop-zone:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- credits ---------- */
.credits {
  display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
  padding: 2rem 1.5rem 2.5rem; text-align: center; color: var(--muted); font-size: 0.85rem;
}
.credits p { margin: 0; max-width: 44rem; }
.credits a { color: var(--text); font-weight: 600; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.credits a:hover { color: var(--accent); text-decoration-color: currentColor; }
.credits .star-link {
  display: inline-flex; align-items: center; gap: 0.45rem; margin-top: 0.6rem; padding: 0.4rem 0.85rem;
  border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface);
  text-decoration: none; box-shadow: var(--shadow); transition: all 0.2s;
}
.credits .star-link:hover { border-color: var(--accent); transform: translateY(-1px); }
.credits .gh { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.credits .star-link:hover .gh { animation: wiggle 0.5s ease; }
@keyframes wiggle { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
@media (prefers-reduced-motion: reduce) { .credits .star-link:hover, .credits .star-link:hover .gh { transform: none; animation: none; } }

/* ---------- size panel ---------- */
.size-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.9rem 1.2rem; margin-bottom: 1.2rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 0.7rem;
}
.size-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.size-head > div { display: flex; flex-direction: column; }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-weight: 600; font-size: 1.15rem; }
.size-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.size-bar .seg { height: 100%; min-width: 2px; }
.size-bar .seg + .seg { border-left: 2px solid var(--surface); }
.size-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; font-size: 0.82rem; }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; cursor: help; }
.legend-label { color: var(--muted); }
.legend-value { font-weight: 600; }
.legend-pct { color: var(--muted); font-size: 0.75rem; }
.dot { width: 10px; height: 10px; border-radius: 3px; }
.seg-model { background: #3b6fd4; }
.seg-textures { background: var(--accent); }
.seg-materials { background: #e8a317; }
.seg-componentPreviews { background: #2f9e6e; }
.seg-other { background: #a3abb6; }

/* ---------- tabs & toolbar ---------- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs button { font: inherit; font-weight: 500; color: var(--muted); border: none; border-bottom: 2px solid transparent; background: none; padding: 0.65rem 1rem; cursor: pointer; display: inline-flex; gap: 0.5rem; align-items: center; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }
.count { font-size: 0.75rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0.05rem 0.5rem; color: var(--muted); }

.toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1.2rem; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search .icon { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input#search { padding-left: 2.3rem; }
.result-count { font-size: 0.85rem; color: var(--muted); margin-right: auto; }

/* ---------- dropdown menus (Filter and Actions) ---------- */
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 260px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 0.35rem;
}
.menu-list hr { border: none; border-top: 1px solid var(--border); margin: 0.3rem 0; }
.menu-item {
  display: flex; align-items: center; gap: 0.65rem; width: 100%;
  font: inherit; font-size: 0.9rem; text-align: left; color: var(--text);
  background: none; border: none; border-radius: 6px; padding: 0.55rem 0.7rem; cursor: pointer;
}
.menu-item .icon { color: var(--muted); }
.menu-item:hover:not(:disabled) { background: var(--surface-2); }
.menu-item:disabled { opacity: 0.45; cursor: default; }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-item[role="menuitemradio"] .icon { visibility: hidden; }
.menu-item.selected { font-weight: 600; }
.menu-item.selected .icon { visibility: visible; color: var(--accent); }

#filter-btn.has-filters { border-color: var(--accent); color: var(--accent-hover); }
.filter-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.2rem; height: 1.2rem; padding: 0 0.35rem; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 0.72rem; font-weight: 700; line-height: 1;
}
.submenu-row {
  position: relative; display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.7rem; border-radius: 6px; cursor: default; font-size: 0.9rem;
}
.submenu-row:hover, .submenu-row:focus-within { background: var(--surface-2); outline: none; }
.submenu-label { font-weight: 500; }
.submenu-summary { margin-left: auto; font-size: 0.8rem; color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.submenu-summary.on { color: var(--accent-hover); font-weight: 600; }
.submenu-row > .icon { color: var(--muted); width: 16px; height: 16px; }
.submenu {
  display: none; position: absolute; left: 100%; top: -0.35rem; min-width: 220px; margin-left: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 0.35rem;
}
/* Invisible bridge so the pointer can travel from the row to the submenu. */
.submenu::before { content: ""; position: absolute; top: 0; bottom: 0; left: -8px; width: 8px; }
.submenu-row.flip .submenu { left: auto; right: 100%; margin-left: 0; margin-right: 4px; }
.submenu-row.flip .submenu::before { left: auto; right: -8px; }
.submenu-row:hover .submenu, .submenu-row:focus-within .submenu { display: block; }
.check-row { display: flex; align-items: center; gap: 0.55rem; padding: 0.5rem 0.6rem; border-radius: 6px; cursor: pointer; font-size: 0.9rem; }
.check-row:hover { background: var(--surface-2); }
.check-row input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
/* ---------- form controls ---------- */
input:not([type=checkbox]):not([type=range]), select, .input {
  font: inherit; font-size: 0.9rem; width: 100%;
  padding: 0.45rem 0.6rem; border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--field); color: var(--text); transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { background: var(--surface-2); color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.75rem; font-weight: 500; color: var(--muted); }
.toggle {
  display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; cursor: pointer; user-select: none;
  padding: 0.4rem 0.7rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.toggle:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-hover); }
.toggle input { accent-color: var(--accent); margin: 0; }
.range { width: 100%; accent-color: var(--accent); }

/* ---------- cards (shared by materials and components) ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.card {
  display: flex; gap: 1rem; padding: 0.9rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: border-color 0.15s, box-shadow 0.15s;
}
.card.edited { border-color: var(--edited); box-shadow: 0 0 0 3px var(--edited-soft); }
.media { flex: 0 0 120px; display: flex; flex-direction: column; gap: 0.4rem; }
.preview {
  width: 120px; height: 120px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border); background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
}
.preview img { width: 100%; height: 100%; object-fit: contain; }
.preview .no-preview { display: none; font-size: 0.75rem; color: var(--muted); }
.preview.empty { border-style: dashed; border-color: var(--border-strong); }
.preview.empty .no-preview { display: block; }
/* 3D materials: an isometric cube showing the texture or colour on three shaded faces. */
.preview-3d { container-type: size; perspective: none; }
.cube { position: relative; width: 50cqw; height: 50cqw; transform-style: preserve-3d; transform: rotateX(-35.26deg) rotateY(-45deg); }
.cube .face { position: absolute; inset: 0; background-size: cover; background-position: center; }
.cube .front { transform: translateZ(25cqw); filter: brightness(0.85); }
.cube .right { transform: rotateY(90deg) translateZ(25cqw); filter: brightness(0.62); }
.cube .top { transform: rotateX(90deg) translateZ(25cqw); filter: brightness(1.08); }
.badges { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.badges:empty { display: none; }
.badge { font-size: 0.68rem; font-weight: 600; padding: 0.1rem 0.4rem; border-radius: 4px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.dark { background: var(--inverse); color: var(--on-inverse); border-color: var(--inverse); }
.badge.size-low { background: var(--success-soft); color: var(--success-text); border-color: var(--success-border); }
.badge.size-med { background: var(--edited-soft); color: var(--edited-text); border-color: var(--edited-border); }
.badge.size-high { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-border); }
.fields { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.details { font-size: 0.75rem; color: var(--muted); }
.details:empty { display: none; }
.was { display: flex; align-items: baseline; gap: 0.3rem; font-size: 0.75rem; color: var(--muted); margin-top: -0.3rem; min-width: 0; }
.was[hidden] { display: none; }
.was-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.restore { font: inherit; border: none; background: none; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; flex-shrink: 0; }
.restore:hover { color: var(--accent-hover); }
.chips { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.chips:empty { display: none; }
.chip { font-size: 0.7rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--edited-soft); color: var(--edited-text); border: 1px solid var(--edited-border); }
.chip.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.actions .icon-btn { width: 28px; height: 28px; border-radius: 6px; }
.actions .icon-btn .icon { width: 15px; height: 15px; }
.empty { color: var(--muted); padding: 2rem; text-align: center; grid-column: 1 / -1; }

/* ---------- component hierarchy tree ---------- */
.components-view { display: flex; gap: 0.85rem; align-items: flex-start; }
.components-view .grid { flex: 1; min-width: 0; }
.tree-panel {
  --tree-w: 220px;
  flex: 0 0 var(--tree-w); width: var(--tree-w); position: sticky; top: 4.6rem;
  max-height: min(600px, calc(100vh - 6.5rem)); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.tree-resizer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 6px;
  cursor: col-resize; z-index: 2; touch-action: none;
}
.tree-resizer::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 2px;
  background: transparent; transition: background 0.15s;
}
.tree-resizer:hover::after, body.resizing-tree .tree-resizer::after { background: var(--accent); }
body.resizing-tree { cursor: col-resize; user-select: none; }
.tree-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.4rem;
  padding: 0.5rem 0.65rem; border-bottom: 1px solid var(--border);
}
.tree-title { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.tree-action {
  font: inherit; font-size: 0.72rem; font-weight: 500; color: var(--muted);
  background: none; border: none; padding: 0.1rem 0.3rem; border-radius: 5px; cursor: pointer;
}
.tree-action:hover { color: var(--text); background: var(--surface-2); }
.tree-list { overflow: auto; padding: 0.3rem; display: flex; flex-direction: column; gap: 1px; }
.tree-row {
  display: flex; align-items: center; gap: 0.25rem; width: 100%;
  padding: 0.22rem 0.35rem; border-radius: 5px; font-size: 0.78rem;
  color: var(--text); cursor: pointer; user-select: none; min-width: 0;
}
.tree-row:hover { background: var(--surface-2); }
.tree-row.selected { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.tree-row.group { color: var(--muted); }
.tree-row.group.selected { color: var(--accent-hover); }
.tree-caret {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 16px; height: 16px; padding: 0; background: none; border: none; border-radius: 4px;
  color: var(--muted); cursor: pointer; transition: transform 0.12s;
}
.tree-caret:hover { color: var(--text); background: var(--border); }
.tree-caret .icon { width: 12px; height: 12px; }
.tree-caret.open { transform: rotate(90deg); }
.tree-caret-spacer { width: 16px; flex-shrink: 0; }
.tree-kind { width: 13px; height: 13px; flex-shrink: 0; color: var(--muted); }
.tree-row.selected .tree-kind { color: var(--accent); }
.tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tree-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--edited); flex-shrink: 0; }
.tree-count { font-size: 0.68rem; color: var(--muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.tree-children {
  margin-left: 0.65rem; padding-left: 0.25rem; border-left: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 1px;
}
.tree-section {
  display: flex; align-items: center; gap: 0.25rem; width: 100%;
  margin-top: 0.35rem; padding: 0.3rem 0.35rem 0.2rem; border: none; border-top: 1px solid var(--border);
  background: none; font: inherit; font-size: 0.7rem; font-weight: 600; color: var(--muted);
  cursor: pointer; text-align: left;
}
.tree-section:hover { color: var(--text); }
.tree-empty { font-size: 0.78rem; color: var(--muted); padding: 0.6rem 0.4rem; text-align: center; }

/* ---------- dialog ---------- */
dialog { background: var(--surface); color: var(--text); border: none; border-radius: 14px; padding: 0; width: min(520px, 92vw); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: var(--backdrop); }
dialog form { padding: 1.4rem 1.5rem 1.2rem; display: flex; flex-direction: column; gap: 0.9rem; }
dialog h2 { margin: 0; font-size: 1.1rem; }
#dialog-body { display: flex; flex-direction: column; gap: 0.8rem; }
#dialog-body p { margin: 0; }
.hint { font-size: 0.82rem; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.3rem; }
#dialog-body p.plan-title { font-size: 0.82rem; font-weight: 600; margin-bottom: -0.5rem; }
.plan { margin: 0; padding-left: 1.1rem; font-size: 0.82rem; display: flex; flex-direction: column; gap: 0.3rem; }
.plan-details summary { font-size: 0.82rem; cursor: pointer; color: var(--accent-hover); }
.plan-textures { list-style: none; margin: 0.4rem 0 0; padding: 0 0.5rem 0 0; max-height: 180px; overflow: auto; font-size: 0.78rem; }
.plan-textures li { display: flex; justify-content: space-between; gap: 0.6rem; padding: 0.2rem 0; border-bottom: 1px solid var(--border); }
.plan-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.plan-textures .muted { white-space: nowrap; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 1.2rem; right: 1.2rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 50; max-width: min(420px, 90vw); }
.toast {
  padding: 0.75rem 1rem; border-radius: 10px; background: var(--inverse); color: var(--on-inverse);
  box-shadow: var(--shadow-lg); font-size: 0.9rem; cursor: pointer;
  animation: toast-in 0.2s ease-out; transition: opacity 0.3s, transform 0.3s;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 900px) {
  .components-view { flex-direction: column; }
  .tree-panel { position: static; width: 100%; flex: none; max-height: 220px; }
  .tree-resizer { display: none; }
}

@media (max-width: 760px) {
  main { padding: 1rem; }
  .grid { grid-template-columns: 1fr; }
  .media { flex-basis: 88px; }
  .preview { width: 88px; height: 88px; }
}
