/*
 * Structure shared by every theme. A theme sets the tokens below on :root
 * (and their dark values), then adds whatever only it needs. Nothing in this
 * file names a color; reach for a token, as the app does with its roles
 * (client/src/styles/theme.css).
 *
 *   --ground        page background
 *   --surface       a card on the page
 *   --surface-muted a well inside a card (code, inline code, stamps)
 *   --ink           brand accent: links, logo, the stamp
 *   --text          body text
 *   --text-soft     secondary text
 *   --edge          a card's hairline border
 *   --edge-soft     rules and borders inside a card
 *   --font-*        title / body / ui / meta
 *   --radius, --radius-sm
 */

/* ── fonts (self-hosted, latin subset; OFL licences in assets/fonts) ── */
@font-face {
  font-family: 'IBM Plex Serif';
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url('fonts/ibm-plex-serif-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Serif';
  font-weight: 400;
  font-style: italic;
  font-display: swap;
  src: url('fonts/ibm-plex-serif-latin-400-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Serif';
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  src: url('fonts/ibm-plex-serif-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Serif';
  font-weight: 500;
  font-style: italic;
  font-display: swap;
  src: url('fonts/ibm-plex-serif-latin-500-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-weight: 500;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-weight: 600;
  font-display: swap;
  src: url('fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-weight: 400;
  font-display: swap;
  src: url('fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-weight: 500;
  font-display: swap;
  src: url('fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Courier Prime';
  font-weight: 400;
  font-display: swap;
  src: url('fonts/courier-prime-400-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Courier Prime';
  font-weight: 700;
  font-display: swap;
  src: url('fonts/courier-prime-700-latin.woff2') format('woff2');
}

:root {
  --font-title: 'IBM Plex Serif', ui-serif, Georgia, serif;
  --font-body: 'IBM Plex Serif', ui-serif, Georgia, serif;
  --font-ui: 'IBM Plex Sans', ui-sans-serif, system-ui, sans-serif;
  --font-meta: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --radius: 14px;
  --radius-sm: 8px;
  --measure: 40rem;
  --shell: 46rem;
}

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

html {
  background: var(--ground);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 100%;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main {
  flex: 1;
  width: 100%;
}

.shell {
  width: 100%;
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: max(1.25rem, env(safe-area-inset-left, 0px));
}

a {
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 3px;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  z-index: 2;
}
.skip:focus {
  top: 1rem;
}

/* ── header ── */
.site-header .shell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.5rem 2.75rem;
}
.brand {
  display: inline-flex;
  align-items: flex-end;
  gap: 0.5rem;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  width: 6.75rem;
  height: auto;
  display: block;
}
.brand-label {
  font-family: var(--font-meta);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  padding-bottom: 0.1rem;
}
.site-tools {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.site-nav {
  display: flex;
  gap: 1.1rem;
  font-size: 0.92rem;
}

/* ── light/dark switch: a moon in light (go dark), a sun in dark ── */
.mode-switch {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: var(--ink);
  background: none;
  border: 1px solid var(--edge);
  border-radius: 999px;
  cursor: pointer;
  transition:
    border-color 120ms ease,
    background-color 120ms ease;
}
/* `display` above would otherwise override the attribute that keeps the
   button out of sight until its script has run. */
.mode-switch[hidden] {
  display: none;
}
.mode-switch:hover {
  border-color: var(--ink);
  background: var(--surface-muted);
}
.mode-switch .icon {
  width: 1rem;
  height: 1rem;
}
/* Dark is either chosen (data-mode) or the device's setting with no choice
   made, the same two conditions the themes use. */
.mode-switch .icon + .icon,
:root[data-mode='dark'] .mode-switch .icon:first-child {
  display: none;
}
:root[data-mode='dark'] .mode-switch .icon + .icon {
  display: block;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode='light']) .mode-switch .icon:first-child {
    display: none;
  }
  :root:not([data-mode='light']) .mode-switch .icon + .icon {
    display: block;
  }
}
.site-nav a {
  text-decoration: none;
  color: var(--text);
}
.site-nav a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ── intro ── */
.intro {
  margin-bottom: 2rem;
  max-width: 34rem;
}
.intro-kicker {
  margin: 0 0 0.5rem;
  font-family: var(--font-meta);
  font-size: 0.8rem;
  color: var(--text-soft);
}
.intro-title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 500;
  font-size: clamp(1.6rem, 4.5vw, 2.1rem);
  line-height: 1.2;
  color: var(--ink);
  text-wrap: balance;
}
.intro-body {
  font-size: 1.05rem;
  color: var(--text);
}
.empty {
  color: var(--text-soft);
}

/* ── the front page with nothing published yet ── */
.empty-state {
  display: grid;
  gap: 1rem;
  max-width: var(--measure);
  padding: 1.75rem 1.5rem 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--edge);
  border-radius: var(--radius);
}
.empty-kicker {
  margin: 0;
  font-family: var(--font-meta);
  font-size: 0.8rem;
  color: var(--text-soft);
}
.empty-title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 500;
  font-size: 1.4rem;
  line-height: 1.25;
  color: var(--text);
  text-wrap: balance;
}
.empty-body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text);
  max-width: 60ch;
}
.empty-links {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}
.empty-links li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15rem 0.75rem;
}
.empty-links a {
  color: var(--ink);
  font-weight: 500;
  text-underline-offset: 3px;
}
.empty-links span {
  font-family: var(--font-meta);
  font-size: 0.8rem;
  color: var(--text-soft);
}

/* ── stamp: place, rounded coords, date, reading time ── */
.stamp {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-family: var(--font-meta);
  font-size: 0.75rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stamp > * {
  background: var(--surface-muted);
  border: 1px solid var(--edge-soft);
  border-radius: 999px;
  padding: 0.05rem 0.6rem;
  white-space: nowrap;
}
/* Specific enough (0,2,1) that a theme flattening `.stamp > *` or
   `.card-link .stamp > *` keeps this a pill: a draft has to be unmistakable
   in a preview. */
.stamp > span.stamp-draft {
  color: var(--ground);
  background: var(--ink);
  border-radius: 999px;
  padding: 0.05rem 0.6rem;
}

/* ── post list ── */
.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}
.card-link {
  display: grid;
  gap: 0.5rem;
  padding: 1.1rem 1.25rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition:
    border-color 120ms ease,
    background-color 120ms ease;
}
.card-link:hover {
  border-color: var(--ink);
}
.card-title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 500;
  font-size: 1.25rem;
  line-height: 1.28;
  color: var(--text);
  text-wrap: balance;
}
.card-summary {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-soft);
  max-width: 60ch;
}

