/* ============================================================
   Knowledge Research — Editorial Newsprint Design System
   Shared base stylesheet (tokens + typography + components)

   Linked from every article and the index. Page-specific
   extensions stay inline in each HTML file under a
   "PAGE-SPECIFIC EXTENSIONS" marker.

   Source of truth: this file. When changing a token or a
   component, update here only.
   ============================================================ */

/* ===== DESIGN TOKENS ===== */
:root {
  --bg:        #f4f1ea;
  --bg-warm:   #ebe5d6;
  --paper:     #fbf8f1;

  --ink:       #1a1814;
  --ink-soft:  #4a453d;
  --ink-fade:  #7a7368;

  --rule:        #c9c1ae;
  --accent:      #8b2415;
  --accent-deep: #5c1809;
  --accent-soft: #d4a89b;
  --gold:        #b8893a;
  --shadow:      rgba(26, 24, 20, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Newsreader', Georgia, serif;
  font-size: 18px;
  line-height: 1.7;
  font-feature-settings: "liga" 1, "kern" 1;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(184, 137, 58, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(139, 36, 21, 0.03) 0%, transparent 40%);
}

a { color: inherit; }

/* ===== MASTHEAD ===== */
.masthead {
  border-bottom: 3px double var(--ink);
  padding: 2rem 3rem 1.5rem;
  background: var(--paper);
  position: relative;
}

.masthead-top, .masthead-bottom {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-fade);
}

.masthead-top {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.8rem;
  margin-bottom: 1.2rem;
}

.masthead-bottom {
  margin-top: 1.5rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--rule);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
}

.masthead h1 {
  font-family: 'Fraunces', serif;
  font-weight: 800;
  font-size: clamp(2.5rem, 6vw, 4.8rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  text-align: center;
  font-style: italic;
  color: var(--ink);
}

.masthead .subtitle {
  text-align: center;
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--ink-soft);
  margin: 0.8rem auto 0;
  max-width: 760px;
}

/* ===== CONTAINER ===== */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 3rem;
}

/* ===== PAGE TOOLS (back link + share button) =====
   Sits at the top of .container on every article. Hosts the
   "back to home" link and the share trigger. */
.page-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.back-link {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-fade);
  text-decoration: none;
  padding: 0.4rem 0;
  transition: color 0.15s ease;
}
.back-link:hover { color: var(--accent); }

/* share */
.share { position: relative; }

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s ease;
}
.share-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.share-btn svg {
  width: 14px;
  height: 14px;
  flex: none;
}

.share-popover {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 8px 24px var(--shadow);
  min-width: 200px;
  padding: 0.4rem;
  z-index: 50;
  display: none;
}
.share-popover[data-open="true"] { display: block; }

.share-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--ink);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 0.55rem 0.7rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.12s ease, color 0.12s ease;
}
.share-option:hover { background: var(--bg-warm); color: var(--accent); }
.share-option svg { width: 14px; height: 14px; flex: none; color: var(--ink-fade); }
.share-option:hover svg { color: var(--accent); }

.share-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--paper);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  padding: 0.7rem 1.2rem;
  border-radius: 2px;
  box-shadow: 0 8px 24px var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}
.share-toast[data-show="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== LEAD ===== */
.lead {
  columns: 2;
  column-gap: 3rem;
  margin: 2rem 0 4rem;
  font-size: 1.15rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

.lead p:first-child::first-letter {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 5.5rem;
  float: left;
  line-height: 0.85;
  margin: 0.3rem 0.6rem 0 0;
  color: var(--accent);
  font-style: italic;
}

.lead p { margin-bottom: 1rem; }
.lead strong { color: var(--ink); font-weight: 600; }

/* ===== SECTION HEADERS ===== */
.section-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: var(--accent);
  margin-bottom: 0.6rem;
  display: inline-block;
  padding: 0.3rem 0.7rem;
  background: var(--accent-soft);
  border-radius: 2px;
}

h2 {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 4rem 0 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--rule);
}

h2 .num {
  font-style: italic;
  color: var(--accent);
  font-weight: 400;
  margin-right: 0.5rem;
}

