/* ==========================================================
   Fonts, served from /fonts (Latin characters only, OFL licensed)
   ========================================================== */

/* Doto, a dot-matrix monospace from Google Fonts (Latin subset, via Fontsource).
   Heavy for the name, medium for everything else. */
@font-face {
  font-family: "Doto";
  src: url("fonts/doto-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Doto";
  src: url("fonts/doto-800.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================
   Palettes: one per season, each with a dark version.
   season.js sets <html data-season="…">. Autumn is the
   default, so it's also what shows without JavaScript.
   --dot-alpha balances how strong the dots look per palette.
   ========================================================== */

:root {
  --ground: #e8eadb;
  --ink: #1e2314;
  --ink-2: #50573f;
  --cell: #6f8436;
  --link: #4f6320;
  --dot-alpha: 0.46;
}
html[data-season="winter"] {
  --ground: #e4eaee;
  --ink: #152029;
  --ink-2: #485866;
  --cell: #6f93b3;
  --link: #34607f;
  --dot-alpha: 0.5;
}
html[data-season="spring"] {
  --ground: #e7eedb;
  --ink: #1a2412;
  --ink-2: #4d5a3f;
  --cell: #c49a24;
  --link: #6b5a10;
  --dot-alpha: 0.55;
}
html[data-season="summer"] {
  --ground: #f3eed3;
  --ink: #26220f;
  --ink-2: #5b5536;
  --cell: #cc9a0e;
  --link: #7d5f00;
  --dot-alpha: 0.6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #141810;
    --ink: #e4e7d6;
    --ink-2: #a4ab8e;
    --cell: #9bb068;
    --link: #b8cc85;
    --dot-alpha: 0.42;
  }
  html[data-season="winter"] {
    --ground: #11161c;
    --ink: #dde5ec;
    --ink-2: #9aa8b5;
    --cell: #8fb0cc;
    --link: #a9c6e0;
    --dot-alpha: 0.42;
  }
  html[data-season="spring"] {
    --ground: #141a12;
    --ink: #e6eadb;
    --ink-2: #a7ae98;
    --cell: #d9b24a;
    --link: #e8c86a;
    --dot-alpha: 0.44;
  }
  html[data-season="summer"] {
    --ground: #1a1810;
    --ink: #efe9cf;
    --ink-2: #b3ab88;
    --cell: #f0c93a;
    --link: #f5d76a;
    --dot-alpha: 0.42;
  }
}

/* ==========================================================
   Base
   ========================================================== */

:root {
  color-scheme: light dark;
  --halo: var(--ground);
  --line: color-mix(in srgb, var(--ink) 14%, transparent);
  --line-strong: color-mix(in srgb, var(--ink) 34%, transparent);
  --font: "Doto", ui-monospace, "SF Mono", Menlo, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--ground);
  -webkit-text-size-adjust: 100%;
}

/* A full-height column, so the content can sit at the bottom of the screen. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  padding:
    env(safe-area-inset-top, 0px)
    clamp(1rem, 4vw, 3rem)
    calc(clamp(1.5rem, 6vh, 3.5rem) + env(safe-area-inset-bottom, 0px));
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  font-size: 0.8rem; /* monospace runs wide, so a touch smaller than usual */
  line-height: 1.7;
}

p {
  margin: 0;
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
}

::selection {
  background: var(--cell);
  color: var(--ground);
}

/* ==========================================================
   The Game of Life, fixed behind everything
   ========================================================== */

#backdrop,
#backdrop-soft {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100lvh; /* the largest viewport, so nothing resizes when a phone's toolbar slides away */
  display: block;
  pointer-events: none;
}

#backdrop {
  pointer-events: auto; /* taps on empty space can reach the top canvas */
}

/* Overhangs the screen so its CSS blur never fades at the edges. */
#backdrop-soft {
  inset: -16px;
  width: calc(100% + 32px);
  height: calc(100lvh + 32px);
}

/* ==========================================================
   Content: the name and a few lines, at the bottom center
   ========================================================== */

.panel {
  position: relative;
  width: 100%;
  max-width: 56rem;
  margin: auto auto 0; /* the auto top margin pushes it to the bottom */
  padding: clamp(1rem, 3vw, 1.5rem);
  text-align: center;
  /* No box behind the text: a soft halo in the page color keeps letters crisp over the dots. */
  text-shadow: 0 0 2px var(--halo), 0 0 6px var(--halo), 0 0 12px var(--halo);
}

/* Header */

.head h1 {
  margin: 0;
  font-weight: 800;
  font-size: clamp(1.75rem, 5.5vw, 2.25rem);
  line-height: 1.1;
  color: var(--ink);
  white-space: nowrap;
}

.intro {
  max-width: 80ch;
  margin: 1.25rem auto 0;
  font-size: clamp(0.75rem, 1.9vw, 0.9rem);
  line-height: 1.75;
  color: var(--ink-2);
  white-space: pre-line; /* a list in content.js puts each entry on its own line */
  text-wrap: balance;
}

/* Text links, a divider, then the icons, in one centered row (wrapping on phones). */
.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 1.75rem;
  margin-top: 1.75rem;
}

.pages {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 2.25rem;
}

.pages a {
  display: inline-block;
  padding: 0.6rem 0;
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  margin-right: -0.22em; /* the last letter's tracking would push the word off-center */
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-2);
  transition: color 0.2s;
}

.pages a:hover {
  color: var(--ink);
}

