/* ============================================
   Conway's Game of Life – Stil
   Farben über Variablen anpassbar
   ============================================ */

:root {
  /* Zellenfarben (für lebendig/tot) */
  --cell-living: #22c55e;
  --cell-dead: #0a0a0a;
  /* Graph-Linien (Geburten, Überlebende, Tode) */
  --graph-births: #22c55e;
  --graph-survivals: #3b82f6;
  --graph-deaths: #ef4444;
  /* Optional: Hintergrund und UI */
  --bg-page: #111;
  --bg-controls: #1a1a1a;
  --text-color: #e5e5e5;
  --border-controls: #333;
  --focus-ring: #22c55e;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: linear-gradient(to bottom, #0a0a0a 0%, #1a1a1a 25%, #252525 50%, #1a1a1a 75%, #0a0a0a 100%);
  color: var(--text-color);
  font-family: system-ui, -apple-system, sans-serif;
}

a, a:link, a:visited {
  color: #fff;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* Layout: Steuerung oben, Canvas füllt Rest */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.controls {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-controls);
  border-bottom: 1px solid var(--border-controls);
}

.controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.controls input[type="number"] {
  width: 4.5rem;
  padding: 0.35rem 0.5rem;
  background: #222;
  border: 1px solid var(--border-controls);
  border-radius: 4px;
  color: var(--text-color);
  font-size: 0.9rem;
}

.controls input[type="number"]:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  background: #333;
  border: 1px solid var(--border-controls);
  border-radius: 6px;
  color: var(--text-color);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.controls button:hover {
  background: #444;
  border-color: #555;
}

.controls button:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.controls button.primary {
  background: #166534;
  border-color: #22c55e;
}

.controls button.primary:hover {
  background: #15803d;
}

.header-wiki-link,
.header-youtube-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  padding: 0.35rem;
  border-radius: 4px;
  transition: color 0.15s, opacity 0.15s;
}
.header-wiki-link {
  margin-left: auto;
  color: var(--text-color);
}
.header-wiki-link:hover {
  color: #fff;
  opacity: 0.9;
}
.header-youtube-link {
  color: #ff0000;
}

.header-youtube-link:hover {
  color: #ff3333;
  opacity: 0.9;
}

.control-grid-label .ph {
  font-size: 1.25rem;
}

.controls button#btn-reseed {
  padding: 0.5rem;
}
.controls button#btn-reseed .ph {
  font-size: 1.1rem;
}

.patterns-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.5rem;
  background: transparent;
  border: 1px solid var(--border-controls);
  border-radius: 6px;
  color: var(--text-color);
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.patterns-btn:hover {
  background: #333;
  border-color: var(--focus-ring);
}

.config-rules-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-color);
  cursor: pointer;
  font-size: 1.25rem;
  transition: background 0.15s, color 0.15s;
}
.config-rules-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

#tick-counter {
  font-variant-numeric: tabular-nums;
  min-width: 2.5rem;
  display: inline-block;
  text-align: right;
}

.perf-hint {
  font-size: 0.85rem;
  color: #f59e0b;
  padding: 0.35rem 0.6rem;
  background: rgba(245, 158, 11, 0.12);
  border-radius: 4px;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.perf-hint.hidden {
  display: none;
}

/* Canvas-Container: nimmt restlichen Platz, zentriert Canvas bei Zoom */
.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0.5rem;
}

.canvas-color-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 0.5rem;
  background: rgba(0, 0, 0, 0.6);
  width: 6rem;
}

.canvas-color-control {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.slider-label {
  width: 2rem;
  height: 5rem;
  display: flex;
  align-items: center;
  justify-content: start;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-color);
  writing-mode: vertical-rl;
  transform: rotate(-180deg);
  text-orientation: mixed;
  white-space: nowrap;
}

.slider-vertical-wrap {
  position: relative;
  width: 1.5rem;
  height: 10rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.canvas-color-control input[type="range"] {
  position: absolute;
  width: 10rem;
  height: 1.5rem;
  margin: 0;
  padding: 0;
  left: 50%;
  top: 50%;
  margin-left: -5rem;
  margin-top: -0.75rem;
  transform: rotate(-90deg);
  background: transparent;
}

.canvas-color-left input[type="range"] {
  accent-color: var(--cell-living);
}

.canvas-color-right input[type="range"] {
  accent-color: var(--cell-dead);
}

.canvas-color-control input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--text-color);
  cursor: pointer;
  border: 2px solid var(--bg-controls);
}

.canvas-color-control input[type="range"]::-moz-range-thumb {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--text-color);
  cursor: pointer;
  border: 2px solid var(--bg-controls);
}

.color-presets {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.color-preset {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 2px solid var(--border-controls);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.color-preset:hover {
  border-color: var(--focus-ring);
  transform: scale(1.05);
}

.color-preset-white {
  background: #fff;
}

.color-preset-black {
  background: #000;
}

.canvas-zoom-wrap {
  transform-origin: center center;
  flex-shrink: 0;
}
.canvas-zoom-wrap.grab {
  cursor: grab;
}
.canvas-zoom-wrap.grabbing {
  cursor: grabbing;
}

.imprint-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 0.5rem;
  background: rgba(0, 0, 0, 0.6);
  width: 3rem;
}

.imprint-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  transform: rotate(-90deg);
  transform-origin: center;
  font-size: 0.75rem;
  color: var(--text-color);
}

.imprint-content p {
  margin: 0;
}

#grid-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: var(--cell-dead);
}

/* Graph: Geburten / Überlebende / Tode über die Zeit */
.graph-wrap {
  flex-shrink: 0;
  background: var(--bg-controls);
  border-top: 1px solid var(--border-controls);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 1rem;
  gap: 0.5rem;
  flex-shrink: 0;
}

