:root {
  color-scheme: dark;
  --bg: #0b0d11;
  --text: #e6ebf1;
  --label: #cfd9e4;
  --muted: #7f90a4;
  --accent: #8aabd1;
  --branch-0: #33465b;
  --branch-1: #4d6b8e;
  --branch-2: #7c9ec5;
  --branch-3: #cbd9ea;
  --echo: rgba(138, 171, 209, 0.38);
  --rain: rgba(196, 212, 232, 0.26);
  --flash: #e3ebf6;
  --panel: rgba(14, 18, 24, 0.84);
  --line: rgba(138, 171, 209, 0.18);
  --button: rgba(138, 171, 209, 0.08);
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f9;
  --text: #121820;
  --label: #1b2733;
  --muted: #5c6c7f;
  --accent: #3d638d;
  --branch-0: #b6c4d3;
  --branch-1: #86a0bd;
  --branch-2: #557aa3;
  --branch-3: #1c3653;
  --echo: rgba(61, 99, 141, 0.36);
  --rain: rgba(61, 99, 141, 0.24);
  --flash: #ffffff;
  --panel: rgba(246, 247, 249, 0.9);
  --line: rgba(29, 54, 83, 0.14);
  --button: rgba(61, 99, 141, 0.07);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f6f7f9;
    --text: #121820;
    --label: #1b2733;
    --muted: #5c6c7f;
    --accent: #3d638d;
    --branch-0: #b6c4d3;
    --branch-1: #86a0bd;
    --branch-2: #557aa3;
    --branch-3: #1c3653;
    --echo: rgba(61, 99, 141, 0.36);
    --rain: rgba(61, 99, 141, 0.24);
    --flash: #ffffff;
    --panel: rgba(246, 247, 249, 0.9);
    --line: rgba(29, 54, 83, 0.14);
    --button: rgba(61, 99, 141, 0.07);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

canvas { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

button { font: inherit; color: inherit; cursor: pointer; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.hud { position: fixed; z-index: 2; transition: opacity 0.3s; }
body.bare .hud { opacity: 0; pointer-events: none; }

#top { top: 16px; left: 20px; pointer-events: none; }
h1 { margin: 0; font: 600 17px/1.2 var(--serif); letter-spacing: 0.01em; }
#stats { margin: 3px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }

#controls { top: 14px; right: 16px; display: flex; gap: 6px; }
#controls button {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel); color: var(--muted);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: color 0.15s, border-color 0.15s;
}
#controls button:hover, #controls button:focus-visible { color: var(--text); border-color: var(--accent); outline: none; }
#follow[aria-pressed="true"] { color: var(--accent); }
#grow .when-on, #grow[aria-pressed="true"] .when-off { display: none; }
#grow[aria-pressed="true"] .when-on { display: block; }
#sound .when-on, #sound[aria-pressed="true"] .when-off { display: none; }
#sound[aria-pressed="true"] .when-on { display: block; }
#theme .fill { fill: currentColor; stroke: none; }

#bottom { left: 20px; bottom: 16px; max-width: calc(100vw - 350px); pointer-events: none; }
#bottom p { margin: 0; }
#now { color: var(--muted); }
#activity { color: var(--label); margin-top: 2px !important; }
#hint { color: var(--accent); margin-top: 2px !important; }

#ticker {
  right: 16px; bottom: 14px; margin: 0; padding: 0; list-style: none; width: 290px;
  display: flex; flex-direction: column-reverse; gap: 2px;
}
#ticker li { animation: arrive 0.6s ease-out; }
#ticker li:nth-child(n+4) { opacity: 0.55; }
#ticker button {
  width: 100%; text-align: right; background: none; border: 0; padding: 3px 4px; border-radius: 6px;
  display: flex; flex-direction: column; align-items: flex-end;
}
#ticker button:hover { background: var(--button); }
#ticker .t { color: var(--label); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ticker .s { color: var(--muted); font-size: 11.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes arrive { from { opacity: 0; transform: translateY(6px); } }

#panel {
  position: fixed; z-index: 3; top: 62px; right: 16px; bottom: 16px; width: 360px;
  overflow-y: auto; padding: 18px 20px 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  animation: slide 0.25s ease-out;
}
#panel[hidden] { display: none; }
@keyframes slide { from { opacity: 0; transform: translateX(12px); } }
.close {
  position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; display: grid; place-items: center;
  background: none; border: 0; border-radius: 8px; color: var(--muted);
}
.close:hover { background: var(--button); color: var(--text); }
#panel .source { margin: 0 32px 6px 0; color: var(--accent); font-size: 12px; }
#panel .title { margin: 0 24px 4px 0; font: 600 21px/1.25 var(--serif); }
#panel .desc { margin: 0 0 12px; color: var(--muted); font-style: italic; }
#panel .thumb { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: 9px; margin: 0 0 12px; }
#panel .thumb[hidden] { display: none; }
#panel .extract { margin: 0 0 12px; font: 14.5px/1.55 var(--serif); }
#panel .note:empty, #panel .extract:empty, #panel .desc:empty { display: none; }
#panel .note { margin: 0 0 12px; padding: 9px 11px; border-left: 2px solid var(--accent); background: var(--button); border-radius: 0 8px 8px 0; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
#panel h3, #about h3 { margin: 14px 0 6px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.path { margin: 0 0 16px; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 4px 2px; }
.path li:not(:last-child)::after { content: "→"; color: var(--muted); margin: 0 2px 0 4px; }
.path button { background: none; border: 0; padding: 1px 3px; border-radius: 5px; color: var(--label); text-align: left; }
.path button:hover:not(:disabled) { background: var(--button); color: var(--accent); }
.path button:disabled { color: var(--accent); cursor: default; font-weight: 600; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow-here {
  padding: 7px 13px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--bg); font-weight: 600;
}
.grow-here:disabled { opacity: 0.4; cursor: default; }
.grow-here[hidden], .open[hidden] { display: none; }
.open { color: var(--accent); text-decoration: none; }
.open:hover { text-decoration: underline; }

#tip {
  position: fixed; z-index: 4; pointer-events: none; max-width: 260px; padding: 7px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; flex-direction: column; gap: 1px;
}
#tip[hidden] { display: none; }
#tip span { color: var(--muted); font-size: 12px; }

#about {
  max-width: 600px; width: calc(100vw - 32px); max-height: calc(100vh - 48px); padding: 24px 28px;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
}
#about::backdrop { background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(3px); }
#about h2 { margin: 0 0 10px; font: 600 22px var(--serif); }
#about p { margin: 0 0 10px; font-size: 14px; line-height: 1.55; }
#about .small { font-size: 12.5px; color: var(--muted); }
.keys { display: grid; grid-template-columns: 56px 1fr; gap: 3px 10px; margin: 0 0 10px; font-size: 13.5px; }
.keys dt { font-weight: 600; color: var(--accent); }
.keys dd { margin: 0; }

@media (max-width: 720px) {
  #top { left: 16px; }
  #stats { max-width: 52vw; }
  #bottom { left: 16px; right: 16px; max-width: none; bottom: 12px; }
  #ticker { display: none; }
  #controls { right: 12px; gap: 4px; }
  #controls button { width: 32px; height: 32px; }
  #panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62vh; }
}