h2 small {
  display: block;
  font-family: 'Newsreader', serif;
  font-style: italic;
  color: var(--ink-fade);
  font-weight: 400;
  font-size: 1rem;
  margin-top: 0.6rem;
  letter-spacing: 0;
}

h3 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.4rem;
  color: var(--ink);
  margin: 2rem 0 0.8rem;
  letter-spacing: -0.01em;
}

p { margin-bottom: 1.1rem; }

strong {
  font-weight: 600;
  color: var(--ink);
}

em.term {
  font-style: italic;
  color: var(--accent-deep);
  font-weight: 500;
}

/* ===== KEY STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0 3rem;
  padding: 2rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

.stat {
  text-align: center;
  padding: 0.5rem;
  border-right: 1px solid var(--rule);
}
.stat:last-child { border-right: none; }

@media (max-width: 700px) {
  .stat { border-right: none; border-bottom: 1px solid var(--rule); padding-bottom: 1rem; }
  .stat:last-child { border-bottom: none; }
}

.stat-number {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 3rem;
  line-height: 1;
  color: var(--accent);
  font-style: italic;
  display: block;
}

.stat-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-fade);
  margin-top: 0.6rem;
  line-height: 1.4;
}

/* ===== PULL QUOTE ===== */
.pull-quote {
  margin: 3rem -1rem;
  padding: 2.5rem 3rem;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 400;
  font-size: 1.6rem;
  line-height: 1.4;
  color: var(--ink);
  position: relative;
  text-align: center;
}

.pull-quote::before {
  content: '"';
  position: absolute;
  top: -2rem;
  left: 1.5rem;
  font-size: 6rem;
  color: var(--accent);
  font-weight: 700;
  line-height: 1;
}

.pull-quote-attr {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink-fade);
  margin-top: 1.2rem;
}

/* ===== TABLES ===== */
.table-wrap {
  margin: 2rem 0 3rem;
  overflow-x: auto;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

table caption {
  caption-side: top;
  text-align: left;
  padding: 1rem 1.5rem;
  background: var(--ink);
  color: var(--paper);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 500;
}

th {
  background: var(--bg-warm);
  color: var(--ink);
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: left;
  padding: 0.9rem 1.2rem;
  border-bottom: 2px solid var(--ink);
  vertical-align: top;
}

td {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  line-height: 1.55;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-warm); }

td:first-child {
  font-weight: 600;
  color: var(--accent-deep);
  font-family: 'Fraunces', serif;
}

/* compare-table — second/third columns get tinted heads */
.compare-table th:nth-child(2) { background: #f4d4cd; color: var(--accent-deep); }
.compare-table th:nth-child(3) { background: #d4dccc; color: #3a4a2c; }
.compare-table td:nth-child(2) { background: rgba(244, 212, 205, 0.25); }
.compare-table td:nth-child(3) { background: rgba(212, 220, 204, 0.25); }

/* ===== METHOD CARDS ===== */
.method-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0 3rem;
}

.method-card {
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 1.8rem;
  border-radius: 4px;
  position: relative;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.method-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--shadow);
}

.method-card .badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--paper);
  background: var(--ink);
  padding: 0.25rem 0.6rem;
  border-radius: 2px;
  display: inline-block;
  margin-bottom: 0.8rem;
}

.method-card h4 {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--ink);
  margin-bottom: 0.6rem;
}

.method-card p {
  font-size: 0.95rem;
  color: var(--ink-soft);
  line-height: 1.55;
  margin-bottom: 0.8rem;
}

.method-card .pros, .method-card .cons {
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
.method-card .pros::before { content: "+ "; color: #5a7a3c; font-weight: 700; }
.method-card .cons::before { content: "− "; color: var(--accent); font-weight: 700; }

/* ===== RECOMMENDATION LIST ===== */
.reco-list {
  counter-reset: reco;
  list-style: none;
  margin: 2rem 0;
}

.reco-item {
  counter-increment: reco;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.5rem;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--rule);
  align-items: start;
}

.reco-item:last-child { border-bottom: none; }

.reco-item::before {
  content: counter(reco, decimal-leading-zero);
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 700;
  font-size: 3rem;
  line-height: 1;
  color: var(--accent);
  min-width: 80px;
}

.reco-content h4 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
  color: var(--ink);
}

