:root {
  color-scheme: dark;
  --bg: #12110f;
  --panel: #1b1a17;
  --panel-strong: #23211d;
  --ink: #f3efe6;
  --muted: #b5aa99;
  --line: #3d382f;
  --gold: #c89b3c;
  --red: #b84a3f;
  --green: #4c9b6f;
  --blue: #6895c9;
  --violet: #9a74bd;
  --orange: #d27c3f;
  --gray: #77746d;
  --focus: #f0c96a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 78% 18%, rgba(200, 155, 60, 0.14), transparent 28rem),
    linear-gradient(135deg, #12110f 0%, #191815 46%, #202328 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.file-btn {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #27241f;
  color: var(--ink);
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover,
.file-btn:hover {
  border-color: var(--gold);
  background: #312b20;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.file-btn:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(27, 26, 23, 0.96);
  padding: 22px;
  overflow-y: auto;
}

.brand {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.sigil {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid var(--gold);
  border-radius: 8px;
  background: #2b2316;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.35rem;
  line-height: 1.15;
}

.brand p,
.detail-panel p {
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.45;
}

.search,
.filter-group,
.detail-panel,
.data-tools {
  display: block;
  margin-top: 20px;
}

.search span,
.filter-group h2,
.data-tools h2,
.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input[type="search"],
select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #11100e;
  color: var(--ink);
  padding: 0 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  min-height: 36px;
  padding: 0 6px;
  color: var(--muted);
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--gold);
  color: #14110b;
  font-weight: 800;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.check {
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 32px;
  color: var(--muted);
  font-size: 0.9rem;
}

.check input {
  accent-color: var(--gold);
}

.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 16px;
}

.detail-panel h2 {
  font-size: 1.15rem;
}

.detail-actions,
.tool-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.graph-stage {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

.topbar {
  position: absolute;
  z-index: 2;
  inset: 16px 16px auto 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  background: rgba(18, 17, 15, 0.78);
  backdrop-filter: blur(12px);
  color: var(--muted);
}

.topbar span {
  margin-right: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  font-size: 0.82rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

#graph {
  display: block;
  width: 100%;
  height: 100vh;
  touch-action: none;
  user-select: none;
}

.link {
  stroke-opacity: 0.52;
  stroke-width: 1.7;
}

.link[data-type="parent"] {
  stroke-opacity: 0.72;
  stroke-width: 2.4;
}

.link[data-type="marriage"],
.link[data-type="family"] {
  stroke-opacity: 0.66;
  stroke-width: 2;
}

.link-label {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 700;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(18, 17, 15, 0.94);
  stroke-width: 3px;
  text-anchor: middle;
  text-transform: uppercase;
}

.node {
  cursor: pointer;
}

.node text {
  fill: var(--ink);
  font-size: 12px;
  paint-order: stroke;
  stroke: rgba(18, 17, 15, 0.92);
  stroke-width: 4px;
  pointer-events: none;
}

.portrait-bg {
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 1;
}

.portrait {
  pointer-events: none;
}

.node.dead .portrait {
  filter: grayscale(1) brightness(0.58) contrast(0.92);
  opacity: 0.72;
}

.node.dead .portrait-bg {
  fill: #2a2925;
}

.portrait-ring {
  stroke-width: 4;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.45));
}

.node.selected .portrait-bg,
.node.selected .portrait,
.node.selected .portrait-initials,
.node.selected .dead-mark {
  transform: scale(1.28);
  transform-box: fill-box;
  transform-origin: center;
}

.portrait-initials {
  fill: var(--gold);
  font-size: 11px;
  font-weight: 800;
  stroke: none;
  text-anchor: middle;
}

.dead-mark {
  pointer-events: none;
}

.node.faded,
.link.faded,
.link-label.faded {
  opacity: 0.13;
}

.node.selected .portrait-ring {
  stroke: var(--focus);
  stroke-width: 5px;
  transform: scale(1.28);
  transform-box: fill-box;
  transform-origin: center;
}

.node-info {
  display: none;
  pointer-events: none;
}

.node.selected .node-info {
  display: block;
}

.node-info text {
  paint-order: stroke;
  stroke: rgba(18, 17, 15, 0.85);
  stroke-width: 2px;
}

.node-info-title {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.node-info-line {
  fill: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
}

.house-sigil {
  pointer-events: none;
}

.house-sigil-bg {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.house-sigil-image {
  pointer-events: none;
}

.toast {
  position: absolute;
  right: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100% - 32px));
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18, 17, 15, 0.9);
  color: var(--ink);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100svh;
  }

  .sidebar {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px;
  }

  .brand {
    grid-template-columns: 44px 1fr;
    gap: 10px;
    margin-bottom: 14px;
  }

  .sigil {
    width: 44px;
    height: 44px;
    font-size: 0.82rem;
  }

  h1 {
    font-size: 1.08rem;
  }

  .brand p {
    font-size: 0.86rem;
  }

  .search,
  .filter-group,
  .detail-panel,
  .data-tools {
    margin-top: 12px;
  }

  .checkbox-grid {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .check {
    flex: 0 0 auto;
    min-height: 30px;
    white-space: nowrap;
  }

  .detail-panel {
    padding: 12px;
  }

  .topbar {
    position: static;
    margin: 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 9px 10px;
  }

  .topbar span {
    display: inline-block;
    margin: 0 10px 4px 0;
  }

  .legend {
    justify-content: flex-start;
  }

  #graph {
    height: 68svh;
    min-height: 460px;
  }
}

@media (max-width: 560px) {
  .segmented {
    grid-template-columns: repeat(2, 1fr);
  }

  .segmented button:nth-child(2) {
    border-right: 0;
  }

  .tool-row,
  .detail-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .tool-row > *,
  .detail-actions > * {
    justify-content: center;
    width: 100%;
  }

  .node text.node-name {
    font-size: 10.5px;
  }

  .link-label {
    font-size: 8.5px;
  }

  .node-info-title {
    font-size: 10.5px;
  }

  .node-info-line {
    font-size: 9.25px;
  }

  .toast {
    right: 10px;
    bottom: 10px;
    max-width: calc(100% - 20px);
  }
}
