/* ---------- design tokens ---------- */
:root {
  /* warm parchment palette — nods to the old #FFFFBC body + #FFBBBB cells
     without the 1999 saturation */
  --bg:           #fdf8e8;       /* parchment cream */
  --surface:      #ffffff;
  --surface-2:    #f6efd9;       /* sun-bleached paper */
  --text:         #2a2420;
  --muted:        #6b635c;
  --border:       #e9dcb8;       /* warmer tan border */
  --accent:       #b85c5c;       /* deep coral, evolved from heritage #FFBBBB */
  --accent-soft:  #f8c8c8;       /* a touch closer to the original pink */
  --accent-ink:   #7a3434;
  --accent-warm:  #c89544;       /* antique amber, echoing the old #ffbb33 */
  --link:         #8a3a3a;
  --link-hover:   #5e2424;
  --shadow-sm:    0 1px 2px rgba(70, 50, 20, 0.07);
  --shadow-md:    0 4px 16px rgba(70, 50, 20, 0.10);

  --radius-sm:    4px;
  --radius:       8px;
  --radius-lg:    14px;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.25rem;
  --space-7: 3.5rem;

  --container:    72rem;
  --content:      44rem;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}
img, svg { max-width: 100%; height: auto; display: block; }
button { font: inherit; cursor: pointer; }
a { color: var(--link); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--link-hover); }

/* ---------- typography ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 var(--space-4);
  color: var(--text);
}
h1 { font-size: clamp(1.75rem, 2.5vw + 1rem, 2.5rem); }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
p  { margin: 0 0 var(--space-4); }
.lede { font-size: 1.1rem; color: var(--muted); }

/* ---------- layout primitives ---------- */
.container { max-width: var(--container); margin: 0 auto; padding: 0 var(--space-5); }
.prose     { max-width: var(--content); margin: 0 auto; padding: 0 var(--space-5); }

main { padding: var(--space-6) 0 var(--space-7); }

