:root {
  --bg: #f5eddd;
  --fg: #1d160e;
  --muted: #5f4f3d;
  --line: #d9c9ad;
  --soft: #ebdfc8;
  --card: #fbf5e9;
  --accent: #8e3f17;
  --c0: #a64b24;
  --c1: #b8862b;
  --c2: #5d7a4f;
  --c3: #7b4a68;
  --c4: #4f6b80;
  --c5: #8c6d46;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .1 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--fg);
  font: 15px/1.6 ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
.muted { color: var(--muted); }
.num { text-align: right; }
.nw { white-space: nowrap; }

/* Barra */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top-in {
  max-width: 1400px; margin: 0 auto; padding: 0 24px;
  height: 52px; display: flex; align-items: center; gap: 28px;
}
.brand { font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.top nav { display: flex; gap: 20px; color: var(--muted); }
.search { position: relative; margin-left: auto; width: 260px; }
.search input {
  width: 100%; font: inherit; font-size: 14px;
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: inherit; outline: none;
}
.search input:focus { border-color: var(--muted); }
#results {
  position: absolute; right: 0; top: 40px; width: 360px; max-height: 70vh; overflow: auto;
  margin: 0; padding: 6px; list-style: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .12);
}
#results a { display: flex; flex-direction: column; padding: 6px 10px; border-radius: 6px; line-height: 1.35; }
#results a.on, #results a:hover { background: var(--soft); color: inherit; }
#results small { color: var(--muted); font-size: 12px; }

main { max-width: 1400px; margin: 0 auto; padding: 40px 24px 96px; }

/* Testate */
.hero, .ph { margin-bottom: 40px; }
.ph.with-photo { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 72px; align-items: end; }
.portrait { justify-self: end; }
.portrait img { display: block; max-height: 220px; max-width: 100%; border-radius: 6px; border: 1px solid var(--line); }
.portrait:hover img { border-color: var(--muted); }
.hero h1, .ph h1 { font-size: 34px; line-height: 1.15; letter-spacing: -.02em; font-weight: 650; margin: 0; }
.hero.small h1 { font-size: 28px; }
.eyebrow {
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 6px;
}
.stats, .life { margin: 10px 0 0; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 10px; }
.stats span + span::before, .life span + span::before { content: "•"; margin-right: 10px; opacity: .5; }
.life span:first-child { color: var(--fg); font-variant-numeric: tabular-nums; }
.alt { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.kin { margin: 14px 0 0; font-size: 14px; }

/* Sezioni */
.sec { margin: 0 0 44px; }
.sec h2 {
  font-size: 12px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 10px;
}
.sec h2 a { color: var(--fg); text-transform: none; letter-spacing: 0; font-size: 13px; }
.sec h2 .more { margin-left: auto; color: var(--muted); font-weight: 400; }
.sec h2 .muted { font-weight: 400; letter-spacing: 0; }
.sec h3 { font-size: 12px; font-weight: 500; color: var(--muted); margin: 18px 0 8px; }
.sec h3:first-of-type { margin-top: 0; }

.pgrid { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 72px; }
.pside .sec { position: sticky; top: 76px; }

/* Cronologia */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 148px minmax(0, 1fr); gap: 18px; padding: 10px 0; position: relative; }
.tl li + li { border-top: 1px solid var(--line); }
.tw { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.5; padding-top: 1px; }
.tw small { display: block; font-size: 12px; opacity: .8; }
.te { font-weight: 600; }
.key .te { color: var(--accent); }
.tp, .td { font-size: 14px; color: var(--muted); }
.tp a:hover { color: var(--accent); }
.tn { font-size: 14px; margin-top: 4px; }
.tn p { margin: 0 0 6px; }
.ctx .tt { color: var(--muted); font-size: 14px; }
.ctx .tw { opacity: .75; }
.fn {
  display: inline-block; min-width: 16px; margin-left: 3px; padding: 0 4px;
  font-size: 10px; line-height: 15px; text-align: center; vertical-align: 2px;
  border-radius: 4px; background: var(--soft); color: var(--muted);
}
.fn:hover { color: var(--accent); }

