/* ============================================================
   freeconstitution.org, design system
   Sister site to freescripture.org. Same bones, different flag:
   parchment paper, federal navy ink, heritage red reserved for
   the rights rail and live document anchors, muted gold for
   ratification dates. DM Sans for UI, Source Serif 4 for the
   document itself. 13px floor everywhere.
   ============================================================ */

/* ---- Tokens ---- */
:root {
  /* Paper and ink */
  --paper:        #fbf8f0;
  --paper-warm:   #f4eee0;
  --paper-deep:   #ece3cf;
  --ink:          #161a21;
  --ink-soft:     #454c59;
  --ink-faded:    #68635a;
  --rule:         #ddd4bf;
  --rule-soft:    #e9e1cd;

  /* Patriotic accents, AA on parchment */
  --navy:         #1e3a5f;   /* federal navy, links and structure */
  --navy-deep:    #14283f;
  --red:          #9b2c24;   /* heritage red, rights signals only */
  --red-deep:     #7c211b;
  --gold:         #806019;   /* ratification dates, sparing */

  /* Washes */
  --navy-wash:    #e8edf3;
  --red-wash:     #f4e4e1;

  /* Typography */
  --font-ui:    'DM Sans', system-ui, -apple-system, sans-serif;
  --font-body:  'Source Serif 4', 'Iowan Old Style', Georgia, serif;

  /* Layout */
  --measure: 40rem;
  --gutter: clamp(1rem, 4vw, 2rem);

  /* User-tunable reading prefs */
  --reading-size: 1.125rem;
}

[data-theme="dark"] {
  --paper:        #15181e;
  --paper-warm:   #1c2027;
  --paper-deep:   #232834;
  --ink:          #ece6d8;
  --ink-soft:     #bdb5a3;
  --ink-faded:    #8d867a;
  --rule:         #353b47;
  --rule-soft:    #2a303b;
  --navy:         #8fb0d6;
  --navy-deep:    #aac4e2;
  --red:          #e08a82;
  --red-deep:     #eba39c;
  --gold:         #c5a455;
  --navy-wash:    #1f2733;
  --red-wash:     #33231f;
}
[data-theme="dark"] .site-header { background: #0e1a28; }

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
}

img, svg { max-width: 100%; }
a { color: var(--navy); text-underline-offset: 0.15em; }
a:hover { color: var(--navy-deep); }

.wrap {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---- Skip link and focus ---- */
.skip-link {
  position: absolute; left: 0; top: 0;
  width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
  background: var(--navy); color: #fff;
  text-decoration: none; font-size: 0.875rem; z-index: 100;
}
.skip-link:focus {
  width: auto; height: auto; margin: 0; padding: 0.75rem 1rem;
  overflow: visible; clip: auto; clip-path: none;
  border-radius: 0 0 8px 0;
}
:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---- Header ---- */
.site-header {
  border-bottom: none;
  background: var(--navy-deep);
}
.header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
}
.wordmark {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: #fff;
  text-decoration: none;
}
.wordmark:hover { color: rgba(255,255,255,0.8); }
.site-nav {
  display: flex;
  gap: 1.1rem;
  flex-wrap: wrap;
}
.site-nav a {
  font-size: 0.875rem;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
}
.site-nav a:hover { color: #fff; text-decoration: underline; }

/* ---- Hero ---- */
.hero { padding-top: 3.5rem; padding-bottom: 3rem; }
.hfa-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--ink-faded);
  text-decoration: none;
  margin-bottom: 1.25rem;
}
.hfa-eyebrow:hover { color: var(--navy); }
.hfa-eyebrow-mark {
  display: inline-flex;
  width: 1.25rem; height: 1.25rem;
  border-radius: 50%;
  background: var(--navy);
  color: var(--paper);
  align-items: center; justify-content: center;
}
.hfa-eyebrow-mark svg { width: 0.9rem; height: 0.9rem; }
.hero h1 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0 0 0.6rem;
}
.hero .dot { color: var(--red); }
.hero .lede {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 1.1rem;
  color: var(--ink-soft);
  margin: 0 0 0.35rem;
}
.hero .sublede {
  font-size: 0.9375rem;
  color: var(--ink-faded);
  max-width: 34rem;
  margin: 0 0 1.75rem;
}
.hero-cta-row {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ---- Sections — padding lives in the dividers block below ---- */
.section-eyebrow {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faded);
  margin: 0 0 0.35rem;
}
.section-title {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 0.4rem;
  line-height: 1.1;
}
/* keep h2 in case any page still uses it */
main h2 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: -0.015em;
  margin: 0 0 0.4rem;
}
.section-lede {
  color: var(--ink-soft);
  font-size: 0.9375rem;
  margin: 0 0 1.4rem;
  max-width: 36rem;
}

