/* ============================================================
   СНТ «Черёмуха» — базовые стили: оболочка, шапка, подвал, UI
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  font-family: var(--font-ui);
  font-size: clamp(16px, 1.05rem + .1vw, 18px);
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--accent); color: var(--on-accent); }

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* кросс-страничные переходы — только управляемый фейд-аут при уходе.
   Видимость страницы НЕ завязана на CSS-анимацию (никаких from{opacity:0}),
   поэтому в троттленном/фоновом окне страница никогда не остаётся пустой.
   Фейд-аут добавляется классом по клику пользователя — он безопасен. */
body { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  body { transition: opacity .3s var(--ease-soft); }
  body.is-leaving { opacity: 0; }
}

/* --- типографика --- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.01em;
  text-wrap: balance;
  color: var(--ink);
}
@supports (text-box: trim-both cap alphabetic) {
  h1, h2, h3 { text-box: trim-both cap alphabetic; }
}
p { text-wrap: pretty; }

.display { font-size: clamp(2.6rem, 7vw, 5.4rem); }
.h-xl { font-size: clamp(2rem, 4.5vw, 3.4rem); }
.h-lg { font-size: clamp(1.5rem, 3vw, 2.3rem); }
.h-md { font-size: clamp(1.2rem, 2vw, 1.6rem); }
.lead { font-size: clamp(1.1rem, 1.4vw, 1.35rem); color: var(--ink-soft); line-height: 1.55; }
.eyebrow {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: .8rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  gap: .55em;
}
.eyebrow::before {
  content: "";
  width: 1.8em; height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

/* --- раскладка --- */
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gut); }
.section { padding-block: clamp(56px, 9vw, 120px); }
.stack > * + * { margin-top: 1rem; }

/* --- кнопки --- */
.btn {
  --bg: var(--accent);
  --fg: var(--on-accent);
  display: inline-flex;
  align-items: center;
  gap: .6em;
  padding: .85em 1.5em;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  background: var(--bg);
  color: var(--fg);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .18s var(--ease-soft), box-shadow .25s var(--ease-soft),
              background-color .3s, filter .2s;
  box-shadow: 0 1px 2px oklch(30% 0.05 80 / .12), 0 6px 18px var(--accent-soft);
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.04); box-shadow: var(--shadow-lg); }
.btn:active { transform: translateY(0); }
.btn--ghost {
  --bg: transparent;
  --fg: var(--ink);
  border-color: var(--border-2);
  box-shadow: none;
}
.btn--ghost:hover { background: var(--card-2); box-shadow: var(--shadow); }
.btn--lamp { box-shadow: 0 0 0 1px var(--accent-soft), 0 0 24px var(--lamp); }
.btn .ico { width: 1.15em; height: 1.15em; }

/* искорки, пробегающие по контуру кнопок (цвет — по сезону) */
@property --spark-a { syntax: "<angle>"; inherits: false; initial-value: 0turn; }
.btn { position: relative; }
.btn::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1.6px;
  background: conic-gradient(from var(--spark-a),
    transparent 0 84%,
    color-mix(in oklab, var(--spark) 40%, transparent) 88%,
    var(--spark) 92%, #fff 93.5%, var(--spark) 95%,
    transparent 99%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: 0;
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .btn::after { animation: spark-run 7s var(--ease-soft) infinite; }
  .btn:nth-of-type(2n)::after { animation-duration: 9s; animation-delay: -3s; }
  .btn:nth-of-type(3n)::after { animation-duration: 11s; animation-delay: -6s; }
  .btn:hover::after { animation-duration: 3.4s; }
}
@keyframes spark-run {
  0%   { --spark-a: 0turn; opacity: 0; }
  3%   { opacity: 1; }
  20%  { --spark-a: 1turn; opacity: 1; }
  24%  { --spark-a: 1turn; opacity: 0; }
  100% { --spark-a: 1turn; opacity: 0; }
}

