/* etagi.ck.ua — світла тема: слонова кістка + лісовий зелений, допоміжний — глиняний */

:root {
  /* Палітра */
  --bg: #f5f2ea;
  --bg-pattern: rgba(47, 93, 58, 0.035);
  --surface: #fffdf8;
  --surface-2: #efeadf;
  --surface-3: #e7efe6;
  --ink: #1f2a23;
  --ink-soft: #33413a;
  --muted: #58625b;
  --line: #ddd6c7;
  --line-soft: #e9e3d6;
  --accent: #2f5d3a;
  --accent-hover: #1f4429;
  --accent-soft: #dfeadf;
  --accent-tint: rgba(47, 93, 58, 0.08);
  --clay: #9a4428;
  --clay-soft: #f4e3d9;
  --focus: #1f4429;

  /* Типографіка */
  --f-head: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-body: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --f-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --fs-base: 1rem;
  --fs-sm: 0.875rem;
  --fs-xs: 0.8125rem;
  --lh-body: 1.7;
  --lh-head: 1.3;

  /* Spacing */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;

  /* Радіуси, тіні */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(31, 42, 35, 0.05);
  --shadow-md: 0 2px 6px rgba(31, 42, 35, 0.04), 0 10px 28px rgba(31, 42, 35, 0.06);

  /* Сітка */
  --wrap: 1160px;
  --gutter: 16px;
  --measure: 70ch;
  --header-h: 64px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 24px);
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-pattern) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  overflow-wrap: break-word;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img,
picture,
video,
canvas,
svg,
iframe,
embed,
object {
  display: block;
  max-width: 100%;
  height: auto;
}

iframe {
  border: 0;
  width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--f-head);
  line-height: var(--lh-head);
  color: var(--ink);
  overflow-wrap: break-word;
  hyphens: auto;
}

p, li, dd, dt, td, th, blockquote, figcaption {
  overflow-wrap: break-word;
}

/* Посилання */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: rgba(47, 93, 58, 0.45);
  text-underline-offset: 0.2em;
  transition: color 0.15s ease, text-decoration-color 0.15s ease, background-color 0.15s ease;
}

a:hover {
  color: var(--accent-hover);
  text-decoration-color: currentColor;
  text-decoration-thickness: 2px;
}

a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 4px;
}

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

/* Контейнер */
.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

/* Skip link */
.skip {
  position: absolute;
  left: -9999px;
  top: 0;
}

.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 300;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: var(--r-sm);
  font-family: var(--f-head);
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

/* Шапка */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 253, 248, 0.94);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))) {
  .topbar {
    background: rgba(255, 253, 248, 0.82);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
}

.topbar::before {
  content: "";
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0 70%, var(--clay) 70% 100%);
}

.topbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-4);
  min-height: var(--header-h);
  padding-top: var(--s-2);
  padding-bottom: var(--s-2);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--f-head);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand:hover {
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 var(--s-1);
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--surface);
  font-size: 0.95rem;
  line-height: 1;
}

.menu {
  order: 3;
  width: 100%;
  display: flex;
  gap: var(--s-1);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  font-family: var(--f-head);
  font-weight: 500;
  font-size: 0.9375rem;
  margin: 0 calc(var(--gutter) * -1);
  padding: 0 var(--gutter) var(--s-1);
}

.menu::-webkit-scrollbar {
  display: none;
}

.menu a {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 var(--s-3);
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.menu a:hover {
  color: var(--accent-hover);
  background: var(--accent-tint);
}

.menu a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.lang {
  display: flex;
  gap: 2px;
  margin-left: auto;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-family: var(--f-head);
  font-size: var(--fs-sm);
}

.lang a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 38px;
  padding: 0 var(--s-2);
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lang a:hover {
  color: var(--accent-hover);
}

.lang a[aria-current="true"] {
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

/* Хлібні крихти */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-2);
  margin: var(--s-5) 0 var(--s-4);
  font-family: var(--f-head);
  font-size: var(--fs-sm);
  color: var(--muted);
}

.crumbs a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  color: var(--muted);
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Заголовок статті */
.post-head {
  max-width: 820px;
}

.post-head h1 {
  font-weight: 750;
  font-size: clamp(1.25rem, 1.05rem + 1.3vw, 2rem);
  line-height: 1.3;
  letter-spacing: -0.015em;
  max-width: 34ch;
  color: var(--ink);
}

.post-info {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  margin: var(--s-4) 0 var(--s-5);
  font-family: var(--f-head);
  font-size: var(--fs-sm);
  color: var(--muted);
}

.post-info > * {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}

.post-info > * + *::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--clay);
}

/* Обкладинка */
.cover {
  max-width: calc(var(--wrap) + 120px);
  margin: 0 auto var(--s-6);
  padding: 0 var(--gutter);
}

.cover img {
  width: 100%;
  aspect-ratio: 1200 / 630;
  object-fit: cover;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-md);
}

.cover figcaption {
  margin-top: var(--s-2);
  font-family: var(--f-head);
  font-size: var(--fs-xs);
  color: var(--muted);
}

/* Сітка статті */
.post-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-5);
}

