:root {
  color-scheme: dark;
  --bg: #0d0f14;
  --bg2: #151a27;
  --card: #181d2b;
  --ink: #ece4d0;
  --muted: #a8a28f;
  --line: #2b3247;
  --gold: #e6c36a;
  --display: "Cinzel", "Trajan Pro", Georgia, serif;
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --radius: 14px;
  --accent: var(--gold);
  --nav-h: 56px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1100px 520px at 50% -8%, #202a4a 0%, transparent 62%),
    var(--bg);
  background-repeat: no-repeat;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.55;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--gold); color: #111; padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px;
  height: var(--nav-h);
  padding: 0 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  background: rgba(13, 15, 20, .86);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--display); font-weight: 700; letter-spacing: .08em; text-decoration: none; color: var(--gold); white-space: nowrap; font-size: .95rem; }
.era-nav {
  display: flex; gap: 6px; overflow-x: auto; flex: 1; min-width: 0;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 20px), transparent 100%);
  padding: 4px 14px;
}
.era-nav::-webkit-scrollbar { display: none; }
.era-chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: .9rem; white-space: nowrap;
  transition: background .2s, color .2s, border-color .2s;
}
.era-chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.era-chip:hover { color: var(--ink); }
.era-chip[aria-current="true"] { color: var(--ink); border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); }
@media (max-width: 760px) { .brand { display: none; } }

/* ---------- hero ---------- */
.hero { max-width: 760px; margin: 0 auto; padding: 56px 16px 12px; text-align: center; }
.eyebrow { margin: 0 0 10px; font-family: var(--display); font-size: .78rem; letter-spacing: .28em; text-transform: uppercase; color: var(--muted); }
h1 {
  margin: 0 0 14px; font-family: var(--display); font-weight: 700;
  font-size: clamp(2.3rem, 9vw, 4.4rem); line-height: 1.05; letter-spacing: .04em;
  background: linear-gradient(180deg, #fff3cc 0%, var(--gold) 55%, #a8812f 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lede { margin: 0 auto 28px; max-width: 54ch; color: var(--muted); font-size: 1.12rem; }

/* ---------- controls ---------- */
.controls { display: grid; gap: 12px; text-align: left; }
.search input {
  width: 100%; height: 48px; padding: 0 16px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  font-size: 1rem;
}
.search input::placeholder { color: #7d8196; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg2);
  cursor: pointer; font-size: .92rem; color: var(--muted);
}
.chip[aria-pressed="true"] { color: #14110a; background: var(--gold); border-color: var(--gold); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; margin-right: auto; color: var(--muted); }
.switch input { width: 20px; height: 20px; accent-color: var(--gold); }
.btn {
  min-height: 40px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  background: var(--gold); color: #14110a; border: 1px solid var(--gold); font-weight: 500;
}
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.count { margin: 0; min-height: 1.4em; color: var(--muted); font-size: .95rem; }

.key { margin: 18px 0 0; text-align: left; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px; color: var(--muted); }
.key summary { cursor: pointer; padding: 10px 0; }
.key dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 8px; }
.key dt { font-family: var(--display); color: var(--gold); font-size: .85rem; letter-spacing: .06em; }
.key dd { margin: 0; }
.key p { margin: 0 0 12px; }

/* ---------- timeline ---------- */
.timeline { position: relative; max-width: 1040px; margin: 40px auto 0; padding: 0 16px 80px; }
.spine { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: var(--line); }
.spine-fill { width: 100%; height: 0; background: linear-gradient(180deg, #fff3cc, var(--gold)); box-shadow: 0 0 14px 1px rgba(230, 195, 106, .6); }

.era { position: relative; scroll-margin-top: calc(var(--nav-h) + 8px); }
.era-top { position: relative; padding: 64px 0 32px; }
.era-head {
  position: relative; z-index: 2; max-width: 640px; margin: 0 auto; padding: 24px 24px 20px;
  text-align: center; border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 16%, var(--bg2)), var(--bg2));
  box-shadow: 0 0 44px -14px var(--accent);
}
.era-kicker { margin: 0 0 6px; font-family: var(--display); font-size: .78rem; letter-spacing: .22em; text-transform: uppercase; color: var(--accent); }
.era-head h2 { margin: 0 0 4px; font-family: var(--display); font-size: clamp(1.5rem, 5.5vw, 2.1rem); letter-spacing: .04em; line-height: 1.15; }
.era-meta { margin: 0 0 12px; color: var(--muted); font-style: italic; }
.era-intro { margin: 0 auto 14px; max-width: 46ch; }
.era-toggle {
  min-height: 36px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); color: var(--ink); font-size: .9rem;
}
.era-toggle:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.era.collapsed .events { display: none; }

.events { list-style: none; margin: 0; padding: 0; }
.event {
  --accent: inherit;
  display: grid; grid-template-columns: 1fr 44px 1fr; align-items: start;
  margin: 0 0 20px; position: relative;
}
.event[hidden] { display: none; }
.node {
  grid-column: 2; grid-row: 1; justify-self: center; z-index: 1;
  width: 16px; height: 16px; margin-top: 24px; border-radius: 50%;
  background: var(--bg); border: 3px solid var(--accent);
  transition: background .25s, box-shadow .25s, transform .25s;
}
.event.major .node { width: 22px; height: 22px; margin-top: 21px; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent), 0 0 18px var(--accent); }
.event.open .node { background: var(--accent); }

