:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #d8dde7;
  --text: #1b2130;
  --muted: #5a6477;
  --btn: #eef1f6;
  --input-bg: #f7f8fb;
  --mrca: #a87400;
  --banner-bg: #fdf3d6;
  --banner-text: #6b4a00;
  /* per line (picked below from <html data-line>) */
  --accent-eve: #1d6bb0; --accent-adam: #11776a;
  --btn-primary-eve: #d8e8f7; --btn-primary-adam: #d2eee8;
  /* canvas colors (read by assets/render.js); "other" = dead-end children (sons for Eve, daughters for Adam) */
  --node-text: #0b0e14;
  --dead-edge: rgba(60, 70, 90, 0.16);
  --dead-alpha: 0.22;
  --other-eve: rgba(70, 100, 150, 0.3); --other-adam: rgba(170, 70, 120, 0.28);
  --other-text-eve: rgba(30, 45, 70, 0.7); --other-text-adam: rgba(85, 20, 50, 0.7);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0e14; --panel: #131824; --line: #252c3b; --text: #dde3ee; --muted: #8a94a8;
    --btn: #1d2433; --input-bg: #0b0e14; --mrca: #ffd54a; --banner-bg: rgba(255, 213, 74, 0.08);
    --banner-text: #ffe58a; --node-text: #0b0e14; --dead-edge: rgba(140, 150, 170, 0.14); --dead-alpha: 0.18;
    --accent-eve: #7cc4ff; --accent-adam: #5fd6c1; --btn-primary-eve: #1f3a55; --btn-primary-adam: #17423b;
    --other-eve: rgba(110, 140, 180, 0.35); --other-adam: rgba(205, 120, 165, 0.35);
    --other-text-eve: rgba(200, 215, 235, 0.6); --other-text-adam: rgba(245, 210, 228, 0.65);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0e14; --panel: #131824; --line: #252c3b; --text: #dde3ee; --muted: #8a94a8;
  --btn: #1d2433; --input-bg: #0b0e14; --mrca: #ffd54a; --banner-bg: rgba(255, 213, 74, 0.08);
  --banner-text: #ffe58a; --node-text: #0b0e14; --dead-edge: rgba(140, 150, 170, 0.14); --dead-alpha: 0.18;
  --accent-eve: #7cc4ff; --accent-adam: #5fd6c1; --btn-primary-eve: #1f3a55; --btn-primary-adam: #17423b;
  --other-eve: rgba(110, 140, 180, 0.35); --other-adam: rgba(205, 120, 165, 0.35);
  --other-text-eve: rgba(200, 215, 235, 0.6); --other-text-adam: rgba(245, 210, 228, 0.65);
  color-scheme: dark;
}
/* Eve (default) or Adam, set by assets/line.js */
:root { --accent: var(--accent-eve); --btn-primary: var(--btn-primary-eve); --other: var(--other-eve); --other-text: var(--other-text-eve); }
:root[data-line="adam"] { --accent: var(--accent-adam); --btn-primary: var(--btn-primary-adam); --other: var(--other-adam); --other-text: var(--other-text-adam); }
:root:not([data-line="adam"]) .only-adam, :root[data-line="adam"] .only-eve { display: none; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body {
  display: grid;
  grid-template-columns: 300px 1fr;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, sans-serif;
}

aside {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
}

.head { display: flex; align-items: center; gap: 4px; margin-block: -4px 6px; }
h1 { font-size: 17px; margin: 0; flex: 1; }
/* may wrap to two lines if the title needs the room (wide system fonts) */
.hub-link { color: var(--muted); font-size: 12px; line-height: 1.2; text-align: right; text-decoration: none; }
.hub-link:hover { color: var(--text); text-decoration: underline; }
/* "All projects" only on the hosted site (where ../ is the homepage), not from disk or in the app */
html.hosted:not(.installed) .hub-link[hidden] { display: inline; }

.info-btn, .info-close {
  flex: none; display: inline-grid; vertical-align: middle; place-items: center; width: 2.1rem; height: 2.1rem; padding: 0;
  border: 1px solid transparent; border-radius: 50%; background: transparent; color: var(--muted);
}
.info-btn:hover, .info-close:hover { color: var(--text); border-color: var(--line); }
.info-btn { width: 1.8rem; height: 1.8rem; margin: -4px 0 -2px 2px; } /* inline after the title */
.info-btn svg { width: 1.1rem; height: 1.1rem; }

/* About box (popover: opens and closes without JS, Esc or a click outside closes it) */
.info {
  width: min(36rem, calc(100vw - 32px)); max-height: min(85vh, 46rem); overflow-y: auto;
  padding: 14px 18px 16px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); font-size: 14px; line-height: 1.5;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.info::backdrop { background: rgba(0, 0, 0, .45); }
.info-head { display: flex; align-items: center; gap: 8px; position: sticky; top: -14px; margin: -14px -18px 0; padding: 10px 12px 6px 18px; background: var(--panel); }
.info h2 { font-size: 18px; margin: 0; flex: 1; }
.info h3 { font-size: 15px; margin: 16px 0 4px; }
.info p { margin: 8px 0; }

.lede { color: var(--muted); font-size: 12.5px; margin-block: 0 12px; }
.note { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }

/* Eve / Adam switch: two links (?line=eve, ?line=adam), so it works without JS and from disk */
.line-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-block: 0 12px; }
.line-switch a {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 4px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--btn);
  color: var(--text); text-decoration: none; font-size: 13px; text-align: center;
}
.line-switch small { color: var(--muted); font-size: 11px; }
.line-switch a:hover { border-color: var(--accent); }
.line-switch a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
:root:not([data-line="adam"]) .line-switch a[data-line="eve"],
:root[data-line="adam"] .line-switch a[data-line="adam"] { background: var(--btn-primary); border-color: var(--accent); }

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0 0 12px;
  padding: 10px 12px;
  min-width: 0;
}
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }

label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  flex-wrap: wrap;
}
label.check { justify-content: flex-start; flex-wrap: nowrap; }

input[type="number"], select {
  width: 80px;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  font: inherit;
}
select { width: auto; max-width: 100%; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }

button {
  background: var(--btn);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { width: 100%; margin-top: 6px; background: var(--btn-primary); }
.buttons { display: flex; gap: 8px; }
.buttons button { flex: 1; }
#pwa-install { width: 100%; margin-block: 0 12px; }

dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  margin: 0 0 8px;
  font-size: 13px;
}
dt { color: var(--muted); }
dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.caption { color: var(--muted); font-size: 11px; margin: 6px 0 3px; }

canvas.chart {
  width: 100%;
  height: 80px;
  display: block;
  background: var(--bg);
  border-radius: 4px;
}
canvas.shares { width: 100%; height: 22px; display: block; border-radius: 4px; }

.banner {
  border: 1px solid var(--mrca);
  color: var(--banner-text);
  background: var(--banner-bg);
  border-radius: 8px;
  padding: 10px 12px;
  margin-block: 0 12px;
  font-size: 13px;
}

main { position: relative; min-width: 0; }
/* The tree is one canvas pinned inside a scroll box. The spacer under it gives the box the height of
   the whole tree, and the canvas draws whichever generations match the scroll position. */
.tree-scroll {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.tree-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tree-scroll canvas { position: sticky; top: 0; display: block; width: 100%; height: 100%; }
.tree-jump { position: absolute; right: 16px; bottom: 14px; display: flex; gap: 8px; }
.tree-jump button { border-radius: 999px; padding: 5px 12px; background: var(--panel); box-shadow: 0 2px 10px rgba(0, 0, 0, .18); }
.tree-jump button[hidden] { display: none; }

.pwa-toast {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 60;
  display: flex; gap: .8rem; align-items: center; max-width: calc(100% - 2rem);
  padding: .6rem .7rem .6rem 1rem; border-radius: 12px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}

/* Phone/narrow: one column. Header and playback first, then the tree, then stats and setup. */
@media (max-width: 760px) {
  html, body { height: auto; }
  body { display: flex; flex-direction: column; padding: 12px 0 24px; }
  aside { display: contents; }
  aside > * { margin-left: 16px; margin-right: 16px; } /* parts set only margin-block, so this applies */
  .head { order: 0; margin-top: 0; }
  .line-switch { order: 1; }
  .lede { order: 2; }
  #pwa-install { order: 3; width: auto; }
  #playback { order: 4; }
  main { order: 5; height: 60vh; min-height: 320px; margin: 0 0 12px; background: var(--panel); border-block: 1px solid var(--line); }
  #banner { order: 6; }
  #statsBox { order: 7; }
  #setup { order: 8; }
}
