:root {
  --bg: #fbf8f1;
  --sidebar-bg: #f5f0e4;
  --text: #1f1d1a;
  --muted: #6f6a60;
  --link: #1f3f8f;
  --link-visited: #5b3a86;
  --rule: #e4ddcd;
  --quote: #d8cfbb;
  --code-bg: #f1ece0;
  --current-bg: #e9e1cf;
  color-scheme: light;
  --measure: 38rem;   /* ~65–70 символов */
  --sidebar: 17rem;
  /* Системный шрифт без засечек: на iPhone/Mac — San Francisco, на Android — Roboto, на Windows — Segoe UI */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Тёмная тема: по системной настройке, если посетитель не выбрал светлую вручную… */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a17;
    --sidebar-bg: #211f1b;
    --text: #e7e2d6;
    --muted: #9c968a;
    --link: #9db8f0;
    --link-visited: #c3a7e6;
    --rule: #34312b;
    --quote: #4a463d;
    --code-bg: #26241f;
    --current-bg: #34312b;
    color-scheme: dark;
  }
}
/* …или если выбрал тёмную кнопкой */
:root[data-theme="dark"] {
  --bg: #1b1a17;
  --sidebar-bg: #211f1b;
  --text: #e7e2d6;
  --muted: #9c968a;
  --link: #9db8f0;
  --link-visited: #c3a7e6;
  --rule: #34312b;
  --quote: #4a463d;
  --code-bg: #26241f;
  --current-bg: #34312b;
  color-scheme: dark;
}

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.125rem;          /* 18px */
  line-height: 1.7;
  overflow-wrap: break-word;
}

a { color: var(--link); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:visited { color: var(--link-visited); }
a:hover { text-decoration-thickness: 2px; }

/* --- Основная колонка --- */
.page { padding: 0 1rem; }
.site-header, main {
  max-width: var(--measure);
  margin: 0 auto;
}

/* --- Шапка --- */
.site-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 0 1.75rem;
}
/* Кнопка темы: показываем луну в светлой теме и солнце в тёмной */
/* Правая часть шапки: переключатель перевода и кнопка темы на одной линии */
.header-right { margin-left: auto; display: flex; align-items: center; gap: 1.5rem; }
.theme-button {
  background: none; border: 0; cursor: pointer;
  color: var(--muted);
  padding: 0.4rem; margin-right: -0.4rem;
  border-radius: 6px; line-height: 0;
}
.theme-button:hover { color: var(--text); background: var(--current-bg); }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: inline; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

/* Выбор перевода — тихо, в шапке рядом с кнопкой темы */
.langs { display: flex; flex-wrap: nowrap; gap: 0.75rem; font-size: 0.75rem; letter-spacing: 0.06em; color: var(--muted); }
.langs a, .langs a:visited { color: var(--muted); text-decoration: none; }
.langs a:hover { color: var(--text); text-decoration: underline; }
.langs span { color: var(--text); font-weight: 600; }

.menu-button {
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
  padding: 0.35rem;
  margin: 0 0 0 -0.35rem;
  border-radius: 6px;
  line-height: 0;
}
.menu-button:hover { background: var(--current-bg); }
.icon-close { display: none; }

/* --- Боковое меню --- */
.sidebar {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: var(--sidebar);
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--rule);
  padding: 1.5rem 1.25rem 1.25rem;
  font-size: 0.9375rem;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
}
/* Пустая полоска сверху меню: на телефоне на ней стоит кнопка × */
.sidebar-top { display: none; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.sidebar-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-decoration: none;
}
.sidebar-title:visited { color: var(--muted); }
.sidebar-list { list-style: none; margin: 0; padding: 0; }
.sidebar-list a {
  display: flex;
  align-items: baseline;
  padding: 0.45rem 0.6rem;
  margin: 0 -0.6rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.sidebar-list a:hover { background: var(--current-bg); }
.sidebar-list a[aria-current="page"] { background: var(--current-bg); font-weight: 600; }
/* Подвал меню: мелко и прижат к низу */
.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  display: flex; gap: 1rem;
  font-size: 0.75rem;
}
.sidebar-footer a, .sidebar-footer a:visited { color: var(--muted); }

