/* ==========================================================================
   Joint Health Guide — Design System
   Mobile-first, responsive, accessible, print-friendly.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Brand / semantic colors */
  --green: #2f855a;
  --green-dark: #276749;
  --accent: #3182ce;
  --amber: #dd6b20;
  --contested: #c53030;

  /* Neutrals */
  --text: #1f2933;
  --muted: #52606d;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --border: #e2e8f0;

  /* Tints (soft backgrounds for callouts/badges) */
  --green-tint: #e9f6ef;
  --accent-tint: #e8f1fb;
  --amber-tint: #fdf0e4;
  --contested-tint: #fdeaea;

  /* Typography */
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --line: 1.65;

  /* Spacing scale */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;

  /* Radius & shadow */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(31, 41, 51, 0.06), 0 1px 3px rgba(31, 41, 51, 0.08);
  --shadow-md: 0 2px 6px rgba(31, 41, 51, 0.06), 0 6px 18px rgba(31, 41, 51, 0.08);

  --maxw: 1040px;
}

/* --------------------------------------------------------------------------
   Reset / base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  line-height: var(--line);
  color: var(--text);
  background: var(--bg);
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--green-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Accessible, visible focus state for all interactive elements */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

main {
  display: block;
  padding: var(--sp-5) 0 var(--sp-7);
}

main section {
  margin: var(--sp-6) 0;
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */
h1,
h2,
h3,
h4 {
  line-height: 1.25;
  color: var(--text);
  font-weight: 700;
  margin: 0 0 var(--sp-4);
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(1.7rem, 4vw, 2.4rem);
}

h2 {
  font-size: clamp(1.35rem, 2.6vw, 1.7rem);
  margin-top: var(--sp-6);
  padding-bottom: var(--sp-2);
  border-bottom: 2px solid var(--border);
}

h3 {
  font-size: 1.2rem;
  margin-top: var(--sp-5);
}

p {
  margin: 0 0 var(--sp-4);
}

ul,
ol {
  margin: 0 0 var(--sp-4);
  padding-left: 1.4em;
}

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

.lead {
  font-size: 1.18rem;
  color: var(--muted);
  margin-bottom: var(--sp-5);
  max-width: 70ch;
}

strong {
  font-weight: 700;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.4em;
  font-size: 0.9em;
}

/* --------------------------------------------------------------------------
   Header / nav
   -------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.disclaimer-banner {
  background: var(--amber-tint);
  color: #7c3d10;
  border-bottom: 1px solid #f3d6bb;
  font-size: 0.8rem;
  line-height: 1.4;
  text-align: center;
  padding: 6px 20px;
}

.disclaimer-banner strong {
  color: #6b3208;
}

.disclaimer-banner a {
  color: var(--amber);
  font-weight: 600;
  text-decoration: underline;
}

.nav {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--sp-3) 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 800;
  font-size: 1.12rem;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-right: auto;
}

.brand:hover {
  text-decoration: none;
}

.brand .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  box-shadow: 0 0 0 4px var(--green-tint);
  flex: none;
}

.nav-toggle {
  display: none; /* hidden on desktop */
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.nav-toggle:hover {
  background: var(--bg);
}

.nav-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-1);
}

.nav-links a {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.nav-links a:hover {
  color: var(--green-dark);
  background: var(--green-tint);
  text-decoration: none;
}

.nav-links a.active {
  color: var(--green-dark);
  background: var(--green-tint);
  box-shadow: inset 0 -2px 0 var(--green);
}

/* --------------------------------------------------------------------------
   Hero
   -------------------------------------------------------------------------- */
.hero {
  background:
    radial-gradient(1200px 400px at 80% -20%, var(--green-tint), transparent 60%),
    linear-gradient(180deg, var(--surface), var(--bg));
  border-bottom: 1px solid var(--border);
  padding: var(--sp-7) 0;
}

.hero .container {
  max-width: 840px;
}

.hero h1 {
  margin-bottom: var(--sp-3);
}

.hero p {
  font-size: 1.2rem;
  color: var(--muted);
  max-width: 64ch;
}

.hero .btn {
  margin-top: var(--sp-3);
  margin-right: var(--sp-3);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-block;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  font-size: 0.98rem;
  padding: 0.7em 1.3em;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn:hover {
  background: var(--green-dark);
  text-decoration: none;
  color: #fff;
}

.btn:active {
  transform: translateY(1px);
}

.btn.secondary {
  background: var(--surface);
  color: var(--green-dark);
  border-color: var(--green);
  box-shadow: none;
}

.btn.secondary:hover {
  background: var(--green-tint);
  color: var(--green-dark);
}

/* --------------------------------------------------------------------------
   Breadcrumb
   -------------------------------------------------------------------------- */
.breadcrumb {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: var(--sp-4);
}

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

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

.breadcrumb > * + *::before,
.breadcrumb span + span::before {
  content: "›";
  margin: 0 0.45em;
  color: #b8c2cc;
}

/* --------------------------------------------------------------------------
   Table of contents
   -------------------------------------------------------------------------- */
.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-5) 0;
  box-shadow: var(--shadow-sm);
}

