/* Microverse — a workshop tool, so: dark, dense, and out of the way. */

:root {
  --bg: #101216;
  --panel: #171a20;
  --panel-2: #1d212a;
  --line: #272c36;
  --line-soft: #21252d;
  --text: #dfe4ec;
  --text-dim: #98a1b0;
  --text-faint: #6b7484;
  --accent: #6ea8fe;
  --accent-ink: #0b1118;
  --gold: #d8b071;
  --good: #63c99a;
  --bad: #e4736b;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 15px; letter-spacing: 0.01em; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); margin-bottom: 8px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--text-dim); }

/* ------------------------------------------------------------- top bar -- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 9px; }
.mark {
  width: 16px; height: 16px; border-radius: 4px;
  background: linear-gradient(140deg, var(--accent), var(--gold));
}
.topbar-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.chip {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.chip[data-mode="stl"] { color: var(--accent); border-color: #2e4a77; }
.chip.engine[data-ok="1"] { color: var(--good); border-color: #2c5a46; }
.chip.engine[data-ok="0"] { color: var(--bad); border-color: #5c3330; }

/* -------------------------------------------------------------- layout -- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr) 300px;
}

.panel {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.scroll { overflow-y: auto; overscroll-behavior: contain; padding: 4px 0 28px; }
.scroll::-webkit-scrollbar { width: 10px; }
.scroll::-webkit-scrollbar-thumb { background: #2b313c; border-radius: 6px; border: 3px solid var(--panel); }

/* -------------------------------------------------------- control groups */
.group { border-bottom: 1px solid var(--line-soft); }
.group-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.group-head:hover { background: var(--panel-2); }
.group-title { font-size: 12px; letter-spacing: 0.03em; }
.chev { color: var(--text-faint); transition: transform 0.15s; }
.group.collapsed .chev { transform: rotate(-90deg); }
.group.collapsed .group-body { display: none; }
.group-body { padding: 0 14px 12px; }
.group-note { margin: 0 0 12px; color: var(--text-faint); font-size: 11.5px; }

.ctrl { margin-bottom: 13px; }
.ctrl-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.ctrl-name { color: var(--text-dim); font-size: 12px; }
.ctrl-value { color: var(--text); font-size: 11.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ctrl-help { margin: 5px 0 0; font-size: 11px; color: var(--text-faint); line-height: 1.45; }

.slider-row { display: flex; gap: 8px; align-items: center; }
.slider { flex: 1; min-width: 0; accent-color: var(--accent); height: 18px; }
.num {
  width: 62px; flex: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 6px;
  font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.num:focus, input[type="text"]:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.select, input[type="text"] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font: inherit;
}

.toggle {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-dim);
  padding: 5px 14px;
  cursor: pointer;
  font: inherit;
  min-width: 62px;
}
.toggle.on { background: #1d3252; border-color: #2e4a77; color: var(--accent); }

/* ------------------------------------------------------------- viewport -- */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #0c0e12; }
.canvas-wrap { position: relative; flex: 1; min-height: 0; }
#view { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute;
  pointer-events: none;
  font-size: 11.5px;
  max-width: min(46%, 340px);
}
.overlay-tl {
  top: 12px; left: 14px;
  background: rgba(16, 18, 22, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 11px;
  display: grid;
  gap: 2px;
  min-width: 168px;
  backdrop-filter: blur(3px);
}
.overlay-bl { bottom: 12px; left: 14px; display: grid; gap: 6px; }

.readout-row { display: flex; gap: 10px; justify-content: space-between; color: var(--text-faint); }
.readout-k { color: var(--text-faint); }
.readout-v { color: var(--text-dim); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.note {
  background: #241f14;
  border: 1px solid #4a3d1e;
  color: #e2c98d;
  padding: 6px 9px;
  border-radius: 6px;
  line-height: 1.4;
}

.stage-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}
.views, .stage-right, .seg, .row { display: flex; gap: 6px; align-items: center; }
.stage-bar button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 5px 11px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.stage-bar button:hover:not(:disabled) { color: var(--text); border-color: #3a4150; }
.stage-bar button:disabled { color: var(--accent); border-color: #2e4a77; background: #1a2942; cursor: default; }
.check { display: flex; gap: 6px; align-items: center; color: var(--text-dim); cursor: pointer; }
.seg { gap: 0; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }

/* --------------------------------------------------------------- output -- */
.block { padding: 14px; border-bottom: 1px solid var(--line-soft); }
.block:empty { display: none; }
.field { display: grid; gap: 5px; margin-bottom: 10px; }
.field > span { color: var(--text-dim); font-size: 12px; }

button.primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 7px;
  padding: 9px 12px;
  font: 600 13px/1 inherit;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.55; cursor: default; }

.ghost, .ghost-link {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: inline-block;
}
.ghost:hover, .ghost-link:hover { color: var(--text); border-color: #3a4150; }
.row { margin-top: 8px; flex-wrap: wrap; }
.hint { margin: 8px 0 0; color: var(--text-faint); font-size: 11.5px; line-height: 1.45; }

#job-detail h3 { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }

.detail-grid { display: grid; gap: 3px; margin: 8px 0 10px; }
.detail-row { display: flex; justify-content: space-between; gap: 10px; }
.detail-k { color: var(--text-faint); font-size: 11.5px; }
.detail-v { color: var(--text-dim); font-size: 11.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.detail-row.good .detail-v { color: var(--good); }
.detail-row.bad .detail-v { color: var(--bad); }

.parts { display: grid; gap: 3px; margin-bottom: 10px; }
.part {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 8px;
  font-size: 10.5px;
  color: var(--text-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
}
.part-dim { overflow: hidden; text-overflow: ellipsis; }
.part-name { color: var(--text-dim); }

.downloads { display: flex; flex-wrap: wrap; gap: 6px; }
.download {
  background: #1d3252;
  border: 1px solid #2e4a77;
  color: var(--accent);
  border-radius: 6px;
  padding: 5px 10px;
  text-decoration: none;
  font-size: 11.5px;
}
.download:hover { filter: brightness(1.15); }

.jobs { display: grid; gap: 3px; }
.job {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: 9px;
  align-items: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text-dim);
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.job:hover { background: var(--panel-2); border-color: var(--line); }
.job-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.job-queued .job-dot, .job-running .job-dot { background: var(--gold); animation: pulse 1.1s ease-in-out infinite; }
.job-done .job-dot { background: var(--good); }
.job-failed .job-dot { background: var(--bad); }
.job-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-status { font-size: 11px; color: var(--text-faint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
@keyframes pulse { 50% { opacity: 0.35; } }

.empty { color: var(--text-faint); margin: 0; font-size: 11.5px; }

.filebtn { display: block; position: relative; overflow: hidden; margin-bottom: 8px; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.filebtn span {
  display: block;
  text-align: center;
  background: var(--panel-2);
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 9px;
  color: var(--text-dim);
}
.filebtn:hover span { border-color: var(--accent); color: var(--text); }

/* ---------------------------------------------------------------- flash -- */
.flash {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 14px);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  max-width: min(70vw, 620px);
  font-size: 12.5px;
}
.flash.show { opacity: 1; transform: translate(-50%, 0); }
.flash.bad { border-color: #5c3330; color: #f0a9a3; }

.boot-error {
  position: fixed; inset: 40px; overflow: auto;
  background: #1a1113; border: 1px solid #5c3330; color: #f0a9a3;
  padding: 18px; border-radius: 10px; font-size: 12px; z-index: 99;
}

/* --------------------------------------------------------- narrow screens */
@media (max-width: 1100px) {
  body { overflow: auto; }
  /* Stacked, the layout has to grow to fit its content. Left flexing inside a
     full-height body the rows stay short, the panels spill out of their own
     boxes, and whichever panel comes last in the markup ends up painted over
     the one above it -- controls included. */
  .layout { grid-template-columns: 1fr; height: auto; flex: none; }
  .layout, .panel, .panel .scroll { min-height: auto; }
  .panel-left, .panel-right { border: 0; border-top: 1px solid var(--line); }
  .panel-left .scroll, .panel-right .scroll { max-height: none; overflow: visible; }
  .stage { order: -1; height: 62vh; min-height: 380px; }
}

/* ----------------------------------------------------------- asset credits */
.credits { margin: 10px 0; }
.credits h4 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  font-weight: 600;
}
.credit {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  font-size: 11px;
  padding: 4px 0;
  border-top: 1px solid var(--line-soft);
}
.credit-name { color: var(--text-dim); }
.credit-licence {
  color: var(--good);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
}
.credit-author { grid-column: 1 / -1; color: var(--text-faint); font-size: 10.5px; }

/* ======================================================================== */
/* The model editor.                                                        */
/* ======================================================================== */

.tabs { display: flex; gap: 2px; margin-left: 6px; }
.tabs a {
  color: var(--text-faint);
  text-decoration: none;
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.tabs a:hover { color: var(--text-dim); background: var(--panel-2); }
.tabs a.on { color: var(--accent); border-color: #2e4a77; background: var(--panel-2); }

.chip[data-state="ok"] { color: var(--good); border-color: #2c5a46; }
.chip[data-state="bad"] { color: var(--bad); border-color: #5c3330; }

/* ------------------------------------------------------- the drop target - */
.dropveil {
  position: absolute;
  inset: 10px;
  border: 2px dashed #3d6ea8;
  border-radius: var(--radius);
  background: rgba(20, 30, 45, 0.72);
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 13px;
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.dropveil.on { opacity: 1; }

.stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  text-align: center;
  color: var(--text-dim);
  pointer-events: none;
  padding: 20px;
}
.stage-empty p { margin: 0; max-width: 320px; }

.overlay-tr {
  top: 12px; right: 14px;
  background: rgba(16, 18, 22, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 11px;
  display: grid;
  gap: 5px;
  backdrop-filter: blur(3px);
}
.legend-row { display: flex; align-items: center; gap: 7px; color: var(--text-dim); }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* ------------------------------------------------------------ read-outs -- */
.kv { display: grid; gap: 3px; }
.kv-row { display: flex; gap: 10px; justify-content: space-between; align-items: baseline; }
.kv-k { color: var(--text-faint); font-size: 11.5px; }
.kv-v {
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  text-align: right;
}
.kv-v.warn { color: var(--bad); }

/* Pass/fail list. The detail line carries the count, because "not watertight"
   on its own tells you nothing about how much work it is to fix. */
.checks { display: grid; gap: 7px; }
.check-row { display: flex; gap: 8px; align-items: flex-start; }
.check-mark {
  flex: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 9px;
  margin-top: 1px;
}
.check-row.ok .check-mark { background: #1d3a2e; color: var(--good); }
.check-row.no .check-mark { background: #3a2320; color: var(--bad); }
.check-text { min-width: 0; }
.check-name { font-size: 12px; }
.check-row.no .check-name { color: var(--bad); }
.check-detail { color: var(--text-faint); font-size: 11px; }

.select-sm { width: auto; padding: 4px 8px; font-size: 11.5px; }
.num.wide, .slider.wide { width: 100%; }
.ctrl > .select { width: 100%; }
.check-row.warn .check-mark { background: #3a3117; color: var(--gold); }
.check-row.warn .check-name { color: var(--gold); }
.chip[data-state="warn"] { color: var(--gold); border-color: #5a4a24; }

/* `hidden` is a UA rule, so it loses to the display: grid above it. These two
   are toggled from script and have to actually disappear when they are off. */
.overlay[hidden], .stage-empty[hidden] { display: none; }