/* ---- Jump rail, the signature ---- */
.rail-section { padding-top: 3rem; }
.rail-section h2 { color: var(--ink); }
.jump-rail {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--rule);
}
.jump {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.1rem 0.9rem 1.1rem 1.1rem;
  border-bottom: 1px solid var(--rule);
  border-left: 3px solid transparent;
  text-decoration: none;
  min-height: 3.5rem;
  transition: border-color 120ms ease, background 120ms ease, padding-left 120ms ease;
}
.jump:hover, .jump:focus-visible {
  border-left-color: var(--red);
  background: var(--paper-warm);
  padding-left: 1.35rem;
}
.jump-q {
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.jump:hover .jump-q { color: var(--red-deep); }
.jump-where {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
}
.jump:hover .jump-where { color: var(--red); }

/* ---- Situation cards ---- */
.sit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.9rem;
}
.sit-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.1rem 1.2rem 1rem;
  background: var(--paper-warm);
  border: 1px solid var(--rule);
  border-radius: 10px;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 120ms ease;
}
.sit-card:hover { border-color: var(--navy); color: var(--ink); }
.sit-card h2, .sit-card h3 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.15rem;
  margin: 0;
}
.sit-card p {
  font-size: 0.875rem;
  color: var(--ink-soft);
  margin: 0;
  flex-grow: 1;
}
.sit-go {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--navy);
  margin-top: 0.6rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  align-self: flex-start;
}
.sit-card:hover .sit-go { border-color: var(--navy); background: var(--navy-wash); }

/* ---- Amendments grid ---- */
.grid-label {
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 1.4rem 0 0.6rem;
}
.amend-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}
.amend-cell {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  text-decoration: none;
  background: var(--paper);
  transition: border-color 120ms ease, background 120ms ease;
}
.amend-cell:hover { border-color: var(--navy); background: var(--navy-wash); }
.amend-cell .num {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--red);
  min-width: 1.4rem;
  line-height: 1.3;
}
.amend-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.amend-cell .title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.3;
}
.amend-cell .subject {
  font-size: 0.75rem;
  color: var(--ink-faded);
  line-height: 1.3;
}

/* ---- Articles list ---- */
.article-list { display: flex; flex-direction: column; border-top: 1px solid var(--rule); }
.article-row {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.8rem 0.4rem;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
}
.article-row:hover { background: var(--paper-warm); }
.article-row .num {
  font-size: 0.8125rem;
  color: var(--gold);
  min-width: 5.5rem;
}
.article-row .title {
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}
.article-row:hover .title { color: var(--navy); }

/* ---- Declaration block and CTA ---- */
.declaration-block { padding-bottom: 3rem; }
.cta {
  display: inline-block;
  padding: 0.65rem 1.2rem;
  background: var(--navy);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
}
.cta:hover { background: var(--navy-deep); color: #fff; }
.cta-secondary {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--rule);
}
.cta-secondary:hover {
  background: var(--navy-wash);
  color: var(--navy-deep);
  border-color: var(--navy);
}

