:root {
  color-scheme: light;
  --paper: #f7f7f3;
  --surface: #ffffff;
  --ink: #171918;
  --muted: #646b67;
  --faint: #919892;
  --line: #dfe2dd;
  --line-strong: #c8cdc7;
  --soft: #f0f1ed;
  --focus: #171918;
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  background: var(--paper);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; background: var(--paper); }
body { color: var(--ink); overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: inherit; text-underline-offset: 3px; }

.shell { width: 100%; height: 100vh; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; overflow: hidden; }
.masthead {
  display: grid;
  grid-template-columns: minmax(20rem, 1fr) minmax(22rem, 34rem);
  gap: clamp(2rem, 8vw, 8rem);
  align-items: end;
  padding: 1.4rem clamp(1rem, 3vw, 3rem) 1.15rem;
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface);
}
.eyebrow, .mono {
  font: 500 0.66rem/1.35 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
h1 { margin: 0.28rem 0 0; font-size: clamp(1.8rem, 3.5vw, 3.5rem); line-height: 0.94; letter-spacing: -0.055em; font-weight: 520; }
.intro { max-width: 34rem; color: #4c524e; font-size: 0.86rem; line-height: 1.55; margin: 0; }
.intro strong { color: var(--ink); font-weight: 650; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  padding: 0.65rem clamp(1rem, 3vw, 3rem);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.tool-group { display: flex; align-items: center; gap: 0.38rem; }
.tool-group + .tool-group { padding-left: 0.75rem; border-left: 1px solid var(--line); }
.tool-label { margin-right: 0.25rem; }
.chip, .icon-btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 4px;
  padding: 0.4rem 0.64rem;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 120ms ease, border 120ms ease, opacity 120ms ease;
}
.chip:hover, .icon-btn:hover { background: var(--soft); border-color: #959c96; }
.chip[aria-pressed="false"] { opacity: 0.38; }
.thread-filter.is-focused { opacity: 1; background: #e9ebe6; border-color: #737b75; }
.chip-dot { width: 0.45rem; height: 0.45rem; display: inline-block; border-radius: 50%; margin-right: 0.38rem; }
.icon-btn { width: 2rem; height: 2rem; padding: 0; display: grid; place-items: center; border-radius: 50%; }
.spacer { flex: 1; }

.workspace { min-height: 0; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr) minmax(25rem, 29rem); background: var(--surface); }
.map-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: #fbfbf8;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#genealogy { width: 100%; height: 100%; min-height: 0; display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
#genealogy * { user-select: none; -webkit-user-select: none; }
#genealogy.is-dragging { cursor: grabbing; }
.map-caption { position: absolute; left: 1rem; bottom: 0.75rem; color: var(--faint); pointer-events: none; }
.map-legend {
  position: absolute;
  left: 1rem;
  top: 0.8rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  font-size: 0.66rem;
  color: var(--muted);
  pointer-events: none;
}
.legend-item { display: inline-flex; align-items: center; gap: 0.38rem; white-space: nowrap; }
.legend-line { width: 1.5rem; height: 0; border-top: 1px solid #6f7671; }
.legend-line.thread { border-top-width: 4px; border-color: #6e9e8f; opacity: .55; }
.legend-line.cross { border-top-style: dashed; }

.detail-panel { min-height: 0; border-left: 1px solid var(--line-strong); background: var(--surface); padding: 1.35rem 1.5rem; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
.detail-panel h2 { font-size: 1.32rem; line-height: 1.22; margin: 0.42rem 2.4rem 0.72rem 0; letter-spacing: -0.025em; }
.detail-panel p { color: #4e5651; font-size: 0.8rem; line-height: 1.6; }
.detail-rule { border: 0; border-top: 1px solid var(--line); margin: 1.1rem 0; }
.detail-meta { display: grid; grid-template-columns: auto 1fr; gap: 0.48rem 0.9rem; font-size: 0.73rem; }
.detail-meta dt { color: var(--muted); }
.detail-meta dd { margin: 0; }
.event-identity { display: flex; align-items: center; gap: .42rem; font: 500 .66rem/1.35 ui-monospace, "SFMono-Regular", Consolas, monospace; letter-spacing: .06em; text-transform: uppercase; }
.publication-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 0 0;
  padding: .72rem .78rem;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--soft);
  font-size: .76rem;
  font-weight: 650;
  text-decoration: none;
}
.publication-link:hover { border-color: #8e958f; background: #e9ebe6; }
.trace-switch { display: grid; grid-template-columns: 1fr 1.25fr; gap: .42rem; margin-top: .85rem; }
.trace-switch button { appearance: none; display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .62rem .66rem; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--muted); font-size: .7rem; cursor: pointer; }
.trace-switch button:hover { background: var(--soft); border-color: var(--line-strong); }
.trace-switch button[aria-pressed="true"] { background: #f0f1ed; border-color: #8e958f; color: var(--ink); }
.trace-switch strong { min-width: 1.25rem; height: 1.25rem; display: grid; place-items: center; border-radius: 50%; background: var(--surface); font-size: .64rem; }
.afterlife-note { margin-top: .75rem; padding: .72rem .78rem; border-left: 3px solid var(--line-strong); background: var(--soft); }
.afterlife-note p { margin: .28rem 0 0; }
.connection-group + .connection-group { margin-top: 1rem; }
.connection-heading { margin-bottom: .35rem; }
.connection-list { display: grid; gap: .4rem; }
.connection-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .7rem;
  align-items: center;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 3px;
  padding: .58rem .62rem;
  cursor: pointer;
}
.connection-item:hover { background: var(--soft); border-color: var(--line-strong); }
.connection-title { display: block; font-size: .75rem; line-height: 1.35; }
.connection-arrow { color: var(--faint); }
.reading-note { padding: .7rem; background: var(--soft); border-left: 3px solid var(--line-strong); font-size: .72rem; line-height: 1.5; color: var(--muted); }

.hint-card { min-height: 100%; display: flex; flex-direction: column; justify-content: space-between; }
.area-choices { display: grid; gap: .45rem; margin: 1.15rem 0 1.35rem; }
.area-choice {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .65rem;
  padding: .72rem .75rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  text-align: left;
  font-size: .76rem;
  cursor: pointer;
}
.area-choice:hover { background: var(--soft); border-color: var(--line-strong); }
.area-choice-dot { width: .55rem; height: .55rem; border-radius: 50%; }
.all-areas-dot { border: 1px solid #6f7671; background: linear-gradient(135deg, #2f6f9f 0 33%, #3f7d5a 33% 66%, #b15f3e 66%); }
.show-all-choice { margin-top: .15rem; background: var(--soft); }
.focus-guide { display: grid; gap: .3rem; margin: 1.1rem 0; padding: .75rem .8rem; border-left: 3px solid var(--line-strong); background: var(--soft); color: var(--muted); font-size: .72rem; line-height: 1.45; }
.focus-guide strong { color: var(--ink); font-weight: 620; }
.show-all-button { width: 100%; padding: .65rem .75rem; border: 1px solid var(--line-strong); border-radius: 3px; background: var(--surface); font-size: .74rem; cursor: pointer; }
.show-all-button:hover { background: var(--soft); border-color: #959c96; }
.start-steps { counter-reset: step; margin: 1.2rem 0; }
.start-step { position: relative; padding: .75rem 0 .75rem 2rem; border-top: 1px solid var(--line); color: #4e5651; font-size: .78rem; line-height: 1.45; }
.start-step:last-child { border-bottom: 1px solid var(--line); }
.start-step::before { counter-increment: step; content: counter(step); position: absolute; left: .25rem; top: .76rem; width: 1rem; height: 1rem; border: 1px solid var(--line-strong); border-radius: 50%; display: grid; place-items: center; font: 500 .58rem ui-monospace, monospace; color: var(--muted); }
.key-list { display: grid; gap: .65rem; margin-top: 1rem; }
.event-key { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .62rem .8rem; }
.key-row { display: grid; grid-template-columns: 2rem 1fr; gap: .55rem; align-items: center; color: var(--muted); font-size: .71rem; line-height: 1.35; }
.key-symbol { display: flex; justify-content: center; align-items: center; }
.key-node { width: .65rem; height: .65rem; border: 2px solid #252826; border-radius: 50%; background: #fff; }
.legend-node { position: relative; display: inline-block; width: .76rem; height: .76rem; border-radius: 50%; border: 1.5px solid #4f5953; background: #4f5953; }
.legend-node.pivot::after { content: ""; position: absolute; left: .16rem; top: .16rem; width: .3rem; height: .3rem; border-left: 1.5px solid #fff; border-top: 1.5px solid #fff; transform: rotate(45deg); }
.legend-node.setback { background: transparent; border-style: dashed; }
.legend-node.revival { background: transparent; box-shadow: 0 0 0 2px #fff, 0 0 0 3px #4f5953; }
.legend-node.landmark { width: .92rem; height: .92rem; transform: rotate(45deg); border-radius: 2px; }

.footer { padding: 0.65rem clamp(1rem, 3vw, 3rem); border-top: 1px solid var(--line); color: var(--faint); font-size: 0.66rem; background: var(--paper); }

.year-line { stroke: #e1e4df; stroke-width: 1; }
.year-text, .lane-label { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; fill: #757c77; font-size: 11px; letter-spacing: .04em; }
.lane-label { font-size: 12px; font-weight: 650; }
.lane-key-bg { fill: rgba(255,255,255,.94); stroke: #d8ddd7; stroke-width: 1; }
.lane-key-dot { stroke: #ffffff; stroke-width: 1.5; }
.stream-line { fill: none; stroke-width: 4; opacity: .24; transition: opacity 140ms ease; }
.stream-line.cross { stroke-width: 2; stroke-dasharray: 5 6; opacity: .32; }
.stream-line.trace-muted { opacity: .035; }
.relation { fill: none; stroke-width: 1.15; opacity: 0; transition: opacity 140ms ease, stroke-width 140ms ease; }
.relation.cross { stroke-dasharray: 4 5; }
.relation.hover-active { opacity: .58; }
.node { cursor: pointer; transition: opacity 140ms ease; }
.node-halo { display: none; }
.node-core { stroke: #ffffff; stroke-width: 2.5; }
.node-semantic-ring { fill: none; stroke-width: 1.35; opacity: .72; }
.setback-mark { stroke-dasharray: 7 4; }
.revival-mark { stroke-width: 2; opacity: .8; }
.node-mark { fill: none; stroke: #ffffff; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.node-ring { fill: none; stroke-width: 1; opacity: 0; }
.node-label { fill: #333834; font: 500 10px/1.2 Inter, "Helvetica Neue", Arial, sans-serif; pointer-events: none; paint-order: stroke; stroke: #fbfbf8; stroke-width: 3px; stroke-linejoin: round; }
.lane-key { transition: opacity 160ms ease; }
.area-muted { opacity: .14 !important; }
.dimmed { opacity: .08 !important; }
.selected .node-core { stroke: #151817; stroke-width: 3; }
.selected .node-ring { opacity: 1; stroke: #151817; stroke-width: 1.5; }
.ancestor .node-ring { opacity: 1; stroke-width: 1.5; stroke-dasharray: 2 3; }
.descendant .node-ring { opacity: 1; stroke-width: 2; }
.afterlife .node-ring { stroke-dasharray: 4 3; stroke-width: 2; opacity: 1; }
.tooltip { position: fixed; z-index: 10; pointer-events: none; max-width: 18rem; padding: .65rem .75rem; border: 1px solid var(--line-strong); border-radius: 3px; background: rgba(255,255,255,.97); box-shadow: 0 8px 24px rgba(20,25,22,.12); font-size: .73rem; line-height: 1.45; opacity: 0; transform: translateY(3px); transition: opacity 80ms ease, transform 80ms ease; }
.tooltip.visible { opacity: 1; transform: translateY(0); }
.tooltip strong { display: block; margin-bottom: .15rem; }

@media (max-width: 940px) {
  html, body { height: auto; min-height: 100%; }
  body { overflow: auto; }
  .shell { height: auto; min-height: 100vh; overflow: visible; }
  .masthead { grid-template-columns: 1fr; gap: .7rem; }
  .workspace { overflow: visible; grid-template-columns: 1fr; grid-template-rows: minmax(500px, 66vh) auto; }
  .map-wrap { min-height: 500px; }
  .detail-panel { overflow: visible; border-left: 0; border-top: 1px solid var(--line-strong); max-height: none; }
  .tool-group.labels { display: none; }
}

@media (max-width: 600px) {
  .shell { grid-template-rows: auto auto auto auto; }
  .toolbar { gap: .42rem; }
  .tool-group + .tool-group { padding-left: .42rem; }
  .workspace { grid-template-rows: 60vh auto; }
  #genealogy { min-height: 430px; }
  .map-legend { display: none; }
  .event-key { grid-template-columns: 1fr; }
  .footer { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