/* ── a post ── */
.post {
  max-width: var(--measure);
}
.post-head {
  display: grid;
  gap: 0.9rem;
  margin-bottom: 2.25rem;
}
.post-dateline {
  display: none;
  margin: 0;
}
.post-title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 500;
  font-size: clamp(1.85rem, 5.5vw, 2.6rem);
  line-height: 1.12;
  color: var(--text);
  text-wrap: balance;
  letter-spacing: -0.01em;
}
.post-summary {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.15rem;
  line-height: 1.5;
  color: var(--text-soft);
  text-wrap: pretty;
}
.post-updated {
  margin: 0;
  font-family: var(--font-meta);
  font-size: 0.75rem;
  color: var(--text-soft);
}

.prose {
  font-family: var(--font-body);
  font-size: 1.08rem;
  line-height: 1.75;
  color: var(--text);
  overflow-wrap: break-word;
}
.prose > * {
  margin-block: 0 1.25rem;
}
.prose h2,
.prose h3,
.prose h4 {
  position: relative;
  font-family: var(--font-ui);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  text-wrap: balance;
  scroll-margin-top: 1.5rem;
}
.prose h2 {
  font-size: 1.35rem;
  margin-top: 2.75rem;
}
.prose h3 {
  font-size: 1.12rem;
  margin-top: 2rem;
}
.prose h4 {
  font-size: 1rem;
  margin-top: 1.75rem;
}
.prose .anchor {
  margin-left: 0.4em;
  color: var(--text-soft);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 120ms ease;
}
.prose :is(h2, h3, h4):hover .anchor,
.prose .anchor:focus-visible {
  opacity: 1;
}
.prose a {
  color: var(--ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.prose a:hover {
  text-decoration-thickness: 2px;
}
.prose strong {
  font-weight: 500;
}
.prose ul,
.prose ol {
  padding-left: 1.4rem;
}
.prose li + li {
  margin-top: 0.4rem;
}
.prose li::marker {
  color: var(--ink);
}
.prose blockquote {
  margin-inline: 0;
  padding-left: 1.1rem;
  border-left: 2px solid var(--ink);
  color: var(--text-soft);
  font-style: italic;
}
.prose hr {
  border: 0;
  border-top: 1px solid var(--edge-soft);
  margin-block: 2.5rem;
}
.prose img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--edge-soft);
}
.prose code {
  font-family: var(--font-meta);
  font-size: 0.86em;
  background: var(--surface-muted);
  border: 1px solid var(--edge-soft);
  border-radius: 4px;
  padding: 0.08em 0.35em;
}
.prose pre {
  font-family: var(--font-meta);
  font-size: 0.85rem;
  line-height: 1.65;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  overflow-x: auto;
}
.prose pre code {
  font-size: 1em;
  background: none;
  border: 0;
  padding: 0;
}
.prose table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.92rem;
}
.prose th,
.prose td {
  text-align: left;
  padding: 0.45rem 0.8rem;
  border-bottom: 1px solid var(--edge-soft);
  vertical-align: top;
}
.prose th {
  font-weight: 600;
}
.prose td {
  font-variant-numeric: tabular-nums;
}

