@import url('tokens.css');

/* ---- Reset & base ------------------------------------------------- */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  overflow-x: hidden;
  /* Not padding-top on body: the header is position:sticky, so its resting
     point after scrolling is the true viewport top regardless of body's
     own padding -- inset padding belongs on the sticky header's own
     content instead, below. */
}

body.lightbox-open {
  overflow: hidden;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

img {
  max-width: 100%;
}

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

.icon {
  display: block;
}

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

/* ---- Header (progress bar lives inside it: see below) ---------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transform: translateY(0);
  transition: transform var(--duration) var(--ease);
}

/* One sticky context, one transform: the progress bar used to be its own
   position:fixed element pinned to the viewport, independent of the
   header's own sticky+translateY show/hide -- so on scroll-down (mobile)
   the header would slide away while the progress bar stayed put. Moving
   it inside .site-header as an absolutely-positioned strip makes both
   move together under the same translateY, every time, by construction. */
.reading-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  z-index: 1;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.reading-progress.is-visible {
  opacity: 1;
}

.reading-progress__fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
}

.site-header.is-hidden {
  transform: translateY(-100%);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--gutter);
  /* The notch/status-bar inset belongs here, not on body: this is the
     sticky header's own content, so it needs to stay clear of the notch
     at every scroll position, not just before the first scroll. Falls
     back to 0 on devices/browsers with no safe area (desktop, Android). */
  padding-top: calc(var(--sp-3) + env(safe-area-inset-top, 0px));
  min-height: var(--header-height);
  flex-wrap: wrap;
}

.site-header.is-condensed .site-header__inner {
  display: none;
}

.site-header__condensed {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--gutter);
  padding-top: calc(var(--sp-3) + env(safe-area-inset-top, 0px));
  min-height: var(--header-height);
}

.site-header__condensed-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-header__leading {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 12px;
}

.brand-name {
  font-size: var(--fs-lg);
  font-weight: 700;
}

.site-nav {
  display: flex;
  gap: var(--sp-4);
  margin-right: auto;
}

.site-nav__link {
  text-decoration: none;
  color: var(--text-dim);
  font-size: var(--fs-base);
  font-weight: 500;
  padding: var(--sp-1) 0;
  border-bottom: 2px solid transparent;
}

.site-nav__link.is-current {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.meta-summary {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  white-space: nowrap;
}

.icon-btn.is-spinning svg {
  animation: spin 0.7s linear infinite;
}

/* ---- Site search (header) ------------------------------------------------ */

.site-search {
  position: relative;
}

.site-search__panel {
  position: absolute;
  top: calc(100% + var(--sp-2));
  right: 0;
  width: min(360px, 90vw);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  padding: var(--sp-3);
  z-index: 5;
}

.site-search__input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
}

.site-search__results {
  list-style: none;
  margin: var(--sp-2) 0 0;
  padding: 0;
  max-height: 60vh;
  overflow-y: auto;
}

.site-search__result a {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text);
}

.site-search__result.is-active a,
.site-search__result a:hover {
  background: var(--bg);
}

.site-search__result-type {
  flex-shrink: 0;
  font-size: var(--fs-xs);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.site-search__result-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-search__empty {
  padding: var(--sp-2);
  color: var(--text-dim);
  font-size: var(--fs-sm);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.theme-icon--moon {
  display: none;
}

html[data-theme="light"] .theme-icon--sun {
  display: none;
}

html[data-theme="light"] .theme-icon--moon {
  display: block;
}

/* ---- Footer ----------------------------------------------------------- */

.site-footer {
  padding: var(--sp-6) var(--gutter) calc(var(--sp-10) + env(safe-area-inset-bottom, 0px));
}

.site-footer__inner {
  max-width: var(--content-width-wide);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--text-faint);
}

.site-footer a {
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}

/* ---- New-articles banner --------------------------------------------- */

.new-articles-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--accent);
  color: var(--accent-text);
  font-size: var(--fs-sm);
}

.new-articles-banner button {
  background: var(--accent-text);
  color: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
  font-weight: 600;
}

/* A service-worker update installed while this tab already had an older
   one active -- the new JS is cached and ready, but won't take over the
   already-loaded page until a reload. Fixed to the bottom so it never
   shifts content that's already rendered, unlike the News-only banner
   above, which is part of the page's own flow. */
.sw-update-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--gutter);
  padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
  background: var(--accent);
  color: var(--accent-text);
  font-size: var(--fs-sm);
}

.sw-update-banner button {
  background: var(--accent-text);
  color: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
  font-weight: 600;
}

