/* ModuRack-Konfigurator.
   Dunkle Grundflaeche, damit das schwarze Gehaeuse in der 3D-Ansicht
   und in den Renderings gleich gut sitzt; helle Variante folgt dem
   System. Alle Farben als Tokens, damit beide Themes dieselbe Struktur
   haben. */

:root {
  color-scheme: light dark;

  --bg: #14171c;
  --surface: #1c2027;
  --surface-2: #232830;
  --line: #2e343e;
  --text: #e8ecf2;
  --muted: #9aa5b4;
  --accent: #4bb3c4;
  --accent-ink: #06222a;
  --warn: #d9a441;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f4f6f9;
    --line: #dde2ea;
    --text: #1b1f26;
    --muted: #5f6b7a;
    --accent: #0d7a8c;
    --accent-ink: #ffffff;
    --warn: #9a6b12;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  }
}

* { box-sizing: border-box; }

/* Eigene display-Regeln schlagen die UA-Regel fuer [hidden] - ohne das
   hier blieben Spinner, Rendering-Overlay und Hinweisbox sichtbar,
   obwohl das JavaScript sie versteckt hat. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Kopfzeile ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: .75rem; }

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background:
    linear-gradient(160deg, var(--accent), color-mix(in oklab, var(--accent) 55%, #000));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

.brand h1 { margin: 0; font-size: 1.05rem; letter-spacing: .01em; }
.brand p { margin: 0; font-size: .78rem; color: var(--muted); }

.topbar-meta { display: flex; align-items: center; gap: .6rem; }

.pill {
  font: 500 .74rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .38rem .6rem;
}

/* ---------- Layout ---------- */

#layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  gap: 1rem;
  padding: 1rem;
  align-items: start;
  max-width: 1680px;
  margin: 0 auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .25rem 1rem 1rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.block { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: none; }

