/* ═══════════════════════════════════════════════
   LDP Explainer — Editorial academic explainer
   Extends /css/style.css
   ═══════════════════════════════════════════════ */

/* ── Skip link ── */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  z-index: 100;
  font-size: 13px;
}
.skip-link:focus { top: 0; }

/* ── Article shell ── */
.explainer {
  padding: 56px 0 80px;
  width: min(var(--max), calc(100% - 48px));
  margin: 0 auto;
  position: relative;
}

/* ── Header ── */
.explainer-header {
  margin-bottom: 48px;
  padding-bottom: 36px;
  border-bottom: 1px solid var(--border);
}

.explainer-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--light);
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.explainer h1 {
  font-family: var(--heading);
  font-size: clamp(26px, 3.5vw, 36px);
  line-height: 1.18;
  letter-spacing: -0.3px;
  font-weight: 500;
  margin-bottom: 12px;
}

.explainer-meta {
  font-size: 13px;
  color: var(--light);
  margin-bottom: 24px;
}

.explainer-meta a {
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
}
.explainer-meta a:hover {
  color: var(--text);
  border-color: var(--text);
  opacity: 1;
}

.explainer-abstract {
  font-size: 16px;
  line-height: 1.8;
  color: var(--muted);
  max-width: 60ch;
}

/* ── Table of Contents (fixed sidebar, wide screens only) ── */
.toc {
  display: none;
}

@media (min-width: 1440px) {
  .toc {
    display: block;
    position: fixed;
    top: 140px;
    /* Position to the right of the wide figures (900px) with gap */
    left: calc(50% + var(--max-wide) / 2 + 48px);
    width: 160px;
    font-size: 12px;
    z-index: 10;
  }

  .toc-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--light);
    margin-bottom: 14px;
    font-weight: 500;
  }

  .toc ol {
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .toc li {
    margin-bottom: 0;
  }

  .toc-link {
    display: block;
    padding: 5px 0 5px 12px;
    color: var(--light);
    border-left: 1.5px solid var(--border);
    transition: color 0.2s, border-color 0.2s;
    line-height: 1.4;
    font-size: 12px;
  }

  .toc-link:hover {
    color: var(--muted);
    opacity: 1;
  }

  .toc-link.active {
    color: var(--text);
    border-left-color: var(--text);
  }
}

/* ── Prose ── */
.explainer section {
  margin-bottom: 0;
  scroll-margin-top: 24px;
}

.explainer h2 {
  font-family: var(--heading);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.1px;
  color: var(--text);
  margin: 48px 0 12px;
  scroll-margin-top: 32px;
}

.explainer section:first-of-type h2 {
  margin-top: 0;
}

.explainer h2:focus {
  outline: none;
}

.explainer p {
  font-size: 16px;
  line-height: 1.8;
  color: var(--muted);
  margin: 20px 0;
}

.explainer strong {
  color: var(--text);
}

.explainer code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: rgba(0,0,0,0.04);
  padding: 2px 5px;
  border-radius: 3px;
}

.explainer hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 64px 0;
}

/* ── Section visual separation ── */
.explainer section {
  padding-top: 8px;
}

.section-number {
  font-family: var(--heading);
  font-size: 64px;
  font-weight: 400;
  color: var(--border);
  line-height: 1;
  margin-bottom: -8px;
  letter-spacing: -2px;
  user-select: none;
}

/* Key finding badge */
.key-finding {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--bg);
  background: var(--text);
  padding: 3px 10px;
  border-radius: 2px;
  margin-left: 12px;
  vertical-align: middle;
  position: relative;
  top: -2px;
}

/* Highlighted section — subtle left accent */
.deep-dive--highlight {
  border-left: 3px solid var(--text);
  padding-left: 24px;
  margin-left: -27px;
}

@media (max-width: 768px) {
  .deep-dive--highlight {
    border-left: none;
    padding-left: 0;
    margin-left: 0;
  }
}

/* ── Paper quote ── */
.paper-quote {
  margin: 24px 0;
  padding: 16px 20px;
  border-left: 2px solid var(--border);
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
  font-style: italic;
}

.paper-quote cite {
  display: block;
  margin-top: 8px;
  font-style: normal;
  font-size: 12px;
  color: var(--light);
  font-family: var(--mono);
}