/* ---- Filter bar (News grid) -------------------------------------------- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--gutter);
  border-bottom: 1px solid var(--border);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-full);
  padding: var(--sp-2) var(--sp-4);
  min-height: 40px;
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.chip:hover {
  border-color: var(--accent);
}

.chip[aria-pressed="true"],
.chip.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.filter-toggles {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  cursor: pointer;
  min-height: 40px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  text-decoration: underline;
  cursor: pointer;
  padding: var(--sp-2) 0;
}

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

.sources-panel {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--gutter);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.source-pill {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-xs);
  padding: 5px var(--sp-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-dim);
  background: var(--bg);
}

.source-pill.hidden-source {
  text-decoration: line-through;
  opacity: 0.6;
}

.source-pill.disabled-source {
  opacity: 0.5;
  cursor: default;
}

.source-pill.degraded-source {
  opacity: 0.8;
  cursor: default;
  border-color: var(--warning);
  color: var(--text-dim);
}

/* ---- Category badge --------------------------------------------------- */

.category-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px var(--sp-2);
  border-radius: var(--radius-full);
  text-decoration: none;
  background: color-mix(in srgb, var(--cat) 20%, transparent);
  /* The raw hue (--cat) is a decorative tint; --cat-text-dark/light are
     lightness-adjusted per theme so the label itself clears WCAG AA
     against that tint (checked by calculation -- several hues fail at
     full brightness, especially on the light theme's near-white cards). */
  color: var(--cat-text-dark, var(--cat));
}

html[data-theme="light"] .category-badge {
  color: var(--cat-text-light, var(--cat));
}

/* ---- Bookmark button ---------------------------------------------------- */

.bookmark-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: var(--sp-1);
}

.bookmark-btn .bookmark-btn__on {
  display: none;
  color: var(--accent);
}

.bookmark-btn.is-bookmarked .bookmark-btn__on {
  display: block;
}

.bookmark-btn.is-bookmarked .bookmark-btn__off {
  display: none;
}

.bookmark-btn--icon {
  min-width: 40px;
  min-height: 40px;
  justify-content: center;
}

.bookmark-btn--label {
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: var(--sp-2) var(--sp-4);
  min-height: 40px;
  font-size: var(--fs-sm);
  font-weight: 600;
}

.bookmark-btn--label.is-bookmarked {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- Meta line ---------------------------------------------------------- */

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
  color: var(--text-dim);
}

.meta--sm {
  font-size: var(--fs-xs);
}

.meta--md {
  font-size: var(--fs-sm);
}

.meta__item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.meta__item:not(:last-child)::after {
  content: "\00b7";
  margin-left: var(--sp-2);
  color: var(--text-faint);
}

.meta__source {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  text-decoration: none;
}

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

.meta__authors a {
  color: var(--link);
  text-decoration: underline;
}

.favicon {
  border-radius: 3px;
  display: block;
}

/* ---- Article grid & card ------------------------------------------------ */

.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-5);
  padding: var(--gutter);
  max-width: 1400px;
  margin: 0 auto;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card.is-read {
  opacity: 0.6;
}

.card__image {
  display: block;
  height: 140px;
  position: relative;
  overflow: hidden;
  background: var(--bg-elevated);
}

.card__image img,
.card__image svg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card__done-badge {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: var(--fs-xs);
  font-weight: 700;
  padding: 3px var(--sp-2);
  border-radius: var(--radius-full);
}

.card__body {
  padding: var(--sp-4) var(--sp-4) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  flex: 1;
}

.card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.card__title {
  font-size: var(--fs-md);
  font-weight: 600;
  margin: 0;
  line-height: var(--lh-tight);
}

.card__title a {
  text-decoration: none;
  display: block;
  color: inherit;
}

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