.reco-content p {
  font-size: 1rem;
  color: var(--ink-soft);
  margin-bottom: 0;
}

/* ===== RISK BAR ===== */
.risk-section { margin: 2rem 0 3rem; }

.risk-bar { margin-bottom: 1.2rem; }

.risk-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
}

.risk-bar-label {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
}

.risk-bar-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--accent-deep);
  font-weight: 500;
}

.risk-bar-track {
  height: 12px;
  background: var(--bg-warm);
  border: 1px solid var(--rule);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.risk-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold) 0%, var(--accent) 100%);
  border-right: 2px solid var(--accent-deep);
}

/* ===== INFOBOX ===== */
.infobox {
  background: var(--paper);
  border-left: 4px solid var(--accent);
  padding: 1.5rem 2rem;
  margin: 2rem 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
  border-radius: 0 4px 4px 0;
}

.infobox-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin-bottom: 0.6rem;
  font-weight: 500;
}

/* ===== FIGURE (historical / clinical) ===== */
.figure {
  margin: 2.5rem 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
}

.figure img {
  display: block;
  width: 100%;
  height: auto;
  border-bottom: 1px solid var(--rule);
  background: var(--bg-warm);
}

.figure.figure-wide img {
  max-height: 460px;
  object-fit: cover;
  object-position: center;
}

.figure.figure-tall img {
  max-height: 520px;
  object-fit: cover;
  object-position: center top;
}

.figure figcaption {
  padding: 0.9rem 1.3rem 1rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-fade);
  line-height: 1.55;
}

.figure .caption-title {
  display: block;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 500;
  font-size: 0.95rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  margin-bottom: 0.35rem;
}

.figure .caption-credit a { color: var(--accent); text-decoration: none; }
.figure .caption-credit a:hover { text-decoration: underline; }

.figure-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 2.5rem 0;
}
.figure-pair .figure { margin: 0; }
@media (max-width: 768px) {
  .figure-pair { grid-template-columns: 1fr; }
}

/* ===== REFERENCES ===== */
.references {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 3px double var(--ink);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.references h2 {
  font-size: 1.5rem;
  margin-top: 0;
}

.references ol {
  padding-left: 2rem;
  columns: 2;
  column-gap: 2rem;
}

.references li {
  margin-bottom: 0.6rem;
  break-inside: avoid;
  line-height: 1.5;
}

.references li::marker { color: var(--accent); font-weight: 700; }

.references .credits-heading {
  margin-top: 2.5rem;
  font-family: 'Fraunces', serif;
  font-size: 1.15rem;
  color: var(--ink);
}

.references .credits-note {
  margin-top: 1.2rem;
  font-size: 0.78rem;
  color: var(--ink-fade);
  font-style: italic;
}

/* ===== FOOTER ===== */
footer {
  margin-top: 4rem;
  padding: 2rem 3rem;
  background: var(--ink);
  color: var(--bg);
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  line-height: 1.7;
}

footer p { color: var(--bg-warm); margin-bottom: 0.4rem; }

footer .subtle {
  color: var(--ink-fade);
  text-transform: none;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}

/* ===== RESPONSIVE BASELINE ===== */
@media (max-width: 768px) {
  .masthead { padding: 1.5rem 1.5rem 1rem; }
  .container { padding: 1.5rem; }
  .lead { columns: 1; }
  .references ol { columns: 1; }
  .pull-quote { margin: 2rem 0; padding: 2rem 1.5rem; font-size: 1.3rem; }
  .reco-item { grid-template-columns: 1fr; gap: 0.5rem; }
  .reco-item::before { font-size: 2.2rem; min-width: auto; }
  footer { padding: 1.5rem; }
}

/* ===== PRINT ===== */
@media print {
  body { background: white; }
  .masthead, footer { background: white; color: black; }
  .page-tools, .share-popover, .share-toast { display: none; }
}
