/*
 * The layout of every screen. Colours, fonts and sizes come from theme.css (var(--...)), never typed here.
 * Sections: base, header and footer, then one block per screen (home, list, article, links, media).
 * No fixed widths: columns come from grid's auto-fit and min(), sizes from clamp(), so one stylesheet fits
 * a phone, a tablet and a desktop without breakpoints, apart from the one for printing.
 */

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: var(--leading);
}
main { flex: 1; width: 100%; max-width: var(--page); margin: 0 auto; padding: var(--space-6) var(--gutter); }
h1, h2, h3 { font-family: var(--font-heading); line-height: 1.2; margin: 0 0 var(--space-3); }
h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-2); margin-top: var(--space-6); }
h3 { font-size: var(--step-1); margin-top: var(--space-5); }
p, ul, ol, pre, figure, table { margin: 0 0 var(--space-4); }
a { color: var(--color-accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }
img, video, svg { max-width: 100%; height: auto; }
code, pre { font-family: var(--font-mono); font-size: var(--step--1); }
code { background: var(--color-surface); padding: 0.1em 0.3em; border-radius: var(--radius); }
pre { background: var(--color-surface); padding: var(--space-4); border-radius: var(--radius); overflow-x: auto; border: 1px solid var(--color-border); }
pre code { background: none; padding: 0; }
.lead { font-size: var(--step-1); color: var(--color-muted); max-width: var(--measure); }
.muted { color: var(--color-muted); }
.skip { position: absolute; left: var(--space-2); top: -4rem; background: var(--color-accent); color: var(--color-on-accent); padding: var(--space-2) var(--space-3); border-radius: var(--radius); z-index: 1; }
.skip:focus { top: var(--space-2); }
.button {
  display: inline-block; padding: var(--space-2) var(--space-5); border-radius: var(--radius);
  background: var(--color-accent); color: var(--color-on-accent); text-decoration: none; font-weight: 600;
  border: 2px solid var(--color-accent);
}
.button.secondary { background: transparent; color: var(--color-accent); }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-5); }

/* Header and footer: the same on every page. */
.site-header { border-bottom: 1px solid var(--color-border); background: var(--color-surface); }
.site-header .bar {
  max-width: var(--page); margin: 0 auto; padding: var(--space-3) var(--gutter);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-5);
}
.brand { font-family: var(--font-heading); font-weight: 700; font-size: var(--step-1); color: var(--color-text); text-decoration: none; margin-right: auto; }
.site-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); }
.site-nav a { color: var(--color-text); text-decoration: none; padding: var(--space-1) 0; border-bottom: 2px solid transparent; }
.site-nav a:hover { border-bottom-color: var(--color-border); }
.site-nav a[aria-current="page"] { border-bottom-color: var(--color-accent); font-weight: 600; }
.theme-picker { margin: 0; font-size: var(--step--1); color: var(--color-muted); }
.theme-picker select { font: inherit; color: var(--color-text); background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-1) var(--space-2); }
.site-footer { border-top: 1px solid var(--color-border); color: var(--color-muted); font-size: var(--step--1); }
.site-footer .bar { max-width: var(--page); margin: 0 auto; padding: var(--space-5) var(--gutter); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); }
.site-footer p { margin: 0; }

/* Cards: a grid that is one column on a phone and as many as fit on a wider screen. */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: var(--space-4); padding: 0; list-style: none; }
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-5); }
.card h2, .card h3 { margin-top: 0; font-size: var(--step-1); }
.card p:last-child { margin-bottom: 0; }

/* Screen: home */
.hero { padding: var(--space-7) 0 var(--space-6); }
.hero h1 { max-width: 20ch; }
.band { margin-top: var(--space-7); padding: var(--space-6) var(--space-5); background: var(--color-surface); border-radius: var(--radius-lg); }
.band h2 { margin-top: 0; }
.band p { max-width: var(--measure); }

/* Screen: list (news, posts, events: newest first) */
.entries { list-style: none; padding: 0; max-width: 48rem; }
.entry { padding: var(--space-5) 0; border-bottom: 1px solid var(--color-border); }
.entry h2 { font-size: var(--step-1); margin: var(--space-1) 0 var(--space-2); }
.entry time, .entry .source { font-size: var(--step--1); color: var(--color-muted); }
.entry p { margin-bottom: var(--space-2); }

