/* antihinged site styles. Colours, type sizes and spacing come from tokens.css. */

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

html { -webkit-text-size-adjust: 100%; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: var(--step-0) / var(--leading-text) var(--font-display);
}

::selection { background: var(--second); color: var(--second-ink); }

a { color: var(--accent); text-underline-offset: 0.15em; text-decoration-thickness: var(--line); }
a:hover { text-decoration-thickness: var(--line-heavy); }
:focus-visible { outline: var(--line-heavy) solid var(--accent); outline-offset: var(--space-1); }

/* One reading column, centred, until the window is wide enough for two (see .columns). */
.wrap { max-width: calc(var(--column) + var(--gutter) * 2); margin-inline: auto; padding: var(--space-5) var(--gutter) var(--space-8); }

h1, h2 { line-height: var(--leading-tight); margin: 0; font-weight: 700; }
h1 { font-size: var(--step-3); margin-bottom: var(--space-4); }
/* A heading that is also a link (the home page's sections) looks like any other heading. */
h2 a { color: inherit; text-decoration: none; }
h2 { font-size: var(--step-2); margin-top: var(--space-7); margin-bottom: var(--space-4); }
p { margin: 0 0 var(--space-4); max-width: var(--measure); }

.meta { font-family: var(--font-text); font-size: var(--step--1); color: var(--fg-muted); }
code { font-family: var(--font-mono); font-size: var(--step--1); background: var(--second); color: var(--second-ink); padding: 0 var(--space-1); border-radius: var(--radius); }

/* Masthead */
.masthead {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: var(--space-2) var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: var(--line-heavy) solid var(--rule-strong);
  margin-bottom: var(--space-6);
}
.site-name { font-size: var(--step-3); font-weight: 700; font-variant-caps: small-caps; letter-spacing: var(--tracking-caps); color: var(--fg); text-decoration: none; }
.intro { font-size: var(--step-1); line-height: 1.45; margin-bottom: 0; }

/* One column, capped for reading, until the window is wide enough for two roomy ones */
.columns { display: grid; gap: 0 var(--space-7); }
.columns > section { min-width: 0; max-width: var(--column); }
@media (min-width: 72rem) {
  .wrap { max-width: var(--page); }
  .columns { grid-template-columns: 1.25fr 1fr; align-items: start; }
  .columns.lead { align-items: center; }
  .columns > section { max-width: none; }
}

/* Search (home page) */
.lead { align-items: center; row-gap: var(--space-3); }
.search input {
  width: 100%; padding: var(--space-2) var(--space-3);
  font: var(--step-0) / 1.2 var(--font-text); color: var(--fg);
  background: transparent; border: var(--line) solid var(--rule-strong); border-radius: var(--radius);
}
.search input::placeholder { color: var(--fg-muted); opacity: 1; }
.search input:focus-visible { outline: var(--line-heavy) solid var(--accent); outline-offset: 0; }
.snippet { display: block; grid-column: 2; }
mark { background: var(--second); color: var(--second-ink); padding: 0 var(--line-heavy); border-radius: var(--line); }
.count { margin-left: var(--space-2); font-weight: 400; }
.posts li.none { display: block; }
.ideas li.none { list-style: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Inner pages */
.narrow, .prose { max-width: var(--column); }
.narrow h2:first-child { margin-top: var(--space-6); }
.more { margin-top: var(--space-3); }
.crumb { margin-bottom: var(--space-2); }
.prose h2 { font-size: var(--step-1); margin-top: var(--space-6); margin-bottom: var(--space-3); }
.prose ul { margin: 0 0 var(--space-4); padding-left: var(--space-5); max-width: var(--measure); }
.prose li { padding-block: var(--space-1); }
.prose ul.posts { padding-left: 0; max-width: none; }
pre { margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); overflow-x: auto; background: var(--second); color: var(--second-ink); border-radius: var(--radius); }
pre code { padding: 0; background: none; }
blockquote { margin: var(--space-5) 0 var(--space-5) var(--space-5); font-style: italic; font-size: var(--step-1); line-height: 1.4; }
blockquote p { margin-bottom: var(--space-1); }
blockquote p + p { font-style: normal; font-family: var(--font-text); font-size: var(--step--1); color: var(--fg-muted); }
.log { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-4); }
.log dt { padding-top: var(--space-1); }
.log dd { margin: 0; }
.adjacent { display: grid; gap: var(--space-1); margin-top: var(--space-7); padding-top: var(--space-3); border-top: var(--line) solid var(--rule); max-width: var(--column); }

