/*
 * The palette, type and spacing, then the base elements, the header and footer, and the post.
 *
 * The neutrals are cast toward the accent's hue rather than stock greys, and the dark surfaces sit within a few points of each other:
 * depth comes from a tonal step and a hairline, not a shadow. The accent is a text colour, so the light theme carries a darker one that
 * clears 4.5:1 on white.
 */

:root {
  --surface-0: #ffffff;
  --surface-1: #fcf9f8;
  --surface-2: #f7f3f2;
  --surface-3: #ede9e8;
  --selection: #f0c7ba;
  --border: #eae5de;
  --border-strong: #6f6a67;
  --text: #1e1918;
  --text-muted: #5c5755;
  --text-subtle: #736d6b;
  --accent: #b05333;
  --on-accent: #ffffff;
  --accent-hover: brightness(0.92);
  --shadow-overlay: 0 8px 24px rgb(30 25 24 / 10%);

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s6: 24px;
  --s8: 32px;
  --s10: 40px;
  --s12: 48px;
  --s16: 64px;

  --r-sm: 2px;
  --r: 4px;
  --r-lg: 8px;

  --font-ui: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --t-h1: clamp(1.75rem, 1.4rem + 1.4vw, 2.25rem);
  --t-h2: clamp(1.3rem, 1.18rem + 0.55vw, 1.5rem);
  --t-h3: 1.125rem;
  --t-body: 1rem;
  --t-small: 0.875rem;
  --t-caption: 0.75rem;

  --d-feedback: 140ms;
  --e-out: cubic-bezier(0.16, 1, 0.3, 1);

  --page: 1120px;
  --measure: 68ch;
  --wide: 1080px;

  color-scheme: light;
}

/* Declared twice and kept identical: an explicit choice has to beat the system preference both ways, and one copy lives in a media
   query, so the two selectors cannot be merged. */
:root[data-theme="dark"] {
  --surface-0: #111111;
  --surface-1: #131313;
  --surface-2: #171717;
  --surface-3: #1e1d1c;
  --selection: #5b3a30;
  --border: #232221;
  --border-strong: #7b7573;
  --text: #f4edeb;
  --text-muted: #b3acaa;
  --text-subtle: #948e8c;
  --accent: #d67454;
  --on-accent: #111111;
  --accent-hover: brightness(1.1);
  --shadow-overlay: 0 8px 24px rgb(0 0 0 / 50%);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-0: #111111;
    --surface-1: #131313;
    --surface-2: #171717;
    --surface-3: #1e1d1c;
    --selection: #5b3a30;
    --border: #232221;
    --border-strong: #7b7573;
    --text: #f4edeb;
    --text-muted: #b3acaa;
    --text-subtle: #948e8c;
    --accent: #d67454;
    --on-accent: #111111;
    --accent-hover: brightness(1.1);
    --shadow-overlay: 0 8px 24px rgb(0 0 0 / 50%);
    color-scheme: dark;
  }
}

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

html {
  /* The header would otherwise shift sideways between a page that scrolls and one that doesn't. */
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface-0);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

main {
  flex: 1 0 auto;
}

::selection {
  background: var(--selection);
  color: var(--text);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.015em;
  font-weight: 650;
  overflow-wrap: break-word;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  height: auto;
}

code,
kbd {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.page {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--s4);
}

@media (min-width: 600px) {
  .page {
    padding: 0 var(--s6);
  }
}

.muted {
  color: var(--text-muted);
}

.subtle {
  color: var(--text-subtle);
}

.small {
  font-size: var(--t-small);
}

.caption {
  font-size: var(--t-caption);
}

.mono {
  font-family: var(--font-mono);
}

.skip {
  position: absolute;
  left: -9999px;
  top: var(--s2);
  padding: var(--s2) var(--s4);
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--r);
  z-index: 10;
}

.skip:focus {
  left: var(--s4);
}

/* Controls. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  font: inherit;
  font-weight: 500;
  padding: var(--s2) var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-0);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background var(--d-feedback) var(--e-out),
    border-color var(--d-feedback) var(--e-out),
    color var(--d-feedback) var(--e-out);
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-small {
  padding: var(--s1) var(--s3);
  font-size: var(--t-small);
}

.btn:disabled {
  cursor: default;
  background: var(--surface-0);
  border-color: var(--border);
  color: var(--text-subtle);
  opacity: 0.55;
}

.onward {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  color: var(--accent);
  font-weight: 500;
}

.onward svg {
  transition: transform var(--d-feedback) var(--e-out);
}

.onward:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.onward:hover svg {
  transform: translateX(2px);
}

/* Header and footer. */

.site-header {
  border-bottom: 1px solid var(--border);
}

.site-header .page {
  display: flex;
  align-items: center;
  gap: var(--s4);
  min-height: 60px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* Circles are kept for the avatar: at these sizes the shape is what reads as a person. */
.brand-avatar,
.avatar {
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
}

.brand-avatar {
  width: 28px;
  height: 28px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--s4);
  margin-left: auto;
  font-size: var(--t-small);
}

