:root {
  --bg: #303033;
  --panel: #1c1c1f;
  --panel-2: #232327;
  --panel-3: #2a2a2f;
  --line: #38383e;
  --text: #e8e6e0;
  --text-dim: #9c9aa0;
  --accent: #8fd6b4;
  --accent-dim: rgba(143, 214, 180, 0.16);
  --warn: #f2b06b;
  --danger: #e67a7a;
  --radius: 10px;
  --tree-w: 236px;
  --panel-w: 304px;
  --uv-w: clamp(360px, 38vw, 560px);
  --bottom-timeline-h: 72px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  background: #141416;
  color: var(--text);
  overflow: hidden;
}

button, select, input { font: inherit; color: inherit; }

.shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  position: relative;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .mark {
  width: 12px; height: 12px; border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), #4a8a6c);
  flex: none;
}
.brand h1 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }
.brand p {
  margin: 0; font-size: 11px; color: var(--text-dim);
  max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

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

.toolbar button,
.file-button,
.menu-toggle {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  color: var(--text);
}

.toolbar button:hover, .file-button:hover, .menu-toggle:hover { background: #35353b; }
.toolbar button.is-active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.file-button { display: inline-flex; align-items: center; }
.file-button input { display: none; }

.view-presets {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}
.view-presets button {
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--line);
  padding: 5px 9px;
  min-width: 30px;
  background: var(--panel-3);
}
.view-presets button:last-child { border-right: none; }
.view-presets button.is-active { background: var(--accent-dim); color: var(--accent); }
.view-presets .projection-button {
  min-width: 54px;
  border-left: 1px solid var(--line);
}
.view-presets .projection-button + .projection-button {
  border-left-color: rgba(143, 214, 180, 0.28);
}

.menu { position: relative; }
.menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.menu-toggle::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.75;
}
.menu-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  display: grid;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 5px;
  min-width: 130px;
  z-index: 60;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.menu-popover button {
  background: transparent;
  border: none;
  border-radius: 6px;
  text-align: left;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.menu-popover button:hover { background: var(--panel-3); }

/* ---------------------------------------------------------------- manifest bar */
.manifest-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 14px;
  background: #18181b;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  color: var(--text-dim);
  z-index: 15;
  overflow: hidden;
}
.manifest-bar .mi { white-space: nowrap; }
.manifest-bar .mi.is-warn { color: var(--danger); font-weight: 600; }
.manifest-bar .mi-source {
  margin-left: auto;
  overflow: hidden; text-overflow: ellipsis;
  opacity: 0.7;
}

/* ---------------------------------------------------------------- content grid */
.content {
  display: grid;
  grid-template-columns: var(--tree-w) minmax(0, 1fr) var(--panel-w);
  grid-template-areas: "tree viewport panel";
  min-height: 0;
  position: relative;
}

.shell.is-tree-collapsed .content { grid-template-columns: 34px minmax(0, 1fr) var(--panel-w); }
.shell.is-uv-open .content {
  grid-template-columns: var(--tree-w) minmax(280px, 1fr) var(--uv-w) var(--panel-w);
  grid-template-areas: "tree viewport uv panel";
}
.shell.is-tree-collapsed.is-uv-open .content {
  grid-template-columns: 34px minmax(280px, 1fr) var(--uv-w) var(--panel-w);
}
.shell.is-uv-open.is-uv-expanded .content {
  grid-template-columns: var(--tree-w) minmax(240px, 1fr) var(--uv-w) var(--panel-w);
}
.shell.is-tree-collapsed.is-uv-open.is-uv-expanded .content {
  grid-template-columns: 34px minmax(240px, 1fr) var(--uv-w) var(--panel-w);
}
.shell.is-tree-collapsed .tree-list,
.shell.is-tree-collapsed .tree-foot,
.shell.is-tree-collapsed .tree-head h2 { display: none; }

