/* Дизайн-токены: см. docs/DESIGN.md. Источник палитры - Coddy Agent. */
:root {
  color-scheme: dark;
  --bg: #121212;
  --bg-elevated: #1e1e1e;
  --text: #ffffff;
  --muted: #9ca3af;
  --accent: #9333ea;
  --accent-soft: #c084fc;
  --glass-bg: rgba(30, 30, 30, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 14px 44px rgba(0, 0, 0, 0.4);
  --chip-bg: rgba(147, 51, 234, 0.14);
  --chip-bg-hover: rgba(147, 51, 234, 0.28);
  --chip-border: rgba(147, 51, 234, 0.52);
  --chip-text: rgba(237, 220, 255, 0.96);
  --card-border: rgba(255, 255, 255, 0.07);
  --glow-top: rgba(147, 51, 234, 0.18);
  --glow-side: rgba(147, 51, 234, 0.08);
  --lvl-0: rgba(147, 51, 234, 0.09);
  --lvl-1: rgba(147, 51, 234, 0.3);
  --lvl-2: rgba(147, 51, 234, 0.55);
  --lvl-3: rgba(168, 85, 247, 0.8);
  --lvl-4: #c084fc;
  --radius: 12px;
  --radius-lg: 18px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f8fa;
  --bg-elevated: #ffffff;
  --text: #18181b;
  --muted: #52525b;
  --accent: #7c3aed;
  --accent-soft: #7c3aed;
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(0, 0, 0, 0.08);
  --glass-shadow: 0 14px 44px rgba(15, 23, 42, 0.08);
  --chip-bg: rgba(124, 58, 237, 0.08);
  --chip-bg-hover: rgba(124, 58, 237, 0.2);
  --chip-border: rgba(124, 58, 237, 0.4);
  --chip-text: #5b21b6;
  --card-border: rgba(0, 0, 0, 0.08);
  --glow-top: rgba(124, 58, 237, 0.1);
  --glow-side: rgba(124, 58, 237, 0.05);
  --lvl-0: rgba(124, 58, 237, 0.08);
  --lvl-1: rgba(124, 58, 237, 0.28);
  --lvl-2: rgba(124, 58, 237, 0.5);
  --lvl-3: rgba(124, 58, 237, 0.72);
  --lvl-4: #7c3aed;
}

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

html {
  scroll-behavior: smooth;
  overflow-x: clip;
  scrollbar-gutter: stable;
}

html.nav-scroll-lock {
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.25s ease, color 0.25s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, var(--glow-top), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, var(--glow-side), transparent);
  z-index: 0;
}

a {
  color: var(--accent-soft);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

img {
  max-width: 100%;
  height: auto;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px 48px;
}

/* ---------- Шапка ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--glass-border);
}

/*
 * Стекло лежит на псевдоэлементе, а не на самой шапке: backdrop-filter
 * на предке сделал бы шапку containing block для fixed-потомков
 * и сломал бы мобильную панель меню.
 */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
}

.site-header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
}

.logo img {
  width: 30px;
  height: 30px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Навигация: mobile first - выезжающая панель */
.nav-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  box-shadow: var(--glass-shadow);
  width: min(78vw, 320px);
  padding: 72px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
  border-left: 1px solid var(--glass-border);
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  visibility: hidden;
}

.nav-drawer.is-open {
  transform: translateX(0);
  visibility: visible;
}

.nav-drawer a {
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 17px;
}

.nav-drawer a:hover {
  background: var(--chip-bg);
  text-decoration: none;
}

.nav-drawer a.is-active {
  color: var(--accent-soft);
}

/*
 * Скрим ниже шапки (z-index 100): панель и бургер живут внутри её
 * stacking context и не могут подняться выше 100 относительно корня,
 * поэтому скрим со значением больше 100 накрыл бы открытое меню.
 * Контент (.shell, z-index 1) он всё равно затемняет.
 */
.nav-scrim {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.5);
}

