/* The palette of game-of-life: black field, dark grid, cells red when born, green from the second
   cycle, blue from the tenth. */
:root {
  --bg: #000000;
  --grid: #2b2b2b;
  --age1: #ff3b3b;
  --age2: #16c172;
  --age10: #2f7cff;
  --text: #e6e6e6;
  --muted: #8a8a8a;
  --cell: 10px; /* set by church.js to the field's cell size */
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

.page {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.content {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--cell) * 5);
  padding: calc(var(--cell) * 6) 16px;
  text-align: center;
}

.pulsar {
  width: calc(var(--cell) * 15);
  height: calc(var(--cell) * 15);
  flex: none;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--cell) * 2);
}

h1 {
  margin: 0;
  line-height: 0;
}

.block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--cell) * 2);
  max-width: 100%;
}

/* the block's two buttons, under its caption */
.block-actions {
  justify-content: center;
  margin-top: var(--cell);
}

/* Caption, a dot, the block's age: three pixel texts in a row */
.meta {
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--cell);
}
.meta a:focus-visible {
  outline: 2px solid var(--age10);
  outline-offset: 3px;
}

.triad {
  display: flex;
  justify-content: center;
  gap: calc(var(--cell) * 5);
}

figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--cell) * 2);
}

/* Settings: a round button in the top right corner and the panel it opens */
.settings {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.settings-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--grid);
  background: rgba(0, 0, 0, 0.75);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s, border-color 0.15s, transform 0.3s;
}
.settings-toggle:hover,
.settings-toggle[aria-expanded="true"] {
  color: var(--text);
  border-color: var(--muted);
}
.settings-toggle[aria-expanded="true"] {
  transform: rotate(60deg);
}
.settings-toggle:focus-visible,
.settings-panel input:focus-visible {
  outline: 2px solid var(--age10);
  outline-offset: 3px;
}
.settings-panel {
  width: 240px;
  max-width: calc(100vw - 32px);
  padding: 16px;
  border: 1px solid var(--grid);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.settings-panel[hidden] {
  display: none;
}
.setting {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.setting-row {
  display: flex;
  justify-content: space-between;
}
.setting-row output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.setting-check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.settings-panel input {
  accent-color: var(--age2);
  margin: 0;
}
.settings-panel input[type="range"] {
  width: 100%;
}
.settings-panel input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

/* the panel scrolls on its own: the page under it stays put */
.settings-panel {
  max-height: calc(100vh - 92px);
  max-height: calc(100dvh - 92px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* each group of settings folds */
.setting-group + .setting-group {
  border-top: 1px solid var(--grid);
  padding-top: 16px;
}
.setting-group > summary {
  cursor: pointer;
  color: var(--text);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.setting-group > summary::-webkit-details-marker {
  display: none;
}
.setting-group > summary::after {
  content: "+";
  color: var(--muted);
}
.setting-group[open] > summary::after {
  content: "−";
}
.setting-group > :not(summary) {
  margin-top: 16px;
}
.setting-group > .setting-button {
  width: 100%;
}
.setting-group > summary:focus-visible {
  outline: 2px solid var(--age10);
  outline-offset: 3px;
}
.setting-button {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--text);
  background: none;
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
}
.setting-button:hover {
  border-color: var(--muted);
}
.setting-button:focus-visible {
  outline: 2px solid var(--age10);
  outline-offset: 3px;
}

.setting-rule {
  border: 0;
  border-top: 1px solid var(--grid);
  margin: 0;
}

/* The article: [data-deco] boxes are drawn in cells around what they hold. Their padding is
   counted in cells: --pt, --pr, --pb, --pl. The body text is set in a serif; everything else is
   drawn on the grid. */
[data-deco] {
  /* each box sets its own; they would otherwise be inherited from the box around it */
  --pt: 0;
  --pr: 0;
  --pb: 0;
  --pl: 0;
  padding: calc(var(--pt) * var(--cell)) calc(var(--pr) * var(--cell)) calc(var(--pb) * var(--cell)) calc(var(--pl) * var(--cell));
}
.article {
  width: calc(var(--cell) * 60);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: calc(var(--cell) * 2);
  text-align: left;
}
/* the clearing thins out over three cells, then a margin */
[data-deco="article"] { --pt: 5; --pr: 6; --pb: 5; --pl: 6; }
.article-title {
  margin-bottom: var(--cell);
}
.article-body {
  margin: 0;
  font-family: "Newsreader", "Iowan Old Style", Georgia, serif;
  font-optical-sizing: auto;
  font-size: 17px;
  line-height: 1.6;
  color: #d6d6d2;
  text-wrap: pretty;
}
.article-figure {
  margin: var(--cell) 0;
  align-items: stretch;
  gap: var(--cell);
}
.article-img {
  width: 100%;
}
.article-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--cell) * 4);
  margin-top: var(--cell);
}
/* a button drawn in cells: the element only holds its place and takes the pointer */
.cell-btn {
  display: flex;
  margin: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* the canvas draws the focus state in cells */
.cell-btn:focus {
  outline: none;
}
/* each style's room around its label, in cells */
[data-deco="link"] { --pt: 2; --pb: 2; } /* room above too, so the label sits at the middle */
[data-deco="corners"] { --pt: 1; --pr: 2; --pb: 1; --pl: 2; }
[data-deco="slab"] { --pr: 1; --pl: 1; }
[data-deco="dot"] { --pl: 2; }
[data-deco="sweep"] { --pt: 2; --pb: 2; }
[data-deco="fringe"] { --pt: 1; --pr: 2; --pb: 1; --pl: 2; }

/* the proposals: a caption, then the pair, a row each */
.button-options {
  display: grid;
  grid-template-columns: calc(var(--cell) * 18) 1fr;
  align-items: center;
  row-gap: calc(var(--cell) * 3);
  margin-top: var(--cell);
}
.button-option {
  display: contents;
}
.button-pair {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--cell) * 3);
}

