:root {
  --bg: #0d1117;
  --panel: #151b24;
  --panel-2: #1c2430;
  --line: #2a3441;
  --fg: #dfe6ef;
  --dim: #8d9bad;
  --accent: #ffb238;
  --accent-2: #4da3ff;
  --ok: #46d17f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 13px/1.45 "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.hidden { display: none !important; }

#app { display: flex; height: 100vh; }

/* ------------------------------------------------------------------ panel */
#panel {
  width: 330px; flex: 0 0 330px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 16px 40px;
  overflow-y: auto;
}

#panel h1 { font-size: 17px; margin: 0 0 2px; letter-spacing: .2px; }
#panel .sub { margin: 0 0 16px; color: var(--dim); font-size: 12px; }

section {
  border-top: 1px solid var(--line);
  padding: 14px 0 4px;
}

h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--accent); margin: 0 0 10px; font-weight: 600;
}
h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--dim); margin: 12px 0 6px; font-weight: 600;
}

.tag {
  font-size: 10px; text-transform: none; letter-spacing: 0;
  background: var(--panel-2); color: var(--dim);
  padding: 2px 6px; border-radius: 10px; margin-left: 6px;
}

label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 6px 0; color: var(--dim); font-size: 12px;
}
label.small { display: block; margin: 10px 0 4px; }
label.small select, label.small input[type=range] { width: 100%; margin-top: 4px; }

input[type=number], input[type=text], select {
  width: 96px; padding: 5px 7px;
  background: var(--panel-2); color: var(--fg);
  border: 1px solid var(--line); border-radius: 5px;
  font: inherit;
}
label.small select { width: 100%; }
input[type=number]:focus, select:focus, input[type=text]:focus {
  outline: none; border-color: var(--accent-2);
}

label.chk {
  justify-content: flex-start; color: var(--fg);
  cursor: pointer; margin: 5px 0;
}
label.chk input { accent-color: var(--accent); }

button {
  background: var(--panel-2); color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 12px; font: inherit; cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: #26313f; border-color: #3b4959; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary {
  width: 100%; margin-top: 8px;
  background: var(--accent); color: #241a05;
  border-color: var(--accent); font-weight: 600;
}
button.primary:hover:not(:disabled) { background: #ffc35c; }
/* after the :hover rule on purpose — equal specificity, so source order wins,
   and an active button must stay highlighted while the pointer rests on it */
button.active,
button.active:hover:not(:disabled) {
  background: var(--accent-2); border-color: var(--accent-2);
  color: #06182c; font-weight: 600;
}

.btnrow { display: flex; gap: 6px; }
.btnrow button { flex: 1; padding: 7px 6px; font-size: 12px; }

.info {
  color: var(--dim); font-size: 11.5px; margin-top: 8px;
  white-space: pre-wrap; line-height: 1.5;
}
.hintline { color: var(--dim); font-size: 11.5px; margin: 0 0 10px; }
.foot { color: #5f6b7c; font-size: 11px; margin-top: 20px; line-height: 1.5; }

table.kv { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 11.5px; }
table.kv td { padding: 3px 0; vertical-align: top; }
table.kv td:first-child { color: var(--dim); }
table.kv td:last-child { text-align: right; font-family: ui-monospace, Consolas, monospace; }

.progress {
  height: 5px; background: var(--panel-2); border-radius: 3px;
  overflow: hidden; margin-top: 10px;
}
#uploadBar { height: 100%; width: 0; background: var(--accent-2); transition: width .15s; }

.legend { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; color: var(--dim); font-size: 11px; }
.legend .bar {
  flex: 1; height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, #0000ff, #00ffff 35%, #00ff00 50%, #ffff00 70%, #ff0000);
}
.legend .dzbar {
  background: linear-gradient(90deg, #ff0000, #ffff00 45%, rgba(0,0,0,0) 50%, #78ffff 55%, #0000ff);
}

/* ------------------------------------------------------------------ stage */
#stage { flex: 1; position: relative; min-width: 0; }
#viewport { position: absolute; inset: 0; }
#viewport canvas { display: block; }
#viewport.drawing { cursor: crosshair; }

#overlayTop {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; align-items: center; gap: 8px; pointer-events: none;
}
#overlayTop .spacer { flex: 1; }
#overlayTop button { pointer-events: auto; }
button.ghost {
  background: rgba(21,27,36,.85);
  padding: 6px 10px; font-size: 12px;
}
.pill {
  background: rgba(21,27,36,.85); border: 1px solid var(--line);
  padding: 5px 11px; border-radius: 20px; font-size: 11.5px; color: var(--dim);
}
.pill.on { color: #06182c; background: var(--accent-2); border-color: var(--accent-2); font-weight: 600; }

#hint {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  color: #55606f; font-size: 15px; pointer-events: none;
}

#busy {
  position: absolute; inset: 0; display: flex; gap: 12px;
  align-items: center; justify-content: center;
  background: rgba(13,17,23,.65); color: var(--fg); font-size: 13px;
}
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- playbar */
#playbar {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 10px;
  background: rgba(21,27,36,.92);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px;
}
#playbar button.primary { width: 40px; margin: 0; padding: 6px 0; }
#playbar select { width: 72px; }
#timeline { flex: 1; accent-color: var(--accent); }
#timeLabel { color: var(--dim); min-width: 58px; text-align: right; font-size: 12px; }

