:root {
  --bg: #0b0e13;
  --panel: #11161e;
  --line: #1f2733;
  --text: #d8dee8;
  --muted: #8592a6;
  --accent: #ff9f43;   /* estimate */
  --truth: #7ee0b5;    /* ground truth */
  --part: #ffd27a;
  --front: #4cc9f0;
  --plan: #c084fc;
  --wall: #e05d6f;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

code, output, dd, .label, .legend, .seg button, .hint { font-family: var(--mono); }
code { font-size: 0.88em; color: #b7c3d6; background: #161c26; padding: 1px 5px; border-radius: 4px; }

.top {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 18px;
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: space-between;
}
.brand { display: flex; gap: 14px; align-items: flex-start; }
.mark {
  flex: none;
  width: 14px; height: 14px; margin-top: 9px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 159, 67, 0.12);
}
h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--muted); max-width: 62ch; }
.repo {
  flex: none;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
}
.repo:hover { border-color: #33404f; background: var(--panel); }

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
}

.stage { min-width: 0; }
.canvas-wrap {
  position: relative;
  width: min(100%, max(320px, calc(100vh - 190px)));
  aspect-ratio: 1 / 1;
  margin: 0;
  background: #080a0e;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
canvas { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: linear-gradient(rgba(8, 10, 14, 0.7), rgba(8, 10, 14, 0.86)), url("preview.webp") center / cover no-repeat;
  color: var(--muted);
  font: 13px var(--mono);
  text-align: center;
  padding: 16px;
  transition: opacity 0.3s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay.error { color: var(--wall); }
.done-msg {
  width: min(100%, max(320px, calc(100vh - 190px)));
  box-sizing: border-box;
  margin: 10px 0 0;
  padding: 9px 12px;
  background: rgba(8, 10, 14, 0.88);
  border: 1px solid var(--line);
  border-left: 3px solid var(--truth);
  border-radius: 6px;
  font: 13px/1.45 var(--mono);
  color: var(--text);
}
.done-msg[hidden] { display: none; }
.overlay.error .spinner, .overlay.error .bar, .overlay.error .stage-note, .overlay.error .preview-note { display: none; }
.overlay p { margin: 0; padding: 0 16px; text-shadow: 0 1px 3px #000; }
#status { color: var(--text, #e8edf2); font-size: 14px; }
.bar { width: min(240px, 70%); height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 8%; background: var(--accent); transition: width 0.6s ease; }
.stage-note { font-size: 12px; }
.preview-note { position: absolute; bottom: 10px; font-size: 11px; opacity: 0.7; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.legend {
  list-style: none; margin: 12px 0 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  font-size: 12px; color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 7px; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.sw-true { background: var(--truth); }
.sw-est { background: var(--accent); }
.sw-part { width: 5px; height: 5px; border-radius: 50%; background: var(--part); }
.sw-front { width: 6px; height: 6px; border-radius: 1px; background: var(--front); }
.sw-plan { background: var(--plan); }
.sw-wall { background: repeating-linear-gradient(90deg, var(--wall) 0 4px, transparent 4px 6px); }

.panel { display: flex; flex-direction: column; gap: 16px; }
.controls, .stats {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin: 0;
}
.controls { display: flex; flex-direction: column; gap: 18px; }
.row.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
button {
  font: 500 14px var(--sans);
  color: var(--text);
  background: #19202b;
  border: 1px solid #263040;
  border-radius: 7px;
  padding: 9px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #1f2835; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--front); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a1006; }
button.primary:hover:not(:disabled) { background: #ffb366; }

.field { display: flex; flex-direction: column; gap: 8px; }
.label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; text-transform: uppercase; letter-spacing: 0.04em; }
.label output { color: var(--text); text-transform: none; }
.hint { font-size: 11px; color: #637084; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid #263040; border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; font-size: 12px; padding: 7px 0; }
.seg button + button { border-left: 1px solid #263040; }
.seg button[aria-checked="true"] { background: #243044; color: #fff; }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
.toggles { flex-direction: row; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; color: var(--muted); }
.toggles label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.toggles input { accent-color: var(--accent); margin: 0; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.stats div { min-width: 0; }
.stats dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stats dd { margin: 2px 0 0; font-size: 17px; color: #fff; font-variant-numeric: tabular-nums; }

.notes {
  max-width: 1180px;
  margin: 28px auto 48px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.note { border-top: 1px solid var(--line); padding-top: 16px; }
.note h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; }
.note p { margin: 0 0 12px; color: #b4bfcf; max-width: 68ch; }
.files { font: 12px/1.7 var(--mono); color: #637084 !important; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .canvas-wrap, .done-msg { width: 100%; }
  .notes { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .top { flex-direction: column; gap: 12px; padding: 20px 16px 14px; }
  .layout, .notes { padding: 0 16px; }
  h1 { font-size: 21px; }
  .stats dd { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
