/* LifeCanvas — dark, paintable Conway's Game of Life. All presentation. */

:root {
  --bg: #0a0c10;
  --surface: #121620;
  --surface-2: #1a2030;
  --border: #232b3a;
  --text: #e6ebf2;
  --text-dim: #8a95a8;
  --accent: #34e6b0;
  --accent-2: #5cc8ff;
  --danger: #ff5d6c;
  --grid-line: rgba(255, 255, 255, 0.045);

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;
  --sp-8: 32px;

  --r-ctrl: 6px;
  --r-panel: 12px;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* radial vignette behind the app for depth */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(52, 230, 176, 0.07), transparent 60%),
    radial-gradient(80% 60% at 110% 110%, rgba(92, 200, 255, 0.05), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  flex: 1 1 auto;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-6);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.brand__glyph {
  width: 34px;
  height: 34px;
  display: block;
  flex: 0 0 auto;
  filter: drop-shadow(0 0 6px rgba(52, 230, 176, 0.5));
}

.brand__glyph rect {
  fill: var(--accent);
}

.brand__name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.brand__name b {
  color: var(--accent);
  font-weight: 700;
}

.brand__tag {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0;
}

.stats {
  display: flex;
  align-items: stretch;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  min-width: 84px;
}

.stat__label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stat__value {
  font-family: var(--font-mono);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}

.stat--accent .stat__value {
  color: var(--accent);
}

/* ---------- Main layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
  align-items: start;
}

@media (min-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
}

/* ---------- Stage / canvas ---------- */

.stage {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.02),
    inset 0 12px 40px rgba(0, 0, 0, 0.45),
    0 18px 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  min-height: 320px;
  aspect-ratio: 3 / 2;
}

@media (min-width: 860px) {
  .stage {
    aspect-ratio: auto;
    height: min(72vh, 760px);
  }
}

#grid {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.stage__hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: rgba(18, 22, 32, 0.82);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  pointer-events: none;
  backdrop-filter: blur(6px);
  transition: opacity 220ms ease;
}

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

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.card__title {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0;
}

.row {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.row--transport .btn {
  flex: 1 1 auto;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  padding: 9px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease, color 120ms ease, box-shadow 120ms ease;
  user-select: none;
}

.btn svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.btn:hover {
  background: #20283a;
  border-color: rgba(52, 230, 176, 0.5);
}

.btn:active {
  transform: translateY(1px);
}

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

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06120d;
  box-shadow: 0 0 18px rgba(52, 230, 176, 0.32);
}

.btn--primary:hover {
  background: #45f0bd;
  border-color: #45f0bd;
}

.btn--primary.is-playing {
  background: var(--surface-2);
  color: var(--text);
  border-color: rgba(52, 230, 176, 0.6);
  box-shadow: none;
}

.btn--danger {
  border-color: rgba(255, 93, 108, 0.5);
  color: #ffb3ba;
}

.btn--danger:hover {
  background: rgba(255, 93, 108, 0.16);
  border-color: var(--danger);
  color: #fff;
}

.btn--ghost {
  background: transparent;
}

.btn--icon {
  padding: 9px 11px;
}

.btn.is-armed {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px rgba(52, 230, 176, 0.35) inset;
}

/* ---------- Sliders ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.field__label {
  font-size: 13px;
  color: var(--text-dim);
}

.field__value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(52, 230, 176, 0.55), var(--accent));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #06120d;
  box-shadow: 0 0 10px rgba(52, 230, 176, 0.5);
  transition: transform 100ms ease, box-shadow 100ms ease;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #06120d;
  box-shadow: 0 0 10px rgba(52, 230, 176, 0.5);
}

input[type="range"]:hover::-webkit-slider-thumb,
input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.15);
  box-shadow: 0 0 14px rgba(52, 230, 176, 0.7);
}

input[type="range"]:focus-visible {
  outline: none;
}

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

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

/* ---------- Select ---------- */

.select-wrap {
  position: relative;
  display: block;
}

select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  padding: 9px 34px 9px 12px;
  cursor: pointer;
  transition: border-color 120ms ease;
}

select:hover {
  border-color: rgba(52, 230, 176, 0.5);
}

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

.select-wrap::after {
  content: "";
  position: absolute;
  right: 13px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.select-wrap.is-armed select {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Toggles (pills) ---------- */

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--text-dim);
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.toggle__track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background 150ms ease, border-color 150ms ease;
  flex: 0 0 auto;
}

.toggle__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 150ms ease, background 150ms ease;
}

.toggle input:checked + .toggle__track {
  background: rgba(52, 230, 176, 0.25);
  border-color: var(--accent);
}

.toggle input:checked + .toggle__track::after {
  transform: translateX(16px);
  background: var(--accent);
}

.toggle input:focus-visible + .toggle__track {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.toggle input:checked ~ .toggle__label {
  color: var(--text);
}

/* ---------- Accent swatches ---------- */

.swatches {
  display: flex;
  gap: var(--sp-2);
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  transition: transform 100ms ease, border-color 100ms ease;
}

.swatch:hover {
  transform: scale(1.1);
}

.swatch.is-active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15);
}

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

.preset-btn {
  flex: 1 1 0;
}

/* ---------- Footer ---------- */

.app-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: var(--sp-2) 0 var(--sp-1);
}

.app-footer a {
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 1px dotted transparent;
  transition: color 140ms ease, border-color 140ms ease;
}

.app-footer a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Toast ---------- */

.toast-host {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 50;
  pointer-events: none;
}

.toast {
  background: rgba(18, 22, 32, 0.94);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-in {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Help dialog ---------- */

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.help-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.help {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  max-width: 460px;
  width: 100%;
  padding: var(--sp-6);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  transform: translateY(10px) scale(0.98);
  transition: transform 180ms ease;
}

.help-overlay.is-open .help {
  transform: translateY(0) scale(1);
}

.help h2 {
  margin: 0 0 var(--sp-4);
  font-size: 18px;
}

.help dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px var(--sp-4);
  align-items: baseline;
}

.help dt {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 8px;
  justify-self: start;
  white-space: nowrap;
}

.help dd {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.help__close {
  margin-top: var(--sp-6);
  width: 100%;
}

.iconbtn {
  appearance: none;
  -webkit-appearance: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
  flex: 0 0 auto;
}

.iconbtn:hover {
  color: var(--accent);
  border-color: rgba(52, 230, 176, 0.5);
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
