/* ============================================================
   The Clean Paper — article layout
   The body fills the wide container (aligned to the nav, left & right).
   The contents rail floats fixed at the window's right edge and
   collapses via a pure-CSS toggle (no JavaScript).
   ============================================================ */

/* ----- header: left-aligned to the wide container ----- */
.article-header {
  text-align: left;
  padding: var(--space-7) 0 var(--space-6);
}
.article-header > .container-header {
  width: min(calc(100% - 2rem), var(--container-wide));
  max-width: none;
  margin-inline: auto;          /* centre the container so its left edge matches body + nav */
}
.article-header h1 {
  margin-inline: 0;
  max-width: none;
  font-size: clamp(2rem, 4.4vw, 3.3rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
}
.article-header .article-dek {
  margin-inline: 0;
  max-width: none;
  font-size: 1.2rem;            /* match the body */
  text-align: left;             /* ragged-right, NOT justified */
}
.article-header .article-meta-row { justify-content: flex-start; }

/* ----- body: fills the wide container, slightly larger type ----- */
.article-shell {
  width: min(calc(100% - 2rem), var(--container-wide));
  margin-inline: auto;
  padding-bottom: var(--space-9);
}
.article-main {
  padding-top: var(--space-4);
  font-size: 1.2rem;            /* matched with the dek */
  line-height: 1.7;
}
.article-main .article-section { scroll-margin-top: var(--space-6); }
.article-main .article-section > h2 { margin-top: var(--space-7); }
.article-main .article-section:first-child > h2 { margin-top: 0; }
.article-main .callout { max-width: none; }

/* ----- figures ----- */
.article-figure { margin: var(--space-7) 0; }
.article-figure img {
  display: block;
  width: 100%;
  height: auto;
  border: var(--border-subtle);
  border-radius: var(--radius-md, 6px);
  background: #ffffff;
}
.article-figure figcaption {
  margin-top: var(--space-3);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--tcp-stone);
}
.article-figure .fig-credit {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  color: var(--tcp-stone);
  opacity: 0.75;
}

/* ----- writer's note: optional, collapsible teaching aside (JS-free) ----- */
.writer-note {
  margin: var(--space-6) 0;
  border: var(--border-subtle);
  border-left: 3px solid var(--tcp-gold);
  border-radius: var(--radius-md, 6px);
  background: color-mix(in srgb, var(--tcp-parchment) 12%, var(--tcp-paper));
}
.writer-note > summary {
  cursor: pointer;
  list-style: none;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--tcp-teal);
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}
.writer-note > summary::-webkit-details-marker { display: none; }
.writer-note > summary::before {
  content: "\25B8";                    /* ▸ */
  color: var(--tcp-gold);
  font-size: 0.85em;
  transition: transform 0.15s ease;
  display: inline-block;
}
.writer-note[open] > summary::before { transform: rotate(90deg); }
.writer-note > summary:hover { color: var(--tcp-ink); }
.writer-note-body {
  padding: 0 var(--space-5) var(--space-4) calc(var(--space-4) + 1.1rem);
  font-size: 0.98rem;
  line-height: 1.65;
  color: var(--tcp-stone);
}
.writer-note-body > *:first-child { margin-top: 0; }
.writer-note-body > *:last-child { margin-bottom: 0; }

/* ============================================================
   Contents rail
   Base = in the flow, just below the dek: a compact meta strip (fields laid
   out horizontally, wrapping) + a collapsible table of contents. On wide
   screens (>= 1660px, where it fits beside the 1180px column) it becomes a
   floating panel pinned to the window's right edge. JS-free (checkboxes).
   ============================================================ */
.article-rail {
  width: min(calc(100% - 2rem), var(--container-wide));
  margin: 0 auto var(--space-7);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--tcp-stone);
}
.rail-open,
.rail-close { display: none; }                 /* floating-only controls, hidden in the flow */

/* meta: a boxed, horizontal, wrapping strip */
.rail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-6);
  padding: var(--space-4) var(--space-5);
  border: var(--border-subtle);
  border-radius: var(--radius-md, 6px);
  background: color-mix(in srgb, var(--tcp-parchment) 10%, var(--tcp-paper));
}
.rail-meta > div { line-height: 1.35; }
.rail-meta .k {
  display: block;
  color: var(--tcp-gold);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.05rem;
}
.rail-meta a { word-break: break-word; }

/* contents: collapsed by default in the flow (JS-free checkbox toggle) */
.rail-toc-block {
  margin-top: var(--space-4);
  border: var(--border-subtle);
  border-radius: var(--radius-md, 6px);
  background: var(--tcp-paper);
}
.rail-toc-summary {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--tcp-gold);
}
.rail-toc-summary::before {
  content: "\25B8";
  font-size: 0.85em;
  transition: transform 0.15s ease;
}
.toc-toggle:checked ~ .rail-toc-summary::before { transform: rotate(90deg); }
.rail-toc {
  display: none;
  list-style: none;
  counter-reset: toc;
  margin: 0;
  padding: 0 var(--space-4) var(--space-4);
}
.toc-toggle:checked ~ .rail-toc { display: block; }
.rail-toc li { counter-increment: toc; }
.rail-toc a {
  display: block;
  position: relative;
  padding: 0.22rem 0 0.22rem 1.9rem;
  color: var(--tcp-stone);
  text-decoration: none;
  line-height: 1.3;
}
.rail-toc a::before {
  content: counter(toc) ".";
  position: absolute;
  left: 0;
  top: 0.22rem;
  width: 1.4rem;
  text-align: right;
  color: var(--tcp-gold);
  font-variant-numeric: tabular-nums;
}
.rail-toc a:hover,
.rail-toc a:hover::before { color: var(--tcp-ink); }

