/* ===== Reset ===== */

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

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

img,
picture,
video,
audio,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

audio {
  width: 100%;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
  line-height: 1.2;
}

p {
  text-wrap: pretty;
}

[hidden] {
  display: none !important;
}

:target {
  scroll-margin-block: 5ex;
}

/* ===== Tokens ===== */

:root {
  color-scheme: light dark;

  --text: light-dark(#1a1a1a, #e4e4e7);
  --bg: light-dark(#fafafa, #18181b);
  --text-muted: light-dark(#596066, #a1a1aa);
  --link: light-dark(#2563eb, #60a5fa);
  --code-bg: light-dark(#f4f4f5, #27272a);
  --border: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.12));

  --measure: 65ch;
  --gutter: clamp(1rem, 6vw, 3rem);
}

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

body {
  overflow-wrap: break-word;
  font-family: system-ui, sans-serif;
  font-size: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100svh;
}

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

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

hr {
  border: none;
  border-top: 1px solid var(--border);
}

code {
  font-family:
    ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
    "DejaVu Sans Mono", monospace;
  font-size: 0.9em;
}

input[type="search"] {
  font-size: 1rem;
}

/* ===== Layout ===== */

#nav {
  padding: 1rem var(--gutter);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  border-top: 3px solid #8bb1ff;
  border-bottom: 1px solid var(--border);
}

nav a {
  color: var(--text-muted);
  text-decoration: none;
}

nav a:hover,
nav a[aria-current] {
  color: var(--text);
}

#content {
  width: min(var(--measure), 100% - var(--gutter) * 2);
  margin-inline: auto;
  padding-block: 2rem;
  min-width: 0;
}

/* ===== Post List ===== */

#content > a {
  display: block;
  padding: 1rem 0;
  text-decoration: none;
  color: var(--text);
}

#content > a + a {
  border-top: 1px solid var(--border);
}

#content > a strong {
  display: block;
  font-size: 1.125em;
}

#content > a :is(small, span) {
  color: var(--text-muted);
}

#content > a span {
  display: block;
  margin-top: 0.25em;
}

#content > a:hover strong {
  color: var(--link);
}

/* ===== Article ===== */

article > * + * {
  margin-block-start: 1em;
}

article header {
  margin-block-end: 2rem;
}

article header p {
  color: var(--text-muted);
}

article :is(h2, h3, h4, h5, h6) {
  margin-block-start: 2em;
}

article li + li {
  margin-block-start: 0.25em;
}

article li:has(> input[type="checkbox"]) {
  list-style: none;
}

article :is(blockquote, details) > * + * {
  margin-block-start: 0.75em;
}

article > hr {
  margin-block: 2em;
}

:not(pre) > code {
  background: var(--code-bg);
  padding: 0.125em 0.3em;
  border-radius: 0.25em;
}

pre {
  background: var(--code-bg);
  padding: 1em 1.25em;
  border-radius: 0.375em;
  overflow-x: auto;
  tab-size: 2;
}

pre code {
  font-size: 0.875em;
}

blockquote {
  padding-inline-start: 1em;
  border-inline-start: 3px solid currentColor;
  color: var(--text-muted);
  font-style: italic;
}

article img,
#gen-canvas {
  border-radius: 0.375em;
}

.gallery {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
}

.gallery > img {
  max-height: 50vh;
}

.gallery > img:not(:only-child) {
  height: 40vh;
  max-width: none;
}

.gallery > :is(iframe, video) {
  aspect-ratio: 16 / 9;
  width: 100%;
  border: none;
  border-radius: 0.375em;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
}

th,
td {
  padding: 0.5em 0.75em;
  border: 1px solid var(--border);
}

th {
  font-weight: 600;
  text-align: left;
}

details {
  border: 1px solid var(--border);
  border-radius: 0.375em;
  padding: 0.75em 1em;
}

summary {
  cursor: pointer;
  font-weight: 600;
}

article > nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-block-start: 3rem;
  padding-block-start: 1.5rem;
  border-top: 1px solid var(--border);
}

article > nav a[rel="next"] {
  margin-inline-start: auto;
  text-align: end;
}

/* ===== Focus & Accessibility ===== */

[tabindex="-1"]:focus {
  outline: none;
}

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

#announcer {
  position: absolute;
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Print ===== */

@media print {
  @page {
    margin: 2cm;
  }

  body {
    color: #000;
    background: #fff;
    display: block;
  }

  a {
    color: #000;
  }

  #nav,
  article > nav {
    display: none;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
  }

  h2,
  h3,
  h4 {
    break-after: avoid;
  }

  img,
  pre,
  blockquote,
  table {
    break-inside: avoid;
  }

  pre {
    white-space: pre-wrap;
    overflow: visible;
  }

  video,
  iframe,
  #gen-canvas {
    display: none;
  }

  .gallery {
    flex-wrap: wrap;
    overflow: visible;
  }

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

  p {
    orphans: 3;
    widows: 3;
  }
}
