:root {
  --hintergrund: #141d2b;
  --karte: #1e2a3c;
  --rahmen: #33415a;
  --text: #e6ebf2;
  --text-leise: #d1d8e2;
  --akzent: #5aa9ff;
  --border-radius: 5px;
  --zelle: #26344b;
  --gruen: #4fd16a;
  --elektron: #9fef00;
  --lila: #c58bff;
  --fehler: #ff6b6b;
  /* Skalierungseinheit für die Tabelle: kleiner Wert aus Höhe und Breite */
  --u: min(1vh, 0.8vw);
}

* { box-sizing: border-box; }

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

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;
}

[hidden] { display: none !important; }

.app {
  display: flex;
  align-items: stretch;
  gap: 20px;
  height: 100vh;
  height: 100dvh;
  padding: 20px;
}

.buehne {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .app { flex-direction: column; height: auto; padding: 12px; }
  .panel, .buehne { flex: none; }
}

.panel {
  flex: 0 0 320px;
  /* Steuerelemente behalten ihre Größe, auch wenn das Fenster niedriger wird */
  min-height: min-content;
  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 { align-self: flex-start; }
}

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

.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;
}

/* Abstand zu Info und Eingabefeld: 4px Flex-Lücke + 6px Rand des Info-Containers = 10px */
.aktionen {
  display: flex;
  gap: 8px;
}

.aktion-knopf {
  flex: 1 1 auto;
  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:disabled {
  color: var(--text-leise);
  opacity: 0.45;
  cursor: default;
  border-color: var(--rahmen);
}

.element-eingabe {
  width: 100%;
  padding: 6px 10px;
  background: var(--karte);
  color: var(--text);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
  font: inherit;
  font-size: 16px;
  outline: none;
}

.element-eingabe:focus {
  border-color: var(--akzent);
}

.element-eingabe.gueltig {
  border-color: var(--gruen);
  background: rgba(79, 209, 106, 0.12);
}

.element-eingabe.ungueltig {
  border-color: var(--fehler);
  background: rgba(255, 107, 107, 0.12);
}

.element-info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--karte);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.element-info dt {
  color: var(--text-leise);
}

.element-info dd {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.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;
}

/* Zustandstabelle, füllt die Bildschirmhöhe (Smartboard) */
.tabellen-karte {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(10px, 1.6vh, 20px);
  background: var(--karte);
  border: 1px solid var(--rahmen);
  border-radius: var(--border-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  overflow-x: auto;
  container-type: inline-size;
}

#zustand_chart {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.zustandstabelle {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  color: var(--text);
  font-size: min(clamp(12px, calc(var(--u) * 2.4), 30px), 2.6cqi);
}

.zustandstabelle th {
  padding: 0.3em 0.4em;
  color: var(--text-leise);
  font-weight: 600;
  text-align: center;
  border-bottom: 1px solid var(--rahmen);
}

.zustandstabelle th:first-child,
.zustandstabelle td.energie {
  width: 4.5em;
}

.zustandstabelle td {
  padding: 0.15em 0.2em;
  vertical-align: middle;
  text-align: center;
  border: 1px solid var(--rahmen);
}

.zustandstabelle td.energie {
  color: var(--text-leise);
  font-weight: 600;
}

.chart_cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3em;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  height: clamp(24px, calc(var(--u) * 3.6), 56px);
  padding: 0 0.2em;
  background: var(--zelle);
  color: var(--text-leise);
  border: 1px solid transparent;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.chart_cell .spin {
  min-width: 1.6em;
  font-weight: 600;
}

.chart_cell .quanten {
  font-size: 0.55em;
  color: var(--text-leise);
  white-space: nowrap;
}

/* Bearbeitungshinweise (Grün/Lila) erscheinen nur beim Maus-Hover */
.next_cell,
.prev_cell,
.split_cell {
  cursor: pointer;
}

.next_cell:hover {
  background: var(--gruen);
  color: var(--hintergrund);
  border-color: var(--text);
  filter: brightness(1.12);
}

.prev_cell:hover {
  background: var(--lila);
  color: var(--hintergrund);
  border-color: var(--text);
  filter: brightness(1.12);
}

/* Geteilte Zelle: links hinzufügen (grün), rechts entfernen (lila) */
.split_cell:hover {
  background: linear-gradient(to right, var(--gruen) 50%, var(--lila) 50%);
  color: var(--hintergrund);
  border-color: var(--text);
  filter: brightness(1.12);
}

/* Besetzte Schalen: Pfeile in Elektronenfarbe; im Hover bleibt der dunkle Text lesbar */
.chart_cell.besetzt {
  color: var(--elektron);
}

.chart_cell.besetzt.next_cell:hover,
.chart_cell.besetzt.prev_cell:hover,
.chart_cell.besetzt.split_cell:hover {
  color: var(--hintergrund);
}

/* Ohne Hover-Fähigkeit (Smartboard, Touch): Markierungen dauerhaft anzeigen */
@media (hover: none) {
  .next_cell {
    background: var(--gruen);
    color: var(--hintergrund);
    border-color: var(--text);
  }

  .prev_cell {
    background: var(--lila);
    color: var(--hintergrund);
    border-color: var(--text);
  }

  .split_cell {
    background: linear-gradient(to right, var(--gruen) 50%, var(--lila) 50%);
    color: var(--hintergrund);
    border-color: var(--text);
  }

  .chart_cell.besetzt.next_cell,
  .chart_cell.besetzt.prev_cell,
  .chart_cell.besetzt.split_cell {
    color: var(--hintergrund);
  }
}

/* Hinweise und Copyright, Stil wie in den übrigen Apps */
.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);
}

.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 {
  margin-bottom: 0;
}

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

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

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

.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;
}

@media (max-width: 900px) {
  .tabellen-karte { flex: none; }
  #zustand_chart { min-height: auto; }
  .zustandstabelle { height: auto; font-size: 12px; }
  .chart_cell { height: 28px; min-width: 4em; padding: 0 2px; font-size: 12px; }
}
