/*
  Article-only rules for the long-form writing template.
  Loaded after /assets/css/site.css, which supplies tokens, the topbar,
  the footer, .page, and the base h1/section/hero rules. Everything here
  is specific to a 2,000+ word technical piece: table of contents,
  numbered principles, Mermaid diagrams, data tables, code blocks with
  copy buttons, and the reading-progress bar.
*/

/* ── layout ─────────────────────────────────────────────── */

.article {
  width: min(100%, var(--article, 760px));
  margin: 0 auto;
  min-width: 0;
}

.wide {
  width: min(calc(100vw - 64px), var(--wide, 960px));
  margin-left: 50%;
  transform: translateX(-50%);
  min-width: 0;
}

:root {
  --article: 760px;
  --wide: 960px;
  --radius: 13px;
}

section[id] {
  scroll-margin-top: calc(var(--topbar) + 24px);
}

/* The homepage hero is a full-viewport-height flex block; an article hero
   is a plain padded block above the prose. */
.hero {
  min-height: auto;
  display: block;
  padding: 98px 0 70px;
}

/* ── reading progress ───────────────────────────────────── */
/* A 2,700-word article is exactly where a progress indicator communicates
   real state, so — unlike the homepage — this stays. */

.progress {
  position: fixed;
  top: var(--topbar);
  left: 0;
  z-index: 50;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  box-shadow: 0 0 10px rgba(154, 109, 179, .4);
  pointer-events: none;
}

/* ── article hero ───────────────────────────────────────── */

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 15px;
  margin-bottom: 27px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .015em;
}

.meta .category {
  color: var(--accent-strong);
}

.dek {
  max-width: 760px;
  margin: 29px 0 0;
  color: var(--body);
  font-size: clamp(18px, 2vw, 22px);
  line-height: 1.56;
  letter-spacing: -.006em;
  text-wrap: pretty;
}

.thesis {
  margin: 40px 0 0;
  padding-top: 23px;
  border-top: 1px solid var(--line);
  color: #fff;
  font-size: 15px;
  font-weight: 560;
  letter-spacing: .003em;
}

/* ── article body ───────────────────────────────────────── */

main {
  padding-bottom: 98px;
}

section {
  padding: 72px 0;
}

section:last-child {
  border-bottom: 0;
}

h2 {
  margin: 0 0 24px;
  color: #fff;
  font-size: clamp(28px, 3.7vw, 42px);
  line-height: 1.15;
  letter-spacing: -.01em;
  font-weight: 600;
  text-wrap: balance;
  overflow-wrap: break-word;
  hyphens: auto;
}

h3 {
  margin: 45px 0 12px;
  color: #fff;
  font-size: 21px;
  line-height: 1.3;
  letter-spacing: -.006em;
  font-weight: 600;
}

p {
  margin: 0 0 20px;
  color: var(--body);
}

strong {
  color: #fff;
  font-weight: 620;
}

.lead {
  color: var(--text);
  font-size: 19px;
  line-height: 1.66;
}

blockquote {
  margin: 39px 0;
  padding: 0 0 0 23px;
  border-left: 2px solid var(--accent);
  color: var(--text);
  font-size: 21px;
  line-height: 1.52;
  letter-spacing: -.008em;
}

.note {
  margin: 29px 0;
  padding: 17px 19px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(154, 109, 179, .07);
  color: var(--body);
  font-size: 14px;
  line-height: 1.62;
}

.ref-call {
  margin-left: 2px;
  color: var(--accent-strong);
  font-size: .66em;
  text-decoration: none;
  vertical-align: super;
}

a {
  color: var(--accent-strong);
  text-decoration-color: rgba(185, 142, 214, .35);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: #fff;
  text-decoration-color: #fff;
}

code, pre {
  font-family: var(--font-mono), "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

:not(pre) > code {
  padding: .12em .34em;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font-size: .88em;
  white-space: nowrap;
}

/* ── contents ───────────────────────────────────────────── */

.toc {
  padding: 25px 0 5px;
}

.toc-title {
  margin-bottom: 12px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .14em;
}

.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 25px;
}

.toc a {
  display: flex;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-decoration: none;
}

