:root {
  --hintergrund: #141d2b;
  --karte: #1e2a3c;
  --rahmen: #33415a;
  --buehne: #fdfdfd;
  --text: #e6ebf2;
  --text-leise: #d1d8e2;
  --akzent: #5aa9ff;
  --border-radius: 5px;
}

* { box-sizing: border-box; }

* {
  scrollbar-width: thin;
  scrollbar-color: var(--rahmen) transparent;
}

[hidden] { display: none !important; }

.lade-anzeige {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--hintergrund);
  color: var(--text-leise);
  transition: opacity 0.3s ease;
}

.lade-anzeige.ausgeblendet {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--rahmen);
  border-top-color: var(--akzent);
  border-radius: 50%;
  animation: drehen 0.9s linear infinite;
}

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

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--hintergrund);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.app {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  padding: 20px;
}

.buehne {
  flex: 1 1 0;
  min-width: 0;
  align-self: flex-start;
  background: var(--buehne);
  border-radius: var(--border-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.bild {
  position: relative;
  container-type: inline-size;
}

/* Feste Simulationsfläche 650 x 600: Breite folgt dem Fenster, Höhe bleibt im Sichtbereich */
#szene {
  display: block;
  width: min(100%, calc((100vh - 40px) * 650 / 600));
  aspect-ratio: 650 / 600;
  height: auto;
  margin: 0 auto 0 0;
  touch-action: none;
}

@media (max-width: 900px) {
  .app { flex-direction: column; align-items: stretch; padding: 12px; }
  .panel, .buehne { flex: none; align-self: stretch; }
  #szene { width: 100%; }
}

.panel {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 10px;
  background: var(--karte);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

@media (min-width: 901px) {
  .panel {
    max-height: calc(100vh - 40px);
    overflow-y: auto;
  }
}

.panel h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

#regler {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.steuerung {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  background: var(--hintergrund);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
}

.steuerung label {
  font-weight: 500;
}

/* Schalter wie bei der Vorlage Doppelspaltwelle02 */
.schalter-zeile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-leise);
  cursor: pointer;
}

.schalter {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 22px;
}

.schalter input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.schalter-spur {
  position: absolute;
  inset: 0;
  background: var(--rahmen);
  border-radius: 11px;
  transition: background 0.15s ease;
  pointer-events: none;
}

.schalter-spur::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--text-leise);
  border-radius: 50%;
  transition: transform 0.15s ease;
}

.schalter input:checked + .schalter-spur {
  background: var(--akzent);
}

.schalter input:checked + .schalter-spur::after {
  transform: translateX(18px);
  background: var(--hintergrund);
}

.schalter input:focus-visible + .schalter-spur {
  box-shadow: 0 0 0 4px rgba(90, 169, 255, 0.4);
}

.aktionen {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
}

.aktion-knopf {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 10px;
  white-space: nowrap;
  background: var(--karte);
  color: var(--text);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.aktion-knopf:hover,
.aktion-knopf:focus-visible {
  border-color: var(--akzent);
  outline: none;
}

.aktion-knopf[aria-pressed="true"] {
  background: rgba(90, 169, 255, 0.15);
  border-color: var(--akzent);
}

.aktion-knopf:disabled {
  opacity: 0.45;
  cursor: default;
  border-color: var(--rahmen);
}

.wiedergabe-knopf {
  flex: 0 0 40px;
  width: 40px;
  padding: 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wiedergabe-knopf svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.ueberschrift {
  font-weight: 600;
}

.status {
  min-height: 22px;
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-leise);
}

.status.ok { color: #7fd4a0; }
.status.fehler { color: #ff9a8a; }

.messung .aktionen {
  display: flex;
}

.messung .aktionen .aktion-knopf {
  flex: 1 1 0;
  min-width: 0;
}

.regler-zeile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.regler-spur {
  flex: 1;
  min-width: 0;
}

.zahl-feld {
  display: flex;
  flex: 0 0 auto;
  background: var(--karte);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.zahl-feld:focus-within {
  border-color: var(--akzent);
}

.zahl-eingabe {
  box-sizing: content-box;
  padding: 6px 12px 6px 8px;
  background: transparent;
  color: var(--text);
  border: 0;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
  outline: none;
}

.stepper {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--rahmen);
}

.stepper button {
  flex: 1;
  width: 26px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-leise);
  border: 0;
  cursor: pointer;
}

.stepper button + button {
  border-top: 1px solid var(--rahmen);
}

.stepper button:hover {
  background: var(--rahmen);
  color: var(--text);
}

.stepper svg {
  width: 10px;
  height: 6px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 9 px = halbe Daumenbreite, damit die Marken unter der Daumenmitte liegen */
.skala {
  position: relative;
  height: 30px;
  margin: 0 9px;
  color: var(--text-leise);
  font-size: 12px;
}

.marke {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.marke::before {
  content: '';
  display: block;
  width: 1px;
  height: 6px;
  margin: 0 auto 2px;
  background: var(--text-leise);
}

.marke.kurz::before {
  height: 3px;
  margin-bottom: 0;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  margin: 8px 0px 0px 0px;
  border-radius: 3px;
  background: var(--rahmen);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--akzent);
  border: 3px solid var(--hintergrund);
  box-shadow: 0 0 0 1px var(--akzent);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--akzent);
  border: 3px solid var(--hintergrund);
  box-shadow: 0 0 0 1px var(--akzent);
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px rgba(90, 169, 255, 0.4);
}

input[type="range"]:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 4px rgba(90, 169, 255, 0.4);
}

.icon-leiste {
  display: flex;
  gap: 10px;
}

.icon-button {
  flex: 1 1 0;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--hintergrund);
  color: var(--text-leise);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--text);
  border-color: var(--akzent);
  outline: none;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