.card__excerpt {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card .meta {
  margin-top: auto;
}

.card__also {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  margin: 0;
}

.card__project-chips {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.card__chip {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px var(--sp-2);
}

.card__chip--beginner {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.card__chip--advanced {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

.grid-sentinel {
  height: 1px;
}

.empty-state,
.loading-state,
.error-state {
  text-align: center;
  color: var(--text-dim);
  padding: var(--sp-10) var(--gutter);
}

.error-state {
  color: var(--danger);
}

/* ---- Notice ------------------------------------------------------------- */

.notice {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  margin: var(--sp-5) 0;
  max-width: var(--content-width);
}

.notice--warning {
  border-color: color-mix(in srgb, var(--warning) 40%, var(--border));
  background: color-mix(in srgb, var(--warning) 8%, var(--bg-elevated));
}

.notice--warning .notice__icon {
  color: var(--warning);
}

.notice__icon {
  flex-shrink: 0;
  color: var(--accent);
}

.notice__title {
  display: block;
  margin-bottom: 2px;
}

.notice__body {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  line-height: var(--lh-normal);
}

/* ---- Figure --------------------------------------------------------------- */

.figure {
  margin: 0;
}

/* Belt-and-braces alongside the .figure class: any img the content
   pipeline ever emits inside the reader body must scale proportionally,
   full stop, even if a future code path forgets the class. This is what
   was missing (bug: body-content figures never carried class="figure",
   so they fell back to their raw HTML height attribute -- a fixed pixel
   value -- instead of scaling with width, which is what actually
   distorted them). */
.figure img,
.reader-body img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  cursor: zoom-in;
}

.figure figcaption {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-top: var(--sp-2);
}

.figure figcaption small {
  display: block;
  color: var(--text-faint);
  margin-top: 2px;
}

/* ---- Lightbox -------------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--sp-6);
}

.lightbox__image {
  max-width: 100%;
  max-height: 90vh;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.lightbox__close {
  position: absolute;
  top: var(--sp-5);
  right: var(--sp-5);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
}

/* ---- Reader page ---------------------------------------------------------- */

.reader-main {
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--sp-6) var(--gutter) var(--sp-12);
  display: grid;
  grid-template-columns: minmax(0, var(--content-width)) 220px;
  gap: var(--sp-8);
  align-items: start;
}

.reader-main > .reader-column {
  min-width: 0;
}

.breadcrumb {
  display: flex;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-bottom: var(--sp-3);
}

.breadcrumb a {
  color: var(--text-dim);
  text-decoration: none;
}

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

.reader-title {
  font-size: var(--fs-3xl);
  line-height: var(--lh-tight);
  font-weight: 800;
  margin: 0 0 var(--sp-2);
}

.reader-dek {
  font-size: var(--fs-lg);
  color: var(--text-dim);
  margin: 0 0 var(--sp-3);
  line-height: var(--lh-normal);
}

.reader-byline {
  margin-bottom: var(--sp-4);
}

.underlying-source-note {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  margin: var(--sp-3) 0 0;
}

.underlying-source-note a {
  color: var(--accent);
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
  flex-wrap: wrap;
}

.reader-actions .bookmark-btn--label,
.reader-actions .chip {
  height: 40px;
}

.read-original-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 0 var(--sp-4);
  height: 40px;
  border-radius: var(--radius-full);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.read-original-btn:hover {
  opacity: 0.9;
}

.reader-hero {
  margin: var(--sp-6) 0;
}

.reader-hero .figure {
  max-width: var(--content-width-wide);
  margin: 0 auto;
}

.reader-hero img,
.reader-hero svg {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

/* Text-size steps scale the body only; chrome stays fixed. */
:root {
  --reader-fs: var(--fs-lg);
  --reader-lh: var(--lh-relaxed);
}

html[data-text-size="sm"] {
  --reader-fs: var(--fs-md);
}

html[data-text-size="lg"] {
  --reader-fs: 20px;
}

.reader-body {
  max-width: var(--content-width);
  font-size: var(--reader-fs);
  line-height: var(--reader-lh);
  color: var(--text);
}

.reader-body > *:first-child {
  margin-top: 0;
}

.reader-body p {
  margin: 0 0 var(--sp-5);
}

.reader-body h2,
.reader-body h3,
.reader-body h4 {
  line-height: var(--lh-tight);
  font-weight: 700;
  scroll-margin-top: calc(var(--header-height) + var(--sp-4));
}

.reader-body h2 {
  font-size: var(--fs-xl);
  margin: var(--sp-8) 0 var(--sp-3);
}

.reader-body h3 {
  font-size: var(--fs-lg);
  margin: var(--sp-6) 0 var(--sp-2);
}

.reader-body h4 {
  font-size: var(--fs-md);
  margin: var(--sp-5) 0 var(--sp-2);
}

.reader-body ul,
.reader-body ol {
  margin: 0 0 var(--sp-5);
  padding-left: 1.4em;
}

.reader-body li {
  margin-bottom: var(--sp-2);
}

.reader-body blockquote {
  margin: var(--sp-6) 0;
  padding: 2px var(--sp-5);
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
  font-style: italic;
}

.reader-body code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: var(--font-mono);
}

.reader-body pre code {
  background: none;
  padding: 0;
}

.reader-body figure {
  margin: var(--sp-6) 0;
}

.reader-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 var(--sp-5);
  font-size: 0.92em;
}

.reader-body th,
.reader-body td {
  border: 1px solid var(--border);
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
}

.table-scroll {
  overflow-x: auto;
  margin: 0 0 var(--sp-5);
}

.table-scroll table {
  margin: 0;
}

.reader-body a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--link) 50%, transparent);
}

