:root {
  --bg:         #f5f7f5;
  --paper:      #ffffff;
  --ink:        #1f2a24;
  --muted:      #6b7a72;
  --line:       #e2e8e4;
  --accent:     #3f6b57;
  --accent-2:   #5a8c74;
  --accent-soft:#e5efe9;
  --year-bg:    #eef3ef;
  --year-ink:   #5f7166;
  --shadow-sm:  0 1px 2px rgba(24, 48, 36, .04);
  --shadow-md:  0 4px 12px rgba(24, 48, 36, .08);
  --shadow-lg:  0 12px 32px rgba(24, 48, 36, .15);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, #3a5c4b 0%, #4f7a63 55%, #6a9583 100%);
  color: #fff;
  padding: 40px 24px 32px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  width: 420px; height: 420px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 50%;
  right: -120px; top: -210px;
  box-shadow: 0 0 0 45px rgba(255,255,255,.04), 0 0 0 95px rgba(255,255,255,.025);
  pointer-events: none;
}
.wrap { max-width: 1180px; margin: 0 auto; position: relative; z-index: 1; }
.eyebrow {
  font-size: 11px; letter-spacing: .16em; text-transform: uppercase;
  color: #cfe1d7; font-weight: 700;
}
.hero h1 {
  font-size: clamp(24px, 3.8vw, 36px);
  line-height: 1.1; letter-spacing: -.03em;
  margin: 10px 0 8px;
}
.subtitle { font-size: 15px; color: #dcebe3; margin: 0; }

/* ---------- Main ---------- */
main {
  max-width: 1180px;
  margin: -15px auto 50px;
  padding: 0 22px;
  position: relative;
  z-index: 2;
}

/* ---------- Toolbar ---------- */
.toolbar {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.search-wrap {
  flex: 1 1 280px;
  position: relative;
  min-width: 0;
}
.search-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: #84948b; pointer-events: none;
  width: 16px; height: 16px;
}
.search-wrap input[type=search] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px 9px 36px;
  font: inherit;
  font-size: 13px;
  background: #fbfcfb;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-wrap input[type=search]:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(63,107,87,.1);
}

.year-range {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}
.year-range input[type=number] {
  width: 65px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  font-size: 12px;
  background: #fbfcfb;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  -moz-appearance: textfield;
}
.year-range input[type=number]::-webkit-outer-spin-button,
.year-range input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.year-range input[type=number]:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(63,107,87,.1);
}

.stats { color: var(--muted); font-size: 12px; white-space: nowrap; }
.stats strong { color: var(--accent); }