.toc > strong,
.toc > p {
  display: block;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: var(--sp-2);
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2;
  column-gap: var(--sp-5);
}

.toc li {
  margin-bottom: var(--sp-1);
  break-inside: avoid;
}

.toc a {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
}

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

/* --------------------------------------------------------------------------
   Key takeaways box
   -------------------------------------------------------------------------- */
.key-takeaways {
  background: var(--green-tint);
  border: 1px solid #c6e7d6;
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin: var(--sp-5) 0;
}

.key-takeaways h2,
.key-takeaways h3 {
  margin-top: 0;
  border: 0;
  padding: 0;
  color: var(--green-dark);
  font-size: 1.1rem;
}

.key-takeaways ul {
  margin: var(--sp-2) 0 0;
  padding-left: 1.3em;
}

.key-takeaways li::marker {
  color: var(--green);
}

.key-takeaways > *:last-child {
  margin-bottom: 0;
}

/* --------------------------------------------------------------------------
   Cards / grids
   -------------------------------------------------------------------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--sp-4);
  margin: var(--sp-5) 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease,
    border-color 0.15s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: #cdd9e5;
}

.card h3 {
  margin-top: 0;
}

.card .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--green-tint);
  color: var(--green-dark);
  font-size: 1.4rem;
  margin-bottom: var(--sp-3);
}

.card p:last-child {
  margin-bottom: 0;
}

.card a {
  color: var(--green-dark);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Split / panels
   -------------------------------------------------------------------------- */
.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--sp-4);
  margin: var(--sp-5) 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--muted);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}

.panel h3 {
  margin-top: 0;
}

.panel ul {
  padding-left: 1.2em;
  margin: var(--sp-2) 0 0;
}

.panel.good {
  border-top-color: var(--green);
}

.panel.good h3 {
  color: var(--green-dark);
}

.panel.limit {
  border-top-color: var(--amber);
}

.panel.limit h3 {
  color: #9a4a0f;
}

/* --------------------------------------------------------------------------
   Stat grid
   -------------------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-4);
  margin: var(--sp-5) 0;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5) var(--sp-4);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-num {
  display: block;
  font-size: clamp(1.8rem, 4vw, 2.3rem);
  font-weight: 800;
  line-height: 1.1;
  color: var(--green);
  letter-spacing: -0.02em;
}

.stat-label {
  display: block;
  margin-top: var(--sp-2);
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   Evidence badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-block;
  vertical-align: middle;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1;
  padding: 0.35em 0.6em;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
}

.badge--strong {
  background: var(--green-tint);
  color: var(--green-dark);
  border-color: #bfe3d0;
}

.badge--emerging {
  background: var(--amber-tint);
  color: #9a4a0f;
  border-color: #f3d6bb;
}

.badge--contested {
  background: var(--contested-tint);
  color: var(--contested);
  border-color: #f5c2c2;
}

/* --------------------------------------------------------------------------
   Callouts
   -------------------------------------------------------------------------- */
.callout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-5) 0;
  box-shadow: var(--shadow-sm);
}

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

.callout > *:last-child {
  margin-bottom: 0;
}

.callout--disclaimer {
  background: var(--amber-tint);
  border-color: #f3d6bb;
  border-left-color: var(--amber);
  color: #6b3208;
}

.callout--tip {
  background: var(--green-tint);
  border-color: #c6e7d6;
  border-left-color: var(--green);
}

.callout--mechanism {
  background: var(--accent-tint);
  border-color: #cfe1f6;
  border-left-color: var(--accent);
}

.callout--warning {
  background: var(--contested-tint);
  border-color: #f5c2c2;
  border-left-color: var(--contested);
}

/* "Mechanism:" lead-in heading style */
.mechanism {
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 0 0 var(--sp-2);
}

