:root {
  color-scheme: dark;
  --ink: #f4eddf;
  --muted: #c7baa1;
  --quiet: #918773;
  --night: #0d0d0b;
  --surface: #171610;
  --surface-raised: #211e17;
  --surface-soft: #29241b;
  --line: rgba(230, 203, 145, .22);
  --line-strong: rgba(230, 203, 145, .48);
  --gold: #e0b75e;
  --gold-soft: #f0d493;
  --sky: #84b9c7;
  --danger: #df9a77;
  --header-height: 4.25rem;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 10%, rgba(132, 185, 199, .09), transparent 30rem),
    var(--night);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input,
a {
  -webkit-tap-highlight-color: transparent;
}

button,
select {
  color: var(--ink);
}

a {
  color: var(--gold-soft);
  text-underline-offset: .2em;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  top: .65rem;
  left: .65rem;
  z-index: 200;
  transform: translateY(-160%);
  padding: .7rem .9rem;
  color: #0d0d0b;
  background: var(--gold-soft);
  border-radius: .35rem;
  font-weight: 800;
}

.skip-link:focus {
  transform: none;
}

.app-shell {
  height: 100dvh;
  min-height: 32rem;
  display: grid;
  grid-template-rows: var(--header-height) minmax(0, 1fr);
}

.app-header {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(.65rem, 2vw, 1.4rem);
  min-width: 0;
  padding: .55rem clamp(.7rem, 2.5vw, 1.75rem);
  border-bottom: 1px solid rgba(255, 255, 255, .09);
  background: rgba(10, 10, 8, .92);
  backdrop-filter: blur(16px);
}

.back-link,
.quiet-button {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .55rem .75rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .025);
  text-decoration: none;
  font-size: .78rem;
  font-weight: 750;
  cursor: pointer;
}

.back-link:hover,
.quiet-button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: rgba(224, 183, 94, .08);
}

.title-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .7rem;
}

.brand-mark {
  width: 2.3rem;
  aspect-ratio: 1;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--gold);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font: 600 .68rem/1 Georgia, "Times New Roman", serif;
  letter-spacing: .04em;
}

.title-lockup p,
.title-lockup h1 {
  margin: 0;
}

.title-lockup p {
  color: var(--gold);
  text-transform: uppercase;
  font-size: .58rem;
  font-weight: 850;
  letter-spacing: .16em;
}

.title-lockup h1 {
  overflow: hidden;
  color: var(--ink);
  font: 500 clamp(.95rem, 1.8vw, 1.3rem)/1.15 Georgia, "Times New Roman", serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-count {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--quiet);
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .73rem;
}