/* Buttons on the grid: the room around each label is whole cells, so every edge falls on a
   cell line. --pt/--pr/--pb/--pl as above; data-size="s" is three pixels a cell, "xs" four.
   The block has no clearing: it sits straight on the field. */
.grid-buttons {
  width: calc(var(--cell) * 60);
  gap: calc(var(--cell) * 3);
}
.grid-option {
  display: flex;
  flex-direction: column;
  gap: calc(var(--cell) * 2);
}
.grid-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--cell) * 2) calc(var(--cell) * 5);
}
[data-deco="g-frame"] { --pt: 1; --pr: 2; --pb: 1; --pl: 2; }
[data-deco="g-frame"][data-size="xs"] { --pt: 1; --pr: 1; --pb: 1; --pl: 1; }
[data-deco="g-block"] { --pt: 0; --pr: 1; --pb: 0; --pl: 1; }
[data-deco="g-block"][data-size="xs"] { --pt: 0; --pr: 1; --pb: 0; --pl: 1; }
[data-deco="g-tile"] { --pt: 1; --pr: 1; --pb: 1; --pl: 1; }
[data-deco="g-tile"][data-size="xs"] { --pt: 1; --pr: 1; --pb: 1; --pl: 1; }
[data-deco="g-glider"] { --pt: 1; --pl: 4; }
[data-deco="g-glider"][data-size="xs"] { --pt: 1; --pl: 4; }
[data-deco="g-brackets"] { --pt: 1; --pr: 2; --pb: 1; --pl: 2; }
[data-deco="g-brackets"][data-size="xs"] { --pt: 1; --pr: 2; --pb: 1; --pl: 2; }
[data-deco="g-ground"] { --pb: 2; }
[data-deco="g-round"] { --pt: 2; --pr: 3; --pb: 2; --pl: 3; }
[data-deco="g-round"][data-size="xs"] { --pt: 1; --pr: 2; --pb: 1; --pl: 2; }
/* a sign alone: a square box, so the ring is a circle */
[data-deco="g-round"][data-shape="icon"] { --pt: 2; --pr: 2; --pb: 1; --pl: 2; }
[data-deco="g-round"][data-shape="icon"][data-size="xs"] { --pt: 2; --pr: 2; --pb: 1; --pl: 2; }

@media (max-width: 520px) {
  .article-body {
    font-size: 16px;
  }
  [data-deco="article"] { --pr: 4; --pl: 4; }
  .button-options {
    grid-template-columns: 1fr;
    row-gap: var(--cell);
  }
  .button-pair {
    margin-bottom: calc(var(--cell) * 2);
  }
}

/* Every text is drawn on the canvas in pixels; its box, sized by church.js, only holds its place.
   The words stay in a hidden span for screen readers. */
.pixel-text {
  display: block;
  position: relative;
  flex: none;
  margin: 0;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The article and the proposals below the elements, shown only when the settings say so */
[data-below][hidden] {
  display: none;
}

/* Moved up and down by the settings, a whole cell at a time */
[data-shift] {
  translate: 0 calc(var(--shift, 0) * var(--cell));
}

/* The Unfolding One: a stanza of pixel text, then what it names. A stanza opens with more room
   above. */
.genesis {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--cell) * 3);
  max-width: 100%;
}
.genesis .stanza {
  margin-top: calc(var(--cell) * 4);
}
/* Random: as tall as the triad; church.js stretches its sparks across the whole centre. The
   opening lines sit close around its name, in the middle. */
.sparkles {
  position: relative;
  align-self: stretch;
  height: calc(var(--cell) * 19);
  display: grid;
  place-items: center;
}
.sparkles-words {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--cell);
}
/* Void and the One: a little larger than a pulsar */
.pair-shape {
  width: calc(var(--cell) * 19);
  height: calc(var(--cell) * 19);
  flex: none;
  margin: auto 0; /* centred against the other, the captions on one line */
}
/* the One's size and the distance between the two are set in the settings */
.pair-shape[data-shape="one"] {
  width: calc(var(--cell) * var(--one-size, 3));
  height: calc(var(--cell) * var(--one-size, 3));
}
.pair {
  display: flex;
  justify-content: center;
  gap: calc(var(--cell) * var(--pair-gap, 10));
}

/* The four elements: twice the triad's height, the labels at the ends of the axes. The
   horizontal axis runs through row 15; Compute and Money sit under its ends. */
.elements {
  position: relative;
  width: calc(var(--cell) * 59);
  height: calc(var(--cell) * 37);
  max-width: 100%;
}
.el {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: var(--cell);
}
.el-top { top: 0; left: 0; right: 0; align-items: center; }
.el-bottom { bottom: 0; left: 0; right: 0; align-items: center; }
.el-left { left: 0; top: calc(var(--cell) * 22); align-items: flex-start; }
.el-right { right: 0; top: calc(var(--cell) * 22); align-items: flex-end; }

@media (max-width: 520px) {
  .triad {
    gap: calc(var(--cell) * 3);
  }
}