/* --------------------------------------------------------------------------
   Data table
   -------------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: var(--sp-5) 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 520px;
}

table.data-table caption {
  caption-side: top;
  text-align: left;
  font-size: 0.85rem;
  color: var(--muted);
  padding: var(--sp-3) var(--sp-4) 0;
}

table.data-table th,
table.data-table td {
  padding: 0.6em 0.85em;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

table.data-table th:last-child,
table.data-table td:last-child {
  border-right: 0;
}

table.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--green-dark);
  color: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 0;
  border-right-color: rgba(255, 255, 255, 0.18);
}

table.data-table tbody tr:nth-child(odd) {
  background: #fbfdfe;
}

table.data-table tbody tr:nth-child(even) {
  background: var(--surface);
}

table.data-table tbody tr:hover {
  background: var(--green-tint);
}

table.data-table tbody tr:last-child td {
  border-bottom: 0;
}

table.data-table th[scope="row"],
table.data-table tbody th {
  font-weight: 700;
  background: var(--bg);
}

/* --------------------------------------------------------------------------
   FAQ — native details / summary
   -------------------------------------------------------------------------- */
details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 var(--sp-5);
  margin: var(--sp-3) 0;
  box-shadow: var(--shadow-sm);
}

details summary {
  list-style: none;
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  padding: var(--sp-4) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

details summary::-webkit-details-marker {
  display: none;
}

details summary::after {
  content: "+";
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--green);
  line-height: 1;
  transition: transform 0.2s ease;
  flex: none;
}

details[open] summary::after {
  content: "\2212"; /* minus sign */
}

details summary:hover {
  color: var(--green-dark);
}

details > *:not(summary) {
  margin-top: 0;
  padding-bottom: var(--sp-4);
}

details[open] summary {
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-4);
}

/* --------------------------------------------------------------------------
   References / source list
   -------------------------------------------------------------------------- */
sup a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  font-size: 0.72em;
  padding: 0 0.1em;
}

sup a:hover {
  text-decoration: underline;
}

ol.source-list {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.55;
  padding-left: 1.8em;
}

ol.source-list li {
  margin-bottom: var(--sp-2);
  word-break: break-word;
  scroll-margin-top: 120px;
}

ol.source-list a {
  color: var(--accent);
  word-break: break-word;
}

ol.source-list li:target {
  background: var(--amber-tint);
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.site-footer {
  background: #1a2332;
  color: #cbd5e1;
  padding: var(--sp-7) 0 var(--sp-6);
  margin-top: var(--sp-7);
}

.site-footer .container {
  max-width: var(--maxw);
}

.footer-disclaimer {
  font-size: 0.82rem;
  line-height: 1.6;
  color: #94a3b8;
  max-width: 80ch;
  margin-bottom: var(--sp-5);
}

.footer-disclaimer strong {
  color: #e2e8f0;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-4) 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.footer-links a {
  color: #cbd5e1;
  font-size: 0.9rem;
  font-weight: 600;
}

.footer-links a:hover {
  color: #fff;
}

.copyright {
  font-size: 0.8rem;
  color: #7b8794;
  margin: var(--sp-4) 0 0;
}

/* --------------------------------------------------------------------------
   Responsive — nav collapses under ~760px
   -------------------------------------------------------------------------- */
@media (max-width: 760px) {
  body {
    font-size: 16px;
  }

  .nav-toggle {
    display: inline-block; /* shown on mobile */
  }

  .nav-links {
    display: none; /* hidden until toggled open */
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0;
    margin-top: var(--sp-2);
    border-top: 1px solid var(--border);
    padding-top: var(--sp-2);
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links a {
    padding: 0.7em 0.6em;
    border-radius: var(--radius-sm);
    white-space: normal;
  }

  .nav-links a.active {
    box-shadow: inset 3px 0 0 var(--green);
  }

  .toc ul {
    columns: 1;
  }

  h2 {
    margin-top: var(--sp-5);
  }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */
@media print {
  :root {
    --bg: #fff;
    --surface: #fff;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
    line-height: 1.4;
  }

  .site-header,
  .disclaimer-banner,
  .nav,
  .nav-toggle,
  .site-footer,
  .btn,
  .breadcrumb {
    display: none !important;
  }

  main {
    padding: 0;
  }

  .container {
    max-width: none;
    padding: 0;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  /* Expand external link URLs when printed */
  ol.source-list a[href^="http"]::after,
  main a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #333;
    word-break: break-all;
  }

  .card,
  .panel,
  .stat,
  .callout,
  .toc,
  .key-takeaways,
  .table-wrap,
  details {
    box-shadow: none;
    border: 1px solid #999;
    break-inside: avoid;
  }

  details > *:not(summary) {
    display: block; /* ensure FAQ answers print even if collapsed */
  }

  table.data-table thead th {
    position: static;
    background: #eee !important;
    color: #000;
  }

  h2,
  h3 {
    break-after: avoid;
  }
}