.explorer {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.toolbar {
  position: relative;
  z-index: 25;
  display: grid;
  grid-template-columns: minmax(14rem, 23rem) minmax(12rem, 17rem) minmax(max-content, 1fr);
  align-items: end;
  gap: .65rem;
  padding: .65rem clamp(.7rem, 2.5vw, 1.75rem);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  background: rgba(19, 18, 14, .96);
}

.search-control,
.branch-control {
  position: relative;
  min-width: 0;
}

.search-control > label,
.branch-control > label {
  display: block;
  margin: 0 0 .3rem .2rem;
  color: var(--quiet);
  text-transform: uppercase;
  font-size: .57rem;
  font-weight: 850;
  letter-spacing: .12em;
}

.search-box {
  min-height: 2.65rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .55rem;
  padding: 0 .72rem;
  border: 1px solid var(--line);
  border-radius: .45rem;
  background: rgba(7, 7, 6, .66);
}

.search-box:focus-within {
  border-color: var(--sky);
  box-shadow: 0 0 0 2px rgba(132, 185, 199, .12);
}

.search-box svg {
  width: 1rem;
  fill: none;
  stroke: var(--quiet);
  stroke-width: 1.7;
}

.search-box input {
  width: 100%;
  min-width: 0;
  padding: .55rem 0;
  color: var(--ink);
  border: 0;
  outline: 0;
  background: transparent;
  font-size: .83rem;
}

.search-box input::placeholder {
  color: #817866;
}

.search-box kbd {
  min-width: 1.35rem;
  padding: .18rem .35rem;
  color: var(--quiet);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: .25rem;
  background: rgba(255, 255, 255, .04);
  text-align: center;
  font: 700 .65rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.search-results {
  position: absolute;
  z-index: 80;
  top: calc(100% + .35rem);
  left: 0;
  right: 0;
  max-height: min(23rem, 58dvh);
  overflow: auto;
  padding: .3rem;
  border: 1px solid var(--line-strong);
  border-radius: .5rem;
  background: rgba(14, 14, 11, .985);
  box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, .6);
}

.search-result {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .2rem .7rem;
  padding: .65rem .7rem;
  color: var(--ink);
  border: 0;
  border-radius: .35rem;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.search-result:hover,
.search-result.active {
  background: rgba(224, 183, 94, .11);
}

.search-result strong {
  overflow: hidden;
  font-size: .82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result span,
.search-result small {
  color: var(--quiet);
  font-size: .67rem;
}

.search-result small {
  grid-column: 1 / -1;
}

.search-empty {
  margin: 0;
  padding: .85rem;
  color: var(--quiet);
  font-size: .78rem;
}

.branch-control select {
  width: 100%;
  min-height: 2.65rem;
  padding: .5rem 2.2rem .5rem .7rem;
  border: 1px solid var(--line);
  border-radius: .45rem;
  background: #12110e;
  font-size: .78rem;
  cursor: pointer;
}

.branch-control select:disabled {
  color: var(--quiet);
  cursor: wait;
}

.control-strip {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .35rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.control-strip::-webkit-scrollbar {
  display: none;
}

.control-strip button {
  min-width: max-content;
  min-height: 2.65rem;
  padding: .48rem .72rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: .42rem;
  background: rgba(255, 255, 255, .025);
  font-size: .73rem;
  font-weight: 750;
  cursor: pointer;
}

.control-strip button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: rgba(224, 183, 94, .08);
}

.control-strip .icon-button {
  min-width: 2.65rem;
  padding-inline: .55rem;
  color: var(--ink);
  font-size: 1.2rem;
}

.control-divider {
  width: 1px;
  height: 1.8rem;
  flex: 0 0 auto;
  margin-inline: .15rem;
  background: rgba(255, 255, 255, .12);
}

.tree-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(rgba(224, 183, 94, .028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(224, 183, 94, .028) 1px, transparent 1px),
    radial-gradient(circle at 50% 45%, rgba(224, 183, 94, .055), transparent 30rem),
    #0d0d0b;
  background-size: 32px 32px, 32px 32px, auto, auto;
}

#tree-canvas {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

#tree-canvas:active {
  cursor: grabbing;
}

.tree-link {
  fill: none;
  stroke-width: 1.35;
  stroke-opacity: .55;
}

.tree-node {
  cursor: pointer;
  outline: none;
}

.node-card {
  fill: rgba(27, 25, 20, .98);
  stroke: rgba(255, 255, 255, .16);
  stroke-width: 1;
  filter: drop-shadow(0 .45rem .8rem rgba(0, 0, 0, .28));
  transition: fill .16s ease, stroke .16s ease;
}

.tree-node:hover .node-card,
.tree-node:focus-visible .node-card,
.tree-node.selected .node-card {
  fill: rgba(44, 38, 27, .99);
  stroke: var(--node-color, var(--gold));
  stroke-width: 1.8;
}

.tree-node:focus-visible .node-card {
  filter: drop-shadow(0 0 .45rem rgba(132, 185, 199, .72));
}

.node-branch-line {
  stroke: var(--node-color, var(--gold));
  stroke-width: 4;
  stroke-linecap: round;
}

.node-name {
  fill: var(--ink);
  font: 650 12px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  pointer-events: none;
}

.node-years,
.node-meta {
  fill: #aa9f89;
  font: 500 9.5px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  pointer-events: none;
}

.node-meta {
  fill: #897f6d;
  font-size: 8.5px;
  letter-spacing: .035em;
}

.node-warning {
  fill: var(--danger);
  font: 850 11px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  pointer-events: none;
}

.node-expander {
  cursor: pointer;
}

.node-expander circle {
  fill: #11100d;
  stroke: var(--node-color, var(--gold));
  stroke-width: 1.25;
}

.node-expander:hover circle,
.node-expander:focus-visible circle {
  fill: var(--node-color, var(--gold));
}

.node-expander text {
  fill: var(--ink);
  font: 800 12px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  pointer-events: none;
}

.stage-status,
.gesture-hint {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, .1);
  background: rgba(12, 12, 10, .82);
  backdrop-filter: blur(10px);
}

.stage-status {
  top: .75rem;
  left: .75rem;
  display: flex;
  align-items: baseline;
  gap: .45rem;
  padding: .48rem .62rem;
  border-radius: .35rem;
}

.stage-status strong {
  color: var(--gold-soft);
  font-size: .75rem;
}

.stage-status span {
  color: var(--quiet);
  font-size: .65rem;
}

.gesture-hint {
  left: 50%;
  bottom: .75rem;
  transform: translateX(-50%);
  margin: 0;
  padding: .45rem .68rem;
  color: var(--quiet);
  border-radius: 999px;
  text-align: center;
  white-space: nowrap;
  font-size: .65rem;
  transition: opacity .25s ease;
}

.gesture-hint.dismissed {
  opacity: 0;
}

.mobile-hint {
  display: none;
}

.load-error {
  position: absolute;
  z-index: 20;
  inset: 50% auto auto 50%;
  width: min(30rem, calc(100% - 2rem));
  transform: translate(-50%, -50%);
  padding: 1.2rem;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: .65rem;
  background: rgba(20, 19, 15, .98);
  text-align: center;
  box-shadow: 0 2rem 5rem rgba(0, 0, 0, .6);
}

.load-error strong {
  display: block;
  color: var(--ink);
}

.load-error p {
  margin: .5rem 0 0;
  font-size: .82rem;
  line-height: 1.55;
}

.person-sheet {
  position: absolute;
  z-index: 35;
  top: 5rem;
  right: .75rem;
  bottom: .75rem;
  width: min(22rem, calc(100% - 1.5rem));
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--line-strong);
  border-radius: .7rem;
  background: rgba(16, 15, 12, .975);
  box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, .58);
  animation: sheet-in .22s ease both;
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateX(1rem); }
  to { opacity: 1; transform: none; }
}