/* --- карточки/поверхности --- */
.surface { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: clamp(20px, 3vw, 34px);
  box-shadow: var(--shadow);
  transition: transform .3s var(--ease-soft), box-shadow .3s var(--ease-soft),
              border-color .3s, background-color .9s var(--ease-soft);
}
@supports (corner-shape: superellipse(2)) {
  .card, .btn, .topbar__inner, .chip { corner-shape: superellipse(2.2); }
}
.card--hover:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--border-2); }

.chip {
  display: inline-flex; align-items: center; gap: .45em;
  padding: .4em .9em;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: .85rem; font-weight: 600;
  border: 1px solid color-mix(in oklab, var(--accent) 22%, transparent);
}

/* --- ШАПКА --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  padding: 12px var(--gut);
}
.topbar__inner {
  max-width: var(--maxw);
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 12px 10px 18px;
  border-radius: var(--r-pill);
  background: color-mix(in oklab, var(--card) 82%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid color-mix(in oklab, var(--border) 80%, transparent);
  box-shadow: var(--shadow);
}
.brand { display: inline-flex; align-items: center; gap: 12px; margin-right: auto; min-width: 0; }
.brand__mark { width: 40px; height: 40px; flex: none; }
.brand > span { min-width: 0; }
.brand__name { display: block; font-family: var(--font-display); font-weight: 600; font-size: 1.18rem; line-height: 1.05; white-space: nowrap; }
.brand__sub { display: block; font-size: .72rem; color: var(--ink-faint); letter-spacing: .04em; white-space: nowrap; }

.nav { display: flex; align-items: center; gap: 4px; }
.nav a {
  padding: .55em .95em;
  border-radius: var(--r-pill);
  font-weight: 500;
  font-size: .97rem;
  color: var(--ink-soft);
  transition: background-color .2s, color .2s;
  white-space: nowrap;
}
.nav a:hover { background: var(--card-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }

/* выпадающее меню «Информация» */
.nav-drop { position: relative; }
.nav-drop__btn {
  display: inline-flex; align-items: center; gap: .3em;
  padding: .55em .95em; border: 0; background: none; cursor: pointer;
  border-radius: var(--r-pill); font-weight: 500; font-size: .97rem; color: var(--ink-soft);
  font-family: var(--font-ui);
  transition: background-color .2s, color .2s;
}
.nav-drop__btn:hover { background: var(--card-2); color: var(--ink); }
.nav-drop__btn.is-current { background: var(--accent-soft); color: var(--accent-ink); }
.nav-drop__btn .chev { width: 1em; height: 1em; transition: transform .25s var(--ease-soft); }
.nav-drop[data-open="true"] .nav-drop__btn .chev { transform: rotate(180deg); }
.nav-drop__menu {
  position: absolute; top: calc(100% + 10px); left: 50%; translate: -50% 0;
  display: grid; gap: 2px; min-width: 236px; padding: 8px;
  background: var(--card); border: 1px solid var(--border-2); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  opacity: 0; scale: .96; pointer-events: none; transform-origin: top center;
  transition: opacity .2s var(--ease-soft), scale .2s var(--ease-soft);
  z-index: 80;
}
.nav-drop[data-open="true"] .nav-drop__menu { opacity: 1; scale: 1; pointer-events: auto; }
.nav-drop__menu a {
  display: flex; align-items: center; gap: 11px; padding: .62em .8em; border-radius: var(--r-sm);
  color: var(--ink-soft); font-weight: 500; font-size: .95rem; white-space: nowrap;
  transition: background-color .2s, color .2s;
}
.nav-drop__menu a:hover, .nav-drop__menu a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
.nav-drop__menu a svg { width: 20px; height: 20px; flex: none; opacity: .85; }

/* кнопка «Личный кабинет» */
.lk-btn {
  display: inline-flex; align-items: center; gap: .5em;
  padding: .62em 1.1em; border-radius: var(--r-pill);
  background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: .92rem;
  white-space: nowrap;
  box-shadow: 0 1px 2px oklch(30% 0.05 80 / .12), 0 6px 16px var(--accent-soft);
  transition: transform .18s var(--ease-soft), filter .2s;
}
.lk-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.lk-btn svg { width: 1.15em; height: 1.15em; }
.mobile-lk {
  margin-top: 16px; color: var(--accent-ink) !important; font-weight: 700;
  font-family: var(--font-ui) !important; font-size: 1.1rem !important;
}