/* ---------- Секции статей ---------- */
.topic {
  margin: 0 0 8px;
  scroll-margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.topic:has(.resource:hover) { z-index: 50; }
.topic.hidden { display: none; }

.topic-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  background: var(--paper);
  border-radius: 10px;
  transition: background .2s;
}
.topic-head:hover { background: #fbfcfb; }

.topic-toggle {
  flex-shrink: 0;
  width: 20px; height: 20px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  color: var(--accent);
  font-size: 0;
  transition: background .2s, border-color .2s;
}
.topic-toggle::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 5px; height: 5px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translate(-50%, -65%) rotate(45deg);
  transition: transform .2s;
}
.topic-toggle:hover { background: var(--accent-soft); border-color: #c8d8ce; }
.topic.collapsed .topic-toggle::before {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.topic h2 {
  font-size: 15px;
  letter-spacing: -.015em;
  margin: 0;
  font-weight: 600;
  color: var(--ink);
}

.topic.collapsed .topic-body { display: none; }
.topic-body { padding: 0 14px 14px; }

/* Сдвиг карточек вправо относительно заголовка раздела */
.topic-body > .resources { padding-left: 24px; }

/* Подразделы (свернуты по умолчанию, есть треугольник) */
.subtopic { margin-top: 10px; }
.subtopic-head {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  padding: 6px 0;
}
.subtopic-head:hover h3 { color: var(--accent-2); }
.subtopic-head .subtopic-toggle {
  width: 16px; height: 16px;
  position: relative;
  color: var(--muted);
  font-size: 0;
  transition: transform .2s;
}
.subtopic-head .subtopic-toggle::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 4px; height: 4px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translate(-50%, -65%) rotate(45deg);
}
.subtopic.collapsed .subtopic-toggle { transform: rotate(-90deg); }
.subtopic.collapsed .subtopic-content { display: none; }

.subtopic h3 {
  font-size: 13px;
  color: var(--accent);
  margin: 0;
  font-weight: 600;
}

/* Отступы для подразделов */
.subtopic.level-1 { margin-left: 0; }
.subtopic.level-2 { margin-left: 12px; border-left: 1px solid var(--line); padding-left: 12px; }
.subtopic.level-3 { margin-left: 24px; border-left: 1px solid var(--line); padding-left: 12px; }
.subtopic.level-4 { margin-left: 36px; border-left: 1px solid var(--line); padding-left: 12px; }

/* Сдвиг карточек внутри подразделов */
.subtopic-content > .resources { padding-left: 24px; }

/* ---------- Сетка карточек ---------- */
.resources {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

/* ---------- Карточка ---------- */
.resource {
  position: relative;
  background: #fcfdfc;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  transition: transform .15s ease, border-color .15s, box-shadow .15s, opacity .3s ease;
  opacity: 0;
  transform: translateY(5px);
}
.resource.in-view {
  opacity: 1;
  transform: none;
}
.resource:hover {
  transform: translateY(-1px);
  border-color: #c3d5cb;
  box-shadow: var(--shadow-md);
  z-index: 100 !important;
}
.resource.hidden { display: none; }
.resource.is-dead { cursor: default; }
.resource.is-dead .resource-title { color: #66766c; }

.resource-title {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px;
}
.resource-title .year {
  font-size: 10px;
  font-weight: 500;
  color: var(--year-ink);
  background: var(--year-bg);
  padding: 0px 4px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ---------- Tooltip ---------- */
.tooltip {
  position: absolute;
  left: 20px;
  top: calc(100% + 4px);
  z-index: 9999;
  width: max-content;
  max-width: 280px;
  max-height: 200px;
  overflow-y: auto;
  
  background: #f0f4f2;
  color: #2c3e34;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #dce4df;
  
  box-shadow: 0 8px 24px rgba(30, 50, 40, 0.15), 0 2px 8px rgba(30, 50, 40, 0.1);
  
  font-size: 11px;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-2px);
  transition: opacity .15s, transform .15s, visibility .15s;
  pointer-events: none;
}
.tooltip::before { display: none; }

.resource:hover .tooltip,
.resource:focus-visible .tooltip,
.resource:focus-within .tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.resource.tooltip-up .tooltip {
  top: auto;
  bottom: calc(100% + 4px);
  transform: translateY(2px);
}
.resource.tooltip-up:hover .tooltip,
.resource.tooltip-up:focus-visible .tooltip,
.resource.tooltip-up:focus-within .tooltip {
  transform: translateY(0);
}

/* ---------- Пустое состояние ---------- */
.empty {
  display: none;
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  background: #fff;
  border: 1px dashed #cdd8d1;
  border-radius: 10px;
  margin-top: 15px;
  font-size: 13px;
}

/* ---------- Footer ---------- */
footer {
  border-top: 1px solid var(--line);
  padding: 20px;
  text-align: center;
  color: #8a978e;
  font-size: 11px;
}

/* ---------- Адаптив ---------- */
@media (max-width: 1000px) { .resources { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 768px) { .resources { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 500px) {
  .hero { padding: 30px 16px 24px; }
  main { padding: 0 12px; margin-top: -10px; }
  .resources { grid-template-columns: 1fr; }
  .toolbar { padding: 10px; gap: 8px; }
  .year-range { font-size: 11px; }
  .year-range input[type=number] { width: 60px; padding: 6px; }
  .subtopic.level-2, .subtopic.level-3, .subtopic.level-4 { margin-left: 6px; padding-left: 6px; }
  .topic h2 { font-size: 14px; }
  .topic-head { padding: 10px 12px; }
  .topic-body { padding: 0 12px 12px; }
  
  .topic-body > .resources { padding-left: 0; }
  .subtopic-content > .resources { padding-left: 0; }
  
  .tooltip {
    left: 50%;
    transform: translate(-50%, -2px);
    max-width: 85vw;
  }
  .resource:hover .tooltip,
  .resource:focus-visible .tooltip,
  .resource:focus-within .tooltip {
    transform: translate(-50%, 0);
  }
  .resource.tooltip-up .tooltip {
    transform: translate(-50%, 2px);
  }
  .resource.tooltip-up:hover .tooltip,
  .resource.tooltip-up:focus-visible .tooltip,
  .resource.tooltip-up:focus-within .tooltip {
    transform: translate(-50%, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
  .resource { opacity: 1; transform: none; }
}