.paper-quote cite a {
  color: var(--light);
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
}

.paper-quote cite a:hover {
  color: var(--muted);
  border-color: var(--muted);
  opacity: 1;
}

/* RQ box links */
.rq-box a {
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
}

.rq-box a:hover {
  border-color: var(--text);
  opacity: 1;
}

/* Setup box links */
.setup-box a {
  color: var(--light);
  border-bottom: none;
}

.setup-box a:hover {
  color: var(--muted);
  opacity: 1;
}

/* Prose links — scoped to avoid TOC, cards, profiles */
.explainer section p a,
.explainer .explainer-abstract a,
.explainer .caveat a,
.explainer .insight a,
.explainer figcaption a {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
}
.explainer section p a:hover,
.explainer .explainer-abstract a:hover,
.explainer figcaption a:hover {
  border-color: var(--text);
  opacity: 1;
}

/* ── Figures — break out of the narrow column ── */
.figure--wide {
  --fig-width: min(var(--max-wide), calc(100vw - 48px));
  width: var(--fig-width);
  margin-left: calc((var(--fig-width) - 100%) / -2);
  margin-top: 40px;
  margin-bottom: 40px;
  /* Subtle background to distinguish from prose */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 32px;
}

@media (max-width: 920px) {
  .figure--wide {
    width: 100%;
    margin-left: 0;
    padding: 20px;
  }
}

figcaption {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

figcaption strong {
  color: var(--text);
  font-weight: 500;
}

.fig-note {
  font-style: italic;
  color: var(--light);
}

/* ── Chart containers ── */
.chart-container {
  width: 100%;
  min-height: 120px;
  position: relative;
}

.chart-container svg {
  width: 100%;
  display: block;
}

/* Noscript data tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: var(--mono);
}

.data-table th {
  text-align: left;
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--light);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

/* ── Research question box ── */
.rq-box {
  margin: 0 0 24px 0;
  padding: 14px 20px;
  border-left: 3px solid var(--text);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: rgba(0,0,0,0.02);
  border-radius: 0 4px 4px 0;
  font-style: normal;
}

.rq-box strong {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.5px;
}

/* ── Setup box ── */
.setup-box {
  margin: 0 0 48px 0;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
}

.setup-box .setup-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--light);
  margin: 0 0 10px 0;
  font-weight: 500;
}

.setup-box p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.setup-box strong {
  color: var(--text);
  font-weight: 500;
}

/* ── Session detail ── */
.session-detail {
  margin-top: 12px;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--muted);
  min-height: 20px;
}

/* ── Caveat ── */
.caveat {
  margin: 32px 0;
  padding: 16px 20px;
  border-left: 2px solid var(--border);
  font-size: 14px;
  color: var(--muted);
  line-height: 1.7;
}

.caveat p {
  font-size: 14px;
  margin: 0;
  color: var(--muted);
}

.caveat strong {
  color: var(--muted);
  font-weight: 600;
}

/* ── Routing diagram ── */
.routing-diagram {
  display: grid;
  grid-template-columns: 1fr 120px 1fr;
  gap: 0;
  align-items: start;
  position: relative;
  max-width: 100%;
  margin: 0 auto;
  padding: 8px 0;
}

.routing-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.routing-lines {
  position: relative;
  min-height: 100%;
}