/* Posts */
.posts { list-style: none; margin: 0; padding: 0; border-bottom: var(--line) solid var(--rule); }
.posts li { display: grid; grid-template-columns: minmax(4.5rem, max-content) 1fr; gap: var(--space-3); padding-block: var(--space-2); border-top: var(--line) solid var(--rule); }
.year { display: none; }
.with-year .year, .searching .year { display: inline; }
.posts time { padding-top: var(--space-1); }
/* Half a step down from the headings, so a long title fits its line more often. */
.posts a { font-size: var(--step-half); line-height: 1.3; }

.entries a { font-size: var(--step-0); }
.entries .meta { display: block; }
/* A link written inside a log entry is part of its line, not a title. */
.entries .meta a { font-size: inherit; }

/* Projects */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; vertical-align: top; padding: var(--space-2) var(--space-3) var(--space-2) 0; border-top: var(--line) solid var(--rule); }
th { font-family: var(--font-text); font-size: var(--step--1); font-weight: 600; background: var(--second); color: var(--second-ink); padding-left: var(--space-2); border-top: 0; }
thead + tbody tr:first-child td { border-top: 0; }
.projects td:first-child { padding-left: var(--space-2); }
.projects td span { display: block; }
.projects td:not(:first-child) { white-space: nowrap; font-family: var(--font-text); font-size: var(--step--1); padding-top: var(--space-3); }
.dot { display: inline-block; width: var(--space-3); height: var(--space-3); margin-right: var(--space-1); border: var(--line) solid var(--rule-strong); background: var(--status-active); }
.dot[data-status="simmering"] { background: var(--status-simmering); }
.dot[data-status="dormant"] { background: var(--status-dormant); }
.dot[data-status="shelved"] { background: var(--status-shelved); }

/* Ideas */
.ideas { margin: 0; padding-left: var(--space-6); }
.ideas li { padding-block: var(--space-1); }
.ideas li::marker { font-family: var(--font-mono); font-size: var(--step--1); color: var(--fg-muted); }
/* "Became <project>", after an idea that turned into one: on the same line when it fits. */
.ideas .became { margin-left: var(--space-2); white-space: nowrap; }

/* Footer */
.footer { margin-top: var(--space-8); padding-top: var(--space-3); border-top: var(--line-heavy) solid var(--rule-strong); display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2) var(--space-5); }

/* Theme swatches */
.papers { display: flex; gap: var(--space-2); align-self: center; margin-left: auto; margin-top: var(--space-1); }
.papers button {
  appearance: none; cursor: pointer; padding: 0;
  width: var(--space-5); height: var(--space-5);
  border: var(--line) solid var(--rule-strong); border-radius: var(--radius);
  background: var(--chip);
}
.papers button.auto { background: linear-gradient(135deg, var(--seed-mint) 50%, var(--seed-char) 50%); }
.papers button[aria-pressed="true"] { outline: var(--line-heavy) solid var(--fg); outline-offset: var(--space-1); }

/* Token page */
.tokens td { font-family: var(--font-mono); font-size: var(--step--1); }
.tokens .sample { width: var(--space-8); overflow: hidden; }
.tokens .value { display: block; color: var(--fg-muted); overflow-wrap: anywhere; }
.tokens code { background: none; color: inherit; padding: 0; }
.swatch { display: block; width: var(--space-6); height: var(--space-5); border: var(--line) solid var(--rule-strong); }
.bar { display: block; height: var(--space-2); background: var(--accent); max-width: var(--space-7); }
.glyph { display: block; line-height: 1; font-family: var(--font-display); max-height: var(--space-6); }

/* Play button and the page platformer (game.js) */
.play {
  appearance: none; cursor: pointer; padding: 0; align-self: center; margin-top: var(--space-1);  /* optical: small caps sit low in their line */
  display: grid; place-items: center;
  width: var(--space-5); height: var(--space-5);
  border: var(--line) solid var(--rule-strong); border-radius: var(--radius);
  background: none;
}
.play::before { content: ""; width: var(--space-2); height: var(--space-3); margin-left: var(--line-heavy); background: var(--fg); clip-path: polygon(0 0, 100% 50%, 0 100%); }
.play:hover { background: var(--fg); }
.play:hover::before { background: var(--bg); }
.play[aria-pressed="true"]::before { clip-path: none; margin: 0; width: var(--space-2); height: var(--space-2); }