.card {
  grid-row: 1; position: relative; width: 100%; max-width: 480px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .25s, box-shadow .25s, transform .25s;
}
.event.left .card { grid-column: 1; justify-self: end; }
.event.right .card { grid-column: 3; justify-self: start; }
.card::after { content: ""; position: absolute; top: 31px; width: 22px; height: 2px; background: var(--accent); opacity: .5; }
.event.left .card::after { right: -23px; }
.event.right .card::after { left: -23px; }
.event.major .card { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 9%, var(--card)), var(--card)); }
.card:hover { border-color: var(--accent); }
.event.open .card { box-shadow: 0 10px 34px -14px var(--accent); }

.card-btn { display: block; width: 100%; padding: 14px 16px 12px; background: none; border: 0; text-align: left; cursor: pointer; border-radius: var(--radius); }
.meta { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; font-size: .82rem; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.meta .tag { color: var(--muted); letter-spacing: .02em; text-transform: none; white-space: nowrap; }
.card h3 { margin: 0 0 4px; font-family: var(--display); font-weight: 500; font-size: 1.08rem; line-height: 1.3; letter-spacing: .02em; }
.event.major h3 { font-weight: 700; font-size: 1.16rem; }
.summary { margin: 0; color: #d6cfbb; }
.more { display: inline-block; margin-top: 8px; font-size: .85rem; color: var(--accent); }
.more::after { content: " +"; }
.event.open .more::after { content: " −"; }

.detail { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .3s ease; }
.event.open .detail { grid-template-rows: 1fr; }
.detail > div { overflow: hidden; }
.detail p { margin: 0; padding: 12px 16px 16px; border-top: 1px dashed var(--line); color: var(--muted); }

/* ---------- character lifelines ---------- */
.lives-label { margin: 0 0 8px; font-family: var(--display); font-size: .78rem; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.lives-chips .chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.lives-chips .chip[aria-pressed="true"] { background: color-mix(in srgb, var(--c) 22%, var(--bg2)); color: var(--ink); border-color: var(--c); }
.life-info { margin-top: 10px; padding: 12px 14px; border-left: 3px solid var(--life, var(--gold)); background: var(--bg2); border-radius: 0 10px 10px 0; }
.life-info[hidden], .life-bar[hidden] { display: none; }
.life-info strong { font-family: var(--display); font-weight: 500; letter-spacing: .03em; }
.life-info p { margin: 4px 0 0; color: var(--muted); }

.life-bar {
  position: sticky; top: var(--nav-h); z-index: 45;
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 12px;
  background: rgba(13, 15, 20, .92); border-bottom: 1px solid var(--life);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: .95rem;
}
.life-bar strong { font-family: var(--display); font-weight: 500; }
.life-bar #lifeDates { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.life-bar button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; }
.life-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--life); box-shadow: 0 0 10px var(--life); }

/* the band: drawn per row so it survives expanding cards, filters and true scale */
.has-life { --lifebar: color-mix(in srgb, var(--life) 60%, transparent); }
.has-life .era { scroll-margin-top: calc(var(--nav-h) + 48px); }
.has-life .event:not(.lived) { opacity: .4; }
.has-life .event:not(.lived):hover, .has-life .event:not(.lived):focus-within { opacity: 1; }
.event.lived::before, .era-top.lived-head::before, .life-marker::before {
  content: ""; position: absolute; left: 50%; width: 10px; margin-left: -5px; background: var(--lifebar);
}
.event.lived::before { top: 0; bottom: -20px; }
.era-top.lived-head::before { top: 0; bottom: 0; }
.event.lived .node { box-shadow: 0 0 0 3px var(--lifebar); }
.gap.lived { background: linear-gradient(var(--lifebar), var(--lifebar)) 50% 0 / 10px 100% no-repeat; }
.life-marker { position: relative; list-style: none; z-index: 1; display: flex; justify-content: center; align-items: center; min-height: 44px; margin: 0 0 20px; }
.life-marker.start::before { top: 50%; bottom: -20px; }
.life-marker.end::before { top: 0; bottom: 50%; }
.life-pill {
  position: relative; display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px;
  background: var(--bg2); border: 1px solid var(--life); font-size: .92rem; text-align: center;
}
.life-pill i { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--life); box-shadow: 0 0 8px var(--life); }