.divider {
  width: 1px;
  height: 1.5rem;
  background: var(--line-strong);
}

.pages[hidden],
.divider[hidden] {
  display: none;
}

.social {
  display: flex;
  gap: 0.25rem;
}

.social a {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--ink-2);
  transition: color 0.2s;
}

.social a:hover {
  color: var(--ink);
}

.icon {
  width: 1.4rem;
  height: 1.4rem;
  fill: currentColor;
}

/* ==========================================================
   Pause button and icon sprite
   ========================================================== */

/* A small round button that stays out of the way until you reach for it. */
.pause {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--ink-2);
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 50%;
  opacity: 0.6;
  cursor: pointer;
  transition: opacity 0.2s, border-color 0.2s;
}

.pause:hover,
.pause:focus-visible {
  opacity: 1;
  border-color: var(--line-strong);
}

.pause svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ==========================================================
   Background experiments: each one sets its own page colors
   ========================================================== */

html[data-bg="stars"] {
  color-scheme: dark;
  --ground: #000000;
  --ink: #f2f1ee;
  --ink-2: #a3a2a8;
  --link: #ffffff;
  --cell: #ffffff;
}

html[data-bg="sunlight"] {
  color-scheme: light;
  --ground: #f1efea;
  --ink: #1c1b19;
  --ink-2: #57544e;
  --link: #7d4f17;
  --cell: #8a8780;
  --halo: transparent; /* dark text on a pale wall needs no halo */
}

html[data-bg="autumn"] {
  color-scheme: light;
  --ground: #ede7dd;
  --ink: #2b221b;
  --ink-2: #66574a;
  --link: #8a3b16;
  --cell: #b5532c;
}

html[data-bg="winter"] {
  color-scheme: dark;
  --ground: #161f29;
  --ink: #eef2f6;
  --ink-2: #a9b5c2;
  --link: #cfe0f2;
  --cell: #cfe0f2;
}

html[data-bg="garden"] {
  color-scheme: light;
  --ground: #eef0e4;
  --ink: #1f2619;
  --ink-2: #525c45;
  --link: #4b6b2a;
  --cell: #7f9866;
}

/* Background picker: only shown with ?tweaks in the address */
.tweaks { display: none; }
html.show-tweaks .tweaks {
  display: flex;
}
.tweaks {
  position: fixed;
  left: max(1rem, env(safe-area-inset-left, 0px));
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  max-width: calc(100vw - 5rem);
  font-size: 0.85rem;
}
.tweaks-panel {
  padding: 0.75rem;
  background: var(--ground);
  border: 1px solid var(--line-strong);
}
.tweaks-panel[hidden] { display: none; }
.tweaks fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.tweaks legend { margin-bottom: 0.4rem; color: var(--ink-2); }
.seg { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 0.75rem;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  cursor: pointer;
}
.seg input:checked + label { background: var(--ink); color: var(--ground); border-color: var(--ink); }
.seg input:focus-visible + label { outline: 2px solid var(--link); outline-offset: 2px; }
.tweaks-toggle {
  min-height: 36px;
  padding: 0 0.85rem;
  font: inherit;
  color: var(--ink-2);
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 18px;
  cursor: pointer;
}
.tweaks-toggle:hover { color: var(--ink); border-color: var(--line-strong); }

/* A still picture layer underneath the canvases (Winter's backdrop) */
#backdrop-base {
  position: fixed;
  inset: 0;
  height: 100lvh;
  background-size: 100% 100%;
  pointer-events: none;
}
#backdrop-base[hidden] { display: none; }

/* Sunlight: three layers of leaf shadows, each swaying at its own pace around the top-right corner,
   where the branches would be. Pure CSS motion: nothing is redrawn. */
#sun-layers {
  position: fixed;
  inset: 0;
  height: 100lvh;
  overflow: hidden;
  pointer-events: none;
  background: radial-gradient(120% 90% at 85% 0%, rgba(255, 249, 238, 0.95), rgba(255, 249, 238, 0) 62%);
}
#sun-layers[hidden] { display: none; }
#sun-layers > div {
  position: absolute;
  background-size: 100% 100%;
  transform-origin: 100% 0;
  will-change: transform;
}
.sun-layers-0 { opacity: 0.12; animation: sway-far 14s ease-in-out infinite alternate; }
.sun-layers-1 { opacity: 0.16; animation: sway-mid 9s ease-in-out infinite alternate; }
.sun-layers-2 { opacity: 0.2; animation: sway-near 6.5s ease-in-out infinite alternate; }
@keyframes sway-far { from { transform: rotate(-0.5deg); } to { transform: rotate(0.6deg) translate(-8px, 6px); } }
@keyframes sway-mid { from { transform: rotate(0.6deg); } to { transform: rotate(-0.7deg) translate(6px, -4px); } }
@keyframes sway-near { from { transform: rotate(-0.9deg) translate(4px, 0); } to { transform: rotate(0.8deg) translate(-6px, 5px); } }
html.paused #sun-layers > div { animation-play-state: paused; }
@media (prefers-reduced-motion: reduce) {
  #sun-layers > div { animation: none; }
}

/* The name of a star or object under the pointer (stars background) */
.sky-label {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 5;
  pointer-events: none;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--ground) 72%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--ink);
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 120ms ease-out;
}
.sky-label.show { opacity: 1; }
.sky-label span { display: block; color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { .sky-label { transition: none; } }