/* Замок у закрытых эссе */
.lock { color: var(--muted); vertical-align: -0.05em; flex: none; }
h1 .lock { width: 0.5em; height: 0.5em; vertical-align: 0.12em; margin-right: 0.3em; }
.locked-teaser { font-size: 1.15rem; margin: 0 0 2rem; }
.locked-box {
  border: 1px solid var(--rule); border-radius: 8px;
  padding: 1.25rem 1.5rem; color: var(--muted);
}
.locked-box p { margin: 0; }
.locked-box p + p { margin-top: 0.75rem; }

/* Порядковый номер эссе */
.essay-number {
  display: inline-block;
  min-width: 1.6em;
  color: var(--muted);
  font-size: 0.8em;
  font-variant-numeric: tabular-nums;
}
.sidebar-list .essay-number { flex: 0 0 1.75em; text-align: center; margin-right: 0.4rem; }
.essay-list .essay-number { width: 1.5em; min-width: 0; text-align: center; margin-right: 0.4rem; font-size: 0.95rem; }
.backdrop { display: none; }

/* Широкий экран: меню слева (можно спрятать кнопкой), текст — в центре оставшегося места */
@media (min-width: 64rem) {
  .page { margin-left: var(--sidebar); padding: 0 2rem; }
  .sidebar-hidden .sidebar { display: none; }
  .sidebar-hidden .page { margin-left: 0; }
}

/* Телефон и планшет: меню выезжает по кнопке */
@media (max-width: 63.99rem) {
  .sidebar {
    z-index: 20;
    width: min(20rem, 85vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    visibility: hidden;
  }
  .menu-open .sidebar { transform: none; visibility: visible; }
  .menu-open .backdrop {
    display: block;
    position: fixed; inset: 0; z-index: 10;
    background: rgba(0, 0, 0, 0.35);
  }
  .menu-open { overflow: hidden; }
  /* Кнопка ☰ в открытом меню встаёт в его верхний угол и становится × */
  .sidebar-top { display: block; min-height: 2.25rem; margin-bottom: 1.25rem; }
  .menu-open .menu-button {
    position: fixed; top: 1.5rem; left: 0.9rem; z-index: 30;
    margin: 0;
  }
  .menu-open .icon-burger { display: none; }
  .menu-open .icon-close { display: inline; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* --- Список эссе --- */
.essay-list { list-style: none; margin: 0; padding: 0; }
.essay-list li { margin: 0 0 1.9rem; }
.essay-link { font-size: 1.2rem; font-weight: 600; line-height: 1.35; }
.teaser { margin: 0.3rem 0 0.2rem; font-style: italic; }
.lang-hint { font-size: 0.7rem; letter-spacing: 0.06em; color: var(--muted); border: 1px solid var(--rule); border-radius: 3px; padding: 0 0.25rem; vertical-align: 0.15em; }
.essay-list time, .meta, .muted { color: var(--muted); font-size: 0.875rem; }

/* --- Эссе --- */
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 1.75rem; font-weight: 700; letter-spacing: -0.015em; }
.meta { margin: 0 0 2.25rem; }
.prose h2 { font-size: 1.4rem; margin: 2.4rem 0 0.6rem; font-weight: 700; line-height: 1.3; }
.prose h3 { font-size: 1.15rem; margin: 2rem 0 0.5rem; font-weight: 700; }
.prose p { margin: 0 0 1.2em; }
.prose img { max-width: 100%; height: auto; display: block; margin: 1.75rem auto; border-radius: 4px; }
.prose blockquote {
  margin: 1.75rem 0; padding: 0.1rem 0 0.1rem 1.1rem;
  border-left: 3px solid var(--quote); color: var(--muted); font-style: italic;
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
.prose code { background: var(--code-bg); padding: 0.1em 0.3em; border-radius: 3px; font-size: 0.9em; }
.prose pre { background: var(--code-bg); padding: 1rem; overflow-x: auto; border-radius: 4px; }
.prose pre code { background: none; padding: 0; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin-bottom: 0.5rem; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; margin: 1.5rem 0; font-size: 0.95rem; }
.prose th, .prose td { border: 1px solid var(--rule); padding: 0.4rem 0.6rem; }

.draft-tag {
  display: inline-block;
  font-size: 0.8rem;
  color: #8a5a00; background: #fff2cc;
  padding: 0.1rem 0.4rem; border-radius: 3px;
}
.versions { padding-left: 1.2rem; }
.back { margin: 3rem 0 0; }
main { padding-bottom: 5rem; }

@media (max-width: 30rem) {
  .site-header { padding: 1.25rem 0 1.5rem; }
  h1 { font-size: 1.65rem; }
  body { font-size: 1.0625rem; }  /* 17px */
}
