:root {
  --bg: #11110f;
  --bar: #1a1916;
  --line: #2c2a26;
  --text: #f3efe6;
  --muted: #a39e94;
  --orange: #c94f0a;
  --orange-strong: #e85d04;
  --orange-deep: #a83d05;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

button, label, input { font: inherit; color: inherit; }

.kg-map-bar {
  flex: none;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
}

.kg-map-version {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.kg-map-brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
}

.kg-map-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.kg-map-nav a { color: var(--muted); text-decoration: none; }

.kg-map-nav a.kg-map-cta,
a.kg-map-cta {
  background: var(--orange);
  color: #fff;
  border-radius: 4px;
  padding: 7px 12px;
  text-decoration: none;
  font-weight: 650;
}

.layout {
  display: flex;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

.side, .panel {
  flex: none;
  min-width: 200px;
  height: 100%;
  overflow: auto;
  background: rgba(22, 21, 18, .92);
  padding: 14px 14px 24px;
}

.side { width: 280px; }

.panel {
  width: 300px;
  flex-shrink: 0;
  background: #24221e;
  border-left: 3px solid var(--orange);
}

.panel.is-closed, #handlePanel.is-closed { display: none; }

.panel .title { margin: 0; font-size: 18px; line-height: 1.25; }

.handle {
  flex: none;
  width: 8px;
  cursor: col-resize;
  background: #1a1916;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  touch-action: none;
}

.handle:hover, .handle.dragging { background: var(--orange-deep); }

.side h2, .panel h2 {
  margin: 14px 0 8px;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}

.side .kg-map-summary { padding: 0; max-width: none; }

.side .kg-map-summary h1 {
  font-size: 16px;
  line-height: 1.3;
  margin: 0 0 8px;
}

.side .kg-map-summary h2 {
  margin: 12px 0 4px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--text);
}

.side .kg-map-summary p,
.side .kg-map-summary li { margin: 0 0 6px; }

.side .kg-map-summary ul,
.side .kg-map-summary ol { margin: 0 0 8px; padding-left: 1.1rem; }

.side .kg-map-summary a,
.panel a { color: var(--orange-strong); }

.modes, .relations { display: flex; flex-wrap: wrap; gap: 6px; }

.modes button, .ghost, .rel-more, .panel-head button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
}

.modes button[aria-pressed="true"] {
  background: var(--orange-deep);
  border-color: var(--orange-deep);
}

.check {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
}

.relations .check { width: 100%; }

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

.count { color: var(--muted); font-variant-numeric: tabular-nums; }

.problems, .rel-list { list-style: none; margin: 0; padding: 0; }

.problems button, .rel-jump {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  cursor: pointer;
  color: var(--text);
}

.problems button strong { display: block; color: var(--orange-strong); font-size: 12px; }

