/* ==========================================================================
   Древо философских учений — стили
   Палитра: холодная «чертёжная» бумага, чернильный синий, цвета традиций
   ========================================================================== */
:root {
  --paper: #e9edf1;
  --surface: #ffffff;
  --ink: #16202e;
  --muted: #566274;
  --rule: #c9d1db;
  --navy: #1b2a41;
  --navy-soft: #2b3d5a;
  --focus: #0b57d0;

  --serif: "Palatino Linotype", "Book Antiqua", Palatino, "URW Palladio L", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------
   Верхняя панель (главная)
   ------------------------------------------------------------------ */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px;
  padding: 10px 20px;
  background: var(--navy); color: #fff;
}
.topbar h1 {
  margin: 0; font-family: var(--serif); font-weight: 700;
  font-size: 1.35rem; letter-spacing: 0.01em;
}
.topbar .sub { margin: 0; color: #b8c4d8; font-size: 0.85rem; }
.topbar .spacer { flex: 1; }

.tool {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.88rem; color: #e3e9f3;
}
.tool input[type="search"] {
  width: 220px; max-width: 46vw;
  padding: 7px 12px; border-radius: 6px; border: 1px solid #44587a;
  background: #12203a; color: #fff; font: inherit;
}
.tool input[type="search"]::placeholder { color: #8fa0bc; }
.tool button {
  width: 34px; height: 34px; border-radius: 6px;
  border: 1px solid #44587a; background: #12203a; color: #fff;
  font-size: 1.15rem; line-height: 1; cursor: pointer;
}
.tool button:hover { background: #22375c; }
.tool .zoom-val { min-width: 3.2em; text-align: center; font-variant-numeric: tabular-nums; }
.tool label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px;
  padding: 8px 20px; background: #f6f8fa; border-bottom: 1px solid var(--rule);
  font-size: 0.82rem; color: var(--muted);
}
.legend .dot {
  display: inline-block; width: 12px; height: 12px; border-radius: 3px;
  margin-right: 6px; vertical-align: -1px;
}
.legend .sample { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { width: 38px; height: 12px; }

/* ------------------------------------------------------------------
   Область с древом
   ------------------------------------------------------------------ */
#viewport {
  flex: 1; min-height: 0; overflow: auto; position: relative;
  background: var(--paper);
  cursor: grab;
  scrollbar-width: thin;
}
#viewport.dragging { cursor: grabbing; user-select: none; }

/* Шкала времени, закреплённая сверху */
#axis {
  position: sticky; top: 0; z-index: 20; height: 58px;
  background: var(--navy-soft);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}
#axis .era {
  position: absolute; top: 0; height: 26px; overflow: hidden;
  padding: 0 10px; line-height: 26px;
  font-family: var(--serif); font-size: 0.86rem; font-weight: 700; color: #fff;
  border-right: 1px solid rgba(255, 255, 255, 0.28);
  white-space: nowrap;
}
#axis .era span { position: sticky; left: 10px; }
#axis .tick {
  position: absolute; top: 30px; transform: translateX(-50%);
  font-size: 0.74rem; color: #d3dcec; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#axis .tick::before {
  content: ""; position: absolute; left: 50%; top: -5px; width: 1px; height: 4px;
  background: #8fa0bc;
}

#stage { position: relative; }
#stage .era-col { position: absolute; top: 0; bottom: 0; }
#stage .era-col.alt { background: rgba(27, 42, 65, 0.045); }
#stage .grid { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(27, 42, 65, 0.09); }
#stage .grid.major { background: rgba(27, 42, 65, 0.16); }

#stage .lane {
  position: absolute; left: 0; right: 0;
  border-top: 1px solid var(--rule);
}
#stage .lane-label {
  position: sticky; left: 0; display: inline-block;
  padding: 4px 12px; margin: 6px 0 0 8px;
  font-family: var(--serif); font-size: 0.86rem; font-weight: 700;
  color: var(--lane); background: rgba(255, 255, 255, 0.88);
  border-radius: 4px; border-left: 4px solid var(--lane);
  z-index: 3;
}

#links { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 1; overflow: visible; }
#links path { fill: none; transition: opacity 0.15s; }
#links path.parent { stroke-width: 2; opacity: 0.8; }
#links path.anti { stroke: #c0392b; stroke-width: 1.4; stroke-dasharray: 5 4; opacity: 0.55; }
#links.hide-anti path.anti { display: none; }

