:root {
  --bg: #0b0e14;
  --panel: #151a26;
  --panel-2: #0e1422;
  --border: #262e44;
  --text: #e8ecf4;
  --muted: #8b93a9;
  --accent: #6ea8fe;
  --run: #22c55e;
  --run-hover: #4ade80;
  --run-ink: #0f172a;
  --ok: #3dd68c;
  --err: #ff6369;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }

html {
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #1a2540 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- App top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  background: var(--run);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.8);
}
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -0.02em; white-space: nowrap; }
.brand h1 span { color: var(--accent); }
.cmd {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  background: #0e1320; border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 8px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.top-actions { display: flex; align-items: center; gap: 10px; flex: none; }

/* ---------- Workbench ---------- */
.workbench {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 20px 48px;
}
.leftcol, .centercol, .inspector { min-width: 0; }
.centercol { display: flex; flex-direction: column; gap: 14px; }
.col-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.thumb-wrap { margin-top: 14px; }
.thumb-wrap[hidden] { display: none; }
.desc-wrap { margin-top: 14px; }
.desc-wrap[hidden] { display: none; }
.desc-wrap .objlist-head { align-items: center; }
#descBody p { font-size: 13px; line-height: 1.55; color: var(--text); margin: 0 0 8px; }
#descBody p:last-child { margin-bottom: 0; }
#descBody p.dim { color: var(--muted); }
.thumb-wrap img {
  display: block; width: 100%; max-height: 220px; object-fit: contain;
  background: #000; border: 1px solid var(--border); border-radius: 10px;
}
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }

/* ---------- Viewport ---------- */
.drop {
  border: 1.5px dashed #33406a;
  border-radius: 12px;
  padding: 34px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #101624;
  color: var(--muted);
}
.drop:hover, .drop.drag { border-color: var(--accent); background: #131b31; }
.drop input { display: none; }
.drop .big { font-size: 15px; font-weight: 600; margin: 8px 0 4px; color: var(--text); }
.drop .small { font-size: 13px; }
.preview { margin-top: 0; display: none; }
.preview.show { display: block; }
.preview-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 48px 18px; }
.preview.show ~ .preview-empty { display: none; }
.canvas-wrap { background: #000; border-radius: 10px; overflow: hidden; }
.canvas-wrap canvas { display: block; width: 100%; max-height: calc(100vh - 380px); min-height: 240px; object-fit: contain; }
.overlay-controls {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px;
  font-size: 13px; color: var(--muted);
}
.overlay-controls label {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 6px 10px; border-radius: 7px;
  transition: background 0.15s, color 0.15s;
}
.overlay-controls label:hover { background: #1a2340; color: var(--text); }
.overlay-controls label:has(input:checked) { background: #1a2340; color: var(--text); }
.overlay-controls input { accent-color: var(--accent); }
.viewport-foot {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--muted); margin-top: 10px; font-family: var(--mono);
}

/* ---------- Inspector rail ---------- */
.inspector { min-width: 0; }
.inspector-empty { color: var(--muted); font-size: 13px; }
.scene-wrap[hidden], .objlist-wrap[hidden] { display: none; }
.conf-row[hidden] { display: none; }
.conf-row { margin: 0; }
.conf-row .objlist-head { margin-bottom: 2px; }
.conf-row input[type='range'] {
  width: 100%; margin: 0; padding: 0;
  accent-color: var(--accent); cursor: pointer;
}
.conf-row + .scene-wrap, .conf-row + .objlist-wrap { margin-top: 14px; }
.objlist-wrap { margin-top: 18px; }
.scene-wrap + .objlist-wrap { margin-top: 18px; }
.objlist-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.objlist-head h3 { font-size: 12px; margin: 0; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.collapse-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; padding: 0; margin: 0 0 8px;
  font: inherit; color: inherit; cursor: pointer; text-align: left;
}
.collapse-head h3 { font-size: 12px; margin: 0; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.collapse-head .chev { margin-left: auto; color: var(--muted); font-size: 14px; line-height: 1; transition: transform 0.15s; }
.collapse-head:hover .chev { color: var(--text); }
.collapsible.collapsed .collapse-head .chev { transform: rotate(-90deg); }
.collapsible.collapsed .obj-list, .collapsible.collapsed .scene-pills { display: none; }
.scene-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.scene-pill {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-2); font-size: 13px;
}
.scene-pill .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.scene-pill .v { font-weight: 650; }
.obj-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
}
.obj-item {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px; row-gap: 4px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-2); cursor: pointer; font-size: 13px; min-width: 0;
  transition: border-color 0.15s, background 0.15s;
}
.obj-item:hover, .obj-item.active { border-color: var(--accent); background: #131b31; }
.obj-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.obj-item .name {
  flex: 1 1 0; min-width: 0; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.obj-item .meta {
  flex: 1 1 100%; min-width: 0; padding-left: 20px;
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  overflow-wrap: anywhere;
}
.text-item .name { font-family: var(--mono); font-size: 14px; font-weight: 500; }
.text-item .quote { color: var(--muted); font-size: 14px; }

/* ---------- Buttons / pills / status ---------- */
button {
  appearance: none; border: 0; border-radius: 10px; padding: 11px 16px;
  font-size: 14px; font-weight: 650; cursor: pointer;
  font-family: var(--sans);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
button:focus-visible, .drop:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.top-actions button { padding: 9px 14px; }
button.primary { background: var(--run); color: var(--run-ink); }
button.primary:hover:not(:disabled) { background: var(--run-hover); }
button.primary:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.ghost:hover { color: var(--text); border-color: #3a4670; }
button.sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.pill {
  font-family: var(--mono); font-size: 11px; padding: 4px 8px;
  border-radius: 999px; border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}
.status { font-size: 13px; margin-top: 12px; min-height: 20px; color: var(--muted); }
.status.loading { color: var(--accent); }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

/* ---------- Terminal output ---------- */
.terminal { margin: 0; padding: 0; overflow: hidden; }
.term-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.term-dots { display: inline-flex; gap: 6px; }
.term-dots i { width: 10px; height: 10px; border-radius: 50%; background: #2c3652; }
.term-dots i:first-child { background: #ff5f57; }
.term-dots i:nth-child(2) { background: #febc2e; }
.term-dots i:nth-child(3) { background: #28c840; }
.term-head h2 {
  font-size: 12px; margin: 0; font-weight: 500;
  font-family: var(--mono); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.term-head button { margin-left: auto; }
.terminal pre {
  margin: 0; background: #0a0f1c; padding: 14px 16px;
  overflow: auto; max-height: 280px; min-height: 110px;
  font-family: var(--mono); font-size: 12px; line-height: 1.5; white-space: pre;
  border: 0; border-radius: 0;
}
.terminal footer { padding: 10px 14px; color: var(--muted); font-size: 12px; font-family: var(--mono); }
.empty { color: #4d5878; }
.spinner {
  display: inline-block; width: 13px; height: 13px; margin-right: 6px; vertical-align: -2px;
  border: 2px solid rgba(110, 168, 254, 0.3); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  * { transition: none !important; }
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .cmd { display: none; }
  .canvas-wrap canvas { max-height: 50vh; min-height: 180px; }
}

/* ---------- Full-height app shell (wide screens) ---------- */
/* NOTE: this block must stay last so its rules beat same-specificity base rules. */
@media (min-width: 1100px) {
  html, body { height: 100%; }
  body { display: flex; flex-direction: column; overflow: hidden; }
  .topbar { flex: none; }
  .workbench {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 290px minmax(0, 1fr) 380px;
    gap: 14px;
    align-items: stretch;
    padding-bottom: 16px;
  }
  .leftcol, .inspector { position: static; min-height: 0; overflow-y: auto; }
  .centercol { min-height: 0; }
  .viewport { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .preview.show { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .canvas-wrap { flex: 1; min-height: 0; position: relative; }
  .canvas-wrap canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%; max-height: none; min-height: 0;
  }
  .overlay-controls, .viewport-foot { flex: none; }
  .terminal { flex: none; }
  .terminal pre { max-height: 190px; min-height: 70px; }
}

/* ---------- wasm build: engine / weights loader ---------- */
.engine-wrap { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.engine-wrap .objlist-head { align-items: center; }
.load-row { margin-top: 10px; }
.load-top {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-size: 12px; color: var(--muted); margin-bottom: 5px;
}
.load-top span:first-child { font-family: var(--mono); color: #b9c2d6; }
.load-pct { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.load-row .bar {
  height: 4px; border-radius: 999px; background: #0a1020;
  border: 1px solid var(--border); overflow: hidden;
}
.load-row .bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--run));
  transition: width 120ms linear;
}
.load-note { font-size: 11.5px; line-height: 1.45; color: var(--muted); margin: 12px 0 0; }
.pill.busy { color: var(--accent); border-color: rgba(110, 168, 254, 0.45); }
.pill.ok { color: var(--ok); border-color: rgba(61, 214, 140, 0.45); }
.pill.err { color: var(--err); border-color: rgba(255, 99, 105, 0.45); }
@media (prefers-reduced-motion: reduce) {
  .load-row .bar i { transition: none; }
}

* {
  scrollbar-width: thin; /* options: auto, thin, none */
  scrollbar-color: #6366f1 #1e293b; /* thumb color, track color */
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px; /* for horizontal bars */
}

::-webkit-scrollbar-track {
  background: #1e293b;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb {
  background: #6366f1;
  border-radius: 10px;
  border: 2px solid #1e293b; /* creates a padding effect */
}

::-webkit-scrollbar-thumb:hover {
  background: #818cf8;
}