#viewport { grid-area: viewport; position: relative; min-width: 0; min-height: 0; background: var(--bg); }
#viewport.is-drop-target,
[data-tab-panel="anim"].is-drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
}
#viewport canvas { display: block; width: 100%; height: 100%; }
.ortho-grid-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* ---------------------------------------------------------------- tree panel */
.tree-panel {
  grid-area: tree;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
  z-index: 10;
}

.tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.tree-head h2 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-dim); }
.tree-head h2 span { color: var(--accent); margin-left: 4px; }
.tree-head button {
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  width: 22px; height: 22px; cursor: pointer; font-size: 11px; line-height: 1;
}

.tree-list { overflow-y: auto; padding: 6px; min-height: 0; }

.tree-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-radius: 7px;
  margin-bottom: 2px;
}
.tree-row.is-selected .tree-name { background: var(--accent-dim); color: var(--accent); }
.tree-row.is-hidden .tree-name { opacity: 0.42; }

.tree-eye {
  background: transparent;
  border: none;
  color: var(--text-dim);
  width: 22px;
  cursor: pointer;
  font-size: 10px;
  flex: none;
}
.tree-eye:hover { color: var(--accent); }

.tree-name {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.tree-name:hover { background: var(--panel-3); }
.tree-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-name small { color: var(--text-dim); font-size: 10px; flex: none; }

.tree-foot {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line);
}
.tree-foot button {
  flex: 1;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 0;
  font-size: 11px;
  cursor: pointer;
}
.tree-foot button:hover { background: #35353b; }

/* ---------------------------------------------------------------- right panel */
.panel {
  grid-area: panel;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
  z-index: 10;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 0 7px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.panel section[data-tab-panel] {
  display: none;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  min-width: 0;
  min-height: 0;
}
.panel section[data-tab-panel].is-active { display: block; }

.panel h2 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.bg-title { margin-top: 16px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.section-actions { display: inline-flex; align-items: center; gap: 6px; }
.section-head button,
.selection-head button,
.sources-title button,
.anim-file-button,
.inline-danger-button {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11px;
  cursor: pointer;
}
.inline-danger-button:hover { background: #3a272b; border-color: rgba(224, 102, 102, 0.65); color: #ffb0b0; }
.inline-danger-button:disabled { opacity: 0.42; cursor: default; border-color: var(--line); color: var(--text-dim); }
.anim-file-button {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
}
.anim-file-button:hover { background: #35353b; }
.anim-file-button input { display: none; }

.stats { display: grid; gap: 4px; margin: 0 0 12px; }
.stats > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 8px;
  background: var(--panel-2);
  border-radius: 6px;
  font-size: 12px;
}
.stats dt { color: var(--text-dim); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; }

.display-toggles { display: grid; gap: 4px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 2px;
  cursor: pointer;
}
.toggle kbd {
  margin-left: auto;
  font-size: 9px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

.field { display: grid; gap: 4px; font-size: 12px; margin-bottom: 8px; min-width: 0; }
.clip-library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-dim);
  min-width: 0;
}
.clip-library-head > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clip-library-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.clip-library-actions .inline-danger-button {
  min-width: 32px;
  padding-inline: 7px;
  text-align: center;
}
.clip-library-toggle {
  min-width: 0;
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: none;
  color: inherit;
  padding: 0;
  font-size: 11px;
  cursor: pointer;
}
.clip-library-label {
  flex: none;
}
.clip-library-active {
  flex: 1;
  min-width: 0;
  color: var(--text);
  opacity: 0.88;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clip-library-toggle strong {
  flex: none;
  color: var(--accent);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.clip-library-toggle::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(45deg);
  transition: transform 0.16s ease;
}
.clip-library.is-collapsed .clip-library-toggle::after {
  transform: rotate(-45deg);
}
.field select,
.field input {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
}
.display-mode-field span {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-dim);
}
.display-mode-field kbd {
  font-size: 9px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

.range { display: grid; gap: 2px; font-size: 12px; margin-bottom: 6px; }
.range span { color: var(--text-dim); font-size: 11px; }
.range input { accent-color: var(--accent); width: 100%; }

.key-direction-field small {
  color: var(--text-dim);
  font-size: 10px;
}
.key-direction-pad {
  width: 156px;
  height: 156px;
  justify-self: center;
  display: grid;
  place-items: center;
  outline: none;
  cursor: crosshair;
}
.key-direction-pad:focus-visible .key-direction-ring {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(143, 214, 180, 0.16);
}
.key-direction-ring {
  position: relative;
  width: 138px;
  height: 138px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(143, 214, 180, 0.18) 0 3px, transparent 4px),
    radial-gradient(circle at center, transparent 0 33%, rgba(143, 214, 180, 0.08) 34% 35%, transparent 36%),
    linear-gradient(90deg, transparent calc(50% - 0.5px), rgba(143, 214, 180, 0.24) 50%, transparent calc(50% + 0.5px)),
    linear-gradient(0deg, transparent calc(50% - 0.5px), rgba(143, 214, 180, 0.24) 50%, transparent calc(50% + 0.5px)),
    var(--panel-2);
}
.key-direction-ring::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px dashed rgba(143, 214, 180, 0.24);
  border-radius: 50%;
  pointer-events: none;
}
.key-direction-axis {
  position: absolute;
  color: var(--text-dim);
  font-size: 9px;
  pointer-events: none;
}
.axis-n { top: 5px; left: 50%; transform: translateX(-50%); }
.axis-e { right: 7px; top: 50%; transform: translateY(-50%); }
.axis-s { bottom: 5px; left: 50%; transform: translateX(-50%); }
.axis-w { left: 7px; top: 50%; transform: translateY(-50%); }
.key-direction-handle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: #ffe0a6;
  box-shadow: 0 0 0 4px rgba(143, 214, 180, 0.18);
  transform: translate(-50%, -50%);
  cursor: grab;
  z-index: 2;
}
.key-direction-handle:active { cursor: grabbing; }

/* animation */
.anim-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.clip-library {
  display: grid;
  gap: 6px;
  margin: 8px 0 10px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.clip-library.is-collapsed {
  padding: 8px;
}
.clip-library.is-collapsed .clip-list,
.clip-library.is-collapsed .clip-library-actions {
  display: none;
}
.clip-list {
  display: grid;
  gap: 4px;
  max-height: 150px;
  overflow-y: auto;
  padding-right: 2px;
}
.clip-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  outline: none;
}
.clip-row:hover,
.clip-row:focus-visible { background: rgba(255, 255, 255, 0.04); }
.clip-row.is-active {
  background: var(--accent-dim);
  color: var(--accent);
}
.clip-row-check {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.clip-row-main {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.clip-row-play {
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid transparent;
}
.clip-row.is-active .clip-row-play {
  border-left-color: var(--accent);
}
.clip-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clip-row-meta {
  display: grid;
  justify-items: end;
  gap: 1px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.clip-row-meta strong {
  color: inherit;
  font-size: 11px;
}
.clip-row-meta small {
  color: var(--text-dim);
  font-size: 10px;
}
.clip-empty {
  margin: 2px 0;
  color: var(--text-dim);
  font-size: 11px;
}
.toggle.compact { margin-left: auto; padding: 0; }
.anim-panel-playback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin: 8px 0 6px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.shell.is-bottom-timeline-open .anim-panel-playback {
  display: none;
}
.anim-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.anim-timeline {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.anim-timeline.is-collapsed { display: none; }
.timeline-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.timeline-head strong {
  color: var(--accent);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.timeline-head span:last-child { text-align: right; }
.anim-timeline input {
  width: 100%;
  accent-color: var(--accent);
}

.bottom-timeline {
  position: fixed;
  left: var(--tree-w);
  right: var(--panel-w);
  bottom: 0;
  height: var(--bottom-timeline-h);
  z-index: 80;
  transform: translateY(var(--bottom-timeline-h));
  transition: transform 0.18s ease;
  pointer-events: none;
}
.shell.is-tree-collapsed .bottom-timeline { left: 34px; }
.shell.is-bottom-timeline-open .bottom-timeline { transform: translateY(0); }
.bottom-timeline-toggle {
  position: absolute;
  top: -34px;
  right: 0;
  width: 112px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(35, 35, 39, 0.98);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  pointer-events: auto;
  font-size: 12px;
  font-weight: 600;
}
.bottom-timeline-toggle::after {
  content: "";
  display: block;
  width: 10px;
  height: 10px;
  flex: none;
  border-right: 3px solid var(--accent);
  border-bottom: 3px solid var(--accent);
  transform: rotate(225deg);
  transition: transform 0.18s ease;
}
.shell.is-bottom-timeline-open .bottom-timeline-toggle::after {
  transform: rotate(45deg);
}
.bottom-timeline-inner {
  position: absolute;
  inset: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-areas:
    "meta actions spacer"
    "track track track";
  row-gap: 5px;
  align-items: center;
  padding: 8px 18px 10px;
  background: rgba(28, 28, 31, 0.98);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.32);
  pointer-events: auto;
}
.bottom-timeline-meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  font-size: 11px;
  color: var(--text-dim);
}
.bottom-timeline-meta strong {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bottom-timeline-actions {
  grid-area: actions;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.timeline-icon-button {
  width: 28px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.timeline-icon-button:hover { background: #35353b; border-color: var(--accent); }
.timeline-icon-button:disabled { opacity: 0.42; cursor: default; border-color: var(--line); }
.timeline-play-icon {
  width: 0;
  height: 0;
  margin-left: 2px;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid currentColor;
}
.timeline-icon-button.is-playing .timeline-play-icon {
  width: 11px;
  height: 12px;
  margin-left: 0;
  border-top: none;
  border-bottom: none;
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor;
}
.timeline-stop-icon {
  width: 11px;
  height: 11px;
  background: currentColor;
  border-radius: 2px;
}
.bottom-timeline-track {
  grid-area: track;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 11px;
}
.bottom-timeline-track input {
  width: 100%;
  accent-color: var(--accent);
}

.swatches { display: flex; gap: 8px; }
.swatch {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--swatch);
  cursor: pointer;
}
.swatch.is-active { border-color: var(--accent); }
.swatch-white { box-shadow: inset 0 0 0 1px var(--line); }

/* selection card */
.selection-card { background: var(--panel-2); border-radius: var(--radius); padding: 10px; }
.selection-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.selection-head h3 { margin: 0; font-size: 12px; }

.selection-info { display: grid; gap: 4px; margin: 0; }
.selection-info > div { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.selection-info dt { color: var(--text-dim); flex: none; }
.selection-info dd { margin: 0; text-align: right; word-break: break-word; }

.sources-row { flex-direction: column; }
.sources-row .sources-title { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.sources-row dd { text-align: left; margin-top: 4px; font-size: 11px; color: var(--text-dim); max-height: 130px; overflow-y: auto; }
.sources-row.is-collapsed dd { display: none; }
.sources-row.is-empty .sources-title button { opacity: 0.4; cursor: default; }

/* textures */
.texture-summary { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; line-height: 1.5; }
.texture-list { display: grid; gap: 8px; }
.texture-list.is-collapsed { display: none; }
.texture-empty { color: var(--text-dim); font-size: 12px; }

.texture-item {
  display: flex;
  gap: 10px;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px;
}
.texture-thumb {
  flex: none;
  width: 52px; height: 52px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background-color: #101012;
  background-image: var(--texture-thumb);
  background-size: cover;
  cursor: zoom-in;
}
.texture-meta { min-width: 0; font-size: 11px; display: grid; gap: 1px; }
.texture-meta strong { font-size: 12px; }
.texture-meta span, .texture-meta small { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.texture-pbr { color: var(--accent) !important; }
.texture-meta dl { margin: 4px 0 0; display: grid; gap: 1px; }
.texture-meta dl div { display: flex; gap: 6px; }
.texture-meta dt { color: var(--text-dim); min-width: 44px; }
.texture-meta dd { margin: 0; }

/* ---------------------------------------------------------------- uv panel */
.uv-panel {
  grid-area: uv;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(18, 18, 20, 0.97);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  z-index: 30;
  overflow: hidden;
}

.uv-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 10px;
  z-index: 3;
  cursor: col-resize;
  touch-action: none;
}
.uv-resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 2px;
  background: transparent;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.uv-resize-handle:hover::after,
.shell.is-resizing-uv .uv-resize-handle::after {
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(143, 214, 180, 0.2);
}
.shell.is-resizing-uv,
.shell.is-resizing-uv * {
  cursor: col-resize !important;
  user-select: none !important;
}

.uv-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.uv-title h2 { margin: 0; font-size: 13px; }
.uv-title p { margin: 2px 0 0; font-size: 11px; color: var(--text-dim); }
.uv-actions { display: flex; align-items: center; gap: 6px; }
.uv-actions button, .uv-actions select {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 11px;
  cursor: pointer;
}
.uv-actions button.is-active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.uv-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 14px;
}
#uvCanvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  background: #050607;
  border: 1px solid var(--line);
}
.uv-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  margin: 0; color: var(--text-dim); font-size: 13px;
  pointer-events: none;
}

/* ---------------------------------------------------------------- lasso */
.lasso-overlay { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 90; }
.lasso-rect { fill: rgba(143, 214, 180, 0.12); stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 6 4; }

/* ---------------------------------------------------------------- loader / drop / status */
.loader {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  gap: 10px;
  justify-items: center;
  background: rgba(20, 20, 23, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 26px;
  z-index: 70;
}
.loader[hidden] { display: none; }
.loader .bar { width: 200px; height: 5px; border-radius: 4px; background: var(--panel-3); overflow: hidden; }
.loader .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.loader strong { font-size: 12px; font-weight: 500; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.drop {
  position: fixed;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: rgba(143, 214, 180, 0.07);
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 95;
}
.drop.is-visible { opacity: 1; }
.drop.is-anim {
  border-color: #9fb8ff;
  background: rgba(159, 184, 255, 0.09);
  color: #c6d5ff;
}
.drop.is-model {
  border-color: var(--accent);
  background: rgba(143, 214, 180, 0.08);
}

.status {
  display: block;
  width: calc(100% - 24px);
  margin: 0 12px 10px;
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(20, 20, 23, 0.72);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  min-height: 26px;
  line-height: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- toasts */
.toasts {
  position: fixed;
  top: 54px;
  right: calc(var(--panel-w) + 14px);
  display: grid;
  gap: 8px;
  z-index: 120;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 12px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: auto;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast button {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 11px;
  padding: 3px 9px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- texture modal */
.texture-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 10, 0.72);
  z-index: 140;
}
.texture-modal[hidden] { display: none; }

.texture-dialog {
  width: min(860px, 92vw);
  max-height: 90vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.texture-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.texture-dialog-head h2 { margin: 0; font-size: 14px; }
.texture-dialog-head p { margin: 2px 0 0; font-size: 11px; color: var(--text-dim); }
.texture-dialog-actions { display: flex; align-items: center; gap: 12px; }
.zoom-hint { font-size: 10px; color: var(--text-dim); }
.texture-dialog-actions button {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}

.texture-preview-stage {
  min-height: 300px;
  max-height: 56vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    repeating-conic-gradient(#1a1a1d 0% 25%, #232327 0% 50%) 0 / 24px 24px;
  cursor: grab;
  touch-action: none;
}
.texture-preview-stage:active { cursor: grabbing; }
#texturePreviewImage {
  max-width: 100%;
  max-height: 54vh;
  image-rendering: pixelated;
  transition: transform 0.06s linear;
  user-select: none;
}

.texture-preview-info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 14px;
  margin: 0;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
}
.texture-preview-info div { display: flex; gap: 6px; }
.texture-preview-info dt { color: var(--text-dim); }
.texture-preview-info dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3f3f45; }
::-webkit-scrollbar-track { background: transparent; }