/* Зміст */
.toc {
  font-family: var(--f-head);
  font-size: var(--fs-sm);
  padding: var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}

.toc-title {
  margin-bottom: var(--s-2);
  font-weight: 700;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--clay);
}

.toc ol,
.toc ul {
  list-style: none;
  display: grid;
  gap: 2px;
  counter-reset: toc;
}

.toc li {
  counter-increment: toc;
}

.toc a {
  display: flex;
  gap: var(--s-2);
  align-items: baseline;
  min-height: 44px;
  padding: var(--s-2) var(--s-2);
  border-radius: var(--r-sm);
  color: var(--ink-soft);
  text-decoration: none;
  line-height: 1.4;
}

.toc a::before {
  content: counter(toc, decimal-leading-zero);
  flex-shrink: 0;
  font-family: var(--f-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.toc a:hover {
  background: var(--accent-tint);
  color: var(--accent-hover);
}

/* Стаття */
.post {
  min-width: 0;
  max-width: calc(var(--measure) + 2 * 56px);
  padding: var(--s-5) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
}

.post > * {
  max-width: var(--measure);
}

.post p {
  margin-bottom: 1.2em;
}

.post .intro {
  font-size: 1.1em;
  line-height: 1.65;
  color: var(--ink-soft);
  padding-bottom: var(--s-4);
  margin-bottom: var(--s-5);
  border-bottom: 1px dashed var(--line);
}

.post h2 {
  position: relative;
  font-size: clamp(1.125rem, 1.02rem + 0.6vw, 1.5rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 2em 0 0.7em;
  padding-top: var(--s-4);
  border-top: 1px solid var(--line-soft);
}

.post h2::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  width: 48px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
}

.post h3 {
  font-size: clamp(1.0625rem, 1rem + 0.3vw, 1.2rem);
  font-weight: 650;
  line-height: 1.35;
  margin: 1.6em 0 0.5em;
  color: var(--ink-soft);
}

.post h4 {
  font-size: 1rem;
  margin: 1.4em 0 0.4em;
}

.post strong,
.post b {
  font-weight: 700;
  color: var(--ink);
}

/* Списки */
.post ul,
.post ol {
  margin: 0 0 1.3em;
  padding-left: 1.4em;
}

.post li {
  margin-bottom: 0.45em;
  padding-left: 0.2em;
}

.post li::marker {
  color: var(--accent);
  font-weight: 700;
}

.post ol li::marker {
  font-family: var(--f-head);
  font-size: 0.9em;
}

.post li > ul,
.post li > ol {
  margin: 0.45em 0 0;
}

/* Підсумок */
.summary {
  margin: var(--s-2) 0 var(--s-5);
  padding: var(--s-4);
  background: var(--surface-3);
  border: 1px solid #cfdfd0;
  border-radius: var(--r-md);
}

.summary-title {
  font-family: var(--f-head);
  font-weight: 700;
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: var(--s-2) !important;
}

.summary p:last-child,
.summary ul:last-child,
.summary ol:last-child {
  margin-bottom: 0;
}

/* Терміни */
.terms {
  display: grid;
  gap: var(--s-3);
  margin: 0 0 1.5em;
}

.terms div {
  padding: var(--s-3) var(--s-4);
  background: var(--bg);
  border-left: 3px solid var(--clay);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

.terms dt {
  font-family: var(--f-head);
  font-weight: 700;
  color: var(--ink);
  margin-bottom: var(--s-1);
}

.terms dd {
  color: var(--muted);
}

/* Цитати */
.post blockquote {
  position: relative;
  margin: 1.6em 0;
  padding: var(--s-5) var(--s-4) var(--s-4) var(--s-5);
  background: var(--clay-soft);
  border-left: 4px solid var(--clay);
  border-radius: 0 var(--r-md) var(--r-md) 0;
}

.post blockquote::before {
  content: "\201C";
  position: absolute;
  top: -0.05em;
  left: 0.35em;
  font-family: Georgia, serif;
  font-size: 3rem;
  line-height: 1;
  color: rgba(154, 68, 40, 0.35);
}

.post blockquote p {
  margin: 0;
  font-size: 1.08em;
  line-height: 1.6;
  font-style: italic;
  color: var(--ink-soft);
}

.post blockquote p + p {
  margin-top: var(--s-3);
}

.post blockquote cite,
.post blockquote footer {
  display: block;
  margin-top: var(--s-3);
  font-family: var(--f-head);
  font-size: var(--fs-sm);
  font-style: normal;
  color: var(--muted);
}

/* Код */
code,
kbd,
samp {
  font-family: var(--f-mono);
  font-size: 0.875em;
}

:not(pre) > code {
  padding: 0.12em 0.4em;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  color: #6f3620;
  overflow-wrap: anywhere;
  word-break: break-word;
}

pre {
  max-width: 100%;
  margin: 0 0 1.4em;
  padding: var(--s-4);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: #f3f0e6;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-family: var(--f-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--ink);
  tab-size: 2;
}

pre code {
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  font-size: inherit;
  white-space: pre;
}

kbd {
  padding: 0.1em 0.4em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
}

/* Таблиці */
table {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0 0 1.5em;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
  font-family: var(--f-head);
  font-size: var(--fs-sm);
  line-height: 1.5;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}

th,
td {
  padding: var(--s-3) var(--s-4);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line-soft);
  min-width: 120px;
}

th {
  background: var(--surface-3);
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:nth-child(even) {
  background: #faf8f2;
}

tbody tr:hover {
  background: var(--accent-tint);
}

tbody tr:last-child td {
  border-bottom: 0;
}

/* Медіа в тексті */
.post figure {
  margin: 1.6em 0;
}

.post figure img {
  border-radius: var(--r-sm);
}

.post figcaption {
  margin-top: var(--s-2);
  font-family: var(--f-head);
  font-size: var(--fs-xs);
  color: var(--muted);
}

hr {
  height: 1px;
  margin: var(--s-6) 0;
  border: 0;
  background: var(--line);
}

/* Читайте також */
.more {
  margin-top: var(--s-7);
  padding: var(--s-6) 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.more h2 {
  font-size: clamp(1.125rem, 1.02rem + 0.5vw, 1.4rem);
  font-weight: 700;
  margin-bottom: var(--s-4);
}

.more-list {
  list-style: none;
  display: grid;
  gap: var(--s-3);
}

.more-list li {
  min-width: 0;
}

.more-list a {
  display: grid;
  gap: var(--s-1) var(--s-5);
  height: 100%;
  padding: var(--s-4);
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.more-list a:hover {
  background: var(--surface);
  border-color: #bcd0bf;
  box-shadow: var(--shadow-md);
}

.more-list a:hover .more-name {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.more-topic {
  justify-self: start;
  padding: 2px var(--s-2);
  border-radius: 999px;
  background: var(--accent-soft);
  font-family: var(--f-head);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.more-topic.is-threat {
  background: var(--clay-soft);
  color: var(--clay);
}

.more-name {
  font-family: var(--f-head);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.35;
}

.more-desc {
  color: var(--muted);
  font-size: 0.95em;
  line-height: 1.6;
}

/* Підвал */
.foot {
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--f-head);
  font-size: var(--fs-sm);
  border-top: 1px solid var(--line);
}

.foot-row {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding-top: var(--s-5);
  padding-bottom: var(--s-5);
}

.foot-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-4);
}

.foot a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  text-decoration: none;
}

.foot a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.dmca {
  padding: 0 var(--s-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--fs-xs);
}

.foot a.dmca {
  min-height: 36px;
}

/* ≥ 480px */
@media (min-width: 480px) {
  :root {
    --gutter: 20px;
  }

  .post {
    padding: var(--s-6) var(--s-5);
  }

  .summary {
    padding: var(--s-4) var(--s-5);
  }

  .post blockquote {
    padding: var(--s-5) var(--s-5) var(--s-5) var(--s-6);
  }
}

/* ≥ 768px */
@media (min-width: 768px) {
  :root {
    --gutter: 28px;
    --header-h: 68px;
  }

  body {
    font-size: 1.0625rem;
  }

  .topbar-row {
    flex-wrap: nowrap;
    gap: var(--s-5);
    padding-top: 0;
    padding-bottom: 0;
  }

  .menu {
    order: 0;
    width: auto;
    margin: 0 auto 0 0;
    padding: 0;
    overflow: visible;
  }

  .lang {
    margin-left: 0;
  }

  .crumbs {
    margin: var(--s-6) 0 var(--s-4);
  }

  .post {
    padding: var(--s-7) 56px;
    border-radius: var(--r-lg);
  }

  .cover img {
    border-radius: var(--r-lg);
  }

  .more {
    padding: var(--s-7) 0;
  }

  .more-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-4);
  }

  .more-list a {
    align-content: start;
    padding: var(--s-5);
  }

  .foot-row {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
  }
}

/* ≥ 1024px */
@media (min-width: 1024px) {
  body {
    font-size: 1.125rem;
  }

  .post-layout {
    grid-template-columns: 240px minmax(0, 1fr);
    gap: var(--s-7);
    align-items: start;
  }

  .toc {
    position: sticky;
    top: calc(var(--header-h) + 24px);
    max-height: calc(100vh - var(--header-h) - 48px);
    overflow-y: auto;
    padding: var(--s-4) var(--s-3);
    background: transparent;
    border: 0;
    border-left: 2px solid var(--line);
    border-radius: 0;
    box-shadow: none;
  }

  .toc-title {
    padding-left: var(--s-2);
  }

  .toc a {
    min-height: 36px;
    padding: 6px var(--s-2);
  }

  .more-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ≥ 1280px */
@media (min-width: 1280px) {
  :root {
    --gutter: 32px;
  }

  .post-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    gap: var(--s-8);
  }
}

/* Зменшення руху */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

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

/* Друк */
@media print {
  body {
    background: #fff;
    font-size: 11pt;
  }

  .topbar,
  .toc,
  .more,
  .foot,
  .skip {
    display: none;
  }

  .post {
    border: 0;
    box-shadow: none;
    padding: 0;
  }
}