@font-face {
  font-family: "Ubuntu";
  src: url("fonts/ubuntu-v11-latin-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Ubuntu";
  src: url("fonts/ubuntu-v11-latin-500.woff2") format("woff2");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Ubuntu";
  src: url("fonts/ubuntu-v11-latin-700.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f3f0e8;
  --panel: #fffdf8;
  --panel-strong: #ebe7dc;
  --ink: #27302d;
  --muted: #747972;
  --line: #d9d3c5;
  --accent: #367d70;
  --accent-dark: #225f57;
  --tradition-japanese: #5577ac;
  --tradition-western: #b86a5d;
  --gold: #ba8c42;
  --shadow: 0 18px 50px rgba(40, 47, 43, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Ubuntu", ui-sans-serif, system-ui, sans-serif;
}

button,
select,
input {
  font: inherit;
}

input {
  font-size: 1.125em;
  font-weight: 400;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  position: relative;
  z-index: 15;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 17px 24px;
  border-bottom: 1px solid rgba(123, 111, 91, 0.17);
  background: rgba(255, 253, 248, 0.9);
  box-shadow: 0 8px 30px rgba(48, 54, 49, 0.04);
  backdrop-filter: blur(18px);
  overflow: visible;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: block;
  object-fit: contain;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.2;
}

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 12px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.advanced-control {
  display: none;
}

label {
  display: grid;
  gap: 7px;
  color: #424440;
  font-size: 13px;
  font-weight: 700;
}

select,
input[type="search"] {
  min-width: 0;
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(132, 122, 103, 0.28);
  border-radius: 22px;
  background: rgba(255, 255, 252, 0.82);
  color: var(--ink);
  padding: 0 16px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input[type="search"]:focus {
  outline: none;
  border-color: rgba(54, 125, 112, 0.66);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(54, 125, 112, 0.09);
}

.search-field {
  position: relative;
  display: grid;
  color: #424440;
  font-size: 13px;
  font-weight: 700;
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 40;
  display: none;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 254, 250, 0.98);
  box-shadow: 0 16px 34px rgba(25, 29, 32, 0.16);
}

.search-results.open {
  display: block;
}

.search-option {
  display: block;
  width: 100%;
  min-height: 40px;
  border: 0;
  border-bottom: 1px solid #ede8df;
  background: transparent;
  color: var(--ink);
  padding: 9px 11px;
  text-align: left;
  cursor: pointer;
}

.search-option:hover,
.search-option:focus {
  background: #f5f2eb;
}

.search-option small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.search-hint {
  min-height: 40px;
  color: var(--muted);
  padding: 10px 11px;
  font-size: 13px;
  font-weight: 600;
}

.detail-panel p,
.detail-list {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.workspace {
  position: relative;
  z-index: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  padding: 0;
}

.embed-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 20px;
  color: var(--accent-dark);
  text-decoration: none;
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.embed-link,
.reset-button {
  font-size: 0.875em;
  font-weight: 400;
}

.reset-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 252, 0.76);
  color: var(--ink);
  cursor: pointer;
}

.reset-button:hover,
.reset-button:focus {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.graph-panel {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: auto;
  border: 0;
  border-radius: 0;
  background:
    radial-gradient(ellipse at 14% 18%, rgba(171, 198, 173, 0.18), transparent 34%),
    radial-gradient(ellipse at 84% 72%, rgba(221, 195, 158, 0.14), transparent 38%),
    linear-gradient(115deg, rgba(255, 255, 255, 0.72), rgba(246, 243, 234, 0.58)),
    #f5f2ea;
  box-shadow: none;
  font-family: "Ubuntu", ui-sans-serif, system-ui, sans-serif;
}

.graph {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
}

.graph::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.78' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
}

.graph-info {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 10;
  display: grid;
  justify-items: start;
  gap: 7px;
  max-width: calc(100% - 28px);
  pointer-events: none;
}

.graph-status {
  max-width: min(420px, calc(100% - 28px));
  border: 1px solid rgba(216, 211, 199, 0.8);
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.86);
  color: var(--muted);
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.3;
  box-shadow: 0 8px 22px rgba(25, 29, 32, 0.08);
  pointer-events: none;
}

.graph-status.is-alert {
  color: #7b3d20;
  border-color: rgba(192, 138, 44, 0.45);
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  border: 1px solid rgba(216, 211, 199, 0.8);
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.86);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(25, 29, 32, 0.08);
  pointer-events: none;
}

.graph-panel > .graph-legend {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 10;
  max-width: calc(100% - 28px);
}

.graph-legend[hidden] {
  display: none;
}

.legend-japanese {
  color: var(--tradition-japanese);
}

.legend-western {
  color: var(--tradition-western);
}

.graph-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.edge-line {
  fill: none;
  stroke: rgba(54, 125, 112, 0.48);
  stroke-width: 2.15;
  stroke-linecap: round;
  filter: url("#line-softness");
}

