:root {
  --ink: #2b2418;
  --muted: #7a6d58;
  --paper: #fbf7ee;
  --card: #fffdf8;
  --line: #cbbd9f;
  --accent: #7a4e1d;
  --oak: #6b4f33;
  --moss: #3f7d4e;
  --moss-soft: #e7f2e4;
  --leaf: #7d8f45;
  --flag: #c9822b;
  --sparse: #b9ad97;
  --bar: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background:
    radial-gradient(1100px 420px at 50% -8%, rgba(125, 143, 69, 0.16), transparent 62%),
    var(--paper);
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", "Liberation Serif", Georgia, serif;
}

body[data-view="chart"] { overflow: hidden; }

body[data-view="lanes"] { overflow-x: hidden; overflow-y: auto; height: auto; min-height: 100%; }

body[data-view="chart"]::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 110px;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(55% 100% at 50% 100%, rgba(154, 163, 146, 0.32), transparent 72%);
}

button, input { font-family: system-ui, sans-serif; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sprig-bg {
  position: fixed;
  top: var(--bar);
  left: 0;
  width: 150px;
  height: 96px;
  z-index: 0;
  pointer-events: none;
  opacity: 0.55;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: rgba(251, 247, 238, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e6dcc6;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand h1 { font-size: 19px; margin: 0; font-weight: 600; white-space: nowrap; }

.leaf-mark { flex: 0 0 auto; }

.sub {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.legend { display: flex; gap: 12px; font: 12px system-ui, sans-serif; color: var(--muted); }

.legend span { white-space: nowrap; }

.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  vertical-align: -2px;
  margin-right: 4px;
  background: #fffdf8;
}

.views {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
}

.views button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 7px 14px;
  font: 600 13px system-ui, sans-serif;
  cursor: pointer;
}

.views button[aria-selected="true"] { background: var(--accent); color: #fff; }

.text-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: 600 13px system-ui, sans-serif;
  cursor: pointer;
  padding: 6px 2px;
}

.search { position: relative; margin-left: auto; }

.search input {
  width: 240px;
  padding: 8px 12px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  color: var(--ink);
}

.search ul {
  position: absolute;
  top: 42px;
  right: 0;
  width: 320px;
  max-height: min(320px, 50vh);
  overflow: auto;
  list-style: none;
  margin: 0;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(60, 40, 10, 0.12);
  display: none;
  z-index: 5;
}

.search ul.show { display: block; }

.search li { padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }

.search li:hover, .search li.on { background: #f3ead7; }

.search li small { color: var(--muted); margin-left: 6px; }

#chart-svg {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--bar);
  width: 100%;
  height: calc(100vh - var(--bar));
  height: calc(100dvh - var(--bar));
  z-index: 1;
  touch-action: none;
  cursor: grab;
  background: transparent;
}

#chart-svg:active { cursor: grabbing; }

body[data-view="lanes"] #chart-svg { display: none; }

.card { cursor: pointer; }

.card rect.bg { fill: var(--card); stroke: #8b6a3e; stroke-width: 1.4; }

.card.living rect.bg { fill: #f4faf4; stroke: var(--moss); stroke-dasharray: 5 3; }
.card.unknown rect.bg { fill: #f7f4ee; stroke: #9a8f78; stroke-dasharray: 4 3; }

.card.sparse rect.bg { fill: #f1ece1; stroke: var(--sparse); stroke-dasharray: 2 3; }

.card.ghost rect.bg { fill: none; stroke: var(--sparse); stroke-dasharray: 4 4; }

.card.focus rect.bg { stroke: var(--accent); stroke-width: 3; }

.card.focus { filter: drop-shadow(0 4px 10px rgba(122, 78, 29, 0.28)); }

.card:hover rect.bg { fill: #f6eedb; }

.card .nm { font: 600 13px "Iowan Old Style", Palatino, "Liberation Serif", Georgia, serif; fill: var(--ink); }

.card .yr { font: 12px system-ui, sans-serif; fill: var(--muted); }

.card.living .yr { fill: var(--moss); }

.card.ghost .nm { fill: #9b8f78; font-style: italic; font-weight: 400; }

.link { fill: none; stroke: #8d6b43; stroke-width: 1.8; stroke-linecap: round; }

.link.step { stroke: #7d8f6a; stroke-dasharray: 5 4; }

.sprig { fill: var(--leaf); pointer-events: none; }

.sprig.moss { fill: #9aa392; }

.dot { fill: #e8dfcc; }

.dot.on { fill: var(--accent); }

.flag { fill: var(--flag); }

.band {
  font: 600 11px system-ui, sans-serif;
  fill: #b0a283;
  letter-spacing: 0.12em;
}

.plus { fill: #b0a283; font: 14px Georgia, serif; }

.crumb {
  position: fixed;
  left: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: calc(100% - 84px);
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid #e0d5bd;
  border-radius: 20px;
  padding: 7px 14px;
  font: 13px system-ui, sans-serif;
  color: var(--muted);
}

.crumb b { color: var(--ink); font-weight: 650; }

.zoomctl {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zoomctl button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 18px;
  color: var(--ink);
  cursor: pointer;
}

body[data-view="lanes"] .zoomctl,
body[data-view="lanes"] .crumb,
body[data-view="lanes"] .sprig-bg { display: none; }

#lanes { display: none; }

body[data-view="lanes"] #lanes { display: block; margin-top: calc(var(--bar) + 64px); }

#axis {
  position: fixed;
  left: 0;
  top: var(--bar);
  height: 64px;
  z-index: 15;
  background: rgba(251, 247, 238, 0.96);
  border-bottom: 1px solid #e6dcc6;
  display: none;
}

body[data-view="lanes"] #axis { display: block; }

#axis text { font: 12px system-ui, sans-serif; fill: var(--muted); }

#axis .ev { font: 600 10px system-ui, sans-serif; fill: #a39274; letter-spacing: 0.04em; }

#axis .axis-note { font: 11px system-ui, sans-serif; fill: var(--moss); }

.era { opacity: 0.72; }

.now { stroke: var(--line); stroke-dasharray: 2 3; }

.row { cursor: pointer; }

.row:hover .rbg { fill: #f3ead7; }

.rbg { fill: transparent; }

.row .nm { font: 13px "Iowan Old Style", Palatino, "Liberation Serif", Georgia, serif; fill: var(--ink); }

.row .nm.sparse { fill: #9b8f78; }

.yr { font: 11px system-ui, sans-serif; fill: var(--muted); }

.yr.missing { fill: var(--sparse); font-style: italic; }

.yr.note { font-style: italic; }

.bar { rx: 6; }

.hdr rect { fill: #efe6d2; }

.hdr-mark { fill: var(--oak); }

.hdr text {
  font: 700 12px system-ui, sans-serif;
  letter-spacing: 0.08em;
  fill: #5b3d1f;
}

.dim { opacity: 0.22; }

.kin { stroke: var(--accent); stroke-width: 1.4; fill: none; stroke-dasharray: 3 3; }

.hl .rbg { fill: #fbe9c4; }

.living-chip { fill: #f4faf4; stroke: var(--moss); stroke-dasharray: 4 3; }
.living-chip.unknown { fill: #f7f4ee; stroke: #9a8f78; }

.living-label { font: 11px system-ui, sans-serif; fill: var(--moss); }

#panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 400px;
  max-width: 100vw;
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -10px 0 30px rgba(60, 40, 10, 0.15);
  transform: translateX(105%);
  transition: transform 0.25s ease;
  z-index: 30;
  overflow-y: auto;
  padding: 22px 22px 48px;
  overscroll-behavior: contain;
}

#panel.open { transform: none; }

#panel .x {
  position: absolute;
  top: 12px;
  right: 14px;
  border: 0;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

#panel h2 { margin: 6px 32px 2px 0; font-size: 24px; line-height: 1.15; font-weight: 600; }

#panel .life { color: var(--muted); font-size: 15px; margin-bottom: 10px; }

.badges { padding-right: 28px; }

.badge {
  display: inline-block;
  font: 12px/1.6 system-ui, sans-serif;
  padding: 0 8px;
  border-radius: 10px;
  margin: 0 4px 4px 0;
}

.badge.living { background: var(--moss-soft); color: var(--moss); }
.badge.unknown { background: #f3efe6; color: #6d6456; }

.badge.flag { background: #fbebd3; color: #8a5212; }

.badge.src { background: #efe7d6; color: #5d4a2b; }

.badge.line { background: #ebe4f3; color: #5a3f7a; }

.meter {
  display: flex;
  gap: 3px;
  margin: 8px 0 14px;
  align-items: center;
  font: 12px system-ui, sans-serif;
  color: var(--muted);
}

.meter b { width: 18px; height: 6px; border-radius: 3px; background: #e8dfcc; }

.meter b.on { background: var(--accent); }

.meter span { margin-left: 6px; }

#panel dl { margin: 0; }

#panel dt {
  font: 600 11px system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 14px;
}

#panel dd { margin: 3px 0 0; font-size: 15px; line-height: 1.4; }

#panel dd.missing, .missing { color: var(--sparse); font-style: italic; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 4px 10px;
  font: 13px system-ui, sans-serif;
  cursor: pointer;
  color: var(--ink);
}

.chip.living { border-style: dashed; border-color: var(--moss); }

.chip:hover { background: #f3ead7; }

.chip small { color: var(--muted); font-weight: 400; }

.src-label {
  font: 600 11px system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 16px 0 0;
}

.arks { margin-top: 8px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }

.arks a, #questions a { color: var(--accent); }

.private {
  margin-top: 4px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #eef5ef;
  color: #2f5a3a;
  font-size: 14px;
  line-height: 1.45;
}

.notes {
  font-size: 14px;
  line-height: 1.5;
  color: #4a4030;
  background: #f7f1e3;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
}

details summary {
  cursor: pointer;
  font: 600 12px system-ui, sans-serif;
  color: var(--muted);
  margin-top: 14px;
}

.actions { margin-top: 8px; }

.btn {
  font: 600 13px system-ui, sans-serif;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: #fff;
  border-radius: 18px;
  padding: 8px 14px;
  cursor: pointer;
  margin: 12px 6px 0 0;
}

.btn.primary { background: var(--accent); color: #fff; }

#questions {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  width: min(560px, calc(100vw - 28px));
  max-height: min(72vh, 680px);
  padding: 22px 22px 28px;
  box-shadow: 0 16px 40px rgba(60, 40, 10, 0.2);
}

#questions::backdrop { background: rgba(43, 36, 24, 0.35); }

#questions h2 { margin: 0 32px 8px 0; font-size: 22px; }

#questions p { color: #4a4030; font-size: 14px; line-height: 1.45; }

#questions ol { margin: 10px 0 0; padding-left: 18px; }

#questions li { margin: 8px 0; font-size: 14px; line-height: 1.4; }

#questions .x {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: none;
  font-size: 22px;
  color: var(--muted);
  cursor: pointer;
}

.noscript {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 80px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  z-index: 5;
}

@media (max-width: 700px) {
  .topbar { padding: max(8px, env(safe-area-inset-top)) 10px 8px; gap: 6px 8px; }
  .sub, .legend, .sprig-bg { display: none; }
  .brand { order: 1; flex: 1 1 auto; }
  .brand h1 { font-size: 17px; }
  .text-btn { order: 2; margin-left: auto; }
  .views { order: 3; flex: 1 1 100%; }
  .search { order: 4; }
  .views button { flex: 1; padding: 8px 8px; white-space: nowrap; }
  .search { margin-left: 0; flex: 1 1 100%; }
  .search input, .search ul { width: 100%; }
  .zoomctl button { width: 44px; height: 44px; }
  #panel {
    top: auto;
    bottom: 0;
    height: 72%;
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    transform: translateY(105%);
    padding-top: 18px;
  }
  #panel.open { transform: none; }
  #panel::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #d6cab2;
    margin: -6px auto 8px;
  }
  body.panel-open .crumb,
  body.panel-open .zoomctl { display: none; }
}

@media (min-width: 701px) {
  .topbar { z-index: 40; }
  #panel {
    top: var(--bar);
    height: calc(100vh - var(--bar));
    height: calc(100dvh - var(--bar));
  }
  body.panel-open .zoomctl { right: 416px; }
}

@media (prefers-reduced-motion: reduce) {
  #panel { transition: none; }
}
