/* ==========================================================================
   Дизайн-система «Без Хаоса» — Ghost 5+ Theme Stylesheet
   ========================================================================== */

/* --- 1. Fonts (@font-face) --- */
@font-face {
  font-family: "Onest Variable";
  src: url("../fonts/onest-variable.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: Onest;
  src: url("../fonts/onest-400.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: Onest;
  src: url("../fonts/onest-600.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: Onest;
  src: url("../fonts/onest-800.ttf") format("truetype");
  font-weight: 800;
  font-display: swap;
}

/* --- 2. Design Tokens (:root) --- */
:root {
  --paper: #ffffff;
  --ink: #101112;
  --stone: #6f6258;
  --teal: #6f6258;
  --muted: #5e6565;
  --line: #d7dddd;

  --pad: clamp(1.25rem, 3vw, 3.5rem);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font-sans: "Onest Variable", Onest, Arial, sans-serif;
}

/* --- 3. Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  scroll-behavior: smooth;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.35;
  background: var(--paper);
  color: var(--ink);
}

::selection {
  background: var(--stone);
  color: var(--paper);
}

:focus-visible {
  outline: 3px solid var(--stone);
  outline-offset: 4px;
}

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

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

button, input, textarea, select {
  font: inherit;
  border-radius: 0;
}

.skip-link {
  position: fixed;
  z-index: 999;
  left: 1rem;
  top: -5rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.75rem 1rem;
  font-weight: 600;
  transition: top 200ms var(--ease);
}

.skip-link:focus {
  top: 1rem;
}

.section-shell {
  padding-left: var(--pad);
  padding-right: var(--pad);
}

.site-main {
  flex: 1 0 auto;
}

/* --- 4. Navigation & Header --- */
.site-header {
  position: static;
  width: 100%;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 1.55rem var(--pad);
  z-index: 10;
}

.site-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.wordmark {
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--ink);
  text-decoration: none;
}

.site-nav {
  display: flex;
  gap: clamp(1rem, 2vw, 2.25rem);
  align-items: center;
  font-size: 0.92rem;
  letter-spacing: -0.015em;
}

.site-nav a {
  color: var(--ink);
  text-decoration: none;
  min-height: 2.5rem;
  display: inline-flex;
  align-items: center;
  transition: color 200ms var(--ease);
}

.site-nav a:hover,
.site-nav a:focus-visible {
  color: var(--stone);
}

.site-nav a.nav-current {
  font-weight: 600;
  border-bottom: 1px solid var(--ink);
}

.site-nav .nav-mobile {
  color: var(--stone);
}

.site-nav .nav-mobile span {
  display: inline-block;
  margin-left: 0.15em;
  transition: transform 220ms var(--ease);
}

.site-nav .nav-mobile:hover span {
  transform: translate(2px, -2px);
}

.site-nav .nav-action {
  color: var(--stone);
  border-bottom: 1px solid var(--stone);
  padding-bottom: 0.2rem;
  min-height: auto;
}

.site-nav .nav-action:hover {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

@media (max-width: 800px) {
  .site-header {
    padding-top: 1.1rem;
    padding-bottom: 1.1rem;
  }
  .site-nav a:not(.nav-action) {
    display: none;
  }
}

/* --- 5. Footer (Exact Spec) --- */
.site-footer.footer-detailed {
  display: block;
  border: 0;
  padding: 0;
  background: var(--ink);
  color: var(--paper);
  font-size: clamp(0.85rem, 1.15vw, 1.15rem);
  line-height: 1.4;
  margin-top: 0;
}

.footer-top {
  padding-top: clamp(3rem, 6vw, 5.5rem);
  padding-bottom: clamp(2rem, 4vw, 3.5rem);
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 2rem;
  align-items: end;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.footer-detailed .footer-email {
  display: grid;
  justify-self: start;
  gap: 0.2rem;
  color: var(--paper);
  border: 0;
  text-decoration: none;
  font-size: clamp(1.1rem, 2vw, 2rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.05em;
  transition: color 200ms var(--ease);
}

.footer-detailed .footer-email:hover {
  color: #d6dddd;
}

.footer-email span {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ea5a5;
}

.footer-bottom {
  padding-top: 1.5rem;
  padding-bottom: 2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.42);
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) auto;
  gap: 2rem;
  align-items: start;
}

.footer-bottom .footer-legal {
  display: grid;
  gap: 0.3rem;
  max-width: 62rem;
  margin: 0;
  color: #d6d6d6;
  font-style: normal;
  font-size: 0.85rem;
  line-height: 1.4;
}

.footer-legal-brand {
  color: var(--paper);
  font-weight: 600;
}

.footer-bottom a {
  color: var(--paper);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  padding-bottom: 0.2rem;
  white-space: nowrap;
  font-size: 0.85rem;
  transition: opacity 200ms var(--ease);
}

.footer-bottom a:hover {
  opacity: 0.75;
}

@media (max-width: 800px) {
  .footer-top {
    min-height: auto;
    padding-top: 3.5rem;
    padding-bottom: 2.5rem;
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  .footer-bottom {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  .footer-bottom a {
    justify-self: start;
  }
}

/* --- 6. Blog Hero & Index Feed --- */
.blog-hero {
  padding-top: clamp(4rem, 9vw, 8rem);
  padding-bottom: clamp(3rem, 6vw, 6rem);
  border-bottom: 1px solid var(--ink);
}

.blog-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.blog-title {
  margin: 0;
  font-size: clamp(3.2rem, 8vw, 7.5rem);
  font-weight: 800;
  line-height: 0.84;
  letter-spacing: -0.065em;
  max-width: 13ch;
  text-wrap: balance;
}

.blog-description {
  margin: 2rem 0 0;
  max-width: 38rem;
  color: var(--muted);
  font-size: clamp(1.05rem, 1.6vw, 1.35rem);
  line-height: 1.4;
}

/* Feed Grid */
.post-feed-section {
  padding-top: clamp(2rem, 4vw, 3rem);
  padding-bottom: clamp(2.5rem, 5vw, 4rem);
}

.post-feed {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
}

.post-card {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  padding: clamp(1.5rem, 2.5vw, 2.5rem);
  position: relative;
  transition: background 300ms var(--ease), color 300ms var(--ease);
}

.post-card:hover {
  background: #faf9f7;
}

.post-card-image-link {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #f0f0ee;
  margin-bottom: 1.5rem;
  border-radius: 0;
}

.post-card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
  transition: transform 600ms var(--ease);
}

.post-card:hover .post-card-image {
  transform: scale(1.05);
}

.post-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.post-card-tag {
  color: var(--stone);
  font-weight: 600;
}

.post-card-title {
  margin: 0 0 1rem;
  font-size: clamp(1.4rem, 2vw, 2rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.post-card-title a {
  color: var(--ink);
  transition: color 200ms var(--ease);
}

.post-card-title a:hover {
  color: var(--stone);
}

.post-card-excerpt {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
  flex-grow: 1;
}

.post-card-more {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--stone);
  border-bottom: 1px solid var(--stone);
  padding-bottom: 0.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  width: max-content;
  transition: color 200ms var(--ease), border-color 200ms var(--ease);
}

.post-card-more:hover {
  color: var(--ink);
  border-color: var(--ink);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.75rem 0 0;
  border-top: 1px solid var(--line);
  margin-top: 2rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.pagination-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--stone);
  border-bottom: 1px solid var(--stone);
  padding-bottom: 0.2rem;
  font-weight: 600;
}

.pagination-item:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.pagination-location {
  letter-spacing: 0.02em;
}

/* --- 7. Single Post Template --- */
.post-article {
  padding-top: clamp(3rem, 6vw, 6rem);
}

.post-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: clamp(2.5rem, 5vw, 4.5rem);
}

.post-header-inner {
  max-width: 62rem;
  margin: 0;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.25rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 1.75rem;
}

.post-meta .post-primary-tag {
  color: var(--stone);
  font-weight: 600;
  border-bottom: 1px solid currentColor;
}

.post-title {
  margin: 0;
  font-size: clamp(2.8rem, 6.5vw, 6.2rem);
  font-weight: 800;
  line-height: 0.86;
  letter-spacing: -0.06em;
  text-wrap: balance;
}

.post-lead {
  margin: 2rem 0 0;
  font-size: clamp(1.15rem, 2vw, 1.6rem);
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--muted);
  max-width: 48rem;
}

.post-feature-figure {
  margin: clamp(2.5rem, 5vw, 4.5rem) 0 0;
  width: 100%;
}

.post-feature-img {
  width: 100%;
  max-height: 75vh;
  object-fit: cover;
  border-radius: 0;
  background: #f0f0ee;
}

.post-feature-caption {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* Editorial Content (.gh-content) */
.post-body {
  padding-top: clamp(3rem, 6vw, 5rem);
  padding-bottom: clamp(2.5rem, 5vw, 4rem);
}

.gh-content {
  max-width: 56rem;
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--ink);
}

.gh-content p,
.gh-content ul,
.gh-content ol {
  max-width: 72ch;
  margin-top: 0;
  margin-bottom: 1.4rem;
}

.gh-content h1,
.gh-content h2,
.gh-content h3,
.gh-content h4,
.gh-content h5,
.gh-content h6 {
  color: var(--ink);
  text-wrap: balance;
}

.gh-content h2 {
  margin: clamp(3rem, 6vw, 5rem) 0 1.2rem;
  font-size: clamp(2rem, 4vw, 3.5rem);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.04em;
  border-top: 1px solid var(--line);
  padding-top: 2rem;
}

.gh-content h3 {
  margin: 2.5rem 0 1rem;
  font-size: clamp(1.4rem, 2.5vw, 2.2rem);
  font-weight: 600;
  line-height: 1.0;
  letter-spacing: -0.03em;
}

.gh-content h4 {
  margin: 2rem 0 0.8rem;
  font-size: clamp(1.15rem, 2vw, 1.5rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.gh-content a {
  color: var(--stone);
  border-bottom: 1px solid currentColor;
  transition: color 200ms var(--ease);
}

.gh-content a:hover {
  color: var(--ink);
}

.gh-content blockquote {
  margin: 2.5rem 0;
  padding: 0.2rem 0 0.2rem 1.6rem;
  border-left: 2px solid var(--stone);
  font-size: clamp(1.15rem, 1.8vw, 1.4rem);
  line-height: 1.35;
  color: var(--ink);
  font-style: normal;
}

.gh-content blockquote p {
  margin-bottom: 0.6rem;
}

.gh-content blockquote p:last-child {
  margin-bottom: 0;
}

.gh-content ul,
.gh-content ol {
  padding-left: 1.4rem;
}

.gh-content li + li {
  margin-top: 0.45rem;
}

.gh-content hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 3.5rem 0;
}

.gh-content code {
  font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
  font-size: 0.88em;
  background: #f0f0ee;
  color: var(--ink);
  padding: 0.15em 0.35em;
  border-radius: 0;
}

.gh-content pre {
  margin: 2.5rem 0;
  padding: 1.5rem;
  background: var(--ink);
  color: var(--paper);
  border-radius: 0;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.45;
}

.gh-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

.gh-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 2.5rem 0;
  font-size: 0.95rem;
}

.gh-content th,
.gh-content td {
  border-bottom: 1px solid var(--line);
  padding: 0.85rem 1rem;
  text-align: left;
}

.gh-content th {
  font-weight: 600;
  border-bottom: 1px solid var(--ink);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

/* Ghost Card Embeds */
.gh-content .kg-card {
  margin: 2.5rem 0;
  border-radius: 0;
}

.gh-content .kg-image-card img {
  width: 100%;
  border-radius: 0;
}

.gh-content .kg-card figcaption {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.6rem;
  text-align: left;
}

.gh-content .kg-bookmark-card {
  width: 100%;
}

.gh-content .kg-bookmark-container {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 0;
  text-decoration: none;
  color: inherit;
  background: var(--paper);
  transition: border-color 200ms var(--ease);
}

.gh-content .kg-bookmark-container:hover {
  border-color: var(--ink);
}

.gh-content .kg-bookmark-content {
  padding: 1.5rem;
  flex-grow: 1;
}

.gh-content .kg-bookmark-title {
  font-weight: 600;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.gh-content .kg-bookmark-description {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 1rem;
}

.gh-content .kg-bookmark-metadata {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.gh-content .kg-bookmark-thumbnail {
  width: 33%;
  min-width: 160px;
  max-width: 240px;
  position: relative;
}

.gh-content .kg-bookmark-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
}

.gh-content .kg-callout-card {
  background: #f7f6f4;
  border-left: 3px solid var(--ink);
  padding: 1.5rem;
  border-radius: 0;
}

/* Post Footer / Navigation */
.post-footer-nav {
  margin-top: clamp(2.5rem, 5vw, 4rem);
  border-top: 1px solid var(--line);
  padding-top: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.text-action {
  display: inline-flex;
  gap: 0.6rem;
  align-items: center;
  color: var(--stone);
  border-bottom: 1px solid var(--stone);
  padding-bottom: 0.25rem;
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  transition: color 200ms var(--ease), border-color 200ms var(--ease);
}

.text-action:hover {
  color: var(--ink);
  border-color: var(--ink);
}

/* --- 8. Standalone Page Template (.page-template) --- */
.page-article {
  padding-top: clamp(3rem, 6vw, 5rem);
  padding-bottom: clamp(2.5rem, 5vw, 4rem);
}

.page-header {
  border-bottom: 1px solid var(--ink);
  padding-bottom: clamp(2rem, 5vw, 4rem);
  margin-bottom: clamp(3rem, 6vw, 5rem);
}

.page-title {
  margin: 0;
  font-size: clamp(3rem, 7vw, 6.5rem);
  font-weight: 800;
  line-height: 0.86;
  letter-spacing: -0.06em;
}

/* --- 9. Responsive Adjustments --- */
@media (max-width: 768px) {
  .post-feed {
    grid-template-columns: 1fr;
  }
  .kg-bookmark-container {
    flex-direction: column-reverse;
  }
  .kg-bookmark-thumbnail {
    width: 100%;
    height: 180px;
    max-width: none;
  }
}

/* --- 10. Kinetic Motion System & Micro-interactions --- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2.5px;
  width: 0%;
  background: var(--stone);
  z-index: 1000;
  pointer-events: none;
  transition: width 90ms linear;
}

/* Page arrive kinetic keyframes (identical to bezhaosa.ru foundations.css) */
@keyframes header-arrive {
  from { opacity: 0; transform: translateY(-0.5rem); }
  to { opacity: 1; transform: none; }
}

@keyframes hero-line-arrive {
  from {
    opacity: 0;
    transform: translateY(0.85em);
    clip-path: inset(0 0 100% 0);
  }
  to {
    opacity: 1;
    transform: none;
    clip-path: inset(-0.2em -4em);
  }
}

@keyframes hero-support-arrive {
  from {
    opacity: 0;
    transform: translateY(0.65rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Hero elements arrive automatically on load — no JS/IntersectionObserver delay */
html.motion-ready .site-header {
  animation: header-arrive 480ms 90ms both var(--ease);
}

html.motion-ready .blog-hero .blog-label,
html.motion-ready .post-header .post-meta {
  animation: hero-support-arrive 520ms 40ms both var(--ease);
}

html.motion-ready .blog-hero .blog-title,
html.motion-ready .post-header .post-title,
html.motion-ready .page-header .page-title {
  animation: hero-line-arrive 640ms 100ms both var(--ease);
}

html.motion-ready .blog-hero .blog-description,
html.motion-ready .post-header .post-lead {
  animation: hero-support-arrive 560ms 220ms both var(--ease);
}

/* Scroll reveal motion classes (for feed cards and article content) */
html.motion-ready .motion-pending {
  will-change: opacity, transform, clip-path;
}

html.motion-ready .motion-clip {
  opacity: 0;
  clip-path: inset(0 0 100% 0);
  transition: opacity 560ms var(--ease), clip-path 760ms var(--ease);
}

html.motion-ready .motion-side {
  opacity: 0;
  transform: translateX(-1.25rem);
  transition: opacity 520ms var(--ease), transform 680ms var(--ease);
}

html.motion-ready .motion-quiet {
  opacity: 0;
  transform: translateY(0.75rem);
  transition: opacity 520ms var(--ease), transform 680ms var(--ease);
  transition-delay: 140ms;
}

html.motion-ready .motion-step {
  opacity: 0;
  transform: translateY(1rem);
  transition: opacity 460ms var(--ease), transform 620ms var(--ease);
  transition-delay: var(--motion-delay, 0ms);
}

html.motion-ready .motion-visible {
  opacity: 1;
  transform: none;
  will-change: auto;
}

html.motion-ready .motion-clip.motion-visible {
  clip-path: inset(-0.2em -4em);
}

html.motion-ready .motion-from-up.motion-clip:not(.motion-visible) {
  clip-path: inset(100% 0 0 0);
}

html.motion-ready .motion-from-up.motion-quiet:not(.motion-visible),
html.motion-ready .motion-from-up.motion-step:not(.motion-visible) {
  transform: translateY(-1rem);
}

html.motion-ready .motion-from-up.motion-side:not(.motion-visible) {
  transform: translateX(1.25rem);
}

@media (max-width: 800px) {
  html.motion-ready .motion-side {
    transform: translateX(-0.65rem);
  }
}

/* Card hover micro-interactions */
.post-card-more span,
.text-action span {
  display: inline-block;
  transition: transform 220ms var(--ease);
}

@media (hover: hover) and (pointer: fine) {
  .post-card:hover .post-card-more span,
  .post-card-more:hover span,
  .post-cta-link:hover span {
    transform: translate(0.22rem, -0.12rem);
  }

  .post-back-link:hover span {
    transform: translateX(-0.25rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
