:root {
  color-scheme: dark;
  --bg: #0d0e10;
  --bg-grad: radial-gradient(130% 110% at 50% 0%, #22242a 0%, #0d0e10 62%);
  --ink: #f2f3f5;
  --ink-dim: #9fa4ad;
  --line: #2b2e35;
  --surface: rgba(20, 22, 26, 0.82);
  --accent: #e2613f;
  --radius: 10px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#stage { position: relative; width: 100%; height: 100dvh; background: var(--bg-grad); }

#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------------------------------------------------------- masthead */

#masthead {
  position: absolute;
  top: 24px;
  left: 28px;
  max-width: 24rem;
  pointer-events: none;
}

#masthead h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.4vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.015em;
}

#masthead p {
  margin: 6px 0 0;
  color: var(--ink-dim);
  font-size: 0.8125rem;
  line-height: 1.45;
}

#masthead a { color: var(--ink-dim); pointer-events: auto; }
#masthead a:hover { color: var(--accent); }

/* ------------------------------------------------------------- panel */

#panel {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 232px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 4px 16px 16px;
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  scrollbar-width: thin;
}

#panel section { padding: 14px 0 2px; border-top: 1px solid var(--line); }
#panel section:first-of-type { border-top: 0; }

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

/* switches */

.switches { display: flex; flex-direction: column; gap: 2px; }

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8125rem;
  text-transform: capitalize;
}

.switch:hover { background: rgba(255, 255, 255, 0.05); }

.switch input { appearance: none; margin: 0; width: 28px; height: 16px; flex: none;
  background: #35383f; border-radius: 99px; position: relative; cursor: pointer;
  transition: background 0.16s ease; }

.switch input::after { content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%; background: #9298a2;
  transition: transform 0.16s ease, background 0.16s ease; }

.switch input:checked { background: color-mix(in srgb, var(--accent) 70%, #000); }
.switch input:checked::after { transform: translateX(12px); background: #fff; }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* chips */

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

.chips button {
  flex: 1 1 auto;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.chips button:hover { background: rgba(255, 255, 255, 0.12); }
.chips button.on { border-color: var(--accent); color: #fff; }
.chips button.primary { background: var(--accent); color: #fff; font-weight: 500; }
.chips button.primary:hover { background: color-mix(in srgb, var(--accent) 85%, #fff); }
.chips button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* slider */

.slider { display: block; margin: 0 0 12px; font-size: 0.8125rem; }
.slider > span { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--ink-dim); }
.slider output { font-family: var(--mono); font-size: 0.75rem; color: var(--ink); }

.slider input {
  appearance: none; width: 100%; height: 3px; margin: 0;
  background: #35383f; border-radius: 99px; cursor: pointer;
}

.slider input::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--ink); border: 0; }
.slider input::-moz-range-thumb { width: 14px; height: 14px; border: 0;
  border-radius: 50%; background: var(--ink); }
.slider input:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* specs */

#specs { margin: 0; font-size: 0.8125rem; }

#specs div {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
#specs div:last-child { border-bottom: 0; }
#specs dt { color: var(--ink-dim); white-space: nowrap; }
#specs dd { margin: 0; text-align: right; font-family: var(--mono); font-size: 0.75rem; }

.note { margin: 0; color: var(--ink-dim); font-size: 0.75rem; line-height: 1.45; }

/* readout + loading */

#readout {
  position: absolute; bottom: 22px; left: 28px;
  font-family: var(--mono); font-size: 0.75rem; color: var(--ink-dim);
  pointer-events: none;
}

#readout #part-name { color: var(--ink); }

#loading {
  position: absolute; inset: 0; display: flex; gap: 10px;
  align-items: center; justify-content: center;
  color: var(--ink-dim); font-size: 0.8125rem;
  background: var(--bg-grad);
  transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}

/* Take it out of the page once it has faded; on narrow screens it covers the
   controls as well as the canvas, so opacity alone is not enough. */
#loading.done { opacity: 0; visibility: hidden; pointer-events: none; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ------------------------------------------------------------ narrow */

@media (max-width: 760px) {
  body { overflow: auto; }
  /* Stack it, and put the title above the viewer rather than after it. */
  #stage { height: auto; min-height: 100dvh; display: flex; flex-direction: column; }
  #masthead { order: 1; position: static; padding: 20px 16px 4px; max-width: none; left: auto; top: auto; }
  #view { order: 2; position: relative; height: 56dvh; flex: none; }
  #panel { order: 3; }
  #readout { order: 4; }
  #panel {
    position: static; width: auto; max-height: none; margin: 16px;
    backdrop-filter: none;
  }
  #readout { position: static; padding: 0 16px 20px; }
  #loading { position: absolute; inset: 0 0 auto; height: 100%; }
}