.nav-burger {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 42px;
  height: 42px;
  padding: 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  z-index: 130;
  position: relative;
}

.nav-burger-bar {
  display: block;
  height: 2px;
  width: 100%;
  border-radius: 2px;
  background: var(--text);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-drawer.is-open ~ .header-actions .nav-burger .nav-burger-bar:nth-child(1),
.nav-burger[aria-expanded="true"] .nav-burger-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-burger[aria-expanded="true"] .nav-burger-bar:nth-child(2) {
  opacity: 0;
}

.nav-burger[aria-expanded="true"] .nav-burger-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.theme-toggle {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--chip-bg);
}

.theme-toggle .icon-sun,
:root[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

/* ---------- Hero ---------- */

/* на мобильных hero занимает первый экран целиком (минус шапка 63px),
   секция "Обо мне" появляется только при скролле */
.hero {
  position: relative;
  min-height: calc(100vh - 63px);
  min-height: calc(100svh - 63px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 24px 0 28px;
}

@media (min-width: 720px) {
  .hero {
    min-height: 74vh;
  }
}

#hero-graph {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
}

.hero-content {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.hero-content a {
  pointer-events: auto;
}

.hero h1 {
  margin: 0 0 4px;
  font-size: clamp(34px, 7vw, 56px);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.hero-tagline {
  margin: 0;
  max-width: 560px;
  font-size: clamp(16px, 3vw, 19px);
  color: var(--muted);
}

/* ---------- Секции ---------- */

section {
  padding: 40px 0 8px;
  scroll-margin-top: 76px;
}

section h2 {
  font-size: clamp(24px, 5vw, 32px);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.section-lead {
  color: var(--muted);
  margin: 0 0 24px;
  max-width: 640px;
}

/* Обо мне */

.about-grid {
  display: grid;
  gap: 20px;
}

.about-photo {
  /* сброс браузерного margin у figure, иначе карточка съезжает */
  margin: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: radial-gradient(ellipse 90% 70% at 50% 100%, rgba(147, 51, 234, 0.35), transparent),
    var(--bg-elevated);
  border: 1px solid var(--card-border);
}

.about-photo img {
  display: block;
  width: 100%;
  height: auto;
}

.about-bio p {
  margin: 0 0 14px;
}

.facts {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
}

.fact {
  list-style: none;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
}

.fact strong {
  display: block;
  font-size: 15px;
}

.fact span {
  color: var(--muted);
  font-size: 14px;
}

/* Проекты */

.cards {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
  margin: 0;
  padding: 0;
  list-style: none;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--glass-bg);
  border: 1px solid var(--card-border);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.project-card:hover {
  transform: translateY(-2px);
  border-color: var(--chip-border);
}

.project-card h3 {
  margin: 0;
  font-size: 17px;
}

.project-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14.5px;
  flex-grow: 1;
}

.project-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
}

.lang-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}

.stars-badge {
  display: inline-flex;
  line-height: 0;
}

.stars-badge img {
  height: 20px;
  width: auto;
  border-radius: 4px;
}

.subheading {
  margin: 30px 0 12px;
  font-size: 20px;
}

/* Активность */

.activity-wrap {
  padding: 18px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  /* высота SVG 108px, подпись и паддинги, чтобы рендер карты не сдвигал контент */
  min-height: 178px;
}

/* скроллится только полоса с SVG, подпись и легенда остаются на месте */
.activity-scroll {
  overflow-x: auto;
  cursor: grab;
}

.activity-scroll.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.activity-wrap svg {
  display: block;
}

/* волна появления: задержка на каждый столбец выставляется из JS */
.activity-wrap svg rect {
  animation: activity-pop 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards;
  transition: filter 0.15s ease;
}

.activity-wrap svg rect:hover {
  filter: brightness(1.6) saturate(1.3);
}

@keyframes activity-pop {
  from {
    opacity: 0;
    transform: scale(0.4);
    transform-origin: center;
    transform-box: fill-box;
  }
}

.activity-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 16px;
  margin-top: 12px;
}

