/* VAEL — biblioteca. Notte pastello per default, giorno chiaro se il sistema lo chiede. */
:root {
  color-scheme: dark;
  --bg: #12102b;
  --surface: #1b1838;
  --surface-2: #241f48;
  --line: #3a3466;
  --text: #f1edff;
  --text-2: #c9c2ec;
  --muted: #9a93c4;
  --accent: #ffd59a;
  --accent-2: #ff9fc0;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: rgba(201, 194, 236, 0.12);
  --shadow: 0 10px 30px rgba(5, 3, 20, 0.35);
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f0ff;
    --surface: #fbf8ff;
    --surface-2: #efe9fb;
    --line: #d9d0f0;
    --text: #1d1838;
    --text-2: #433c66;
    --muted: #6b6390;
    --accent: #9a5b00;
    --accent-2: #b0386a;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --grid: rgba(67, 60, 102, 0.12);
    --shadow: 0 10px 30px rgba(60, 40, 120, 0.12);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-2); }
h1, h2, h3 { line-height: 1.2; font-weight: 700; letter-spacing: 0.01em; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0.2em 0 0.3em; }
h2 { font-size: 1.4rem; margin: 2.2em 0 0.8em; }
.muted, small { color: var(--muted); }
.lead { font-size: 1.15rem; color: var(--text-2); max-width: 46em; }
.empty { color: var(--muted); font-style: italic; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1.6rem;
  padding: 0.8rem max(16px, calc((100% - 1100px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: 0.35em; }
.brand span { letter-spacing: 0.05em; font-weight: 500; color: var(--muted); margin-left: 0.7em; font-size: 0.85em; }
nav { display: flex; flex-wrap: wrap; gap: 0.2rem 1rem; }
nav a { color: var(--text-2); text-decoration: none; padding: 0.2em 0; border-bottom: 2px solid transparent; }
nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; padding: 1.5rem max(16px, calc((100% - 1100px) / 2)); }

.hero { padding: 2rem 0 1rem; }
.button {
  display: inline-block; padding: 0.7em 1.3em; border-radius: 999px;
  background: var(--accent); color: #2a1a00; text-decoration: none; font-weight: 700;
}
.button:hover { color: #2a1a00; filter: brightness(1.08); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 1.5rem 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 0.9rem 1rem; }
.tile span { display: block; color: var(--muted); font-size: 0.85rem; }
.tile b { font-size: 1.7rem; font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  display: flex; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 0.2em; font-size: 1.1rem; }
.card p { margin: 0.1em 0; font-size: 0.95rem; }
.card.extinct { opacity: 0.85; }
.card.extinct .portrait { filter: grayscale(0.7) sepia(0.25); }
.portrait { flex: none; border-radius: 50%; background: radial-gradient(circle at 50% 40%, var(--surface-2), transparent 70%); }
.portrait.none { width: 96px; height: 96px; }
.dagger { color: var(--muted); font-weight: 400; }

.tree ul { list-style: none; margin: 0; padding-left: 1.4rem; border-left: 1px dashed var(--line); }
.tree > ul { border-left: 0; padding-left: 0; }
.tree li { margin: 0.25rem 0; }
.tree .node { display: inline-flex; align-items: center; gap: 0.5rem; padding: 2px 10px 2px 2px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.tree .node small { margin-left: 0.3rem; }
.tree li.gone > .node { opacity: 0.7; }
.tree li.gone > .node canvas { filter: grayscale(0.8); }

h3.day { margin: 1.6em 0 0.4em; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.chron { margin: 0; padding-left: 1.2rem; }
.chron li { margin: 0.25em 0; }
.chron li::marker { color: var(--muted); }
.chron .k-species::marker, .chron .k-record::marker { color: var(--accent); }
.chron .k-extinct::marker { color: var(--muted); }
.chron .k-climate::marker, .chron .k-house::marker { color: var(--accent-2, var(--accent)); }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 18px; }
.chart { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px 10px; }
.chart figcaption { font-weight: 700; margin-bottom: 0.3rem; }
.chart .now { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.85rem; }
.plot { position: relative; }
.plot svg { display: block; width: 100%; height: auto; overflow: visible; outline: none; }
.plot svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
svg .gl { stroke: var(--grid); stroke-width: 1; }
svg .axis { stroke: var(--line); stroke-width: 1; }
svg .tick { fill: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
svg .direct { fill: var(--text-2); font-size: 15px; }
svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .line.s1, .key.s1 { stroke: var(--series-1); background: var(--series-1); }
svg .line.s2, .key.s2 { stroke: var(--series-2); background: var(--series-2); }
svg .line.s3, .key.s3 { stroke: var(--series-3); background: var(--series-3); }
svg .cross { stroke: var(--text-2); stroke-width: 1; opacity: 0; }
svg .cross.on { opacity: 0.5; }
.legend { display: flex; gap: 1rem; list-style: none; margin: 0 0 0.4rem; padding: 0; font-size: 0.85rem; color: var(--text-2); }
.key { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.tip {
  position: absolute; top: 4px; transform: translateX(10px); pointer-events: none;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px;
  font-size: 0.85rem; box-shadow: var(--shadow); white-space: nowrap;
}
.tip.left { transform: translateX(calc(-100% - 10px)); }
.tip b, .tip span { display: block; }
.tip b { color: var(--text); }
.tip span { color: var(--text-2); font-variant-numeric: tabular-nums; }

.lex { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.lex th, .lex td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lex th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.lex td:nth-child(3), .lex td:nth-child(4) { font-variant-numeric: tabular-nums; }
.glyph { width: 30px; height: 30px; fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.certainty { display: inline-block; margin-left: 0.4rem; padding: 0 0.5em; border-radius: 999px; font-size: 0.8rem; border: 1px solid var(--line); color: var(--text-2); }
.certainty.strong { border-color: var(--accent); color: var(--accent); }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.records { list-style: none; padding: 0; margin: 0; counter-reset: r; }
.records li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.records li div { display: flex; flex-direction: column; }
.records span { color: var(--text-2); font-variant-numeric: tabular-nums; }

.prose { max-width: 46em; }
.downloads li { margin: 0.4em 0; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .lex th:nth-child(4), .lex td:nth-child(4) { display: none; }
}
[hidden] { display: none !important; }

/* Culture: dialetti per casata e luoghi */
.songs { display: flex; gap: 6px; align-items: flex-end; min-height: 48px; }
.songs .bar { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.songs .bar i { display: block; width: 10px; background: var(--accent, #8fd3ff); border-radius: 3px 3px 0 0; opacity: .8; }
.songs .bar .glyph { width: 14px; height: 14px; order: 2; }
ul.places { list-style: none; padding: 0; }
ul.places li { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.big { font-size: 1.15em; }

/* Plants */
.plants td:first-child { width: 60px; padding: 2px 0; }
.plant { display: block; }
.hist { display: flex; align-items: flex-end; gap: 3px; height: 52px; margin: 0.4rem 0 0.2rem; }
.hist i { flex: 1; display: block; background: var(--accent); opacity: 0.75; border-radius: 3px 3px 0 0; min-width: 6px; }

.genesis-video { display: block; width: min(100%, 360px); aspect-ratio: 9 / 16; margin: 1.5rem auto; border-radius: 18px; background: #0b0a1c; box-shadow: var(--shadow); }
table.rules { border-collapse: collapse; font-size: 0.92rem; }
table.rules td { padding: 0.2em 1.2em 0.2em 0; border-bottom: 1px solid var(--line); }

a.button { display: inline-block; padding: 0.6em 1.4em; border-radius: 999px; background: var(--accent); color: var(--bg); text-decoration: none; font-weight: 600; }

/* F9: pagine World e Complexity */
.worldmap { width: 100%; height: auto; border-radius: 10px; display: block; background: #20283c; }
.maps2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .maps2 { grid-template-columns: 1fr; } }
.ladder td { vertical-align: top; }
.ladder tr.note td { border-top: 0; padding-top: 0; font-size: 0.9em; }
.st { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.85em; white-space: nowrap; }
.st-yes { background: #1f6f4a; color: #eafff3; }
.st-no { background: #4a4f6a; color: #e6e8f5; }
.st-na { background: transparent; border: 1px solid #6a7090; color: #b9bfdc; }