/* ----- wide screens: float the rail at the window's right edge ----- */
@media (min-width: 1660px) {
  .article-rail {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 15rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    margin: 0;
    padding: var(--space-5);
    background: var(--tcp-paper);
    border: var(--border-subtle);
    border-right: none;
    border-top-left-radius: var(--radius-md, 8px);
    border-bottom-left-radius: var(--radius-md, 8px);
    box-shadow: -10px 0 28px -20px rgba(4, 32, 52, 0.3);
    transition: transform 0.25s ease;
    z-index: 30;
  }
  .rail-toggle:not(:checked) ~ .article-rail { transform: translate(100%, -50%); }

  .rail-close {
    display: grid;
    position: absolute;
    top: 0.35rem;
    right: 0.5rem;
    width: 1.7rem;
    height: 1.7rem;
    place-items: center;
    border-radius: 50%;
    color: var(--tcp-stone);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
  }
  .rail-close:hover { color: var(--tcp-ink); background: var(--tcp-mist); }

  .rail-open {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    place-items: center;
    width: 1.4rem;
    height: 3.4rem;
    background: var(--tcp-paper);
    border: var(--border-subtle);
    border-right: none;
    border-top-left-radius: var(--radius-md, 8px);
    border-bottom-left-radius: var(--radius-md, 8px);
    color: var(--tcp-gold);
    cursor: pointer;
    user-select: none;
    z-index: 31;
  }
  .rail-open::before { content: "\2039"; font-size: 1.1rem; line-height: 1; }
  .rail-toggle:not(:checked) ~ .rail-open { display: grid; }

  /* meta: stacked column inside the narrow panel */
  .rail-meta {
    display: block;
    padding: 0;
    border: none;
    background: none;
    margin-bottom: var(--space-6);
  }
  .rail-meta > div { margin-bottom: var(--space-3); }

  /* contents: always visible inside the panel (toggle becomes a plain label) */
  .rail-toc-block { margin-top: 0; border: none; background: none; }
  .rail-toc-summary { cursor: default; padding: 0 0 var(--space-3); }
  .rail-toc-summary::before { content: none; }
  .rail-toc { display: block; padding: 0; }
}

/* ---- byline + contributor IDs (foot of the article) ---------------------- */
.article-byline {
  max-width: none;
  margin: var(--space-6) 0 var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--tcp-line, rgba(4, 32, 52, 0.12));
  font-size: 0.95rem;
  line-height: 1.6;
}
.article-byline .byline-people { margin: 0; color: var(--tcp-ink); }
.article-byline .byline-pub {
  margin: var(--space-2) 0 0;
  color: var(--tcp-stone);
  font-size: 0.88rem;
}
.article-byline .author { white-space: nowrap; }
.article-byline .id-link {
  margin-left: 0.28em;
  vertical-align: -0.16em;
  line-height: 0;
}
.article-byline .id-icon { height: 1.05em; width: auto; display: inline-block; }

/* ----- language switcher: a sober, JS-free dropdown in the nav ----------------
   Shows the current language; opens a small menu of the languages this page is
   actually published in. Only rendered when there is more than one. Built on the
   same <details> idiom as the writer-note / contents rail (no JavaScript). */
.lang-switcher {
  position: relative;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}
.lang-switcher > summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.6rem;
  border: var(--border-subtle);
  border-radius: var(--radius-md, 6px);
  color: var(--tcp-stone);
  white-space: nowrap;
  user-select: none;
}
.lang-switcher > summary::-webkit-details-marker { display: none; }
.lang-switcher > summary::after {
  content: "\25BE";                       /* ▾ */
  font-size: 0.8em;
  color: var(--tcp-gold);
  transition: transform 0.15s ease;
}
.lang-switcher[open] > summary::after { transform: rotate(180deg); }
.lang-switcher > summary:hover { color: var(--tcp-ink); border-color: var(--tcp-gold); }
.lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 40;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  min-width: 100%;
  background: var(--tcp-paper);
  border: var(--border-subtle);
  border-radius: var(--radius-md, 6px);
  box-shadow: 0 8px 24px -14px rgba(4, 32, 52, 0.35);
}
.lang-menu li { margin: 0; }
.lang-menu a {
  display: block;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm, 4px);
  color: var(--tcp-stone);
  text-decoration: none;
  white-space: nowrap;
}
.lang-menu a:hover { background: var(--tcp-mist, color-mix(in srgb, var(--tcp-parchment) 30%, var(--tcp-paper))); color: var(--tcp-ink); }
.lang-menu a[aria-current="true"] { color: var(--tcp-teal); font-weight: 600; }