.post-foot {
  margin-top: 3rem;
  display: grid;
  gap: 1.5rem;
}

/* ── share: a row of round icon buttons, under the heading and at the end ── */
.share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}
.share-label {
  margin: 0;
  font-family: var(--font-meta);
  font-size: 0.8rem;
  color: var(--text-soft);
}
.share-end .share-label {
  flex-basis: 100%;
}
/* Under the heading the row speaks for itself; the label stays for screen
   readers, which announce the region by it. */
.share-top .share-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.share-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
/* No `display` on the <li>: it would override the `hidden` attribute that
   keeps the script-only buttons out of sight until the script shows them. */
.share-item {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 999px;
  cursor: pointer;
  transition:
    border-color 120ms ease,
    background-color 120ms ease;
}
.share-item:hover {
  border-color: var(--ink);
  background: var(--surface-muted);
}
.icon {
  display: block;
  width: 1.05rem;
  height: 1.05rem;
}
/* Sits beside the icons, so "link copied." appearing doesn't push the page. */
.share-status {
  margin: 0;
  font-family: var(--font-meta);
  font-size: 0.8rem;
  color: var(--text-soft);
  overflow-wrap: anywhere;
}
.share-status:empty {
  display: none;
}
.signoff {
  display: none;
}
.tags {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-family: var(--font-meta);
  font-size: 0.8rem;
}
.tags a {
  display: inline-block;
  padding: 0.15rem 0.7rem;
  border: 1px solid var(--edge);
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
}
.tags a::before {
  content: '#';
  opacity: 0.6;
}
.tags a:hover {
  border-color: var(--ink);
}

.pager {
  max-width: var(--measure);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
  margin-top: 2.5rem;
}
.pager a {
  display: grid;
  gap: 0.2rem;
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.pager a:hover {
  border-color: var(--ink);
}
.pager-next {
  text-align: right;
  grid-column: 2;
}
.pager-label {
  font-family: var(--font-meta);
  font-size: 0.72rem;
  color: var(--text-soft);
}
.pager-title {
  font-family: var(--font-title);
  font-size: 1rem;
  line-height: 1.3;
}

/* ── tags index ── */
.tag-index {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  max-width: 30rem;
}
.tag-index li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius-sm);
}
.tag-index a {
  color: var(--ink);
  text-decoration: none;
}
.tag-index a:hover {
  text-decoration: underline;
}
.tag-count {
  font-family: var(--font-meta);
  font-size: 0.85rem;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

/* ── footer ── */
.site-footer {
  margin-top: 5rem;
  border-top: 1px solid var(--edge-soft);
}
.site-footer .shell {
  display: grid;
  gap: 1rem;
  padding-block: 2rem calc(2.5rem + env(safe-area-inset-bottom, 0px));
  font-size: 0.88rem;
  color: var(--text-soft);
}
.maker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  max-width: 34rem;
}
.maker-mark {
  flex: none;
  width: 2.5rem;
  height: auto;
  color: var(--ink);
}
.site-footer a {
  color: var(--text);
  text-underline-offset: 3px;
}
.site-footer a:hover {
  color: var(--ink);
}