/* индикатор текущего мира + переключатель */
.world {
  display: inline-flex; align-items: center; gap: 8px;
  padding: .42em .5em .42em .85em;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-2);
  background: var(--card-2);
  font-size: .85rem; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.world__dot { width: 1.5em; height: 1.5em; flex: none; }
.world__label { color: var(--ink-soft); }

.burger {
  display: none;
  width: 44px; height: 44px;
  border: 1px solid var(--border-2);
  border-radius: 50%;
  background: var(--card-2);
  cursor: pointer;
  place-items: center;
  flex: none;
}
.burger svg { width: 20px; height: 20px; }

/* мобильное меню */
.mobile-nav {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: var(--gut);
  background: color-mix(in oklab, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s var(--ease-soft);
}
.mobile-nav[data-open="true"] { opacity: 1; pointer-events: auto; }
.mobile-nav a {
  font-family: var(--font-display);
  font-size: 2rem;
  text-align: center;
  padding: .35em;
  color: var(--ink);
}
.mobile-nav a[aria-current="page"] { color: var(--accent-ink); }
.mobile-nav__close {
  position: absolute; top: var(--gut); right: var(--gut);
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid var(--border-2); background: var(--card);
  display: grid; place-items: center; cursor: pointer;
}

/* --- ПОДВАЛ --- */
.footer {
  position: relative;
  margin-top: 40px;
  padding-block: clamp(48px, 7vw, 90px);
  background: var(--paper-2);
  border-top: 1px solid var(--border);
}
.footer__grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: clamp(28px, 5vw, 64px);
}
.footer h4 { font-family: var(--font-ui); font-size: .82rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 1em; }
.footer__links { display: grid; gap: .6em; }
.footer__links a { color: var(--ink-soft); transition: color .2s; }
.footer__links a:hover { color: var(--accent-ink); }
.footer__bottom {
  margin-top: clamp(32px, 5vw, 56px);
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 12px 24px; justify-content: space-between;
  font-size: .85rem; color: var(--ink-faint);
}

/* --- появление по скроллу (scroll-driven, fallback = просто видно) --- */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .reveal {
      animation: reveal-in linear both;
      animation-timeline: view();
      animation-range: entry 2% cover 22%;
    }
    /* лёгкий «стэггер» по столбцам в сетках */
    .grid .reveal:nth-child(2), .info-grid .reveal:nth-child(2) { animation-range: entry 5% cover 25%; }
    .grid .reveal:nth-child(3), .info-grid .reveal:nth-child(3) { animation-range: entry 8% cover 28%; }
    .grid .reveal:nth-child(4), .info-grid .reveal:nth-child(4) { animation-range: entry 11% cover 31%; }

    /* заголовки секций «выезжают» по мере прокрутки */
    .section-head.reveal { animation-range: entry 0% cover 30%; }

    /* индикатор прогресса чтения — чистый scroll()-timeline */
    .scroll-progress {
      transform: scaleX(0);
      animation: sp-grow linear both;
      animation-timeline: scroll(root block);
    }
  }
}
@keyframes reveal-in {
  from { opacity: 0; transform: translateY(34px) scale(.99); }
  to   { opacity: 1; transform: none; }
}
@keyframes sp-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* полоса прогресса чтения */
.scroll-progress {
  position: fixed; top: 0; left: 0; z-index: 100;
  height: 3px; width: 100%;
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--accent), var(--accent-ink));
  box-shadow: 0 0 10px var(--accent-soft);
  pointer-events: none;
}

