/* ============================================================
   The Johnston Family Story — stylesheet
   Design goals (Jerry is in his mid-70s):
   - Easy on the eyes: low-saturation warm palette, soft contrast
     (dark warm-gray text on warm paper, not black-on-white)
   - Highly legible: clean sans body, gentle serif headings
   - Adjustable text size (see the A- / A+ control in the header)
   - Big tap targets, generous spacing, durable system fonts only
   ============================================================ */

:root {
  /* ----- calm, low-saturation palette ----- */
  --bg:         #f4f2ec;   /* warm paper */
  --paper:      #fbfaf6;   /* cards / reading surface */
  --paper-edge: #e4dfd2;   /* hairline borders */
  --ink:        #312f2a;   /* dark warm gray — softer than black */
  --ink-soft:   #635d53;   /* muted secondary text */
  --accent:     #4c6276;   /* muted slate blue */
  --accent-dk:  #39536a;   /* links / headings accent */
  --accent-soft:#aebcc6;
  --tan:        #b6a37f;   /* muted, desaturated gold */
  --tan-soft:   #efe9da;
  --green:      #5d6f59;   /* muted sage */
  --green-soft: #eef1ea;
  --link:       #39536a;
  --link-visited:#4a4a6a;

  --shadow:     0 1px 2px rgba(49,47,42,.05), 0 6px 18px rgba(49,47,42,.05);
  --radius:     10px;
  --maxread:    42rem;
  --maxwide:    64rem;

  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Root font size IS the user text-size control's lever.
     Everything below is sized in rem/em so it scales together.
     site.js overrides this from a saved preference. */
  font-size: 20px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

/* ---------- Links ---------- */
a { color: var(--link); text-underline-offset: 2px; }
a:visited { color: var(--link-visited); }
a:hover, a:focus { color: var(--accent-dk); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--accent-dk); color: #fff; padding: .75rem 1.25rem;
  border-radius: 0 0 var(--radius) 0; text-decoration: none; font-weight: 700;
}
.skip-link:focus { left: 0; color: #fff; }

/* ---------- Header / nav (light & calm) ---------- */
.site-header {
  background: #efece3;
  color: var(--ink);
  border-bottom: 1px solid var(--paper-edge);
}
.site-header__inner {
  max-width: var(--maxwide);
  margin: 0 auto;
  padding: .55rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem 1.1rem;
}
.site-header__brand {
  display: flex; align-items: baseline; gap: .55rem;
  margin-right: auto;
  text-decoration: none; color: var(--accent-dk);
  font-family: var(--serif);
}
.site-header__brand:hover, .site-header__brand:focus { color: var(--accent); }
.site-header__brand b { font-size: 1.2rem; letter-spacing: .01em; }
.site-header__brand span { font-size: .9rem; color: var(--ink-soft); font-family: var(--sans); }
.mainnav { display: flex; flex-wrap: wrap; gap: .2rem; }
.mainnav a {
  color: var(--ink); text-decoration: none;
  padding: .5rem .8rem; border-radius: var(--radius);
  font-size: 1.02rem; white-space: nowrap;
}
.mainnav a:hover, .mainnav a:focus { background: #e4dfd2; color: var(--accent-dk); }
.mainnav a[aria-current="page"] { background: #e0dccf; color: var(--accent-dk); font-weight: 700; }

/* ---------- Text-size control (injected by site.js) ---------- */
.textsize {
  display: flex; align-items: center; gap: .3rem;
  border-left: 1px solid var(--paper-edge); padding-left: .8rem; margin-left: .2rem;
}
.textsize .ts-label { font-size: .85rem; color: var(--ink-soft); margin-right: .1rem; }
.textsize button {
  font-family: var(--serif); cursor: pointer; line-height: 1;
  border: 1px solid var(--accent-soft); background: var(--paper); color: var(--accent-dk);
  border-radius: 8px; padding: .35rem .55rem; font-weight: 700;
}
.textsize button:hover, .textsize button:focus { background: #eef2f5; border-color: var(--accent); }
.textsize button.ts-sm { font-size: .85rem; }
.textsize button.ts-md { font-size: 1rem; }
.textsize button.ts-lg { font-size: 1.25rem; }

/* ---------- Page shell ---------- */
.wrap { max-width: var(--maxwide); margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
main { display: block; }

.reading {
  max-width: var(--maxread);
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem clamp(1.25rem, 4vw, 3rem) 3rem;
}
.reading.wide { max-width: var(--maxwide); }

/* ---------- Headings & text ---------- */
h1, h2, h3, h4 { font-family: var(--serif); color: var(--ink); line-height: 1.25; }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.5rem); margin: 0 0 .25em; }
h2 { font-size: clamp(1.4rem, 3vw, 1.8rem); margin: 2.2em 0 .5em; color: var(--accent-dk);
     border-bottom: 1px solid var(--paper-edge); padding-bottom: .2em; }
h3 { font-size: 1.3rem; margin: 1.8em 0 .4em; color: var(--green); }
p { margin: 0 0 1.1em; }
.lead { font-size: 1.12rem; color: var(--ink-soft); }
.eyebrow {
  text-transform: uppercase; letter-spacing: .16em; font-size: .82rem;
  color: var(--tan); font-weight: 700; margin: 0 0 .4em; font-family: var(--sans);
}
.subtitle { font-size: 1.18rem; color: var(--ink-soft); font-style: italic; margin: 0 0 1.5em;
  font-family: var(--serif); }
hr { border: 0; border-top: 1px solid var(--paper-edge); margin: 2.5em 0; }
strong, b { color: var(--ink); }

/* drop-cap on chapter opener */
.reading .opener::first-letter {
  font-size: 3.2em; line-height: .8; float: left;
  padding: .05em .12em 0 0; color: var(--accent); font-weight: 700; font-family: var(--serif);
}

/* ---------- Breadcrumb / back ---------- */
.crumb { font-size: .92rem; margin: 0 0 1.2rem; color: var(--ink-soft); }
.crumb a { text-decoration: none; }
.crumb a:hover { text-decoration: underline; }

/* ---------- Person links inline ---------- */
a.person {
  text-decoration: none;
  border-bottom: 1.5px solid var(--accent-soft);
  font-weight: 600;
  white-space: nowrap;
}
a.person:hover, a.person:focus { background: #eef2f5; border-bottom-color: var(--accent); }

/* ---------- Citation markers ---------- */
.cite {
  font-size: .7em; vertical-align: super; line-height: 0;
  text-decoration: none; font-weight: 700;
  color: var(--accent); padding: 0 .1em;
}
.cite::before { content: "["; }
.cite::after  { content: "]"; }
.cite:hover, .cite:focus { background: #eef2f5; }

/* ---------- "At a Glance" factbox ---------- */
.glance {
  background: var(--tan-soft);
  border: 1px solid #e0d7c2;
  border-left: 5px solid var(--tan);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  margin: 1.5em 0 2em;
}
.glance h2, .glance h3 { margin-top: 0; border: 0; color: var(--accent-dk); }
.glance dl { display: grid; grid-template-columns: max-content 1fr; gap: .35em 1em; margin: 0; }
.glance dt { font-weight: 700; color: var(--green); }
.glance dd { margin: 0; }
@media (max-width: 34rem) {
  .glance dl { grid-template-columns: 1fr; gap: .1em; }
  .glance dd { margin: 0 0 .6em; }
}

/* ---------- Pull quote ---------- */
.pullquote {
  margin: 2em 0; padding: 1.2em 1.4em;
  border-left: 5px solid var(--accent);
  background: #eef2f5;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 1.12rem; font-style: italic; color: var(--ink);
}
.pullquote cite { display: block; margin-top: .6em; font-size: .92rem; font-style: normal;
  color: var(--ink-soft); font-weight: 600; }
.pullquote cite::before { content: "— "; }

/* ---------- Did You Know ---------- */
.didyouknow {
  margin: 2em 0; padding: 1.2em 1.4em;
  background: var(--green-soft);
  border: 1px solid #d2dccd;
  border-radius: var(--radius);
}
.didyouknow b.label { display: block; color: var(--green); letter-spacing: .1em;
  text-transform: uppercase; font-size: .8rem; margin-bottom: .4em; }

/* ---------- Research note ---------- */
.researchnote {
  margin: 2em 0; padding: 1.2em 1.4em;
  background: var(--tan-soft); border: 1px dashed var(--tan);
  border-radius: var(--radius);
}
.researchnote b.label { display: block; color: #8a7340; letter-spacing: .1em;
  text-transform: uppercase; font-size: .8rem; margin-bottom: .4em; }
.researchnote ul { margin: .4em 0 0; padding-left: 1.2em; }
.researchnote li { margin: .3em 0; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 1.5em 0; padding: 0; border-left: 2px solid var(--accent-soft); }
.timeline li { position: relative; padding: 0 0 1.1em 1.4em; }
.timeline li::before {
  content: ""; position: absolute; left: -.5rem; top: .5em;
  width: .75rem; height: .75rem; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--paper);
}
.timeline .when { font-weight: 700; color: var(--green); display: block; }

/* ---------- Tags ---------- */
.tag {
  display: inline-block; font-size: .76rem; font-weight: 700;
  padding: .15em .6em; border-radius: 999px; letter-spacing: .02em;
  vertical-align: middle; white-space: nowrap;
}
.tag.unconfirmed { background: #f0e6d2; color: #87642a; border: 1px solid #d9c79c; }
.tag.confirmed   { background: var(--green-soft); color: #44563f; border: 1px solid #c0cdb9; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans); font-size: 1.02rem; font-weight: 700;
  padding: .65rem 1.1rem; border-radius: var(--radius);
  border: 2px solid var(--accent); background: var(--accent); color: #fff;
  cursor: pointer; line-height: 1.2;
}
.btn:hover, .btn:focus { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn.ghost { background: transparent; color: var(--accent-dk); }
.btn.ghost:hover, .btn.ghost:focus { background: #eef2f5; }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- Read-aloud bar (+ injected voice/speed controls) ---------- */
.readaloud {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  margin: 0 0 1.6em; padding-bottom: 1em; border-bottom: 1px solid var(--paper-edge);
}
.readaloud .ra-opts {
  display: flex; flex-wrap: wrap; gap: .4rem .8rem; align-items: center;
  font-size: .9rem; color: var(--ink-soft);
}
.readaloud label { font-size: .9rem; color: var(--ink-soft); }
.readaloud select, .readaloud input[type="range"] {
  font-family: var(--sans); font-size: .95rem; vertical-align: middle;
}
.readaloud select {
  padding: .35rem .5rem; border: 1px solid var(--accent-soft);
  border-radius: 8px; background: var(--paper); color: var(--ink); max-width: 13rem;
}

/* ---------- Chapter / people cards ---------- */
.cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); margin: 1.5em 0; }
.card {
  display: block; text-decoration: none; color: var(--ink);
  background: var(--paper); border: 1px solid var(--paper-edge);
  border-radius: var(--radius); padding: 1.2rem 1.3rem; box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.card:hover, .card:focus {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(49,47,42,.09), 0 12px 28px rgba(49,47,42,.09);
  color: var(--ink); border-color: var(--accent-soft);
}
.card .num { font-size: .82rem; letter-spacing: .1em; text-transform: uppercase; color: var(--tan); font-weight: 700; }
.card .card-title { font-size: 1.25rem; margin: .15em 0 .35em; color: var(--accent-dk); font-family: var(--serif); }
.card .card-sub { color: var(--ink-soft); font-size: 1rem; }
@media (prefers-reduced-motion: reduce) { .card:hover, .card:focus { transform: none; } }

/* ---------- Search ---------- */
.search { margin: 1.5em auto; max-width: var(--maxread); }
.search label { display: block; font-weight: 700; margin-bottom: .4em; color: var(--green); }
.search-row { display: flex; gap: .5rem; }
.search input[type="search"] {
  flex: 1; font-family: var(--sans); font-size: 1.05rem;
  padding: .7rem .9rem; border: 2px solid var(--accent-soft);
  border-radius: var(--radius); background: var(--paper); color: var(--ink);
}
.search input[type="search"]:focus { border-color: var(--accent); outline: none; }
#search-results { margin: 1em 0 0; padding: 0; list-style: none; }
#search-results li { margin: 0 0 .6em; }
#search-results a { font-weight: 700; text-decoration: none; }
#search-results .ctx { display: block; color: var(--ink-soft); font-size: .95rem; font-weight: 400; }
#search-results .empty { color: var(--ink-soft); font-style: italic; }

/* ---------- Chat box ---------- */
.chat {
  max-width: var(--maxread); margin: 2em auto 0;
  background: var(--paper); border: 1px solid var(--paper-edge);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.4rem 1.5rem;
}
.chat h2 { margin-top: 0; }
.chat .chat-row { display: flex; gap: .5rem; margin: .8em 0; }
.chat input[type="text"], .chat input[type="password"] {
  flex: 1; font-family: var(--sans); font-size: 1.05rem;
  padding: .7rem .9rem; border: 2px solid var(--accent-soft);
  border-radius: var(--radius); background: #fff; color: var(--ink);
}
.chat input:focus { border-color: var(--accent); outline: none; }
.chat .examples { font-size: .95rem; color: var(--ink-soft); }
.chat .examples button {
  background: #eef2f5; border: 1px solid var(--accent-soft); color: var(--accent-dk);
  border-radius: 999px; padding: .25em .8em; margin: .2em .3em .2em 0; cursor: pointer;
  font-family: var(--sans); font-size: .92rem;
}
.chat .examples button:hover { background: #e3ebf0; }
#chat-answer, #add-answer { margin-top: 1em; padding: 1em 1.1em; background: #eef2f5;
  border-radius: var(--radius); border: 1px solid var(--accent-soft); white-space: pre-wrap;
  line-height: 1.55; }
#chat-answer:empty, #add-answer:empty { display: none; }
#add-answer h2 { font-size: 1.15rem; margin: .8em 0 .3em; border: 0; color: var(--accent-dk); }
.chat .cost { font-size: .85rem; color: var(--ink-soft); margin-top: .5em; }
.chat .cost:empty { display: none; }
.chat .note { font-size: .88rem; color: var(--ink-soft); margin-top: .8em; }
.chat .locknote { font-size: .9rem; color: var(--ink-soft); }

/* ---------- Talk-it-through transcript ---------- */
.discuss-log { margin: .8em 0; display: flex; flex-direction: column; gap: .5rem; }
.discuss-log:empty { display: none; }
.dmsg { padding: .6em .9em; border-radius: var(--radius); max-width: 92%; white-space: pre-wrap; line-height: 1.5; }
.dmsg.user { align-self: flex-end; background: #dfe7ec; }
.dmsg.ai { align-self: flex-start; background: #eef2f5; border: 1px solid var(--accent-soft); }
.dmsg .who { font-size: .72rem; color: var(--ink-soft); display: block; margin-bottom: .2em; text-transform: uppercase; letter-spacing: .06em; }
.dmsg .photo { font-size: .82rem; color: var(--green); font-weight: 700; }
.dmsg.thinking { color: var(--ink-soft); font-style: italic; }

/* ---------- Jerry's notes box ---------- */
.notes {
  margin: 2.5em 0 0; padding: 1.3em 1.5em;
  background: var(--green-soft); border: 1px solid #d2dccd; border-radius: var(--radius);
}
.notes h2 { margin-top: 0; border: 0; color: var(--green); }
.notes code { background: #fff; padding: .1em .4em; border-radius: 5px; border: 1px solid var(--paper-edge); }

/* ---------- Family additions (auto-published, fact-checked) ---------- */
.family-additions:empty { display: none; }
.family-additions h2 { margin-top: 2em; }
.addition {
  margin: 1em 0; padding: 1.1em 1.3em;
  background: var(--green-soft); border: 1px solid #cfdac9;
  border-left: 5px solid var(--green); border-radius: var(--radius);
}
.addition .add-meta { font-size: .85rem; color: var(--ink-soft); margin-bottom: .4em; }
.addition .add-meta b { color: var(--green); }
.addition .add-text { white-space: pre-wrap; }
.addition .add-del {
  float: right; font-size: .8rem; color: var(--ink-soft);
  background: none; border: 1px solid var(--paper-edge); border-radius: 6px;
  padding: .1em .5em; cursor: pointer;
}
.addition .add-del:hover { color: #a23; border-color: #d9b3b3; }
.add-intro { color: var(--ink-soft); font-size: .98rem; }

/* ---------- Sources list ---------- */
.sources-list { list-style: none; padding: 0; margin: 1em 0; }
.sources-list li {
  margin: 0 0 1em; padding: .9em 1.1em; background: #faf8f2;
  border: 1px solid var(--paper-edge); border-radius: var(--radius);
}
.sources-list .src-title { font-weight: 700; }
.sources-list .src-meta { font-size: .9rem; color: var(--ink-soft); }
.sources-list .src-note { font-size: .98rem; margin-top: .3em; }

/* ---------- Family tree ---------- */
.tree { margin: 1.5em 0; }
.tree ul { list-style: none; margin: 0; padding-left: 1.3rem; border-left: 2px solid var(--accent-soft); }
.tree > ul { border-left: 0; padding-left: 0; }
.tree li { margin: .35em 0; }
.tree details > summary {
  cursor: pointer; padding: .55rem .8rem; border-radius: var(--radius);
  background: var(--paper); border: 1px solid var(--paper-edge);
  list-style: none; display: flex; align-items: baseline; gap: .5rem;
}
.tree details > summary::-webkit-details-marker { display: none; }
.tree details > summary::before {
  content: "▸"; color: var(--accent); font-weight: 700; transition: transform .12s ease;
  display: inline-block;
}
.tree details[open] > summary::before { transform: rotate(90deg); }
.tree summary:hover, .tree summary:focus { background: #eef2f5; }
.tree .leaf {
  padding: .5rem .8rem; border-radius: var(--radius);
  background: #faf8f2; border: 1px dashed var(--paper-edge); display: inline-block;
}
.tree .who { font-weight: 700; }
.tree .who a { text-decoration: none; }
.tree .meta { color: var(--ink-soft); font-size: .95rem; }
.tree .gen-label { color: var(--tan); font-weight: 700; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .08em; }
.tree-controls { display: flex; gap: .6rem; margin-bottom: 1em; flex-wrap: wrap; }

/* ---------- Responsive tables ---------- */
.table-scroll { overflow-x: auto; margin: 1.5em 0; border-radius: var(--radius); }
table.chart { border-collapse: collapse; width: 100%; min-width: 38rem; background: var(--paper); }
table.chart th, table.chart td { text-align: left; padding: .7rem .9rem; border: 1px solid var(--paper-edge); vertical-align: top; }
table.chart thead th { background: var(--accent); color: #fff; }
table.chart tbody tr:nth-child(even) { background: #faf8f2; }

/* ---------- Footer ---------- */
.site-footer {
  background: #33312c; color: #d8d2c5; margin-top: 3rem;
  border-top: 3px solid var(--tan);
}
.site-footer__inner { max-width: var(--maxwide); margin: 0 auto; padding: 2rem 1.25rem;
  font-size: .96rem; }
.site-footer a { color: #cdbb95; }
.site-footer p { margin: .3em 0; }

/* ---------- Home launcher ---------- */
.hero { text-align: center; background: linear-gradient(180deg, #efece3, #e7e1d3);
  border: 1px solid var(--paper-edge); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(2rem, 6vw, 3.25rem) 1.5rem; margin: 0 auto 1.5rem; max-width: var(--maxwide); }
.hero .eyebrow { color: var(--tan); }
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); margin: .1em 0; color: var(--accent-dk); }
.hero .surnames { letter-spacing: .06em; color: var(--green); font-weight: 700; margin: .6em 0; font-family: var(--sans); }
.hero .places { color: var(--ink-soft); font-style: italic; }
.hero .gift { margin-top: 1.2em; font-size: 1.02rem; }
.hero .gift b { color: var(--accent-dk); }

.launcher { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  max-width: var(--maxwide); margin: 1.5rem auto; }
.launch { display: flex; gap: .9rem; align-items: flex-start; text-decoration: none; color: var(--ink);
  background: var(--paper); border: 1px solid var(--paper-edge); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.3rem 1.4rem;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.launch:hover, .launch:focus { transform: translateY(-2px); border-color: var(--accent-soft); color: var(--ink);
  box-shadow: 0 4px 8px rgba(49,47,42,.09), 0 12px 28px rgba(49,47,42,.09); }
.launch .ic { font-size: 2rem; line-height: 1; }
.launch .lt { font-family: var(--serif); font-size: 1.3rem; color: var(--accent-dk); margin: 0 0 .15em; }
.launch .ls { color: var(--ink-soft); font-size: 1rem; }
@media (prefers-reduced-motion: reduce) { .launch:hover, .launch:focus { transform: none; } }

/* ---------- Back to top ---------- */
.backtotop { position: fixed; right: 1rem; bottom: 1rem; z-index: 50; display: none;
  font-family: var(--sans); font-size: 1rem; font-weight: 700; cursor: pointer;
  background: var(--accent); color: #fff; border: 2px solid #fff; border-radius: 999px;
  padding: .7rem 1.1rem; box-shadow: 0 3px 10px rgba(49,47,42,.25); }
.backtotop:hover, .backtotop:focus { background: var(--accent-dk); }
.backtotop.show { display: block; }

/* ---------- Utility ---------- */
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.small { font-size: .9rem; }
.mt0 { margin-top: 0; }
.dedication { font-style: italic; font-size: 1.12rem; text-align: center; color: var(--ink-soft);
  max-width: 34rem; margin: 1.5em auto; line-height: 1.8; font-family: var(--serif); }