/* ---- Document pages ---- */
.doc { padding-top: 2.25rem; padding-bottom: 2rem; }
.breadcrumb {
  font-size: 0.8125rem;
  color: var(--ink-faded);
  margin: 0 0 1.25rem;
}
.breadcrumb a { color: var(--ink-faded); }
.breadcrumb a:hover { color: var(--navy); }
.eyebrow {
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faded);
  margin: 0 0 0.4rem;
}
.eyebrow .ratified { color: var(--gold); text-transform: none; letter-spacing: 0; }
.doc h1 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: clamp(1.9rem, 5vw, 2.6rem);
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 1rem;
}
.doc .lede {
  font-size: 1.05rem;
  color: var(--ink-soft);
  margin: 0 0 1.25rem;
  max-width: 36rem;
}

/* On-this-page chips */
.section-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 1.5rem;
}
.section-chips a {
  font-size: 0.8125rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  text-decoration: none;
  color: var(--navy);
  background: var(--paper);
}
.section-chips a:hover { border-color: var(--navy); background: var(--navy-wash); }

/* Reading controls */
.reading-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 1.25rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
}
.rc-label { font-size: 0.8125rem; color: var(--ink-faded); margin-right: 0.2rem; }
.reading-controls button {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}
.reading-controls button:hover { border-color: var(--navy); color: var(--navy); }
.reading-controls button[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }

/* Document body */
.doc-body {
  font-family: var(--font-body);
  font-size: var(--reading-size);
  line-height: 1.7;
  max-width: var(--measure);
}
.doc-body h2 {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--navy);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
  margin: 2.5rem 0 1rem;
}
.doc-body h3 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.15em;
  margin: 1.75rem 0 0.5rem;
}
.doc-body p { margin: 0 0 1rem; }
.doc-body ul { padding-left: 1.25rem; margin: 0 0 1rem; }
.doc-body li { margin-bottom: 0.45rem; }
.doc-body hr { border: 0; border-top: 1px solid var(--rule); margin: 2rem 0; }

/* Verbatim text, the document itself */
.doc-body h2#verbatim { color: var(--red); border-color: var(--red-wash); }
.doc-body h2#verbatim + p,
.doc-body h2#verbatim ~ p:has(+ h2#plain-english) { }
.doc-body blockquote {
  margin: 0 0 1rem;
  padding: 0.9rem 1.2rem;
  background: var(--paper-warm);
  border-left: 3px solid var(--navy);
  border-radius: 0 8px 8px 0;
}
.doc-body blockquote p { margin: 0; }

/* Situation cards: quotes are things you can say out loud */
.situation .doc-body blockquote {
  border-left-color: var(--red);
  font-size: 1.1em;
  font-weight: 600;
}

/* Contested aside */
.contested {
  margin: 2.25rem 0 0;
  padding: 1.1rem 1.3rem;
  background: var(--navy-wash);
  border: 1px solid var(--rule);
  border-radius: 10px;
  max-width: var(--measure);
}
.contested h2 {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--navy);
  margin: 0 0 0.5rem;
}
.contested p { font-size: 0.9375rem; color: var(--ink-soft); margin: 0 0 0.5rem; }
.contested ul { margin: 0; padding-left: 1.25rem; font-size: 0.9375rem; }
.contested li { margin-bottom: 0.3rem; }

/* Related links */
.related { margin: 2rem 0 0; max-width: var(--measure); }
.related h2 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.2rem;
  margin: 0 0 0.75rem;
}
.related-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.related-card {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.875rem;
  color: var(--navy);
  background: var(--paper-warm);
}
.related-card:hover { border-color: var(--navy); }

/* Legal note */
.legal-note {
  margin: 2.25rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.8125rem;
  color: var(--ink-faded);
  max-width: var(--measure);
}