.vlegend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); }
.vbar {
  width: 90px; height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, #1a59ff, #00e5ff 35%, #19ff40 50%, #fff21a 70%, #ff2619);
}

.stereo {
  width: 100%; margin-top: 10px; border-radius: 8px;
  border: 1px solid var(--line); display: block;
}

#panel h1 .ver {
  font: 11px ui-monospace, Consolas, monospace;
  color: var(--dim); border: 1px solid var(--line);
  border-radius: 20px; padding: 1px 7px; vertical-align: middle;
}
.doclinks { margin: -10px 0 16px; font-size: 12px; color: var(--line); }
.doclinks a { color: var(--accent-2); text-decoration: none; }
.doclinks a:hover { text-decoration: underline; }

/* -------------------------------------------------------------------- tabs */
/* Ten stacked sections made the sidebar several screens long. Grouping them
   into panes keeps every control one click away instead of one scroll hunt. */
#tabs {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 3px;
  margin: 0 -16px 4px; padding: 0 16px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
#tabs button {
  flex: 1 1 0; min-width: 0;
  position: relative;
  padding: 7px 2px; font-size: 11.5px;
  border-radius: 7px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#tabs button.on {
  background: var(--accent-2); border-color: var(--accent-2);
  color: #06182c; font-weight: 600;
}
/* the active tab must stay highlighted under the pointer */
#tabs button.on:hover:not(:disabled) {
  background: var(--accent-2); border-color: var(--accent-2);
}
/* something reported a result in a pane you were not looking at */
#tabs button .dot {
  display: none;
  position: absolute; top: 4px; right: 5px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}
#tabs button.flag .dot { display: block; }
#tabs button.on .dot { display: none; }

[hidden] { display: none !important; }
.pane > section:first-of-type { border-top: none; padding-top: 6px; }
.pane > .foot { margin-top: 26px; }

/* Sections fold away so a dense pane (Analysis carries four) can be trimmed to
   whatever you are actually using. Everything starts open — this is opt-in. */
section > h2 { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 6px; }
section > h2::before {
  content: ""; flex: 0 0 auto;
  width: 0; height: 0; margin-right: 1px;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent; border-bottom: 4px solid transparent;
  transform: rotate(90deg); transition: transform .12s;
}
section.folded > h2::before { transform: rotate(0deg); }
section.folded > *:not(h2) { display: none; }
section > h2:hover { color: #ffd08a; }

.info.bad { color: #ff8b80; }

/* Errors used to live only in the sidebar, which is easy to miss when you are
   looking at the 3D view or sitting on another tab. */
#toast {
  position: absolute; left: 50%; top: 64px; transform: translateX(-50%);
  max-width: 560px; z-index: 20;
  background: rgba(38, 20, 20, .96); color: #ffd9d5;
  border: 1px solid var(--warn); border-left-width: 4px;
  border-radius: 8px; padding: 11px 16px;
  font-size: 13px; line-height: 1.5; white-space: pre-wrap;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
}

/* Sign out sits in the doc-links row rather than floating: absolutely
   positioned it anchored to the viewport, not the panel, and covered the
   3D view controls. */
.linkish {
  background: none; border: 0; padding: 0;
  color: var(--dim); font: inherit; cursor: pointer; text-decoration: underline;
}
.linkish:hover { color: var(--fg); }

/* ------------------------------------------------------------- saved runs */
.runlist { margin-top: 8px; }
.runitem {
  border: 1px solid var(--line); border-radius: 6px;
  padding: 9px 10px; margin-bottom: 8px; background: var(--panel-2);
}
.runitem.current { border-color: var(--accent); }
.runitem .rname { font-weight: 600; font-size: 12.5px; }
.runitem .rmeta { color: var(--dim); font-size: 11px; margin-top: 3px; }
.runitem .rnotes { color: var(--dim); font-size: 11px; margin-top: 4px; font-style: italic; }
.runitem .rbtns { margin-top: 7px; display: flex; gap: 6px; }
.runitem .rbtns button { flex: 1; padding: 5px 8px; font-size: 11.5px; }
.runitem .danger { background: none; border: 1px solid var(--line); color: var(--dim); }
.runitem .danger:hover { border-color: #ff6b6b; color: #ff6b6b; }
.runempty { color: var(--dim); font-size: 12px; padding: 6px 0; }