.game-layer { position: absolute; top: 0; left: 0; width: 0; height: 0; z-index: 5; pointer-events: none; }
.game-player, .game-thing { position: absolute; top: 0; left: 0; }
.game-player { background: var(--second); border: var(--line) solid var(--second-ink); border-radius: var(--radius); }
.game-player::before, .game-player::after { content: ""; position: absolute; top: 25%; width: var(--line-heavy); height: var(--space-1); background: var(--second-ink); }
.game-player::before { right: 20%; }
.game-player::after { right: 55%; }
.game-player[data-dir="left"]::before { right: auto; left: 20%; }
.game-player[data-dir="left"]::after { right: auto; left: 55%; }

/* Hinged things. Sizes are set by game.js; the pixel values here are sprite geometry. */
.game-thing .body { position: absolute; inset: 0; }
.game-thing[data-dir="left"] .body { transform: scaleX(-1); }
.game-thing i { position: absolute; display: block; background: var(--fg); border-radius: var(--line); box-shadow: 0 0 0 var(--line) var(--bg); }
.game-thing .pin { width: calc(6px * var(--game-scale, 1)); height: calc(6px * var(--game-scale, 1)); border-radius: 50%; background: var(--second); box-shadow: 0 0 0 var(--line) var(--second-ink); z-index: 1; }
.snapper .base { left: 0; right: 0; bottom: 0; height: 40%; }
.snapper .jaw { left: 0; right: 0; bottom: 44%; height: 40%; transform-origin: 0 100%; animation: snap 0.45s infinite alternate ease-in; }
.snapper .pin { left: calc(-2px * var(--game-scale, 1)); bottom: 30%; }
.flapper .wing { top: 40%; width: 50%; height: 22%; }
.flapper .wing.a { left: 0; transform-origin: 100% 50%; animation: flap-a 0.22s infinite alternate; }
.flapper .wing.b { left: 50%; transform-origin: 0 50%; animation: flap-b 0.22s infinite alternate; }
.flapper .pin { left: calc(50% - 3px * var(--game-scale, 1)); top: calc(50% - 3px * var(--game-scale, 1)); }
@keyframes snap { from { transform: rotate(-40deg); } to { transform: rotate(0); } }
@keyframes flap-a { from { transform: rotate(38deg); } to { transform: rotate(-22deg); } }
@keyframes flap-b { from { transform: rotate(-38deg); } to { transform: rotate(22deg); } }
/* Freed: the pin drops out and the two halves drift off. */
.game-thing.freed i { animation: drift 0.7s forwards ease-out; }
.game-thing.freed .pin { animation: pin-fall 0.7s forwards ease-in; }
@keyframes drift { to { transform: translateY(-30px) rotate(25deg); opacity: 0; } }
@keyframes pin-fall { to { transform: translateY(70px); opacity: 0; } }
/* Freed spirit: rises, sways and fades. */
.game-spirit { position: absolute; width: calc(10px * var(--game-scale, 1)); height: calc(13px * var(--game-scale, 1)); animation: spirit-rise 2.6s forwards ease-out; }
.game-spirit i { position: relative; display: block; width: 100%; height: 100%; background: var(--fg); border-radius: 50% 50% 35% 35% / 60% 60% 25% 25%; box-shadow: 0 0 var(--space-2) var(--fg); animation: spirit-sway 0.9s infinite alternate ease-in-out; }
.game-spirit i::before { content: ""; position: absolute; top: 35%; left: 22%; width: 2px; height: 2px; border-radius: 50%; background: var(--bg); box-shadow: 4px 0 0 var(--bg); }
@keyframes spirit-rise {
  0% { transform: translateY(0) scale(0.4); opacity: 0; }
  12% { transform: translateY(-12px) scale(1); opacity: 0.95; }
  80% { opacity: 0.8; }
  100% { transform: translateY(-170px) scale(1); opacity: 0; }
}
@keyframes spirit-sway { from { transform: translateX(-7px) rotate(-8deg); } to { transform: translateX(7px) rotate(8deg); } }
.game-hud {
  position: fixed; left: var(--gutter); bottom: var(--gutter); right: var(--gutter); z-index: 6;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); width: fit-content; max-width: calc(100% - var(--gutter) * 2);
  padding: var(--space-2) var(--space-3);
  background: var(--second); color: var(--second-ink); border: var(--line) solid var(--second-ink); border-radius: var(--radius);
  font-family: var(--font-text); font-size: var(--step--1);
}
.game-hud button { appearance: none; cursor: pointer; font: inherit; font-weight: 600; color: inherit; background: none; border: var(--line) solid currentColor; border-radius: var(--radius); padding: 0 var(--space-2); }

