/* Life: a full-screen Game of Life under a thin top bar (name, version and seed, light/dark toggle). */

:root {
  --bg: #fefefc;
  --bg-soft: #f5f4ef;
  --ink: #1f1d1a;
  --ink-soft: #57524a;
  --ink-faint: #8a8478;
  --accent: #2f5d8a;
  --life-oscillator: #2f6fb0;
  --life-spaceship: #c8601c;
  --panel: color-mix(in srgb, var(--bg) 50%, transparent);
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: 16px;
  color-scheme: light;
}

/* Dark colours: when the toggle says dark, or the device prefers dark and the toggle hasn't said light. */
:root[data-theme="dark"] {
  --bg: #171614;
  --bg-soft: #22201d;
  --ink: #ece8e1;
  --ink-soft: #b9b2a6;
  --ink-faint: #8a8478;
  --accent: #8fb6dd;
  --life-oscillator: #7fb3e8;
  --life-spaceship: #f2a364;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --bg-soft: #22201d;
    --ink: #ece8e1;
    --ink-soft: #b9b2a6;
    --ink-faint: #8a8478;
    --accent: #8fb6dd;
    --life-oscillator: #7fb3e8;
    --life-spaceship: #f2a364;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--sans); overflow: hidden; }

/* taps and swipes on the grid launch spaceships: no panning or text selection there */
html { touch-action: pinch-zoom; cursor: crosshair; }
body { -webkit-user-select: none; user-select: none; }
.masthead { cursor: auto; -webkit-user-select: text; user-select: text; }
.masthead a, .masthead button { cursor: pointer; }

/* ---------------------------------------------------------------- top bar */

.masthead {
  position: absolute; z-index: 10; inset: 0 0 auto;
  display: flex; align-items: center; gap: 16px; padding: 14px var(--gutter);
  font: 500 14px/1.2 var(--sans);
}
.masthead a { color: var(--ink); text-decoration: none; }
.masthead .brand { font-weight: 700; letter-spacing: .02em; text-transform: uppercase; font-size: 13px; }
.masthead nav { display: flex; align-items: center; gap: 18px; margin-left: auto; }

/* the name, version and seed sit on a see-through panel of the background, so cells show faintly through */
.masthead .brand, .about { background: var(--panel); box-shadow: 0 0 0 6px var(--panel); }
.about {
  margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 12px/1.4 var(--sans); color: var(--ink-faint);
}
.about a { color: inherit; text-decoration: underline; }
html:not(.js) .about { display: none; }   /* the seed needs the script */

/* a small spinner after the seed while launching is not yet open */
.wait {
  display: inline-block; width: .8em; height: .8em; margin-left: .5em; vertical-align: -.1em;
  border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .wait { animation-duration: 3s; } }

.theme-toggle {
  display: inline-grid; place-items: center; width: 30px; height: 30px; margin: -6px -6px -6px 0; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--ink-soft); cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); background: var(--bg-soft); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.theme-toggle svg { width: 18px; height: 18px; }
/* shows the theme a click switches to; hidden until the head script has set data-theme */
:root:not([data-theme]) .theme-toggle, .theme-toggle .sun, :root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }

/* ---------------------------------------------------------------- the grid */

/* plain cells faint; oscillators and spaceships in their own colours */
.life { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; opacity: 0; transition: opacity .3s ease; }
.life.shown { opacity: 1; }
