:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #d8dde7;
  --text: #1b2130;
  --muted: #5a6477;
  --accent: #1d6bb0;
  --btn: #eef1f6;
  --btn-primary: #d8e8f7;
  --input-bg: #f7f8fb;
  --eve: #a87400;
  --banner-bg: #fdf3d6;
  --banner-text: #6b4a00;
  /* canvas colors (read by assets/render.js) */
  --node-text: #0b0e14;
  --dead-edge: rgba(60, 70, 90, 0.16);
  --dead-alpha: 0.22;
  --son: rgba(70, 100, 150, 0.3);
  --son-text: rgba(30, 45, 70, 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; --accent: #7cc4ff;
    --btn: #1d2433; --btn-primary: #1f3a55; --input-bg: #0b0e14; --eve: #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;
    --son: rgba(110, 140, 180, 0.35); --son-text: rgba(200, 215, 235, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0e14; --panel: #131824; --line: #252c3b; --text: #dde3ee; --muted: #8a94a8; --accent: #7cc4ff;
  --btn: #1d2433; --btn-primary: #1f3a55; --input-bg: #0b0e14; --eve: #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;
  --son: rgba(110, 140, 180, 0.35); --son-text: rgba(200, 215, 235, 0.6);
  color-scheme: dark;
}

* { 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: 6px; margin: -4px 0 6px; }
h1 { font-size: 18px; margin: 0; flex: 1; }
.hub-link { color: var(--muted); font-size: 12px; text-decoration: none; white-space: nowrap; }
.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; }

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

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; }

input[type="number"] {
  width: 80px;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
  font: inherit;
}
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 { 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: 0 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(--eve);
  color: var(--banner-text);
  background: var(--banner-bg);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 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; }
  .head { order: 0; margin-top: 0; }
  .lede { order: 1; }
  #pwa-install { order: 2; width: auto; }
  #playback { order: 3; }
  main { order: 4; height: 60vh; min-height: 320px; margin: 0 0 12px; background: var(--panel); border-block: 1px solid var(--line); }
  #banner { order: 5; }
  #statsBox { order: 6; }
  #setup { order: 7; }
}