/* Карточки течений */
.node {
  position: absolute; z-index: 2;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 4px 9px 4px 11px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-left: 5px solid var(--c);
  border-radius: 5px;
  text-decoration: none; overflow: hidden;
  box-shadow: 0 1px 2px rgba(27, 42, 65, 0.12);
  transition: opacity 0.15s, box-shadow 0.15s, transform 0.15s;
}
.node:hover, .node:focus-visible {
  box-shadow: 0 4px 14px rgba(27, 42, 65, 0.28);
  z-index: 10;
}
.node .n-name {
  font-family: var(--serif); font-weight: 700; font-size: 0.86rem; line-height: 1.15;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.node .n-years { font-size: 0.74rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* подсветка связей при наведении */
#stage.has-focus .node { opacity: 0.28; }
#stage.has-focus .node.rel { opacity: 1; }
#stage.has-focus .node.rel-anti { opacity: 1; border-color: #c0392b; }
#stage.has-focus .node.self { opacity: 1; }
#stage.has-focus #links path { opacity: 0.1; }
#stage.has-focus #links path.rel { opacity: 1; stroke-width: 3; }
#stage.has-focus #links path.anti.rel { stroke-width: 2.2; }

/* поиск */
#stage.searching .node { opacity: 0.25; }
#stage.searching .node.match { opacity: 1; box-shadow: 0 0 0 3px #ffcf4d, 0 3px 10px rgba(0,0,0,.2); }

.empty-note { padding: 40px; color: var(--muted); }

/* ------------------------------------------------------------------
   Страница течения
   ------------------------------------------------------------------ */
.page { max-width: 1040px; margin: 0 auto; padding: 0 20px 80px; }
.page-bar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--navy); color: #fff;
}
.page-bar a { color: #fff; text-decoration: none; font-size: 0.95rem; }
.page-bar a:hover { text-decoration: underline; }
.page-bar .site { font-family: var(--serif); font-weight: 700; color: #b8c4d8; }

.hero {
  margin: 28px 0 8px; padding: 26px 28px 24px;
  background: var(--surface); border: 1px solid var(--rule);
  border-left: 10px solid var(--c);
  border-radius: 6px;
}
.hero h1 {
  margin: 0 0 6px; font-family: var(--serif); font-size: clamp(1.9rem, 4.4vw, 2.8rem);
  line-height: 1.1; letter-spacing: -0.005em;
}
.hero .years { margin: 0; font-size: 1.15rem; font-variant-numeric: tabular-nums; color: var(--ink); }
.hero .trad { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }
.hero .summary { margin: 16px 0 0; max-width: 62ch; font-family: var(--serif); font-size: 1.12rem; line-height: 1.6; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin: 14px 0 0; }
.fact {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 14px 18px;
}
.fact dt { font-size: 0.82rem; color: var(--muted); margin: 0 0 3px; }
.fact dd { margin: 0; font-family: var(--serif); font-size: 1.05rem; }
.fact dd a { color: var(--focus); }

.block { margin: 34px 0 0; }
.block h2 {
  margin: 0 0 14px; font-family: var(--serif); font-size: 1.5rem;
  padding-bottom: 8px; border-bottom: 2px solid var(--ink);
}
.block h3 { margin: 18px 0 8px; font-size: 0.98rem; color: var(--muted); font-weight: 600; }

.essence { margin: 0; padding: 0; list-style: none; counter-reset: pt; }
.essence li {
  counter-increment: pt; position: relative;
  padding: 14px 18px 14px 56px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px;
  font-family: var(--serif); font-size: 1.06rem; line-height: 1.55;
}
.essence li::before {
  content: counter(pt); position: absolute; left: 16px; top: 12px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--c); color: #fff;
  font-family: var(--sans); font-size: 0.9rem; font-weight: 700;
  display: grid; place-items: center;
}

.chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.chip {
  display: block; text-decoration: none;
  padding: 9px 14px 9px 14px; min-width: 150px; max-width: 280px;
  background: var(--surface); border: 1px solid var(--rule); border-left: 5px solid var(--c);
  border-radius: 5px;
}
.chip:hover { box-shadow: 0 3px 10px rgba(27, 42, 65, 0.2); }
.chip b { display: block; font-family: var(--serif); font-size: 0.98rem; line-height: 1.2; }
.chip small { color: var(--muted); font-size: 0.8rem; }
.none { color: var(--muted); margin: 0; }

.reps { margin: 0; padding-left: 1.2em; columns: 2 260px; }
.reps li { margin-bottom: 4px; }
.reps a { color: var(--focus); }

/* Персоналии */
.persons { display: grid; gap: 16px; }
.person {
  display: grid; grid-template-columns: 132px 1fr; gap: 20px;
  padding: 18px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 6px;
  scroll-margin-top: 20px;
}
.person.flash { animation: flash 2.2s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px #ffcf4d; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .person.flash { animation: none; outline: 3px solid #ffcf4d; } }

.avatar {
  width: 132px; height: 168px; border-radius: 4px; overflow: hidden;
  background: #dfe5ec; border: 1px solid var(--rule);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.noimg {
  display: grid; place-items: center;
  background: var(--c); color: #fff;
  font-family: var(--serif); font-size: 2.2rem; font-weight: 700;
}
.person h3 { margin: 0; font-family: var(--serif); font-size: 1.3rem; color: var(--ink); }
.person .p-years { margin: 2px 0 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.person dl { margin: 12px 0 0; display: grid; grid-template-columns: 9.5em 1fr; gap: 6px 14px; font-size: 0.95rem; }
.person dt { color: var(--muted); }
.person dd { margin: 0; }
.person dd a { color: var(--focus); }
.person .beliefs { margin: 0; font-size: 1rem; line-height: 1.55; }

.not-found { max-width: 600px; margin: 80px auto; padding: 0 20px; }
.not-found h1 { font-family: var(--serif); }

footer.site-foot { margin-top: 60px; color: var(--muted); font-size: 0.85rem; }

@media (max-width: 640px) {
  .person { grid-template-columns: 1fr; }
  .avatar { width: 112px; height: 144px; }
  .person dl { grid-template-columns: 1fr; gap: 2px; }
  .person dt { margin-top: 6px; }
  .hero { padding: 20px 18px; }
  .tool input[type="search"] { width: 150px; }
}