.block h2 {
  margin: 0 0 .5rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.sub { margin: .35rem 0 0; font-size: .8rem; color: var(--muted); }

/* ---------- Optionen ---------- */

.choices { display: grid; gap: .4rem; }

.choice {
  display: grid;
  grid-template-columns: 1fr;
  gap: .1rem;
  text-align: left;
  padding: .55rem .7rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}

.choice:hover:not(:disabled) { border-color: color-mix(in oklab, var(--accent) 55%, var(--line)); }

.choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.choice.on {
  background: color-mix(in oklab, var(--accent) 16%, var(--surface-2));
  border-color: var(--accent);
}

.choice-name { font-weight: 600; font-size: .92rem; }
.choice-note { font-size: .76rem; color: var(--muted); }
.choice.on .choice-note { color: color-mix(in oklab, var(--accent) 70%, var(--text)); }

.choice.off {
  cursor: not-allowed;
  opacity: .5;
}
.choice.off .choice-note { color: var(--warn); }

.notice {
  margin: .25rem 0 0;
  padding: .55rem .7rem;
  font-size: .8rem;
  border-radius: 9px;
  color: var(--warn);
  background: color-mix(in oklab, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in oklab, var(--warn) 35%, transparent);
}

.dims { margin: 0; font-size: 1.1rem; font-weight: 600; letter-spacing: .01em; }

/* ---------- Bühne ---------- */

.stage {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  min-width: 0;
}

.stage-view {
  position: relative;
  background:
    radial-gradient(120% 90% at 50% 5%,
      color-mix(in oklab, var(--surface) 92%, var(--accent)) 0%,
      var(--surface) 55%,
      color-mix(in oklab, var(--surface) 80%, #000) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: clamp(380px, calc(100vh - 12rem), 820px);
  overflow: hidden;
}

#viewer { display: block; width: 100%; height: 100%; touch-action: none; }
#viewer.dimmed { visibility: hidden; }

/* Die Renderings fuellen ihre quadratische Leinwand nur zu gut der
   Haelfte; wo genau der Inhalt sitzt, steht als imageBox im Katalog
   (siehe catalog.image_box()) und kommt hier als --zoom/--dx/--dy an.

   inset+margin:auto statt width/height:100%, damit das Element genau
   so gross wird wie das eingepasste Bild und nicht wie die ganze
   Buehne. Nur dann beziehen sich die Prozentwerte in translate() auf
   das Bild - bei einer nicht-quadratischen Buehne saesse der Versatz
   sonst daneben. Ueberstehendes schneidet .stage-view ab. */
.photo {
  position: absolute;
  inset: 0;
  margin: auto;
  width: auto;
  height: auto;
  max-width: calc(100% - 2rem);
  max-height: calc(100% - 2rem);
  transform: scale(var(--zoom, 1)) translate(var(--dx, 0), var(--dy, 0));
}

.stage-tools {
  position: absolute;
  top: .75rem;
  right: .75rem;
  display: flex;
  gap: .4rem;
}

.stage-explode {
  position: absolute;
  left: .9rem;
  bottom: .9rem;
  display: grid;
  gap: .2rem;
  padding: .5rem .7rem;
  border-radius: 10px;
  background: color-mix(in oklab, var(--surface) 82%, transparent);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

.stage-explode label { font-size: .72rem; color: var(--muted); }
.stage-explode input { width: 170px; accent-color: var(--accent); }

.segmented {
  display: flex;
  background: color-mix(in oklab, var(--surface) 82%, transparent);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  backdrop-filter: blur(6px);
}

.segmented button {
  border: none;
  background: transparent;
  color: var(--muted);
  font: 600 .78rem/1 inherit;
  padding: .45rem .7rem;
  cursor: pointer;
}

.segmented button.on { background: var(--accent); color: var(--accent-ink); }
.segmented button:disabled { opacity: .4; cursor: not-allowed; }

.ghost {
  background: color-mix(in oklab, var(--surface) 82%, transparent);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font: 600 .78rem/1 inherit;
  padding: .45rem .7rem;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.ghost:hover:not(:disabled) { border-color: var(--accent); }
.ghost:disabled { opacity: .4; cursor: not-allowed; }

.stage-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  font-size: .85rem;
  color: var(--muted);
  background: color-mix(in oklab, var(--surface) 70%, transparent);
  pointer-events: none;
}

.spin {
  width: 15px; height: 15px;
  border: 2px solid color-mix(in oklab, var(--accent) 40%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* ---------- Teileleiste ---------- */

.stage-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.stage-dims { text-align: right; }
.stage-dims .sub { margin: 0; }

.parts-strip { display: flex; flex-wrap: wrap; gap: .4rem; }
.parts-strip.disabled { opacity: .35; pointer-events: none; }

.part-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: .38rem .8rem;
  font: 600 .78rem/1 inherit;
  cursor: pointer;
}

.part-chip.on { color: var(--text); border-color: color-mix(in oklab, var(--accent) 45%, var(--line)); }
.part-chip:not(.on) { text-decoration: line-through; }

/* ---------- Downloads / Listen ---------- */

.download-main {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .7rem .85rem;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  font-weight: 600;
}
.download-main:hover { filter: brightness(1.08); }
.download-main strong { display: block; font-size: .92rem; }
.download-main em { display: block; font-style: normal; font-size: .76rem; opacity: .85; }

.dl-icon {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: color-mix(in oklab, var(--accent-ink) 18%, transparent);
  font-size: .95rem;
}

.parts-list { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: 1px; }

.parts-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .5rem;
  padding: .45rem .55rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
}
.parts-list a:hover { background: var(--surface-2); }
.part-name { font-size: .88rem; }
.part-name::before { content: "↓ "; color: var(--muted); }
.part-meta { font-size: .73rem; color: var(--muted); white-space: nowrap; }

.hints, .bom { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.hints li { font-size: .82rem; color: var(--muted); padding-left: 1rem; position: relative; }
.hints li::before { content: "•"; position: absolute; left: .2rem; color: var(--accent); }

.bom li { display: grid; grid-template-columns: 2.4rem 1fr; gap: .1rem .5rem; font-size: .85rem; }
.bom b { color: var(--accent); font-variant-numeric: tabular-nums; }
.bom em { grid-column: 2; font-style: normal; font-size: .74rem; color: var(--muted); }

/* ---------- Fehlerseite ---------- */

.fatal { max-width: 34rem; margin: 20vh auto; padding: 0 1.5rem; }
.fatal h1 { font-size: 1.2rem; }
.fatal p { color: var(--muted); }

/* ---------- Schmale Fenster ---------- */

@media (max-width: 1180px) {
  #layout { grid-template-columns: 280px minmax(0, 1fr); }
  #details { grid-column: 1 / -1; position: static; max-height: none; }
}

@media (max-width: 800px) {
  #layout { grid-template-columns: 1fr; padding: .75rem; }
  .panel { position: static; max-height: none; }
  .stage-view { height: 60vh; }
  .stage-foot { flex-direction: column; }
  .stage-dims { text-align: left; }
  .stage-explode { position: static; margin: .5rem; }
}