/* Screen: article (how-to, guide, about): one column of reading text, a contents list beside it when it fits. */
.article { display: grid; grid-template-columns: minmax(0, var(--measure)); gap: var(--space-6); }
@supports (width: max(1px, 1px)) {
  .article.with-toc { grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), max-content)); }
  .article.with-toc > .prose { max-width: var(--measure); }
}
.toc { font-size: var(--step--1); border-left: 3px solid var(--color-border); padding-left: var(--space-4); align-self: start; }
.toc h2 { font-size: var(--step-0); margin-top: 0; }
.toc ol { padding-left: var(--space-4); margin: 0; }
.prose > h2:first-child { margin-top: 0; }
.note { border-left: 4px solid var(--color-accent); background: var(--color-surface); padding: var(--space-4); border-radius: 0 var(--radius) var(--radius) 0; }
.note p:last-child { margin-bottom: 0; }
.steps { padding-left: var(--space-5); }
.steps li { margin-bottom: var(--space-3); }

/* Screen: links (resources, each with what it is) */
.link-cards a { display: block; height: 100%; text-decoration: none; color: inherit; }
.link-cards a:hover { border-color: var(--color-accent); }
.link-cards .card { height: 100%; }
.link-cards strong { color: var(--color-accent); font-size: var(--step-1); display: block; margin-bottom: var(--space-2); }
.link-cards span { display: block; }
.link-cards .url { font-family: var(--font-mono); font-size: var(--step--1); color: var(--color-muted); overflow-wrap: anywhere; }

/* Screen: media (pictures, video, sound) */
figure { margin-left: 0; margin-right: 0; }
figcaption { font-size: var(--step--1); color: var(--color-muted); margin-top: var(--space-2); }
.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: var(--space-4); }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); }
.player video, .player audio { width: 100%; border-radius: var(--radius); background: var(--color-surface); }

@media print {
  .site-header, .site-footer, .toc, .skip { display: none; }
  body { background: none; color: black; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* apps.html: each app's card; its stage shows the picture, then the build (white on black), then the app */
.apps { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); gap: var(--space-5); padding: 0; list-style: none; }
.app h2 { margin: var(--space-4) 0 var(--space-2); font-size: var(--step-1); }
.app-stage { display: flex; flex-direction: column; aspect-ratio: 16 / 10; overflow: hidden; border-radius: var(--radius); background: var(--color-console-bg); color: var(--color-console-text); }
.app-shot { display: block; width: 100%; height: 100%; object-fit: cover; }
.app-log { flex: 1; margin: 0; padding: var(--space-3); overflow-y: auto; white-space: pre-wrap; font-family: var(--font-mono); font-size: var(--step--1); background: var(--color-console-bg); color: var(--color-console-text); border: 0; border-radius: 0; }
.app-frame { flex: 1; display: block; width: 100%; border: 0; background: var(--color-console-bg); }
.app-bar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3); background: var(--color-surface); color: var(--color-text); border-bottom: 1px solid var(--color-border); }
.app-title { font-weight: 600; white-space: nowrap; }
.app-progress { flex: 1; height: 0.5rem; border-radius: 999px; background: var(--color-border); overflow: hidden; }
.app-progress-fill { display: block; width: 0; height: 100%; background: var(--color-accent); transition: width 0.25s linear; }
.app-eta { font-size: var(--step--1); color: var(--color-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.app-sizes { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.app-sizes button { display: flex; align-items: center; justify-content: center; }
.app-sizes svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.app-sizes svg .solid { fill: currentColor; stroke: none; }
.app-bar button { min-height: 2.75rem; min-width: 2.75rem; padding: 0 var(--space-3); font: inherit; font-size: var(--step--1); background: none; color: inherit; border: 1px solid var(--color-border); border-radius: var(--radius); cursor: pointer; }
.app-bar button[aria-pressed="true"] { background: var(--color-accent); color: var(--color-on-accent); border-color: var(--color-accent); }
.app-bar .app-close { font-size: var(--step-2); line-height: 1; border: 0; }
.app-links { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.app-step { font-size: var(--step--1); color: var(--color-muted); }
.app-step:empty { display: none; }
/* Large: the window under the site's header (runner.js sets --app-top). Full screen: the browser's own. */
.app.is-window .app-stage { position: fixed; top: var(--app-top, 0); right: 0; bottom: 0; left: 0; z-index: 10; aspect-ratio: auto; border-radius: 0; }
.app.is-full .app-stage { position: fixed; inset: 0; z-index: 20; aspect-ratio: auto; border-radius: 0; }
body.app-window-open { overflow: hidden; }
.app-stage:fullscreen { aspect-ratio: auto; width: 100%; height: 100%; border-radius: 0; }
.app-shot[hidden], .app-log[hidden], .app-frame[hidden], .app-bar[hidden], .app-progress[hidden], .app-eta[hidden], .app-sizes[hidden] { display: none; }
@media (max-width: 30rem) { .app-title { display: none; } }