/* true-scale gaps */
.scale-note { margin: 0; padding: 10px 14px; border-left: 3px solid var(--gold); background: var(--bg2); border-radius: 0 10px 10px 0; color: var(--muted); font-size: .92rem; }
.scale-note[hidden] { display: none; }
.gap { position: relative; list-style: none; z-index: 1; }
.gap::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 8px; margin-left: -4px;
  background: repeating-linear-gradient(180deg, var(--bg) 0 9px, transparent 9px 18px);
}
.gap-pill {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: inline-flex; flex-direction: column; align-items: center; white-space: nowrap;
  padding: 6px 14px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line);
  font-family: var(--display); font-size: .82rem; letter-spacing: .06em; color: var(--gold);
}
.gap-pill small { font-family: var(--serif); font-size: .72rem; letter-spacing: 0; color: var(--muted); font-style: italic; }
.era > .gap { margin-bottom: -48px; } /* the age banner already carries its own top margin */
.empty { text-align: center; color: var(--muted); padding: 40px 0; position: relative; z-index: 2; background: var(--bg); }

/* reveal on scroll (only when JS runs) */
.js .event { opacity: 0; transform: translateY(18px); transition: opacity .5s ease, transform .5s ease; }
.js .event.in { opacity: 1; transform: none; }

/* ---------- footer, to-top ---------- */
.foot { max-width: 640px; margin: 0 auto; padding: 24px 16px 56px; text-align: center; color: var(--muted); font-size: .92rem; border-top: 1px solid var(--line); }
.to-top {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 60;
  width: 48px; height: 48px; border-radius: 50%; cursor: pointer;
  background: var(--gold); color: #14110a; border: 0; font-size: 1.3rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
.to-top[hidden] { display: none; }
.noscript { text-align: center; color: var(--gold); }

/* ---------- phone layout ---------- */
@media (max-width: 760px) {
  body { font-size: 17px; }
  .hero { padding-top: 40px; }
  .spine { left: 38px; margin-left: -1px; }
  .event { grid-template-columns: 44px 1fr; }
  .node { grid-column: 1; }
  .event.left .card, .event.right .card { grid-column: 2; justify-self: stretch; max-width: none; }
  .event.left .card::after, .event.right .card::after { left: -23px; right: auto; }
  .era-top { padding-top: 48px; }
  .era-head { padding: 20px 16px 16px; }
  .gap::before { left: 22px; }
  .event.lived::before, .era-top.lived-head::before, .life-marker::before { left: 22px; }
  .gap.lived { background-position: 17px 0; }
  .life-marker { justify-content: flex-start; padding-left: 40px; }
  .lives-chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 6px; scrollbar-width: none; }
  .lives-chips::-webkit-scrollbar { display: none; }
  .lives-chips .chip { flex: none; }
  .gap-pill { left: 40px; transform: translateY(-50%); align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js .event { opacity: 1; transform: none; transition: none; }
  .detail { transition: none; }
}
@media print {
  .topbar, .controls, .to-top { display: none; }
  .js .event { opacity: 1; transform: none; }
  .detail { grid-template-rows: 1fr; }
}

/* ---------- family trees ---------- */
.tree-btn {
  flex: none; height: 36px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid var(--gold); color: var(--gold); font-size: .9rem; white-space: nowrap;
}
.tree-btn:hover { background: color-mix(in srgb, var(--gold) 16%, transparent); }
body:has(dialog[open]) { overflow: hidden; }

.lineage {
  padding: 0; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--ink);
  width: min(960px, 94vw); height: min(88vh, 880px); max-width: none; max-height: none; overflow: hidden;
}
.lineage[open] { display: flex; flex-direction: column; }
.lineage::backdrop { background: rgba(5, 6, 10, .75); backdrop-filter: blur(3px); }
.lin-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; }
.lin-head h2 { margin: 0; font-family: var(--display); font-size: 1.25rem; letter-spacing: .05em; color: var(--gold); }
.lin-close { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; }
.lin-tools { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; padding: 0 16px 10px; border-bottom: 1px solid var(--line); }
.lin-field { display: grid; gap: 4px; font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.lin-field[hidden] { display: none; }
.lin-field select {
  height: 40px; min-width: 170px; padding: 0 10px; border-radius: 10px; font-size: 1rem; letter-spacing: 0; text-transform: none;
  background: var(--bg2); color: var(--ink); border: 1px solid var(--line);
}
.lin-tools .chip:disabled { opacity: .4; cursor: not-allowed; }
.lin-actions { display: flex; gap: 8px; margin-left: auto; }
.lin-actions [hidden] { display: none; }
.lin-who { margin: 0; padding: 8px 16px; color: var(--muted); font-style: italic; border-bottom: 1px solid var(--line); }
.lin-body { flex: 1; overflow: auto; padding: 14px 16px 24px; -webkit-overflow-scrolling: touch; }
.lin-foot { margin: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.lin-foot .lkey { margin-right: 10px; white-space: nowrap; }
.lin-foot .lkey::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; background: var(--k); }
.lin-empty, .lin-sum, .lin-hint { color: var(--muted); }
.lin-line { margin: 18px 0 8px; font-family: var(--display); font-weight: 500; font-size: .9rem; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }

.elf { --k: #7fc8ff; } .man { --k: #e0a458; } .half { --k: #c28bff; } .maia { --k: #ffe08a; }
.lcard {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; max-width: 100%;
  padding: 6px 12px; border: 1px solid var(--line); border-left: 4px solid var(--k, var(--line)); border-radius: 10px; background: var(--card);
}
.lcard.root { box-shadow: 0 0 0 2px color-mix(in srgb, var(--k) 45%, transparent); }
.lcard.gap { border: 1px dashed var(--line); background: transparent; color: var(--muted); font-style: italic; }
.lname { padding: 0; border: 0; background: none; cursor: pointer; font-family: var(--display); font-size: .98rem; letter-spacing: .02em; text-align: left; }
.lname:hover { text-decoration: underline; color: var(--k); }
.llife { color: var(--muted); font-size: .85rem; }
.lpartner { padding: 0; border: 0; background: none; cursor: pointer; color: var(--gold); font-size: .88rem; }
.lpartner:hover { text-decoration: underline; }
.lnote { flex-basis: 100%; color: var(--muted); font-size: .85rem; font-style: italic; }

.tree { list-style: none; margin: 0; padding: 0 0 0 20px; }
.tree.root { padding-left: 0; }
.tree .n, .tree .union-head { position: relative; padding: 5px 0 5px 22px; }
.tree.root > .n { padding-left: 0; }
.tree .n::before, .tree .union-head::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; border-left: 1px solid var(--line); }
.tree .n:last-child::before { bottom: auto; height: 22px; }
.tree .n::after { content: ""; position: absolute; left: 0; top: 22px; width: 16px; border-top: 1px solid var(--line); }
.tree.root > .n::before, .tree.root > .n::after { display: none; }
.union-head { color: var(--gold); font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; padding-top: 10px; }
.nrow { display: flex; align-items: flex-start; gap: 6px; }
.ltoggle {
  flex: none; width: 28px; height: 28px; margin-top: 4px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg2); color: var(--muted); position: relative;
}
.ltoggle::before { content: "−"; }
.n.collapsed > .nrow > .ltoggle::before { content: "+"; }
.lspacer { flex: none; width: 28px; }
.n.collapsed > ul { display: none; }