@media (max-width: 30rem) {
  .site-header .shell {
    padding-block: 1.1rem 2rem;
  }
  .brand-mark {
    width: 5.5rem;
  }
  .site-nav {
    gap: 0.85rem;
  }
  .prose {
    font-size: 1.03rem;
  }
  .pager {
    grid-template-columns: minmax(0, 1fr);
  }
  .pager-next {
    grid-column: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ── theme: letters ── */
/*
 * letters (direction C) — latestagehumanism.com's one ground, one ink.
 *
 * Blush in light, the site's `dark` in dark (latestagehumanism/src/index.css).
 * Helvetica for titles and the index, Courier Prime for the letter itself.
 * Cards become ruled rows, and every post ends with the losien.to wordmark
 * as a signature under "lo siento,".
 */
:root {
  color-scheme: light;
  --ground: #f2cfe4;
  --surface: #f2cfe4;
  --surface-muted: rgb(175 64 44 / 0.08);
  --ink: #af402c;
  --text: #af402c;
  --text-soft: #a14a3a;
  --edge: rgb(175 64 44 / 0.4);
  --edge-soft: rgb(175 64 44 / 0.25);
  --font-title: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-ui: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-body: 'Courier Prime', 'Courier New', ui-monospace, monospace;
  --font-meta: 'Courier Prime', 'Courier New', ui-monospace, monospace;
  --radius: 0;
  --radius-sm: 0;
  --measure: 38rem;
}

/* Dark: the device's setting first, then the reader's own choice from the
   header switch, which sets data-mode on <html> and is remembered (see
   templates.js). The same tokens twice, because a media query and an
   attribute can't share one rule; test/indexing.test.js keeps them equal. */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode='light']) {
    color-scheme: dark;
    --ground: #13201f;
    --surface: #13201f;
    --surface-muted: rgb(180 198 174 / 0.08);
    --ink: #b4c6ae;
    --text: #b4c6ae;
    --text-soft: #97ab91;
    --edge: rgb(180 198 174 / 0.4);
    --edge-soft: rgb(180 198 174 / 0.22);
  }
}
:root[data-mode='dark'] {
  color-scheme: dark;
  --ground: #13201f;
  --surface: #13201f;
  --surface-muted: rgb(180 198 174 / 0.08);
  --ink: #b4c6ae;
  --text: #b4c6ae;
  --text-soft: #97ab91;
  --edge: rgb(180 198 174 / 0.4);
  --edge-soft: rgb(180 198 174 / 0.22);
}

.site-header .shell {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 1rem;
  margin-bottom: 2.25rem;
}
.intro-title,
.post-title,
.card-title {
  font-weight: 700;
  letter-spacing: -0.025em;
}

/* nothing published yet: a note on the page, not a card */
.empty-state {
  background: none;
  border-width: 0 0 0 2px;
  border-style: solid;
  border-color: var(--ink);
  padding: 0.25rem 0 0.25rem 1.25rem;
}
.empty-title {
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* rows, not cards */
.cards {
  gap: 0;
}
.card-link {
  background: none;
  border: 0;
  border-bottom: 1px solid var(--edge);
  border-radius: 0;
  padding: 1rem 0;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  column-gap: 1rem;
}
.card-link:hover .card-title {
  text-decoration: underline;
  text-underline-offset: 4px;
}
.card-link .stamp {
  grid-row: 1 / span 2;
  align-content: start;
}
.card-link .stamp > :not(.stamp-date, .stamp-draft) {
  display: none;
}
.stamp > * {
  background: none;
  border: 0;
  padding: 0;
}
.card-title {
  font-size: 1.15rem;
}
@media (max-width: 30rem) {
  .card-link {
    grid-template-columns: minmax(0, 1fr);
  }
  .card-link .stamp {
    grid-row: auto;
  }
}

/* a letter: dateline top right, then the title, then the typed body */
.post-dateline {
  display: block;
  text-align: right;
  font-family: var(--font-meta);
  font-size: 0.9rem;
}
.post-head .stamp {
  display: none;
}
.post-summary {
  font-family: var(--font-ui);
  font-size: 1.05rem;
}
.prose {
  font-size: 1rem;
  line-height: 1.7;
}
.prose h2,
.prose h3,
.prose h4 {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.prose pre {
  background: var(--surface-muted);
  border-style: dashed;
}
.prose blockquote {
  font-style: normal;
}

.signoff {
  display: grid;
  gap: 0.5rem;
  justify-items: start;
  color: var(--ink);
  font-family: var(--font-body);
}
.signoff-mark {
  width: 9rem;
  height: auto;
}
/* the closing share row is the letter's p.s.; the icons drop their circles
   and stand in the ink alone */
.share-end {
  padding-top: 1rem;
  border-top: 1px dashed var(--ink);
}
.share-end .share-label {
  font-size: 0.95rem;
  color: var(--ink);
}
.share-end .share-label::before {
  content: 'p.s. ';
}
.share-list {
  gap: 0.25rem;
}
.share-item {
  background: none;
  border-color: transparent;
}
.share-item:hover {
  background: none;
  border-color: var(--ink);
}
.tags a {
  border: 0;
  background: none;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.pager a,
.tag-index li {
  background: none;
}
.site-footer {
  border-top: 2px solid var(--ink);
}