/* Oszilloskop auf der Bühne; die Maße skalieren mit der Bühnenbreite. */
.oszi {
  position: absolute;
  right: 25px;
  bottom: 25px;
  width: 52cqw;
  transform: scale(0.7);
  transform-origin: bottom right;
  padding: 1.1cqw 2.2cqw;
  display: flex;
  flex-direction: column;
  gap: 1cqw;
  background: linear-gradient(180deg, #3b424c 0%, #2a2f37 100%);
  border: 1px solid #15181d;
  border-radius: 2cqw;
  box-shadow: 0 1cqw 3cqw rgba(0, 0, 0, 0.35), inset 0 0.3cqw 0 rgba(255, 255, 255, 0.12);
  color: #e8ecf1;
  font-size: max(10px, 1.5cqw);
  user-select: none;
}

.oszi-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1cqw;
  cursor: grab;
  touch-action: none;
}

.oszi.zieht .oszi-kopf { cursor: grabbing; }

.oszi-marke {
  font-size: max(9px, 1.4cqw);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #c9d0da;
}

.oszi-led {
  flex: none;
  width: max(8px, 1.6cqw);
  height: max(8px, 1.6cqw);
  border-radius: 50%;
  background: #3b2a2a;
  box-shadow: inset 0 0 0 1px #111;
}

.oszi-led.an {
  background: #5cff7a;
  box-shadow: 0 0 0.8cqw #5cff7a;
}

.oszi-koerper {
  display: flex;
  align-items: center;
  gap: 2cqw;
}

.oszi-schirm-rahmen {
  flex: 1 1 auto;
  min-width: 0;
  padding: 1.1cqw;
  background: #161a20;
  border: 1px solid #0c0e11;
  border-radius: 1.2cqw;
}

#oszischirm {
  display: block;
  width: 100%;
  aspect-ratio: 5 / 4;
  background: #000;
  border-radius: 0.4cqw;
}

.oszi-bedienfeld {
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2cqw;
}

.oszi-regler {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6cqw;
}

.oszi-knopf {
  position: relative;
  width: max(26px, 7.5cqw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5a616c, #1b1f25 70%);
  border: 1px solid #0c0e11;
  box-shadow: 0 0.4cqw 0.8cqw rgba(0, 0, 0, 0.5);
  transform: rotate(var(--winkel, -135deg));
  cursor: grab;
  touch-action: none;
}

.oszi-knopf.dreht { cursor: grabbing; }

.oszi-knopf:focus-visible {
  outline: 2px solid var(--akzent);
  outline-offset: 2px;
}

.oszi-knopf::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 8%;
  width: 2px;
  height: 34%;
  margin-left: -1px;
  background: #ffb347;
  border-radius: 1px;
}

.oszi-beschriftung {
  font-size: max(9px, 1.25cqw);
  font-weight: 600;
  color: #c9d0da;
}

.oszi-anzeige {
  min-width: 9cqw;
  padding: 0.2cqw 0.8cqw;
  background: #0c0e11;
  border-radius: 0.6cqw;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: max(9px, 1.25cqw);
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: #7dff9b;
}

.modal-stapel {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(340px, calc(100vw - 40px));
  pointer-events: none;
}

.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  pointer-events: auto;
  padding: 12px 10px 16px 14px;
  background: var(--karte);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* 40 px breiter als der Stapel, nach links erweitert, damit der rechte Rand gleich bleibt */
.modal.modal-breit {
  width: min(380px, calc(100vw - 40px));
  margin-left: calc(min(340px, 100vw - 40px) - min(380px, 100vw - 40px));
}

.modal h2 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
}

.modal-schliessen {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-leise);
  border: 0;
  border-radius: var(--border-radius);
  cursor: pointer;
}

.modal-schliessen:hover {
  color: var(--text);
  background: var(--rahmen);
}

.modal-schliessen svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.modal-text {
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rahmen) transparent;
  color: var(--text-leise);
  font-size: 13px;
  padding-right: 6px;
}

.modal-text p {
  margin: 0 0 8px;
}

.modal-text p:last-child,
.modal-text ul:last-child,
.modal-text ol:last-child {
  margin-bottom: 0;
}

.modal-text ul,
.modal-text ol {
  margin: 0;
  padding-left: 18px;
}

.modal-text li + li {
  margin-top: 6px;
}

.modal-text strong {
  color: var(--text);
}

.modal-text .raster {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 16px;
  padding-left: 0;
  margin-bottom: 10px;
  list-style: none;
}

.modal-text .raster li + li { margin-top: 0; }

.modal-text .warnung {
  margin: 12px 0 0;
  padding: 8px 10px;
  color: var(--text);
  background: rgba(255, 154, 138, 0.12);
  border: 1px solid #ff9a8a;
  border-radius: var(--border-radius);
}

.modal-text .warnung strong { color: #ff9a8a; }

.modal-fortschritt {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--rahmen);
}

.modal-fortschritt span {
  display: block;
  height: 100%;
  background: var(--akzent);
  transform-origin: left center;
}