.chain { list-style: none; margin: 0 0 12px; padding: 0; }
.chain li { position: relative; padding: 0 0 20px 26px; }
.chain li::before { content: ""; position: absolute; left: 7px; top: 14px; bottom: -14px; border-left: 2px solid var(--line); }
.chain li:last-child::before { display: none; }
.chain li::after { content: ""; position: absolute; left: 2px; top: 11px; width: 12px; height: 12px; border-radius: 50%; background: var(--bg); border: 2px solid var(--gold); }

@media (max-width: 760px) {
  .lineage { width: 100vw; height: 100dvh; max-height: none; border: 0; border-radius: 0; }
  .lin-field select { min-width: 0; width: 100%; }
  .lin-field { flex: 1 1 140px; }
  .lin-actions { margin-left: 0; }
  .tree { padding-left: 14px; }
  .tree .n, .tree .union-head { padding-left: 16px; }
  .tree .n::after { width: 10px; }
}

.tree-cta { margin: -8px 0 24px; }

/* let scrolling rows shrink inside the grid instead of widening the page */
.controls { grid-template-columns: minmax(0, 1fr); }
.controls > * { min-width: 0; }

/* ring custody chain */
#ringsLabel { margin-top: 14px; }
.life-chain { margin: 8px 0 0; padding-left: 22px; color: var(--muted); }
.life-chain li { margin: 3px 0; }
.life-chain strong { color: var(--ink); font-weight: 500; }
.life-info .btn { margin-top: 10px; }