.reader-body iframe {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: var(--sp-5) 0;
}

/* ---- Code blocks --------------------------------------------------------- */

.code-block {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  overflow-x: auto;
  margin: 0 0 var(--sp-5);
  font-size: 0.85em;
  font-family: var(--font-mono);
}

.code-block__copy {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.code-block__copy.is-copied {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Table of contents ---------------------------------------------------- */

.toc {
  position: sticky;
  top: calc(var(--header-height) + var(--sp-4));
  font-size: var(--fs-sm);
}

.toc__toggle {
  display: none;
}

.toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}

.toc__item a {
  display: block;
  padding: var(--sp-1) var(--sp-3);
  color: var(--text-dim);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1px;
}

.toc__item--h3 a {
  padding-left: var(--sp-5);
  font-size: var(--fs-xs);
}

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

.toc__item a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
}

/* ---- End of article -------------------------------------------------------- */

.end-of-article {
  margin-top: var(--sp-10);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--border);
  max-width: var(--content-width);
}

.attribution {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin: 0 0 var(--sp-4);
}

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

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-6);
}

.tag {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: var(--sp-1) var(--sp-3);
  min-height: 32px;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-decoration: none;
}

.tag:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.cross-link {
  display: inline-block;
  margin-bottom: var(--sp-6);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.cross-link:hover {
  text-decoration: underline;
}

.related {
  margin-bottom: var(--sp-8);
}

.related__title {
  font-size: var(--fs-lg);
  margin: 0 0 var(--sp-4);
}

.related__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-4);
}

.prev-next {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

.prev-next__link {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.prev-next__link:hover {
  border-color: var(--accent);
}

.prev-next__link--next {
  text-align: right;
  grid-column: 2;
}

.prev-next__label {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.prev-next__title {
  font-size: var(--fs-sm);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Fallback reader view ---------------------------------------------- */

.reader-fallback-excerpt {
  font-size: var(--reader-fs);
  line-height: var(--reader-lh);
  color: var(--text);
  max-width: var(--content-width);
  margin: var(--sp-5) 0;
}

.reader-fallback-note {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  max-width: var(--content-width);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
}

/* ---- Task-list checkboxes ("Verify it works") ------------------------- */

.reader-body input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0 var(--sp-2) 0 calc(-1 * var(--sp-1) - 20px);
  vertical-align: -4px;
  accent-color: var(--accent);
}

.reader-body ul:has(input[type="checkbox"]) {
  list-style: none;
  padding-left: 24px;
}

.reader-body ul:has(input[type="checkbox"]) li {
  min-height: 44px;
  display: flex;
  align-items: center;
}

/* ---- Step progress (project detail page) -------------------------------- */

.reader-body h2.step-heading,
.reader-body h3.step-heading {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.step-checkbox {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin-left: calc(-1 * var(--sp-3));
  cursor: pointer;
}

.step-checkbox input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
  vertical-align: initial;
  cursor: pointer;
}

.step-heading.is-done {
  color: var(--text-dim);
  text-decoration: line-through;
  text-decoration-color: var(--text-faint);
}

.toc__item--step a {
  position: relative;
}

.toc__item--step.is-done a {
  color: var(--text-faint);
  text-decoration: line-through;
}

/* ---- Tag hub and bookmarks pages ---------------------------------------- */

.content-section {
  margin: 0 auto var(--sp-2);
  padding: 0 var(--gutter);
  max-width: 1400px;
}

.content-section__title {
  font-size: var(--fs-lg);
  margin: 0 0 var(--sp-2);
}

/* ---- Trending on GitHub (Projects index page) --------------------------- */

.trending-section {
  padding: var(--sp-6) var(--gutter) var(--sp-10);
  max-width: 1400px;
  margin: 0 auto;
  border-top: 1px solid var(--border);
}

.trending-section__lead {
  color: var(--text-dim);
  font-size: var(--fs-sm);
  margin: 0 0 var(--sp-5);
  max-width: 60ch;
}

.trending-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-4);
}

.trending-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  text-decoration: none;
  color: inherit;
}

.trending-card:hover {
  border-color: var(--accent);
}

.trending-card__top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
}

.trending-card__stars {
  font-weight: 600;
  color: var(--text);
}

.trending-card__lang,
.trending-card__category {
  color: var(--text-faint);
}

.trending-card__category {
  margin-left: auto;
}

.trending-card__name {
  font-size: var(--fs-base);
  font-weight: 600;
  margin: 0;
  overflow-wrap: anywhere;
}