.graph-header-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.graph-header-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-color);
}

.graph-header-cycle {
  margin-left: auto;
  font-size: 0.8rem;
  color: #22c55e;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 4px rgba(34, 197, 94, 0.6);
}

.graph-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-color);
  cursor: pointer;
  transition: background 0.15s, transform 0.25s ease;
}

.graph-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.graph-toggle-btn .ph {
  font-size: 1.1rem;
  transition: transform 0.3s ease;
}

.graph-wrap.graph-collapsed #graph-toggle-icon {
  transform: rotate(180deg);
}

.graph-body {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  padding: 0 1rem 0.5rem;
  max-height: 180px;
  min-height: 140px;
  overflow: hidden;
  transition: max-height 0.35s ease-out;
}

.graph-main {
  flex: 3;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.graph-stats-panel {
  flex: 1;
  min-width: 0;
  padding: 0.25rem 0.5rem 0.25rem 0.75rem;
  border-left: 1px solid var(--border-controls);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-color);
  overflow: hidden;
}

.graph-stats-panel::-webkit-scrollbar {
  width: 6px;
}

.graph-stats-panel::-webkit-scrollbar-track {
  background: transparent;
}

.graph-stats-panel::-webkit-scrollbar-thumb {
  background-color: #22c55e;
  border-radius: 999px;
}

.graph-stats-panel {
  scrollbar-width: thin;
  scrollbar-color: #22c55e transparent;
}

.graph-stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.graph-stats-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: inherit;
  cursor: pointer;
}

.graph-stats-toggle-btn .ph {
  font-size: 1rem;
}

.graph-stats-content {
  max-height: 999px;
  overflow-y: auto;
  padding-top: 0.25rem;
  transition: max-height 0.25s ease-out, padding-top 0.25s ease-out;
}

.graph-stats-panel.graph-stats-collapsed .graph-stats-content {
  max-height: 0;
  padding-top: 0;
}

.graph-stats-title {
  font-weight: 600;
  font-size: 0.85rem;
}

.graph-stats-group {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.graph-stats-group-header {
  font-size: 0.8rem;
  opacity: 0.9;
}

.graph-stats-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.graph-stats-row {
  display: flex;
  justify-content: space-between;
  gap: 0.35rem;
  background: transparent;
  border: none;
  padding: 0.1rem 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.graph-stats-row:hover {
  background: rgba(255, 255, 255, 0.06);
}

.graph-stats-row-seed {
  font-variant-numeric: tabular-nums;
}

.graph-stats-row-ticks {
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.graph-wrap.graph-collapsed .graph-body {
  max-height: 0;
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.stagnation-badge {
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: #052e16;
  background: #22c55e;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  text-align: center;
}

.stagnation-badge.hidden {
  display: none;
}

#rates-graph {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  border-radius: 4px;
  background: var(--bg-controls);
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-color);
  opacity: 0.9;
}

.graph-legend-item::before {
  content: '';
  display: inline-block;
  width: 0.75rem;
  height: 3px;
  margin-right: 0.35rem;
  vertical-align: middle;
  border-radius: 1px;
}

.graph-legend-births::before { background: var(--graph-births); }
.graph-legend-survivals::before { background: var(--graph-survivals); }
.graph-legend-deaths::before { background: var(--graph-deaths); }

/* Voll-Lauf-Graph: Gesamtlauf bis Endstadium oder Cap */
.graph-full-run-wrap {
  flex-shrink: 0;
  height: 140px;
  padding: 0.5rem 1rem;
  background: var(--bg-controls);
  border-top: 1px solid var(--border-controls);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.graph-full-run-wrap.hidden {
  display: none;
}

.graph-full-run-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-color);
  opacity: 0.9;
}

#rates-graph-full {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  border-radius: 4px;
  background: var(--bg-controls);
}

/* Mobile: Zoom ausblenden, Kopf platzsparender */
@media (max-width: 768px) {
  .zoom-controls {
    display: none !important;
  }
  .graph-body {
    flex-direction: column;
    max-height: none;
    min-height: 0;
  }
  .graph-main {
    flex: none;
  }
  .graph-stats-panel {
    flex: none;
    border-left: none;
    border-top: 1px solid var(--border-controls);
  }
  .controls {
    padding: 0.4rem 0.5rem;
    gap: 0.5rem;
  }
  .controls label {
    gap: 0.25rem;
    font-size: 0.85rem;
  }
  .controls input[type="number"] {
    width: 3.5rem;
    padding: 0.3rem 0.4rem;
    font-size: 0.85rem;
  }
  .controls button {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
  }
  .controls button#btn-reseed {
    padding: 0.45rem;
  }
  #tick-counter {
    min-width: 2rem;
  }
}

/* Regeln-Modal */
.rules-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.rules-modal.rules-modal-open {
  display: flex;
}

.rules-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.rules-modal-dialog {
  position: relative;
  background: var(--bg-controls);
  border: 1px solid var(--border-controls);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.rules-modal-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-color);
}

.rules-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rules-form-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-color);
}

.rules-form-label input[type="number"] {
  width: 3rem;
  padding: 0.35rem 0.5rem;
  background: #222;
  border: 1px solid var(--border-controls);
  border-radius: 4px;
  color: var(--text-color);
  font-size: 0.9rem;
}

.rules-form-label input[type="number"]:focus {
  outline: none;
  border-color: var(--focus-ring);
}

.rules-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.rules-modal-actions button {
  flex: 1;
  min-width: 0;
}

.pattern-btn {
  padding: 0.6rem 0.9rem;
  background: #333;
  border-radius: 6px;
  border: 1px solid var(--border-controls);
  color: var(--text-color);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.pattern-btn:hover {
  background: #444;
  border-color: var(--focus-ring);
}