/* Touch play (game.js adds .game-touch to <html> while a game is played by touch). Nothing here
   touches the page's own scrolling, zooming or selection: only the game's controls opt out of the
   browser's gestures, each for its own area and no wider. */

/* The status bar moves to the top left, out of the thumbs' way, and says only what it must. */
.game-hud.touch {
  top: calc(env(safe-area-inset-top, 0px) + var(--space-2)); bottom: auto;
  left: calc(env(safe-area-inset-left, 0px) + var(--space-2)); right: auto;
  max-width: calc(100% - var(--space-4) - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3); gap: var(--space-1) var(--space-3);
  background: color-mix(in oklab, var(--second) 88%, transparent);
  white-space: pre;
}
.game-hud.touch button { min-width: var(--space-7); min-height: calc(var(--space-7) - var(--space-1)); padding: 0 var(--space-3); touch-action: manipulation; }

/* The controls: move on the left, drop and jump on the right, inside the screen's safe area.
   Only the controls themselves take touches (and hold off scrolling and zooming while pressed);
   a finger anywhere else, the strip between them included, reaches the page and scrolls it. */
.game-pads {
  position: fixed; z-index: 6; pointer-events: none;
  left: calc(env(safe-area-inset-left, 0px) + var(--gutter)); right: calc(env(safe-area-inset-right, 0px) + var(--gutter));
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-5));
  display: flex; justify-content: space-between; align-items: flex-end;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.pad-move, .pad-act { display: flex; align-items: flex-end; gap: var(--space-2); }
/* The rocker is one control (the thumb slides across it), so it is the whole pair. */
.pad-move { pointer-events: auto; touch-action: none; }
.pad-act .pad { pointer-events: auto; }
.pad {
  appearance: none; display: grid; place-items: center; padding: 0; margin: 0;
  width: var(--space-8); height: var(--space-8);
  font: var(--step-1) / 1 var(--font-text); color: var(--second-ink);
  background: color-mix(in oklab, var(--second) 62%, transparent);
  border: var(--line) solid var(--second-ink); border-radius: var(--radius);
  touch-action: none; -webkit-tap-highlight-color: transparent;
}
.pad-move .pad { pointer-events: none; }
.pad-drop { width: calc(var(--space-7) + var(--space-2)); height: calc(var(--space-7) + var(--space-2)); }
.pad-jump { width: calc(var(--space-8) + var(--space-4)); height: calc(var(--space-8) + var(--space-4)); font-size: var(--step-2); }
.pad.held { background: var(--second); }

/* The finder: an arrow on the top or bottom edge when the player is out of sight (game.js). */
.game-finder {
  appearance: none; cursor: pointer; position: fixed; z-index: 7; display: grid; place-items: center; padding: 0;
  width: var(--space-7); height: var(--space-7);
  font: var(--step-0) / 1 var(--font-text); color: var(--second-ink);
  background: var(--second); border: var(--line-heavy) solid var(--second-ink); border-radius: 50%;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.game-finder[data-edge="up"] { top: calc(env(safe-area-inset-top, 0px) + var(--space-2)); }
.game-finder[data-edge="down"] { bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-8)); }
/* On touch the status bar is at the top and the controls at the bottom: stay clear of both. */
html.game-touch .game-finder[data-edge="up"] { top: calc(env(safe-area-inset-top, 0px) + var(--space-8)); }
html.game-touch .game-finder[data-edge="down"] { bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-5) + var(--space-8) + var(--space-4) + var(--space-2)); }

/* A thumb-sized target for the small play button. */
@media (pointer: coarse) {
  .play { position: relative; }
  .play::after { content: ""; position: absolute; inset: calc(var(--space-3) * -1); }
}