.toc a span {
  flex: 0 0 auto;
  color: var(--faint);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.toc a:hover {
  color: #fff;
}

/* ── principles ─────────────────────────────────────────── */

.principles {
  margin-top: 35px;
  border-top: 1px solid var(--line);
}

.principle {
  display: grid;
  grid-template-columns: 48px 205px minmax(0, 1fr);
  gap: 18px;
  padding: 19px 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.principle .n {
  color: var(--faint);
  font: 12px/1.6 var(--font-mono);
}

.principle .title {
  color: #fff;
  font-weight: 610;
}

.principle .desc {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

/* ── diagrams ───────────────────────────────────────────── */

.diagram {
  margin-top: 37px;
  margin-bottom: 37px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.diagram-label {
  margin-bottom: 18px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .13em;
  text-align: left;
}

.mermaid {
  width: 100% !important;
  min-width: 0 !important;
  margin: 0 auto !important;
  padding: 0 !important;
  display: grid !important;
  place-items: center !important;
  text-align: center !important;
}

.mermaid svg {
  display: block !important;
  float: none !important;
  max-width: 100% !important;
  height: auto !important;
  margin-inline: auto !important;
}

/* Sequence diagrams include actors, notes and lifelines outside the main
   content group. Preserve Mermaid's native viewBox instead of cropping it. */
.diagram-native-viewbox {
  overflow: visible;
}

.diagram-native-viewbox .mermaid {
  padding: 8px 14px 14px !important;
}

.diagram-native-viewbox .mermaid svg {
  width: min(100%, 820px) !important;
  max-width: 100% !important;
  overflow: visible !important;
}

/* ── tables ─────────────────────────────────────────────── */

.table-wrap {
  margin-top: 33px;
  margin-bottom: 33px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .008);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

caption {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

th, td {
  padding: 14px 15px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.55;
}

tr:last-child td {
  border-bottom: 0;
}

th {
  color: var(--faint);
  background: rgba(255, 255, 255, .018);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 680;
  text-transform: uppercase;
  letter-spacing: .115em;
}

td {
  color: var(--body);
}

.reference-table th:nth-child(1),
.reference-table td:nth-child(1) { width: 22%; }

.reference-table th:nth-child(2),
.reference-table td:nth-child(2) { width: 25%; }

.validation-table th:nth-child(1),
.validation-table td:nth-child(1) { width: 25%; }

.validation-table th:nth-child(2),
.validation-table td:nth-child(2) { width: 18%; }

.status {
  color: var(--accent-strong);
  font-weight: 680;
}

/* ── code ───────────────────────────────────────────────── */

.code-block {
  position: relative;
  margin: 29px 0;
}

pre:not(.mermaid) {
  margin: 0;
  padding: 43px 20px 20px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #080709;
  color: var(--text);
  font-size: 13px;
  line-height: 1.64;
  tab-size: 2;
  -webkit-overflow-scrolling: touch;
}

.copy {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 2;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(13, 11, 16, .94);
  color: var(--muted);
  font: inherit;
  font-family: var(--font-mono);
  font-size: 10px;
  cursor: pointer;
}

.copy:hover {
  color: #fff;
  border-color: var(--accent);
}

/* ── findings / roadmap / metrics ───────────────────────── */

.finding {
  padding: 23px 0;
  border-top: 1px solid var(--line);
}

.finding:last-child {
  border-bottom: 1px solid var(--line);
}

.finding-head {
  display: flex;
  gap: 13px;
  align-items: baseline;
  margin-bottom: 8px;
}

.finding-num {
  flex: 0 0 auto;
  color: var(--faint);
  font: 11px var(--font-mono);
}

.finding-title {
  color: #fff;
  font-weight: 620;
}

.finding p {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.62;
}

.roadmap {
  margin-top: 29px;
  border-top: 1px solid var(--line);
}

.roadmap-item {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 17px;
  padding: 17px 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.version {
  padding-top: 3px;
  color: var(--accent-strong);
  font: 11px var(--font-mono);
  white-space: nowrap;
}

.roadmap-item h3 {
  margin: 0 0 5px;
  font-size: 16px;
}

.roadmap-item p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

/* ── references / footer ────────────────────────────────── */

.refs {
  padding-left: 22px;
  color: var(--muted);
  font-size: 14px;
}

.refs li {
  margin-bottom: 8px;
  scroll-margin-top: calc(var(--topbar) + 20px);
}

footer {
  width: 100%;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 12px;
  line-height: 1.65;
}

.footer-inner {
  width: min(calc(100% - 40px), var(--article));
  margin: 0 auto;
  min-width: 0;
}

.footer-copy {
  display: block;
  max-width: 680px;
  overflow-wrap: anywhere;
}

/* ── global responsive safeguards ───────────────────────── */

main,
header,
footer,
section,
.article,
.wide,
.diagram,
.table-wrap,
.code-block,
.principle,
.finding,
.roadmap-item {
  min-width: 0;
}

pre,
code,
.finding-title,
.roadmap-item p,
.principle .desc {
  overflow-wrap: anywhere;
}

/* ── laptop / tablet ─────────────────────────────────────── */

@media (max-width: 1024px) {
  .wide {
    width: min(calc(100vw - 32px), 900px);
  }

  .diagram {
    padding: 22px 20px;
  }
}

/* ── mobile ──────────────────────────────────────────────── */

@media (max-width: 760px) {
  .footer-inner {
    width: calc(100% - 24px);
  }

  .footer-copy {
    max-width: 100%;
  }

  .hero {
    padding: 66px 0 52px;
  }

  .dek {
    margin-top: 24px;
    font-size: 17px;
    line-height: 1.58;
  }

  .thesis {
    margin-top: 31px;
    padding-top: 20px;
    font-size: 14px;
    line-height: 1.55;
  }

  .toc {
    padding-top: 21px;
  }

  .toc ol {
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
  }

  section {
    padding: 54px 0;
  }

  h3 {
    margin-top: 38px;
    font-size: 20px;
  }

  .lead {
    font-size: 17px;
  }

  blockquote {
    margin: 31px 0;
    padding-left: 17px;
    font-size: 18px;
    line-height: 1.55;
  }

  .wide {
    width: 100%;
    margin-left: 0;
    transform: none;
  }

  .principle {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 12px;
    padding: 17px 0;
  }

  .principle .title {
    line-height: 1.5;
  }

  .principle .desc {
    grid-column: 2;
    font-size: 14px;
  }

  .diagram {
    width: 100%;
    margin: 27px auto;
    padding: 17px 10px 15px;
    overflow: hidden;
  }

  .diagram-label {
    margin-bottom: 14px;
    padding-left: 2px;
  }

  .mermaid svg {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
  }

  .diagram-native-viewbox {
    overflow: hidden;
  }

  .diagram-native-viewbox .mermaid {
    padding: 6px 4px 10px !important;
  }

  .diagram-native-viewbox .mermaid svg {
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  /* Mobile tables become readable stacked records, not tiny horizontal tables. */
  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100% !important;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  tr {
    margin-bottom: 11px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
  }

  td {
    display: grid;
    grid-template-columns: 105px minmax(0, 1fr);
    gap: 12px;
    padding: 7px 0;
    border: 0 !important;
    font-size: 13px;
  }

  td::before {
    content: attr(data-label);
    color: var(--faint);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 680;
    text-transform: uppercase;
    letter-spacing: .09em;
  }

  .code-block {
    margin: 25px 0;
  }

  pre:not(.mermaid) {
    padding: 41px 14px 16px;
    font-size: 12px;
    line-height: 1.62;
  }

  .copy {
    top: 8px;
    right: 8px;
  }

  .finding-head {
    align-items: flex-start;
  }

  .roadmap-item {
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 12px;
  }

  :not(pre) > code {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 430px) {
  .footer-inner {
    width: calc(100% - 20px);
  }

  .hero {
    padding-top: 55px;
    padding-bottom: 48px;
  }

  .meta {
    gap: 6px 12px;
  }

  .diagram {
    padding-inline: 8px;
  }

  td {
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 10px;
  }

  .roadmap-item {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
  }

  .version {
    padding-top: 0;
  }
}

@media (max-width: 360px) {
  .footer-inner {
    width: calc(100% - 16px);
  }

  section {
    padding: 48px 0;
  }

  .diagram {
    padding-inline: 6px;
  }

  td {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
  }

  td::before {
    margin-top: 2px;
  }

  pre:not(.mermaid) {
    font-size: 11px;
    padding-inline: 12px;
  }

  .finding-head {
    gap: 9px;
  }
}