.routing-card {
  padding: 12px 14px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.routing-model {
  padding: 12px 14px;
  border-radius: 4px;
  background: var(--text);
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  line-height: 1.4;
}

.routing-tag {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.5;
  margin-bottom: 2px;
}

.routing-latency {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
  color: var(--text);
  transition: color 0.3s;
}

.routing-latency.fast { color: var(--text); }
.routing-latency.slow { color: var(--light); }

.routing-summary {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.routing-savings {
  font-weight: 500;
  color: var(--text);
}

.routing-lines line {
  stroke-width: 1.5;
  fill: none;
  transition: opacity 0.3s;
}
.routing-lines line.a2a { stroke: var(--light); stroke-dasharray: 4 3; }
.routing-lines line.ldp { stroke: var(--text); stroke-width: 2; }

/* ── Toggle bar ── */
.toggle-bar {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  width: fit-content;
}

.toggle-btn {
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--light);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.toggle-btn:last-child { border-right: none; }
.toggle-btn:hover { color: var(--text); }
.toggle-btn.active {
  background: var(--text);
  color: var(--bg);
}

/* ── Provenance detail ── */
.prov-detail {
  margin-top: 12px;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--muted);
  min-height: 20px;
  transition: opacity 0.2s;
}

/* ── Attack simulation ── */
.attack-sim {
  margin-bottom: 24px;
}

.attack-scene {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 16px;
  padding: 16px 0;
}

.attack-agent {
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.4;
  min-width: 140px;
  text-align: center;
}

.attack-legit {
  background: var(--text);
  color: rgba(255,255,255,0.7);
}

.attack-impersonator {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  transition: border-color 0.3s, box-shadow 0.3s;
}

.attack-impersonator.blocked {
  border-color: #cc4444;
  box-shadow: 0 0 0 2px rgba(204,68,68,0.15);
}

.attack-impersonator.passed {
  border-color: var(--text);
}

.attack-boundary {
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.attack-boundary::before {
  content: '';
  position: absolute;
  top: -12px;
  bottom: -12px;
  left: 50%;
  width: 2px;
  background: var(--border);
  transition: background 0.3s;
}

.attack-boundary.detected::before {
  background: #cc4444;
}

.attack-boundary.passed::before {
  background: var(--text);
}

.attack-boundary-label {
  font-size: 9px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--light);
  background: var(--surface);
  padding: 2px 6px;
  position: relative;
  z-index: 1;
  white-space: nowrap;
  transition: color 0.3s;
}

.attack-boundary.detected .attack-boundary-label {
  color: #cc4444;
}

.attack-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.attack-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 18px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

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

.attack-result {
  text-align: center;
  margin-top: 12px;
  font-size: 13px;
  font-family: var(--mono);
  min-height: 20px;
  transition: opacity 0.2s;
}

.attack-result.detected { color: #cc4444; }
.attack-result.passed { color: var(--muted); }

/* ── Payload comparison ── */
.payload-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 0;
}

.payload-example {
  border-radius: 4px;
  padding: 20px;
}

.payload-text {
  background: var(--bg);
  border: 1px solid var(--border);
}

.payload-frame {
  background: var(--text);
  color: rgba(255,255,255,0.75);
}

.payload-head {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.5;
  margin: 0 0 10px 0;
}

.payload-code {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
  margin: 0;
}

.payload-stat {
  margin: 12px 0 0 0;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.payload-frame .payload-stat {
  color: rgba(255,255,255,0.9);
}

.payload-delta {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.5;
  margin-left: 6px;
}

/* ── Links grid ── */
.link-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 32px 0;
}

a.link-card {
  display: block;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: border-color 0.2s;
}

.explainer a.link-card {
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.link-card:hover {
  border-color: var(--text);
  opacity: 1;
}

.link-card-label {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--light);
  margin-bottom: 3px;
}

.link-card span:last-child {
  font-size: 14px;
  color: var(--text);
}

/* ── BibTeX ── */
.bibtex-details {
  margin: 32px 0;
}

.bibtex-details summary {
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.bibtex-details summary:hover {
  color: var(--text);
}

.bibtex-code {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px 18px;
  white-space: pre-wrap;
  margin: 12px 0 0 0;
}

.bibtex-copy {
  display: inline-block;
  margin-top: 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 5px 12px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--body);
  transition: border-color 0.2s, color 0.2s;
}

.bibtex-copy:hover {
  border-color: var(--text);
  color: var(--text);
}

/* ── Academic profiles ── */
.profiles {
  display: flex;
  gap: 24px;
  margin-top: 24px;
  font-size: 13px;
}

.profiles a {
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
}

.profiles a:hover {
  color: var(--text);
  border-color: var(--text);
  opacity: 1;
}

/* ── Focus styles ── */
.toc-link:focus-visible,
.link-card:focus-visible,
.bibtex-copy:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 4px;
  border-radius: 2px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .explainer {
    width: calc(100% - 32px);
  }

  .routing-diagram {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  .routing-side {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    flex: none;
  }

  .routing-side > * { flex: 0 1 160px; }
  .routing-lines { display: none; }

  .payload-comparison { grid-template-columns: 1fr; }
  .link-grid { grid-template-columns: 1fr; }
}

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