.sheet-handle {
  display: none;
}

.sheet-close,
.dialog-close {
  position: absolute;
  z-index: 3;
  top: .65rem;
  right: .65rem;
  width: 2.6rem;
  min-height: 2.6rem;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 50%;
  background: rgba(10, 10, 8, .8);
  font-size: 1.25rem;
  cursor: pointer;
}

.sheet-close:hover,
.dialog-close:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

#person-image {
  width: calc(100% + 2rem);
  max-height: 12rem;
  margin: -1rem -1rem 1rem;
  object-fit: cover;
  object-position: center 20%;
  border-radius: .7rem .7rem 0 0;
}

.sheet-copy {
  min-width: 0;
}

.sheet-labels {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem;
  padding-right: 2.5rem;
  color: var(--quiet);
  font-size: .67rem;
}

.evidence-badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.65rem;
  padding: .25rem .48rem;
  color: var(--gold-soft);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(224, 183, 94, .075);
  text-transform: uppercase;
  font-size: .55rem;
  font-weight: 850;
  letter-spacing: .08em;
}

.evidence-badge.disputed {
  color: #ffd0b8;
  border-color: rgba(223, 154, 119, .55);
  background: rgba(223, 154, 119, .1);
}

.person-sheet h2 {
  margin: .8rem 2.5rem .2rem 0;
  font: 500 1.75rem/1.06 Georgia, "Times New Roman", serif;
}

.person-years {
  margin: .3rem 0 .8rem;
  color: var(--gold);
  font-size: .78rem;
}

.person-description {
  margin: 0;
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.58;
}

.dispute-note {
  margin: .85rem 0 0;
  padding: .7rem;
  color: #e8c5b4;
  border-left: 3px solid var(--danger);
  background: rgba(223, 154, 119, .08);
  font-size: .76rem;
  line-height: 1.5;
}

.person-facts {
  display: grid;
  gap: .65rem;
  margin: 1rem 0;
  padding: .85rem 0;
  border-block: 1px solid rgba(255, 255, 255, .1);
}

.person-facts div {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  gap: .6rem;
}

.person-facts dt {
  color: var(--quiet);
  font-size: .67rem;
}

.person-facts dd {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
  text-align: right;
  font-size: .72rem;
}

.person-facts button,
.person-facts a {
  padding: 0;
  color: var(--gold-soft);
  border: 0;
  background: transparent;
  text-align: inherit;
  text-decoration: underline;
  text-underline-offset: .2em;
  cursor: pointer;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .45rem;
}

.sheet-actions button,
.sheet-actions a {
  min-height: 2.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .55rem .65rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: .4rem;
  background: rgba(255, 255, 255, .035);
  text-align: center;
  text-decoration: none;
  font-size: .7rem;
  font-weight: 750;
  cursor: pointer;
}

.sheet-actions a {
  grid-column: 1 / -1;
  color: var(--gold-soft);
}

.sheet-actions button:hover,
.sheet-actions a:hover {
  border-color: var(--line-strong);
  background: rgba(224, 183, 94, .08);
}

.method-dialog {
  width: min(54rem, calc(100% - 2rem));
  max-height: min(46rem, calc(100dvh - 2rem));
  overflow: auto;
  padding: clamp(1.2rem, 4vw, 2.2rem);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: .8rem;
  background: #171610;
  box-shadow: 0 2rem 7rem rgba(0, 0, 0, .72);
}

.method-dialog::backdrop {
  background: rgba(3, 3, 2, .76);
  backdrop-filter: blur(6px);
}