/* Pager */
.pager-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 2rem 0 0;
  max-width: var(--measure);
}
.pager {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.pager:hover { border-color: var(--navy); color: var(--navy); }
.pager span { font-family: var(--font-ui); font-weight: 400; font-size: 0.8125rem; color: var(--ink-faded); }
.pager.next { text-align: right; margin-left: auto; }

/* ---- Footer, HfA pattern ---- */
.site-footer {
  margin-top: 3rem;
  border-top: 1px solid var(--rule);
  padding: 3.5rem var(--gutter) 3rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--ink-faded);
}
.foot-tag { font-family: var(--font-body); font-style: italic; margin-bottom: 0.5rem; }
.hfa-madein { margin: 0 0 1.1rem; }
.hfa-heart { color: var(--red); }
.hfa-rule {
  width: 3rem;
  height: 1px;
  background: var(--rule);
  margin: 0 auto 1.1rem;
}
.hfa-mark a { color: var(--navy); }
.hfa-vision { font-size: 0.8125rem; margin-top: 0.25rem; }

/* ---- Section dividers (homepage) ---- */
/* .wrap resets padding to 0 vertically; we use specificity to override */
main section.wrap,
main section:not(.wrap) {
  border-bottom: 1px solid var(--rule);
  padding-top: 3.5rem;
  padding-bottom: 3.5rem;
}
main section.wrap:last-of-type,
main section:not(.wrap):last-of-type { border-bottom: none; padding-bottom: 4rem; }
main section + section { border-top: none; margin-top: 0; }
/* Hero band */
.hero-band {
  background: var(--paper-warm);
  border-bottom: 2px solid var(--rule);
}
.hero-band + section { border-top: none; }

/* ---- Mobile bottom nav ---- */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 90;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom, 0px));
}
.mobile-nav-row {
  display: flex;
  justify-content: space-around;
  max-width: 28rem;
  margin: 0 auto;
}
.mobile-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.3rem 0.75rem;
  text-decoration: none;
  color: var(--ink-faded);
  font-size: 0.6875rem;
  line-height: 1;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav a.active {
  color: var(--navy);
  background: var(--navy-wash);
}
.mobile-nav svg {
  width: 1.25rem; height: 1.25rem;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.mobile-nav a.active svg { stroke-width: 2.2; }

/* ---- Back-to-top button ---- */
.back-to-top {
  display: none;
  position: fixed;
  z-index: 80;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 2.5rem; height: 2.5rem;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: opacity 200ms ease, transform 200ms ease;
  opacity: 0;
  transform: translateY(0.5rem);
  pointer-events: none;
}
.back-to-top svg {
  width: 1rem; height: 1rem;
  stroke: currentColor; fill: none;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.back-to-top.visible {
  display: flex;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.back-to-top:hover { border-color: var(--navy); color: var(--navy); }

/* ---- Sticky section bar (reading pages) ---- */
.sticky-sections {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 85;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: 0.5rem var(--gutter);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transform: translateY(-100%);
  transition: transform 200ms ease;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.sticky-sections.visible { transform: translateY(0); }
.sticky-sections .sticky-title {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.8125rem;
  color: var(--ink);
  white-space: nowrap;
  margin-right: 0.25rem;
  flex-shrink: 0;
}
.sticky-sections a {
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink-soft);
  white-space: nowrap;
  flex-shrink: 0;
}
.sticky-sections a:hover { border-color: var(--navy); color: var(--navy); }
.sticky-sections a.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

/* ---- Small screens ---- */
@media (max-width: 680px) {
  /* Show bottom nav, hide header nav */
  .mobile-nav { display: block; }
  .site-nav { display: none; }
  body { padding-bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px)); }
  .back-to-top { bottom: calc(4rem + env(safe-area-inset-bottom, 0px)); }
  .site-footer { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px)); }

  .jump { padding-right: 0.5rem; }
  .jump-q { font-size: 1rem; }
  .pager-row { flex-direction: column; }
  .pager.next { margin-left: 0; text-align: left; }

  /* 2-column amendment grid on mobile */
  .amend-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 681px) {
  .mobile-nav { display: none !important; }
  .back-to-top { display: flex; }
}