/* ---------- site header / nav ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: saturate(1.2) blur(8px);
}
.site-header .container {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding-top: var(--space-3);
  padding-bottom: var(--space-3);
}
.brand {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { color: var(--accent-ink); }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-left: auto;
  align-items: center;
}
.nav a {
  text-decoration: none;
  color: var(--text);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}
.nav a:hover { background: var(--accent-soft); color: var(--accent-ink); }
.nav a.current { background: var(--accent-soft); color: var(--accent-ink); }

.nav details { position: relative; }
.nav details summary {
  list-style: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  font-size: 0.95rem;
}
.nav details summary::-webkit-details-marker { display: none; }
.nav details summary::after { content: " ▾"; color: var(--muted); }
.nav details summary:hover { background: var(--accent-soft); color: var(--accent-ink); }
.nav details[open] summary { background: var(--accent-soft); color: var(--accent-ink); }
.nav details .menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: var(--space-2);
  min-width: 14rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
}
.nav details .menu a { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-5) 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* ---------- hero ---------- */
.hero {
  position: relative;
  margin: 0 0 var(--space-7);
  border-radius: var(--radius-lg);
  overflow: hidden;
  padding: clamp(var(--space-6), 10vw, var(--space-7)) clamp(var(--space-5), 6vw, var(--space-7));
  color: #fff8e0;
  background:
    linear-gradient(135deg, rgba(122, 52, 52, 0.55) 0%, rgba(40, 30, 20, 0.78) 70%),
    var(--hero-image, none) center/cover no-repeat,
    var(--surface-2);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.hero::after {
  /* subtle warm vignette across the bottom for legibility */
  content: "";
  position: absolute; inset: auto 0 0 0; height: 40%;
  background: linear-gradient(to top, rgba(40, 30, 20, 0.55), transparent);
  pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero h1 {
  color: #fffaf0;
  font-size: clamp(1.9rem, 3vw + 1rem, 2.9rem);
  margin-bottom: var(--space-3);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.hero p { color: #fff5dc; font-size: 1.1rem; max-width: 38rem; }
.hero .fleuron {
  font-family: var(--font-serif);
  color: var(--accent-warm);
  font-size: 1.5rem;
  display: block;
  margin-bottom: var(--space-2);
}

/* ---------- cards & surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--space-4); }

.callout {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius);
  color: var(--accent-ink);
}

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.field label { font-weight: 600; font-size: 0.95rem; }
input[type="text"],
input[type="search"],
input[type="number"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  color: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}
.btn:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--accent-ink);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--accent-soft); }

.search-bar { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.search-bar input[type="search"] { flex: 1 1 18rem; min-width: 12rem; }
.search-bar label { display: inline-flex; gap: var(--space-2); align-items: center; font-weight: 400; color: var(--muted); }

/* ---------- person page ---------- */
.person-header {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
  margin-bottom: var(--space-6);
}
.person-header .portrait {
  width: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  background: var(--surface-2);
}
.person-header .meta dt { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; margin-top: var(--space-3); }
.person-header .meta dd { margin: 0; }
.person-header .meta dl { margin: 0; }
.person-header h1 { margin-bottom: var(--space-2); }
.person-header .lifespan { color: var(--muted); font-size: 1.05rem; margin-bottom: var(--space-3); }

@media (max-width: 640px) {
  .person-header { grid-template-columns: 1fr; }
  .person-header .portrait { width: 160px; }
}

/* relationship grid for partners + children */
.relations { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); }
.relation {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: grid;
  gap: var(--space-2);
}
.relation .partner { display: flex; gap: var(--space-3); align-items: center; }
.relation .partner img { width: 64px; height: 64px; object-fit: cover; border-radius: 50%; }
.relation .partner-name { font-weight: 600; font-family: var(--font-serif); }
.relation .marriage-meta { color: var(--muted); font-size: 0.9rem; }
.relation .children { margin: 0; padding-left: var(--space-5); }
.relation .children li { margin: var(--space-1) 0; }

/* ---------- pedigree (svg tree) ---------- */
.pedigree-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  height: min(80vh, 720px);
}
.pedigree-svg { width: 100%; height: 100%; cursor: grab; user-select: none; }
.pedigree-svg.grabbing { cursor: grabbing; }
.pedigree-node rect {
  fill: var(--surface);
  stroke: var(--border);
  stroke-width: 1;
  rx: 6;
}
.pedigree-node.known rect { fill: #fff; stroke: var(--accent); }
.pedigree-node.focus rect { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.pedigree-node text {
  font-family: var(--font-sans);
  font-size: 13px;
  fill: var(--text);
}
.pedigree-node .name { font-weight: 600; }
.pedigree-node .dates { fill: var(--muted); font-size: 11px; }
.pedigree-node a:hover rect { fill: var(--accent-soft); }
.pedigree-edge { fill: none; stroke: var(--border); stroke-width: 1.5; }

.pedigree-controls {
  position: absolute;
  bottom: var(--space-3);
  right: var(--space-3);
  display: flex;
  gap: var(--space-2);
  background: var(--surface);
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.pedigree-controls button {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  color: var(--text);
}
.pedigree-controls button:hover { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- photo grid ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-5);
}
.photo-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.photo-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}
.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
  filter: saturate(0.92);
}
.photo-card-info {
  padding: var(--space-3) var(--space-4) var(--space-4);
}
.photo-card-name {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.25;
  color: var(--text);
  margin-bottom: 4px;
}
.photo-card-dates {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  font-variant-caps: all-small-caps;
}

/* legacy two-column text list (kept for any other callers) */
.photo-list {
  columns: 2;
  column-gap: var(--space-6);
  list-style: none;
  padding: 0;
}
@media (min-width: 900px) { .photo-list { columns: 3; } }
.photo-list li { break-inside: avoid; padding: var(--space-1) 0; }

/* ---------- map / timeline ---------- */
.map-page { display: flex; flex-direction: column; height: calc(100vh - 80px); padding: 0; }
.map-page .map-intro { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); background: var(--surface); }
.map-page #map { flex: 1; }
.timeline-controls {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.timeline-controls input[type="range"] { flex: 1; }
.timeline-controls .year {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.15rem;
  min-width: 4ch;
  text-align: right;
}

/* ---------- search results ---------- */
.results { list-style: none; padding: 0; }
.results li {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}
.results li .meta { color: var(--muted); font-size: 0.9rem; }

/* ---------- utilities ---------- */
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