.edge-line.routed {
  fill: none !important;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.edge-line.tradition-japanese {
  stroke: var(--tradition-japanese);
}

.edge-line.tradition-western {
  stroke: var(--tradition-western);
}

.edge-line.tradition-transition {
  stroke: rgba(129, 105, 139, 0.74);
}

.edge-line.tradition-hybrid-dash {
  stroke-width: 2.55;
  stroke-dasharray: 8 16;
  stroke-dashoffset: 0;
}

.edge-line.tradition-hybrid-dash.tradition-japanese {
  stroke-dashoffset: 12;
}

.edge-arrow {
  fill: none;
  stroke: rgba(54, 125, 112, 0.72);
  stroke-width: 2.15;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: url("#line-softness");
}

.edge-arrow.tradition-japanese {
  stroke: var(--tradition-japanese);
}

.edge-arrow.tradition-western {
  stroke: var(--tradition-western);
}

.edge-arrow.tradition-transition {
  stroke: rgba(129, 105, 139, 0.86);
}

.edge-group {
  opacity: 1;
  transition: opacity 140ms ease;
}

.dense-graph .edge-group {
  opacity: 0.2;
}

.edge-focus .edge-group {
  opacity: 0.16;
}

.edge-focus .edge-group.is-focused {
  opacity: 1;
}

.dense-graph.edge-focus .edge-group {
  opacity: 0.045;
}

.dense-graph.edge-focus .edge-group.is-focused {
  opacity: 0.95;
}

.edge-line.secondary {
  stroke: rgba(192, 138, 44, 0.45);
  stroke-dasharray: 7 7;
}

.edge-line.secondary.tradition-japanese {
  stroke: #708ce9;
}

.edge-line.secondary.tradition-western {
  stroke: #e47b7b;
}

.person-node {
  position: absolute;
  z-index: 2;
  width: fit-content;
  min-width: 132px;
  max-width: 260px;
  min-height: 68px;
  transform: translate(-50%, -50%) rotate(var(--node-tilt, 0deg));
  border: 1px solid rgba(54, 125, 112, 0.62);
  border-radius: var(--shape-a, 22px) var(--shape-b, 16px) calc(var(--shape-a, 22px) - 5px) calc(var(--shape-b, 16px) + 4px);
  background: rgba(255, 254, 249, 0.94);
  box-shadow:
    0 13px 30px rgba(50, 57, 52, 0.1),
    inset 0 1px rgba(255, 255, 255, 0.86);
  text-align: left;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.person-node::before {
  display: none;
}

.person-node:hover,
.person-node:focus-within {
  z-index: 4;
  transform: translate(-50%, -50%) rotate(0deg) translateY(-3px);
  border-width: 2px;
  border-color: rgba(54, 125, 112, 0.82);
  box-shadow: 0 18px 38px rgba(50, 57, 52, 0.16);
}

.node-main {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 13px 15px 13px 17px;
  text-align: left;
  cursor: pointer;
}

.person-node.root {
  border-color: rgba(186, 140, 66, 0.78);
}

.person-node.tradition-japanese {
  border-color: rgba(85, 119, 172, 0.72);
}

.person-node.tradition-western {
  border-color: rgba(184, 106, 93, 0.72);
}

.person-node.tradition-transition {
  border-color: rgba(129, 105, 139, 0.74);
}

.person-node.anonymized {
  border-color: rgba(133, 136, 132, 0.72);
}

.person-node.unknown-person {
  border-style: dashed;
}

.person-node .person-type-label {
  color: #7a6550;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.person-node strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.25;
}

.person-node span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.empty-state {
  display: none;
}

.detail-panel {
  min-width: 0;
  padding: 18px;
}

.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(360px, calc(100vw - 22px));
  height: 100vh;
  overflow-y: auto;
  border: 0;
  border-radius: 0;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: -12px 0 32px rgba(25, 29, 32, 0.14);
  transform: translateX(104%);
  transition: transform 180ms ease;
}

.detail-open .detail-drawer {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  border: 0;
  background: rgba(32, 33, 36, 0.24);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.detail-open .drawer-backdrop {
  opacity: 0;
  pointer-events: none;
}

.drawer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

#detailContent {
  padding-right: 44px;
}

.detail-panel h2 {
  margin: 5px 0 10px;
  font-size: 24px;
  line-height: 1.15;
}

.detail-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.detail-list div {
  display: grid;
  gap: 3px;
}

.detail-list dt {
  margin: 0.25em 0;
  color: #6e83c4;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.detail-list dd {
  margin: 0;
}

.connection-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.connections-list {
  padding-left: 1em;
}

.connection-list li {
  line-height: 1.4;
}

.tag-list {
  display: grid;
  gap: 3px;
  margin: 0;
  padding-left: 1em;
}

.tag-list li {
  line-height: 1.35;
}

.tag-list li::marker {
  font-size: 0.7em;
}

.connection-main {
  display: block;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.connection-meta {
  display: grid;
  gap: 1px;
  margin-top: 2px;
  margin-bottom: 4px;
  color: #444;
  font-size: 12px;
  line-height: 1.35;
}

.connection-meta span {
  display: block;
}

.embed-body {
  min-height: auto;
  background: transparent;
}

.embed-shell {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.embed-header h1 {
  font-size: 24px;
}

.embed-header-legend {
  flex: 0 0 auto;
}

.embed-graph-panel {
  min-height: 460px;
  box-shadow: none;
}

.embed-detail {
  width: min(380px, calc(100vw - 24px));
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .control-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .data-status {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 18px;
  }

  .workspace {
    padding: 0;
  }

  .topbar {
    gap: 12px;
    align-items: center;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .brand p {
    display: none;
  }

  .topbar-actions {
    grid-column: 2;
    grid-row: 1;
    flex-wrap: wrap;
  }

  .embed-link,
  .reset-button {
    min-height: 38px;
    padding: 0 10px;
  }

  .control-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .control-panel .search-field:last-child {
    grid-column: 1 / -1;
  }

  .control-panel label {
    min-width: 0;
  }

  select {
    min-height: 38px;
  }

  .graph-panel {
    min-height: 0;
  }

  .detail-drawer {
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: 68vh;
    height: auto;
    border-top: 1px solid var(--line);
    border-left: 0;
    border-radius: 8px 8px 0 0;
    transform: translateY(104%);
  }

  .detail-open .detail-drawer {
    transform: translateY(0);
  }
}

@media (max-width: 560px) {
  .embed-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  .person-node,
  .detail-drawer,
  .drawer-backdrop {
    transition: none;
  }
}