/* --- поповер переключателя миров --- */
.world-pop {
  position: fixed;
  z-index: 80;
  width: min(320px, calc(100vw - 24px));
  padding: 16px;
  border-radius: var(--r-md);
  background: var(--card);
  border: 1px solid var(--border-2);
  box-shadow: var(--shadow-lg);
  transform-origin: top right;
  opacity: 0; scale: .96; translate: 0 -6px;
  pointer-events: none;
  transition: opacity .22s var(--ease-soft), scale .22s var(--ease-soft), translate .22s var(--ease-soft);
}
.world-pop[data-open="true"] { opacity: 1; scale: 1; translate: 0 0; pointer-events: auto; }
.world-pop__head { font-weight: 600; display: grid; gap: 2px; margin-bottom: 12px; }
.world-pop__head small { font-weight: 400; font-size: .78rem; color: var(--ink-faint); }
.world-pop__lbl { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); margin: 12px 0 6px; }
.world-pop__row { display: flex; flex-wrap: wrap; gap: 6px; }
.world-opt {
  flex: 1 1 auto;
  padding: .5em .8em;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-2);
  background: var(--card-2);
  font-size: .9rem; font-weight: 500;
  cursor: pointer;
  transition: background-color .2s, color .2s, border-color .2s;
}
.world-opt:hover { border-color: var(--accent); }
.world-opt--auto { flex-basis: 100%; }
.world-opt[aria-pressed="true"] {
  background: var(--accent); color: var(--on-accent);
  border-color: transparent; font-weight: 600;
}

/* --- утилиты --- */
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.grid { display: grid; gap: clamp(16px, 2.4vw, 28px); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.flow > * + * { margin-top: clamp(14px, 2vw, 22px); }
.divider { height: 1px; background: var(--border); border: 0; }
.tabular { font-variant-numeric: tabular-nums; }

/* --- адаптив --- */
@media (max-width: 1100px) {
  .nav, .lk-btn, .world__label { display: none; }
  .burger { display: grid; }
}
@media (max-width: 880px) {
  .footer__grid { grid-template-columns: 1fr 1fr; }
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .cols-2, .cols-4 { grid-template-columns: 1fr; }
  .footer__grid { grid-template-columns: 1fr; }
}

/* ============================================================
   Admin-чип в шапке (виден только залогиненным правленцам).
   Создаётся site.js после fetch /admin/whoami.
   ============================================================ */
.admin-chip {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in oklab, var(--accent) 35%, transparent);
  border-radius: 999px;
  font-size: .82rem; font-weight: 500;
  color: var(--accent-ink);
  margin-right: 8px;
  flex-shrink: 0; /* не даём шапке сжимать чип, иначе бренд переломается */
  white-space: nowrap;
}
.admin-chip__inner {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px;
  color: inherit; text-decoration: none;
  border-radius: 999px;
  transition: background-color .15s;
  max-width: 14ch; overflow: hidden; text-overflow: ellipsis;
}
.admin-chip__inner:hover { background: color-mix(in oklab, var(--accent) 18%, transparent); }
.admin-chip__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.admin-chip__out {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%; color: inherit; text-decoration: none;
  opacity: .65;
  transition: opacity .15s, background-color .15s;
}
.admin-chip__out:hover { opacity: 1; background: color-mix(in oklab, var(--accent) 22%, transparent); }
/* При нехватке места — скрываем логин-текст, оставляем только аватарку и кнопку выхода. */
@media (max-width: 1100px) {
  .admin-chip__name { display: none; }
  .admin-chip__inner { padding: 3px 6px; }
}

/* Дискретная кнопка входа админа — прямоугольный треугольник в правом
   верхнем углу страницы. Прямой угол — в углу окна; гипотенуза идёт
   из верхнего левого в нижний правый угол элемента (по диагонали).
   Видна только гостям. */
.guest-login {
  position: fixed;
  top: 0; right: 0;
  display: block;
  width: 50px; height: 50px;
  z-index: 80; /* выше .topbar (z 60), чтобы клик не перехватывался шапкой */
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
  color: #fff; text-decoration: none;
  cursor: pointer;
  opacity: .45;
  transition: opacity .2s, filter .2s;
}
.guest-login__t {
  position: absolute;
  top: 6px; right: 8px;
  font-size: .78rem; font-weight: 700;
  font-family: var(--font-ui, sans-serif);
  letter-spacing: .02em;
  line-height: 1;
  pointer-events: none;
}
.guest-login:hover, .guest-login:focus-visible {
  opacity: 1; filter: brightness(1.06);
  outline: none;
}
@media (prefers-reduced-motion: reduce) { .guest-login { transition: none; } }