.site-nav a {
  color: var(--text-muted);
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--text);
}

.theme-toggle {
  padding: var(--s1);
  width: 32px;
  height: 32px;
}

/* One icon per appearance; the other hides. The light theme offers the moon, the dark one the sun. */
.theme-toggle .sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun {
    display: block;
  }

  :root:not([data-theme="light"]) .theme-toggle .moon {
    display: none;
  }
}

.site-footer {
  margin-top: var(--s16);
  border-top: 1px solid var(--border);
}

.site-footer .page {
  padding-top: var(--s6);
  padding-bottom: var(--s8);
  display: grid;
  gap: var(--s2);
}

/* The post list. */

.listing h1 {
  margin: var(--s12) 0 var(--s3);
}

.lede {
  max-width: 62ch;
}

.listing > .more {
  margin-top: var(--s4);
}

.entries {
  list-style: none;
  margin: var(--s6) 0 0;
  padding: 0;
  max-width: var(--measure);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.entries li {
  padding: var(--s4);
  border-bottom: 1px solid var(--border);
}

.entries li:last-child {
  border-bottom: 0;
}

.entry-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--s2);
}

.entry-head h2 {
  font-size: var(--t-h3);
}

.entry-head h2 a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.entry-head .date {
  margin-left: auto;
}

.entries .summary {
  margin-top: var(--s2);
  color: var(--text-muted);
}

.entries .more {
  margin-top: var(--s3);
}

/*
 * The post.
 *
 * A grid of three tracks: the text sits in the middle one, a measure wide, and the screenshots break out across all three, up to
 * --wide, centred. Being a grid rather than 100vw arithmetic, the breakout never runs under a scrollbar or off the edge of a phone.
 */

.post {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--s4), 1fr)
    [content-start] min(var(--measure), calc(100% - 2 * var(--s4)))
    [content-end] minmax(var(--s4), 1fr)
    [full-end];
  font-size: var(--t-body);
  line-height: 1.65;
}

.post > * {
  grid-column: content;
  margin: 0;
}

.post > * + * {
  margin-top: var(--s4);
}

.post > .wide {
  grid-column: full;
  justify-self: center;
  width: min(var(--wide), calc(100% - 2 * var(--s4)));
  margin-top: var(--s8);
  margin-bottom: var(--s4);
}

.crumb {
  margin-top: var(--s8);
}

.back {
  color: var(--text-muted);
}

.back:hover {
  color: var(--text);
}

.post > h1 {
  margin-top: var(--s6);
  font-size: var(--t-h1);
}

.byline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s2);
  font-size: var(--t-small);
  line-height: 1.4;
}

.post > .byline {
  margin-top: var(--s4);
  margin-bottom: var(--s4);
}

.avatar {
  width: 32px;
  height: 32px;
}

.who {
  font-weight: 500;
}

.post > .lede {
  font-size: 1.125rem;
  line-height: 1.6;
  color: var(--text);
}

.post > h2 {
  margin-top: var(--s16);
  font-size: var(--t-h2);
  scroll-margin-top: var(--s6);
}

.post > h3 {
  margin-top: var(--s8);
  font-size: var(--t-h3);
}

.post > h2 + p,
.post > h3 + p {
  margin-top: var(--s3);
}

.post > ul,
.post > ol {
  padding-left: 1.2em;
}

.post li + li {
  margin-top: var(--s2);
}

.post a:not(.btn):not(.onward) {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.post code {
  padding: 0 var(--s1);
  background: var(--surface-2);
  border-radius: var(--r-sm);
}

.post > blockquote {
  padding-left: var(--s4);
  border-left: 2px solid var(--border-strong);
  color: var(--text-muted);
}

.toc {
  padding: var(--s4) var(--s6);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.toc h2 {
  font-size: var(--t-caption);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.toc ol {
  margin: var(--s2) 0 0;
  padding-left: 1.4em;
  columns: 2 16rem;
  column-gap: var(--s8);
  font-size: var(--t-small);
}

.toc li {
  break-inside: avoid;
}

.toc li + li {
  margin-top: var(--s1);
}

.toc a {
  color: var(--text-muted);
  text-decoration: none !important;
}

.toc a:hover {
  color: var(--accent);
}

.numbers {
  margin-top: var(--s16) !important;
  padding-top: var(--s6);
  border-top: 1px solid var(--border);
}

.numbers h2 {
  font-size: var(--t-caption);
  font-weight: 500;
  color: var(--text-subtle);
}

.numbers dl {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: var(--s4) var(--s6);
  margin: var(--s4) 0 0;
}

.numbers dt {
  font-size: var(--t-caption);
  color: var(--text-subtle);
}

.numbers dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 500;
}

.post > .fine {
  margin-top: var(--s8);
  font-size: var(--t-small);
  color: var(--text-subtle);
}