.note { max-width: 68ch; }
.note p { margin: 0 0 12px; }
.note a, .tn a, .cu a { color: var(--accent); word-break: break-all; }
.nc { margin: 0; }

.cites { margin: 0; padding-left: 22px; font-size: 14px; }
.cites li { margin-bottom: 10px; padding: 2px 6px; border-radius: 6px; transition: background .6s; }
.cites li.flash { background: var(--soft); transition: none; }
.cites .pg { display: block; color: var(--muted); font-size: 13px; }
.ctx-t { color: var(--muted); font-size: 13px; }
.ctx-t p { margin: 4px 0; }
.cu { font-size: 13px; }

/* Famiglia */
.card {
  display: flex; flex-direction: column; padding: 7px 12px; line-height: 1.35;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; min-width: 0;
}
.card:hover { border-color: var(--muted); color: inherit; }
.card .cn { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.card .cy { font-size: 12px; color: var(--muted); }
.card.empty { color: var(--muted); font-size: 13px; border-style: dashed; background: none; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 13px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line);
  display: inline-flex; gap: 6px; align-items: baseline;
}
.chip small { color: var(--muted); font-size: 11px; }
.chip.half { border-style: dashed; }
.chip:hover { border-color: var(--muted); color: inherit; }
.union + .union { margin-top: 16px; }
.uh { display: flex; align-items: center; gap: 8px; }
.uh .card { flex: 1; }
.amp { color: var(--muted); width: 14px; text-align: center; }
.um { font-size: 12px; color: var(--muted); margin: 4px 0 0 22px; }
.kids { margin: 8px 0 0 22px; padding-left: 12px; border-left: 1px solid var(--line); display: grid; gap: 6px; }