.trending-card__desc {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.bookmark-fallback-list {
  list-style: none;
  margin: 0 auto var(--sp-8);
  padding: 0 var(--gutter);
  max-width: 1400px;
}

.bookmark-fallback-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-2);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}

.bookmark-fallback-row a {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.bookmark-fallback-row a:hover {
  color: var(--accent);
}

.bookmark-fallback-row__meta {
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

/* ---- Requirements box (project detail page) ---------------------------- */

.requirements-box {
  max-width: var(--content-width-wide);
  margin: 0 auto var(--sp-8);
  padding: var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}

.requirements-summary {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-6);
}

.requirements-summary__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.requirements-summary__label {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.requirements-summary__value {
  font-size: var(--fs-lg);
  font-weight: 700;
}

.requirements-box__note {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin: var(--sp-3) 0 0;
}

.requirements-box__heading {
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin: var(--sp-5) 0 var(--sp-2);
}

.requirements-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
}

.requirements-list li {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
}

.requirements-list a {
  color: var(--link);
  text-decoration: underline;
}

.requirements-list__version {
  color: var(--text-faint);
  font-size: var(--fs-xs);
}

.requirements-list__optional {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}

.requirements-box__tested {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  margin: var(--sp-5) 0 0;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.requirements-box__stale-notice {
  margin: var(--sp-4) 0 0;
  max-width: none;
}

/* ---- Projects index / category page ------------------------------------ */

.page-header {
  max-width: var(--content-width-wide);
  padding: var(--sp-6) var(--gutter) 0;
  margin: 0 auto;
}

.page-header h1 {
  font-size: var(--fs-3xl);
  margin: 0 0 var(--sp-2);
}

.page-header__lead {
  color: var(--text-dim);
  font-size: var(--fs-lg);
  margin: 0;
  max-width: 70ch;
}

#category-breadcrumb {
  max-width: var(--content-width-wide);
  margin: var(--sp-4) auto 0;
  padding: 0 var(--gutter);
}

.search-box {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 var(--sp-4);
  height: 40px;
  min-width: 220px;
}

.search-box input {
  flex: 1;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  outline: none;
}

.search-box svg {
  color: var(--text-faint);
  flex-shrink: 0;
}

/* ---- Responsive ---------------------------------------------------------- */

@media (max-width: 960px) {
  .reader-main {
    grid-template-columns: 1fr;
    max-width: var(--content-width);
  }

  .toc {
    position: static;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-3) var(--sp-4);
    margin-bottom: var(--sp-6);
  }

  .toc__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--sp-1) 0;
    font-weight: 600;
  }

  .toc__toggle svg:last-child {
    transition: transform var(--duration) var(--ease);
  }

  .toc__toggle[aria-expanded="true"] svg:last-child {
    transform: rotate(180deg);
  }

  .toc__list {
    display: none;
    border-left: none;
    margin-top: var(--sp-2);
  }

  .toc.is-open .toc__list {
    display: block;
  }
}

@media (max-width: 640px) {
  .requirements-box {
    padding: var(--sp-4);
    margin-left: var(--gutter-mobile);
    margin-right: var(--gutter-mobile);
    width: auto;
  }

  .requirements-summary {
    gap: var(--sp-4);
  }

  .search-box {
    width: 100%;
    min-width: 0;
  }

  /* Anchored to the icon button's own right edge, a panel this wide
     overflows off the left of a narrow viewport (the button sits near,
     not at, the screen edge) -- pin it to the viewport itself instead. */
  .site-search__panel {
    position: fixed;
    top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    left: var(--gutter-mobile);
    right: var(--gutter-mobile);
    width: auto;
  }

  .site-header__inner,
  .site-header__condensed,
  .filter-bar {
    padding-left: var(--gutter-mobile);
    padding-right: var(--gutter-mobile);
  }

  .site-nav {
    order: 3;
    width: 100%;
    margin-right: 0;
    gap: var(--sp-5);
  }

  .meta-summary {
    display: none;
  }

  .article-grid {
    grid-template-columns: 1fr;
    padding: var(--gutter-mobile);
  }

  .reader-main {
    padding: var(--sp-4) var(--gutter-mobile) var(--sp-10);
  }

  .reader-title {
    font-size: var(--fs-2xl);
  }

  .prev-next {
    grid-template-columns: 1fr;
  }

  .prev-next__link--next {
    grid-column: 1;
    text-align: left;
  }

  html {
    --reader-fs: var(--fs-md);
  }

  html[data-text-size="lg"] {
    --reader-fs: var(--fs-lg);
  }
}
