:root {
  --bg: #faf8f8;
  --canvas: #f4f1f1;
  --panel: #ffffff;
  --text: #2b2b2b;
  --muted: #71717a;
  --line: rgba(9, 9, 11, 0.12);
  --line-strong: rgba(9, 9, 11, 0.22);
  --node: #ffffff;
  --node-hover: #f6f3fe;
  --link: rgba(9, 9, 11, 0.22);
  --accent: #856df0;
  --accent-text: #5b45c4;
  --accent-tint: rgba(133, 109, 240, 0.12);
  --b: #12998f;
  --b-tint: rgba(18, 153, 143, 0.13);
  --warn: #d0463f;
  --warn-tint: rgba(208, 70, 63, 0.1);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.05);
  --font: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
:root[saved-theme="dark"] {
  --bg: #161618;
  --canvas: #19191c;
  --panel: #1d1d20;
  --text: #ebebec;
  --muted: #a1a1aa;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.24);
  --node: #222226;
  --node-hover: #2a2832;
  --link: rgba(255, 255, 255, 0.2);
  --accent-text: #b9a9ff;
  --accent-tint: rgba(133, 109, 240, 0.2);
  --b: #2cc2b6;
  --b-tint: rgba(44, 194, 182, 0.17);
  --warn: #ef6b63;
  --warn-tint: rgba(239, 107, 99, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
a { color: var(--accent-text); }

/* ───────── шапка ───────── */
.top {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); flex: none; }
.brand-t { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-t b { font-weight: 700; color: var(--text); }
:root[saved-theme="dark"] .brand img { filter: invert(1) hue-rotate(180deg); }
.title { font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; color: var(--muted); }
.title::before { content: "/"; margin-right: 14px; color: var(--line-strong); }
.search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.search input {
  width: 100%;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 0 14px;
  font: inherit;
  outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.search-results {
  position: absolute;
  top: 44px;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  max-height: 70vh;
  overflow: auto;
}
.res {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
.res small { display: block; color: var(--muted); font-size: 12px; }
.res.on, .res:hover { background: var(--accent-tint); }
.res-dx {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
}
.top-nav { display: flex; align-items: center; gap: 10px; flex: none; }
.top-nav a { text-decoration: none; color: var(--text); font-weight: 500; padding: 6px 10px; border-radius: 8px; }
.top-nav a:hover { background: var(--accent-tint); }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  display: grid;
  place-items: center;
  cursor: pointer;
}

/* ───────── раскладка ───────── */
.app { display: grid; grid-template-columns: minmax(0, 1fr) 420px; height: calc(100vh - 60px); height: calc(100dvh - 60px); }
.stage {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, var(--line) 1px, transparent 0) 0 0 / 22px 22px,
    var(--canvas);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.stage.dragging { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.links { position: absolute; left: 0; top: 0; overflow: visible; }
.links path { fill: none; stroke: var(--link); stroke-width: 1.4; }
.nodes { position: absolute; left: 0; top: 0; }

/* ───────── узлы ───────── */
.node {
  position: absolute;
  left: 0;
  top: 0;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px 0 4px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--node);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, filter 0.2s;
}
.node:hover { background: var(--node-hover); border-color: var(--line-strong); }
.node:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.node-g { width: 28px; height: 28px; flex: none; }
.node-g svg, .row-g svg, .chip-g svg, .card-g svg { display: block; width: 100%; height: 100%; }
.node-t { font-size: 14px; font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.node-tg {
  flex: none;
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--canvas);
  border: 1px solid var(--line);
}
.node-tg:hover { color: var(--text); border-color: var(--line-strong); }
.node-tg.lens-count { background: var(--accent); border-color: var(--accent); color: #fff; }
.node.kind-root { height: 44px; margin-top: -4px; border-radius: 22px; background: var(--accent); border-color: var(--accent); color: #fff; padding-left: 6px; }
.node.kind-root .node-t { font-size: 17px; font-weight: 650; }
.node.kind-root .node-g { width: 32px; height: 32px; }
.node.kind-root .node-tg { background: rgba(255, 255, 255, 0.2); border-color: transparent; color: #fff; }
.node.kind-root:hover { background: var(--accent); filter: brightness(1.06); }
.node.kind-section .node-t { font-weight: 650; }
.node.kind-pattern { border-style: dashed; }
.node.flag::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
  border: 2px solid var(--canvas);
}
.node.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint), var(--shadow); }

/* линза */
.stage.lens-on .node:not(.hit):not(.kind-root) { filter: grayscale(1); opacity: 0.32 !important; }
.stage.lens-on .node.hit-a { border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: var(--accent-tint); }
.stage.lens-on .node.hit-b { border-color: color-mix(in srgb, var(--b) 55%, transparent); background: var(--b-tint); }
.stage.lens-on .node.hit-a.hit-b { background: linear-gradient(90deg, var(--accent-tint), var(--b-tint)); border-color: var(--line-strong); }
.stage.lens-on .node.hit-key.hit-a { border: 2px solid var(--accent); }
.stage.lens-on .node.hit-key.hit-b { border: 2px solid var(--b); }
.stage.lens-on .node.hit-key.hit-a.hit-b { border: 2px solid var(--accent); box-shadow: 0 0 0 3px var(--b-tint); }

/* ───────── инструменты холста ───────── */
.lensbar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}
.lensbar > * { pointer-events: auto; }
.lens-sel {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 4px 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.lens-sel select { border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 500; height: 100%; padding-right: 6px; outline: none; cursor: pointer; max-width: 260px; }
.lens-sel select option, .lens-sel select optgroup { color: #2b2b2b; background: #fff; }
.lens-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.lens-dot.a { background: var(--accent); }
.lens-dot.b { background: var(--b); }
.ghost-btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.ghost-btn:hover { border-color: var(--line-strong); }
.only-mobile { display: none; }
.stage-tools {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.stage-tools button { min-width: 34px; height: 32px; padding: 0 10px; border: 0; border-radius: 8px; background: none; cursor: pointer; font-size: 14px; }
.stage-tools button:hover { background: var(--accent-tint); }
.stage-tools .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.hint { position: absolute; left: 16px; bottom: 10px; margin: 0; font-size: 12px; color: var(--muted); pointer-events: none; }

/* ───────── панель ───────── */
.panel { border-left: 1px solid var(--line); background: var(--panel); position: relative; min-height: 0; }
.panel-body { height: 100%; overflow: auto; padding: 22px 24px 40px; }
.sheet-close { display: none; }
.eyebrow { margin: 0 0 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-text); }
.panel h2 { margin: 0 0 8px; font-size: 22px; line-height: 1.22; font-weight: 700; letter-spacing: -0.01em; }
.panel h3 { margin: 22px 0 8px; font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.panel p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.disclaimer { margin-top: 26px !important; font-size: 12.5px; color: var(--muted); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.crumbs button { border: 0; background: none; padding: 2px 4px; border-radius: 6px; color: var(--muted); cursor: pointer; }
.crumbs button:hover { color: var(--text); background: var(--accent-tint); }
.card-head { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.card-g { width: 104px; height: 104px; flex: none; }
.terms { font-size: 13.5px; color: var(--muted); margin: 0 !important; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 14px; }
.badge { font-size: 12.5px; padding: 3px 9px; border-radius: 999px; background: var(--canvas); border: 1px solid var(--line); }
.badge.warn { background: var(--warn-tint); border-color: transparent; color: var(--warn); font-weight: 600; }
.def { font-size: 15.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 13.5px;
  line-height: 1.25;
  text-align: left;
}
.chip:hover { border-color: var(--accent); background: var(--accent-tint); }
.chip small { color: var(--muted); font-size: 11.5px; }
.dx-chip.key { border-color: var(--accent); background: var(--accent-tint); font-weight: 600; }
.dx-chip.key small { color: var(--accent-text); font-weight: 500; }
.crit-chip { padding-left: 4px; }
.chip-g { width: 22px; height: 22px; flex: none; }
.rows { display: flex; flex-direction: column; gap: 2px; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.row:hover { background: var(--accent-tint); }
.row-g { width: 30px; height: 30px; flex: none; }
.row-t { flex: 1; min-width: 0; font-weight: 500; }
.row-t small { display: block; color: var(--muted); font-weight: 400; font-size: 12.5px; }
.row-n { font-size: 12px; color: var(--muted); }
.article-link { display: inline-block; margin-bottom: 4px; font-weight: 500; text-decoration: none; }
.article-link:hover { text-decoration: underline; }
.intro h2 { font-size: 21px; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.legend li { line-height: 1.45; }
.lg { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin: 0 6px 0 0; vertical-align: -1px; }
.legend li .lg + .lg, .legend li .lg-b { margin-left: 4px; }
.lg-flag { background: var(--warn); }
.lg-a { background: var(--accent); }
.lg-b { background: var(--b); }
.lg-key { border: 2px solid var(--accent); background: var(--accent-tint); border-radius: 4px; }
.sources { margin-top: 20px; font-size: 13px; color: var(--muted); }
.sources summary { cursor: pointer; font-weight: 600; color: var(--text); }
.sources ol { padding-left: 18px; }
.vs { color: var(--muted); font-weight: 400; }
.dot-a, .dot-b { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-a { background: var(--accent); }
.dot-b { background: var(--b); margin-left: 2px; }
.cmp { border-left: 3px solid var(--line); padding-left: 10px; margin-top: 14px; }
.cmp h3 { margin-top: 4px; }
.cmp-a { border-color: var(--accent); }
.cmp-b { border-color: var(--b); }
.cmp-ab { border-image: linear-gradient(var(--accent), var(--b)) 1; }
.ph-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 8px; }
.ph { position: relative; display: block; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--canvas); text-decoration: none; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.25s; }
.ph:hover img { transform: scale(1.04); }
.ph span {
  position: absolute;
  left: 6px;
  bottom: 6px;
  right: 6px;
  font-size: 11.5px;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ───────── мобильный список ───────── */
.mlist { display: none; }

@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr) 360px; }
  .title { display: none; }
  .hint { display: none; }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .top { height: auto; flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  .top-nav { margin-left: auto; }
  .app { display: block; height: auto; }
  .stage { overflow: visible; background: var(--bg); cursor: auto; touch-action: auto; user-select: auto; }
  .world, .stage-tools, .hint { display: none; }
  .lensbar { position: static; padding: 12px 16px 0; }
  .lens-sel { flex: 1 1 100%; }
  .lens-sel select { max-width: none; width: 100%; }
  .only-mobile { display: inline-block; }
  #open-lens-summary { display: none; }
  .stage.lens-on #open-lens-summary { display: inline-block; }
  .mlist { display: block; padding: 12px 16px 40px; }
  .mlist .crumbs { margin-bottom: 10px; }
  .mlist .crumbs b { color: var(--text); font-weight: 650; padding: 2px 4px; }
  .m-about { width: 100%; text-align: left; padding: 10px 14px; margin-bottom: 10px; border-radius: 12px; border: 1px dashed var(--line-strong); background: none; color: var(--accent-text); font-weight: 500; cursor: pointer; }
  .mrows { display: flex; flex-direction: column; gap: 6px; }
  .mrow {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 12px 8px 8px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel);
    text-align: left;
    position: relative;
    min-height: 56px;
  }
  .mrow .row-g { width: 40px; height: 40px; }
  .mrow-n { font-size: 12px; color: var(--muted); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
  .mrow-n.lens-count { background: var(--accent); border-color: var(--accent); color: #fff; }
  .chev { font-size: 22px; color: var(--muted); line-height: 1; }
  .mrow.flag::after { content: ""; position: absolute; top: 6px; left: 40px; width: 9px; height: 9px; border-radius: 50%; background: var(--warn); border: 2px solid var(--panel); }
  .mlist.lens-on .mrow:not(.hit) { opacity: 0.4; }
  .mlist.lens-on .mrow.hit-a { background: var(--accent-tint); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
  .mlist.lens-on .mrow.hit-b { background: var(--b-tint); border-color: color-mix(in srgb, var(--b) 50%, transparent); }
  .mlist.lens-on .mrow.hit-key.hit-a { border: 2px solid var(--accent); }
  .mlist.lens-on .mrow.hit-key.hit-b { border: 2px solid var(--b); }
  .panel {
    position: fixed;
    inset: 0;
    z-index: 50;
    border: 0;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    visibility: hidden;
  }
  .panel.open { transform: none; visibility: visible; }
  .panel-body { padding: 18px 16px 48px; }
  .sheet-close {
    display: grid;
    place-items: center;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--panel);
    font-size: 22px;
    cursor: pointer;
  }
  .card-g { width: 84px; height: 84px; }
  .panel h2 { font-size: 20px; padding-right: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}