/* Ascendenza */
.ascroll { overflow-x: auto; padding-bottom: 4px; }
.icicle { display: grid; gap: 1px; min-width: calc(var(--units) * 4px + 140px); }
.ir { display: grid; grid-template-columns: 64px minmax(0, 1fr) 72px; gap: 10px; height: 30px; }
.ir.big { height: 46px; }
.ir.dot { height: 22px; }
.aread { height: 22px; margin: 0 0 8px 74px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.il, .ik { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; justify-content: center; line-height: 1.2; font-variant-numeric: tabular-nums; }
.il { position: sticky; left: 0; z-index: 1; flex-direction: row; align-items: center; justify-content: space-between; gap: 6px; }
.il small { font-size: 11px; opacity: .8; }
.ik { text-align: right; }
.ics { position: relative; min-width: 0; }
.ic {
  position: absolute; top: 0; bottom: 0;
  box-sizing: border-box; border: 1px solid var(--bg); overflow: hidden;
  background: var(--soft); background-clip: padding-box;
  color: var(--fg); border-radius: 4px;
  display: flex; flex-direction: column; justify-content: center; padding: 0 8px;
  font-size: 13px; line-height: 1.25; white-space: nowrap;
  container-type: inline-size;
}
.ic span, .ic small { overflow: hidden; text-overflow: ellipsis; }
.ic small { font-size: 11px; opacity: .7; }
@container (max-width: 34px) { .ic span { display: none; } }
@container (max-width: 90px) { .ic small { display: none; } }
.ir.dot .ic { padding: 0; border-radius: 3px; }
.ic.leaf { bottom: 50%; }
.ic.leaf small { display: none; }
.ic[data-line="0"] { background-color: color-mix(in oklab, var(--c0) var(--t), var(--bg)); }
.ic[data-line="1"] { background-color: color-mix(in oklab, var(--c1) var(--t), var(--bg)); }
.ic[data-line="2"] { background-color: color-mix(in oklab, var(--c2) var(--t), var(--bg)); }
.ic[data-line="3"] { background-color: color-mix(in oklab, var(--c3) var(--t), var(--bg)); }
.ic[data-line="4"] { background-color: color-mix(in oklab, var(--c4) var(--t), var(--bg)); }
.ic[data-line="5"] { background-color: color-mix(in oklab, var(--c5) var(--t), var(--bg)); }
.ic:hover { color: var(--fg); box-shadow: inset 0 0 0 2px var(--fg); }
.ic.void { background: none; box-shadow: inset 0 0 0 1px var(--line); }

/* Discendenza */
.dlist { margin-top: 20px; }
.dlist > summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.dlist > summary:hover { color: var(--accent); }
.desc { font-size: 14px; }
.desc ul { list-style: none; margin: 2px 0 6px 6px; padding-left: 18px; border-left: 1px solid var(--line); }
.desc li { margin: 1px 0; }
.dn summary { cursor: pointer; list-style: none; }
.dn summary::-webkit-details-marker { display: none; }
.dn summary::before {
  content: "›"; display: inline-block; width: 14px; margin-left: -14px; color: var(--muted);
  transition: transform .15s; transform-origin: 40% 55%;
}
.dn[open] > summary::before { transform: rotate(90deg); }
.dy { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.dc {
  font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 7px; margin-left: 4px;
}
.dn[open] > summary .dc { display: none; }
.dsp { color: var(--muted); font-size: 13px; margin-left: 2px; }
.dsp a { color: var(--fg); }
.desc > .dn { margin-left: 14px; }

/* Home e indici */
.rami { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.ramo {
  display: grid; grid-template-columns: 1fr auto; padding: 10px 14px; border-radius: 8px;
  background: var(--card); border: 1px solid var(--line);
}
.ramo:hover { color: inherit; border-color: var(--muted); }
.ramo span, .ramo small { color: var(--muted); font-variant-numeric: tabular-nums; }
.ramo small { grid-column: 1 / -1; font-size: 12px; }
.heads { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }

.hero:has(.filter) { display: flex; flex-wrap: wrap; align-items: center; gap: 0 32px; }
.hero .filter { margin-top: 10px; }
.hero:has(.filter) > :not(.filter) { flex: 1 1 auto; }
.hero:has(.filter) h1 { width: 100%; }
.filter {
  font: inherit; font-size: 14px; padding: 5px 12px; width: 260px; max-width: 100%;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: inherit; outline: none;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 0 12px 8px 0; border-bottom: 1px solid var(--line); }
td { padding: 7px 12px 7px 0; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.etab td:first-child { width: 160px; }
.etab td:nth-child(2) { width: 160px; }

.pgroups { columns: 4 260px; column-gap: 40px; }
.clist { list-style: none; margin: 0; padding: 0; columns: 4 260px; column-gap: 40px; font-size: 14px; }
.clist.wide { columns: 2 420px; }
.clist li { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; break-inside: avoid; border-bottom: 1px solid var(--line); }
.clist li a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clist small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.clist .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.pgroup { break-inside: avoid; margin-bottom: 28px; }
.pgroup h3 { font-size: 12px; letter-spacing: .1em; color: var(--muted); font-weight: 600; margin: 0 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.plist { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.plist li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.plist span, .pgroup h3 span { color: var(--muted); font-variant-numeric: tabular-nums; letter-spacing: 0; font-weight: 400; }
.srcbody { margin-bottom: 32px; }

/* Storia */
.st-grid { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 56px; }
.st-menu { position: sticky; top: 76px; align-self: start; display: flex; flex-direction: column; font-size: 14px; }
.st-menu a { padding: 4px 12px; border-left: 2px solid var(--line); color: var(--muted); }
.st-menu a:hover { color: var(--fg); }
.st-menu a.on { color: var(--fg); border-left-color: var(--accent); }
.fam-st { margin-bottom: 64px; scroll-margin-top: 72px; }
.fam-st h3 { color: var(--fg); font-size: 28px; line-height: 1.2; letter-spacing: -.01em; font-weight: 650; margin: 0 0 8px; }
.fam-st h3 small { display: block; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.chap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 48px; padding: 28px 0; border-bottom: 1px solid var(--line); }
.chap h4 { font-size: 18px; font-weight: 600; margin: 0 0 14px; }
.line { list-style: none; margin: 0 0 16px; padding: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; max-width: 68ch; }
.line li { padding: 2px 0; }
.line a, .story a, .chap-note a { text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.story a, .chap-note a, .refs a { color: var(--accent); }
.refs { font-size: 14px; color: var(--muted); margin: 0 0 16px; max-width: 68ch; }
.story { max-width: 68ch; font-size: 16px; line-height: 1.7; }
.story p { margin: 0 0 14px; }
.story ul { margin: 0 0 14px; padding-left: 20px; }
.chap-note { align-self: start; font-size: 14px; line-height: 1.65; color: var(--muted); border-left: 2px solid var(--line); padding-left: 18px; }
.chap-note p { margin: 0 0 12px; }
.st-intro { max-width: 68ch; }

.gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 18px; }
.gal.captioned { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px 12px; }
.th { display: flex; flex-direction: column; gap: 6px; }
.th img, .album img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block;
  border-radius: 6px; border: 1px solid var(--line); background: var(--soft);
}
.th:hover img, .album:hover img { border-color: var(--muted); }
.th span { font-size: 12px; line-height: 1.4; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin: 20px 0; }
.album { display: flex; flex-direction: column; gap: 4px; }
.album b { font-weight: 500; margin-top: 4px; }
.album small { color: var(--muted); font-size: 12px; }
.album:hover { color: inherit; }

/* Visore */
#viewer {
  inset: 0; width: 100%; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #18130e; color: #f3ead8; overflow: hidden;
}
#viewer::backdrop { background: transparent; }
.vstage { position: absolute; inset: 0 0 56px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.vstage img { max-width: 92vw; max-height: calc(100vh - 96px); object-fit: contain; cursor: zoom-in; user-select: none; }
#viewer.zoomed .vstage img { cursor: grab; }
#viewer button { background: none; border: 0; color: inherit; cursor: pointer; opacity: .7; font: inherit; }
#viewer button:hover { opacity: 1; }
#viewer .prev, #viewer .next { position: absolute; top: 50%; transform: translateY(-50%); font-size: 44px; line-height: 1; padding: 24px 18px; }
#viewer .prev { left: 4px; }
#viewer .next { right: 4px; }
#viewer.single .prev, #viewer.single .next { display: none; }
#viewer .close { position: absolute; top: 14px; right: 20px; font-size: 14px; }
.vcap { position: absolute; left: 0; right: 0; bottom: 0; height: 56px; display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 0 24px; font-size: 14px; }
.vcap .dy { color: rgba(243, 234, 216, .6); }

@media (max-width: 900px) {
  .pgrid { grid-template-columns: 1fr; gap: 0; }
  .ph.with-photo { grid-template-columns: minmax(0, 1fr) auto; gap: 20px; }
  .portrait img { max-height: 140px; }
  .st-grid, .chap { grid-template-columns: 1fr; gap: 20px; }
  .st-menu { position: static; flex-direction: row; flex-wrap: wrap; gap: 4px 0; }
  .st-menu a { border-left: 0; border-bottom: 2px solid var(--line); }
  .st-menu a.on { border-bottom-color: var(--accent); }
  .pside .sec { position: static; }
  .pside { order: -1; }
}
@media (max-width: 640px) {
  .top-in { padding: 0 16px; gap: 14px; height: auto; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .search { width: 100%; order: 3; }
  .hero .filter { width: 100%; margin-top: 14px; }
  #results { width: 100%; }
  main { padding: 28px 16px 64px; }
  .hero h1, .ph h1 { font-size: 26px; }
  .tl li { grid-template-columns: 1fr; gap: 2px; }
  .ir { grid-template-columns: 58px minmax(0, 1fr) 0; gap: 6px; }
  .ik { display: none; }
  .aread { margin-left: 64px; }
  .il { background: var(--bg); }
  .ptab td:nth-child(3), .ptab td:nth-child(4) { display: none; }
  .etab td:first-child, .etab td:nth-child(2) { width: auto; }
}