.method-dialog form {
  margin: 0;
}

.dialog-kicker {
  margin: 0 3rem .55rem 0;
  color: var(--gold);
  text-transform: uppercase;
  font-size: .66rem;
  font-weight: 850;
  letter-spacing: .13em;
}

.method-dialog > h2 {
  margin: 0 3rem .65rem 0;
  font: 500 clamp(1.8rem, 5vw, 2.7rem)/1.04 Georgia, "Times New Roman", serif;
}

.method-dialog > p:not(.dialog-kicker) {
  max-width: 48rem;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.method-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .7rem;
  margin-top: 1.3rem;
}

.method-grid section {
  padding: .9rem;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: .45rem;
  background: rgba(255, 255, 255, .025);
}

.method-grid h3 {
  margin: 0 0 .35rem;
  color: var(--gold-soft);
  font: 500 1.1rem/1.2 Georgia, "Times New Roman", serif;
}

.method-grid p {
  margin: 0;
  color: var(--muted);
  font-size: .77rem;
  line-height: 1.55;
}

.method-links {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: 1rem;
}

.method-links a {
  min-height: 2.4rem;
  display: inline-flex;
  align-items: center;
  padding: .5rem .65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  text-decoration: none;
  font-size: .7rem;
}

.method-links a:hover {
  border-color: var(--line-strong);
  background: rgba(224, 183, 94, .07);
}

@media (max-width: 920px) {
  .app-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .header-count {
    display: none;
  }

  .toolbar {
    grid-template-columns: minmax(12rem, 1fr) minmax(11rem, 15rem) auto;
  }
}

@media (max-width: 700px) {
  :root {
    --header-height: 3.75rem;
  }

  .app-shell {
    min-height: 26rem;
  }

  .app-header {
    gap: .5rem;
    padding: .42rem max(.55rem, env(safe-area-inset-left)) .42rem max(.55rem, env(safe-area-inset-right));
  }

  .back-link,
  .quiet-button {
    min-width: 2.65rem;
    min-height: 2.65rem;
    padding: .45rem .6rem;
  }

  .back-label,
  .quiet-button {
    font-size: 0;
  }

  .quiet-button::before {
    content: "i";
    font: 700 1rem/1 Georgia, "Times New Roman", serif;
  }

  .brand-mark {
    width: 2rem;
  }

  .title-lockup {
    gap: .5rem;
  }

  .title-lockup p {
    display: none;
  }

  .title-lockup h1 {
    font-size: 1rem;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(8.4rem, .58fr);
    gap: .5rem;
    padding: .5rem max(.55rem, env(safe-area-inset-right)) .52rem max(.55rem, env(safe-area-inset-left));
  }

  .search-control > label,
  .branch-control > label {
    display: none;
  }

  .search-box,
  .branch-control select {
    min-height: 2.55rem;
  }

  .search-box kbd {
    display: none;
  }

  .branch-control select {
    padding-left: .55rem;
    font-size: .68rem;
  }

  .control-strip {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .control-strip button {
    min-height: 2.45rem;
  }

  .stage-status {
    top: .5rem;
    left: .5rem;
  }

  .gesture-hint {
    bottom: max(.5rem, env(safe-area-inset-bottom));
    max-width: calc(100% - 1rem);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .desktop-hint {
    display: none;
  }

  .mobile-hint {
    display: inline;
  }

  .person-sheet {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-height: min(58dvh, 33rem);
    padding: 1.15rem max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    border-width: 1px 0 0;
    border-radius: 1rem 1rem 0 0;
    animation-name: sheet-up;
  }

  @keyframes sheet-up {
    from { opacity: 0; transform: translateY(1.5rem); }
    to { opacity: 1; transform: none; }
  }

  .sheet-handle {
    width: 2.7rem;
    height: .23rem;
    display: block;
    margin: -.55rem auto .8rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, .22);
  }

  #person-image {
    width: 5rem;
    height: 5rem;
    float: left;
    margin: 0 .8rem .55rem 0;
    border-radius: .45rem;
  }

  .person-sheet h2 {
    font-size: 1.5rem;
  }

  .person-description {
    font-size: .8rem;
  }

  .person-facts {
    clear: both;
  }

  .method-dialog {
    width: calc(100% - 1rem);
    max-height: calc(100dvh - 1rem);
    padding: 1.2rem;
  }

  .method-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 410px) {
  .title-lockup .brand-mark {
    display: none;
  }

  .search-box {
    padding-inline: .58rem;
  }

  .search-box input,
  .branch-control select {
    font-size: .67rem;
  }

  .control-strip button {
    padding-inline: .6rem;
  }
}

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