.activity-footer .activity-total {
  margin: 0;
}

.activity-legend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

.activity-legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.activity-legend .lvl-0 {
  background: var(--lvl-0);
}
.activity-legend .lvl-1 {
  background: var(--lvl-1);
}
.activity-legend .lvl-2 {
  background: var(--lvl-2);
}
.activity-legend .lvl-3 {
  background: var(--lvl-3);
}
.activity-legend .lvl-4 {
  background: var(--lvl-4);
}

.activity-wrap rect.lvl-0 {
  fill: var(--lvl-0);
}
.activity-wrap rect.lvl-1 {
  fill: var(--lvl-1);
}
.activity-wrap rect.lvl-2 {
  fill: var(--lvl-2);
}
.activity-wrap rect.lvl-3 {
  fill: var(--lvl-3);
}
.activity-wrap rect.lvl-4 {
  fill: var(--lvl-4);
}

.activity-wrap .activity-month {
  fill: var(--muted);
  font-size: 9px;
  font-family: var(--mono);
}

.activity-total {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-family: var(--mono);
}

/* Доклады */

.talks-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 2px solid var(--chip-border);
}

.talk {
  position: relative;
  padding: 0 0 22px 22px;
}

.talk::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 7px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.talk-year {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

.talk h3 {
  margin: 2px 0 4px;
  font-size: 16.5px;
}

.talk p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* Публикации и каналы */

.channel-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--glass-bg);
  border: 1px solid var(--card-border);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.channel-card:hover {
  transform: translateY(-2px);
  border-color: var(--chip-border);
}

.channel-card h3 {
  margin: 0;
  font-size: 16.5px;
}

.channel-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  flex-grow: 1;
}

.channel-link {
  font-size: 14px;
  font-weight: 500;
}

/* ---------- Футер ---------- */

.site-footer {
  position: relative;
  z-index: 1;
  margin-top: 40px;
}

.site-footer-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 40px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  font-size: 14.5px;
}

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

/* ---------- Появление секций ---------- */

.will-reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1), transform 0.5s
    cubic-bezier(0.22, 1, 0.36, 1);
}

.will-reveal.is-visible {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ---------- Брейкпоинты ---------- */

@media (min-width: 560px) {
  .cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .facts {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 720px) {
  .nav-burger,
  .nav-scrim {
    display: none;
  }

  .nav-drawer {
    position: static;
    width: auto;
    padding: 0;
    flex-direction: row;
    gap: 2px;
    background: transparent;
    border: none;
    /* тень нужна только выезжающей панели, в строке шапки она
       выглядела бы серой подложкой под пунктами */
    box-shadow: none;
    transform: none;
    visibility: visible;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .nav-drawer a {
    padding: 8px 12px;
    font-size: 15px;
    color: var(--muted);
  }

  .nav-drawer a:hover {
    background: transparent;
    color: var(--text);
  }

  .about-grid {
    grid-template-columns: 280px 1fr;
    align-items: start;
  }

  /* на широких экранах карта растягивается на всю ширину контейнера,
     на узких остаётся натуральный размер с горизонтальным скроллом */
  .activity-wrap svg {
    width: 100%;
    height: auto;
  }

  .activity-wrap {
    /* 18px паддинг + svg (ширина * 108/691) + 12px отступ + 22px футер + 18px */
    min-height: calc((100vw - 76px) * 0.1563 + 70px);
  }

  .about-photo {
    position: sticky;
    top: 90px;
  }
}

@media (min-width: 900px) {
  .cards {
    grid-template-columns: repeat(3, 1fr);
  }

  .hero {
    min-height: 78vh;
  }
}

@media (min-width: 960px) {
  /* шелл упёрся в max-width 920, высота карты больше не растёт */
  .activity-wrap {
    min-height: 208px;
  }
}