.note { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.stage .host { position: absolute; inset: 0; opacity: 0; touch-action: none; }

.stage.is-ready .host {
  opacity: 1;
  transition: opacity 200ms ease;
}

.stage .host[hidden] { display: none; }

.labels {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.stage-error {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.stage-error[hidden] { display: none; }

.stage-error p {
  max-width: 380px;
  margin: 0;
  text-align: center;
  border: 1px solid var(--orange);
  background: rgba(17, 17, 15, .94);
  padding: 16px;
}

.stats {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
  max-width: min(420px, calc(100% - 24px));
  background: rgba(17, 17, 15, .86);
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.stats p { margin: 0; }

.hint {
  position: absolute;
  left: 12px;
  bottom: 52px;
  top: auto;
  z-index: 3;
  max-width: 280px;
  margin: 0;
  background: rgba(17, 17, 15, .86);
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.hint[hidden], .pad[hidden], .stats[hidden] { display: none; }

.pad {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  display: grid;
  grid-template-columns: 36px 36px 36px;
  gap: 4px;
}

.pad button {
  width: 36px;
  height: 36px;
  background: #1a1916;
  color: var(--text);
  border: 1px solid var(--line);
  cursor: pointer;
}

.pad button:hover { border-color: var(--orange); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-head h2 { margin: 0; }

.panel .k { color: var(--muted); font-size: 12px; margin-top: 10px; }

.panel .v { margin: 2px 0 0; word-break: break-word; }

.panel .direction {
  margin: 12px 0 4px;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}

.panel .rel-count { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

.panel .problem-call {
  margin-top: 12px;
  padding: 8px;
  border: 1px solid var(--orange);
  color: var(--text);
}

.panel .problem-cta { margin-top: 8px; }

.panel .rel-more { margin-top: 6px; }

.empty { color: var(--muted); }

.kg-map-admin { margin: 16px 0 0; }

.kg-map-admin a, .kg-map-admin button {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  text-decoration: none;
  cursor: pointer;
}

.drawer-toggle, .drawer-close, .backdrop { display: none; }

.search {
  position: absolute;
  z-index: 4;
  left: 12px;
  top: 12px;
  width: min(320px, calc(100% - 24px));
}

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

.search input {
  width: 100%;
  background: #1a1916;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
}

.suggest {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  background: #1a1916;
  border: 1px solid var(--line);
  max-height: 280px;
  overflow: auto;
}

.suggest button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px;
  cursor: pointer;
  color: var(--text);
}

.suggest button:hover, .suggest button:focus-visible { background: #2c2a26; }

.legend-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 0 0 8px;
  color: var(--text);
}

.swatch {
  flex: none;
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
}

.skeleton {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.skeleton[hidden] { display: none; }

.skeleton-node, .skeleton-line {
  position: absolute;
  background: #3a362f;
  animation: kg-rest 1.8s ease-in-out infinite;
}

.skeleton-node {
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.skeleton-node:nth-child(1) { left: 38%; top: 42%; }
.skeleton-node:nth-child(2) { left: 50%; top: 34%; width: 22px; height: 22px; background: #c94f0a; }
.skeleton-node:nth-child(3) { left: 62%; top: 48%; }
.skeleton-line { height: 1px; }
.skeleton-line:nth-child(4) { left: 40%; top: 46%; width: 12%; }
.skeleton-line:nth-child(5) { left: 54%; top: 44%; width: 10%; }

@keyframes kg-rest {
  50% { opacity: .4; }
}

.stage-message {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.stage-message[hidden] { display: none; }

.stage-message p {
  max-width: 380px;
  margin: 0;
  text-align: center;
  border: 1px solid var(--line);
  background: rgba(17, 17, 15, .94);
  padding: 16px;
}

body.resizing, body.resizing * { cursor: col-resize; user-select: none; }

a:focus-visible, button:focus-visible, .handle:focus-visible, input:focus-visible {
  outline: 3px solid var(--orange-strong);
  outline-offset: 2px;
}

@media (max-width: 720px) {
  .drawer-toggle, .drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 8px 12px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 4px;
    cursor: pointer;
  }

  .kg-map-bar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .kg-map-nav { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .layout { position: relative; }

  .side {
    position: absolute;
    z-index: 6;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(100%, 320px) !important;
    max-height: none;
    min-width: 0;
    transform: translateX(-105%);
    transition: transform 200ms ease;
  }

  .layout.is-filters .side { transform: none; }
  .handle { display: none; }

  .panel {
    display: block;
    position: absolute;
    z-index: 6;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    height: min(70vh, 520px);
    width: 100% !important;
    min-width: 0;
    transform: translateY(110%);
    transition: transform 200ms ease;
  }

  .panel.is-open { display: block; transform: none; }
  .panel.is-closed { display: block; }
  .stage { min-height: 0; }

  .modes button,
  .pad button,
  .check,
  .rel-more,
  .panel-head button,
  .search input,
  .suggest button,
  .drawer-toggle,
  .drawer-close,
  .kg-map-cta {
    min-height: 44px;
  }

  .pad { grid-template-columns: 44px 44px 44px; }
  .pad button { width: 44px; height: 44px; }

  .backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 5;
    margin: 0;
    border: 0;
    background: rgba(17, 17, 15, .55);
    color: transparent;
  }

  .hint {
    max-width: calc(100% - 168px);
    bottom: 64px;
  }

  .stats {
    max-width: calc(100% - 168px);
    bottom: 12px;
  }

  .pad { bottom: 12px; }

  .backdrop[hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .stage.is-ready .host,
  .side,
  .panel,
  .skeleton-node,
  .skeleton-line {
    transition: none;
    animation: none;
  }
}
