:root {
  --bg: #0b0b0d;
  --panel: #121215;
  --line: #26262c;
  --ink: #e9e8e4;
  --dim: #8a8a93;
  --accent: #f3efe4;
  --warn: #e0a33c;
  --bad: #e05c4a;
  --good: #6bbf7a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 ui-sans-serif, -apple-system, "Helvetica Neue", sans-serif;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
}

body.bare { grid-template-columns: minmax(0, 1fr); }
body.bare #panel { display: none; }

/* min-width/min-height 0 matter: a grid item defaults to min-*: auto, so an
   oversized canvas would widen this column and push the panel off-screen. */
#stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 7px;
  padding: 24px;
  color: var(--ink);
  text-align: center;
  pointer-events: none;
}

#loading[hidden] { display: none; }
#loading strong { font-size: 13px; font-weight: 600; }
#loading small { color: var(--dim); font-size: 11px; }

#loading.live {
  inset: auto auto 18px 18px;
  grid-template-columns: auto 1fr;
  justify-items: start;
  gap: 1px 10px;
  min-width: min(330px, calc(100% - 36px));
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 18, 21, 0.88);
  text-align: left;
  backdrop-filter: blur(10px);
}

#loading.live .loading-mark { grid-row: 1 / 3; align-self: center; width: 18px; height: 18px; margin: 0; }

.loading-mark {
  width: 26px;
  height: 26px;
  margin-bottom: 5px;
  border: 1px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-turn 1s linear infinite;
}

@keyframes loading-turn { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .loading-mark { animation-duration: 2.5s; }
}

/* The renderer sets the canvas ATTRIBUTE size to w x devicePixelRatio and is
   told not to touch the style, so the CSS size has to be pinned here. Without
   this the canvas lays out at twice its box and drives a runaway resize loop. */
#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 22px 20px;
}

#panel header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sub { margin: 3px 0 0; color: var(--dim); font-size: 12px; }

#panel section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

#panel section.row { display: flex; gap: 18px; }

#panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.chip:hover { color: var(--ink); border-color: #3d3d46; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #111; }

.note { margin: 12px 0 0; color: var(--dim); font-size: 12px; line-height: 1.55; }

.control { margin-bottom: 11px; }

.control-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 3px;
}

.control-head span:last-child { color: var(--dim); font-variant-numeric: tabular-nums; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

details { margin-top: 6px; }

details summary {
  cursor: pointer;
  color: var(--dim);
  font-size: 12px;
  list-style: none;
  padding: 6px 0;
}

details summary::before { content: "▸ "; }
details[open] summary::before { content: "▾ "; }
details summary::-webkit-details-marker { display: none; }
details > div { margin-top: 8px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--dim);
  cursor: pointer;
}

#report {
  margin: 0;
  font: 11px/1.6 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--dim);
  white-space: pre-wrap;
}

#report .ok { color: var(--good); }
#report .warn { color: var(--warn); }
#report .bad { color: var(--bad); }

.actions { display: flex; flex-direction: column; gap: 8px; }

button {
  padding: 9px 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #111;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

button.secondary { background: transparent; border-color: var(--line); color: var(--dim); }
button.secondary:hover { color: var(--ink); border-color: #3d3d46; }

.button-link {
  display: block;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
}

.button-link:hover { color: var(--ink); border-color: #3d3d46; }

footer { margin-top: 20px; color: var(--dim); font-size: 11px; }
footer code { color: var(--ink); }
footer a { color: var(--ink); }

@media (max-width: 760px) {
  html, body { height: auto; min-height: 100%; overflow: auto; }
  body { display: flex; flex-direction: column; }
  #stage { min-height: 56svh; }
  #panel { border-top: 1px solid var(--line); border-left: 0; overflow: visible; }
}
