/* ==========================================================================
   Tokens — see web-style-guide.md for the full rationale behind these values
   ========================================================================== */

:root {
  --font-sans: "Inter", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", Menlo, Consolas, monospace;

  --bg-dark:        #0E1014;
  --bg-light:       #FFFFFF;
  --surface:        #F4F5F6;
  --text-dark:      #111317;
  --text-body:      #3A3D42;
  --text-muted:     #6B6F76;
  --text-on-dark:   #D9DBE0;
  --muted-on-dark:  #8A8D93;
  --accent:         #2EE584;
  --accent-deep:    #1AAE8A;
  --accent-ink:     #13894F;
  --violet:         #2F2854;
  --divider:        #E6E7EA;
  --divider-dark:   #23262C;
  --ghost-number:   #EEF0F2;
}

/* ==========================================================================
   Reset & base
   ========================================================================== */

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

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

body {
  margin: 0;
  font: 400 1.0625rem/1.65 var(--font-sans);
  color: var(--text-body);
  background: var(--bg-light);
}

img { max-width: 100%; display: block; }

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

ul { list-style: none; margin: 0; padding: 0; }

h1, h2, h3, p { margin: 0; }

h1 { font: 800 clamp(2.5rem, 6vw + 0.5rem, 4.75rem) / 1.05 var(--font-sans); letter-spacing: -0.025em; }
h2 { font: 700 clamp(1.75rem, 3vw + 0.5rem, 2.75rem) / 1.12 var(--font-sans); letter-spacing: -0.02em; color: var(--text-dark); }
h3 { font: 700 clamp(1.125rem, 1vw + 0.8rem, 1.375rem) / 1.3 var(--font-sans); color: var(--text-dark); }

.lead {
  font-size: clamp(1.0625rem, 0.5vw + 1rem, 1.25rem);
  line-height: 1.6;
  max-width: 60ch;
}

.label {
  display: inline-block;
  font: 700 0.75rem / 1 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.25em;
}

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

section.section-dark :focus-visible,
.hero :focus-visible {
  outline-color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Placeholder size while header/footer partials are being fetched — avoids a layout jump. */
[data-partial="header"] { display: block; min-height: 77px; background: var(--bg-dark); }
[data-partial="footer"] { display: block; min-height: 158px; background: var(--bg-dark); }

/* ==========================================================================
   Layout helpers
   ========================================================================== */

.container {
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: clamp(1.25rem, 5vw, 4rem);
}

.section {
  padding-block: clamp(4rem, 10vw, 8rem);
  background: var(--bg-light);
}

.section-surface { background: var(--surface); }

.section-dark {
  background: var(--bg-dark);
  position: relative;
  overflow: hidden;
}

.section-dark h2 { color: #FFFFFF; }
.section-dark .lead { color: var(--text-on-dark); }

.section-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.section-label .rule {
  width: 28px;
  height: 2px;
  background: var(--accent);
  flex-shrink: 0;
}

.section-label .label { color: var(--text-muted); }
.section-dark .section-label .label { color: var(--muted-on-dark); }

.section h2 { margin-bottom: 1rem; }
.section .lead { margin-bottom: 2.5rem; }

/* ==========================================================================
   Buttons & links
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 700 0.875rem / 1 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 1rem 1.5rem;
  border-radius: 4px;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
  border: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-dark);
}

.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, white); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  background: transparent;
  border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
  color: var(--accent);
}

.section-dark .btn-secondary,
.hero .btn-secondary { color: var(--accent); }

.btn-secondary:hover { border-color: currentColor; }
.btn-secondary:active { transform: translateY(1px); }

.text-link {
  color: var(--accent-ink);
  text-underline-offset: 0.25em;
  text-decoration: underline 1px var(--accent);
  font-weight: 500;
}

.text-link:hover { text-decoration-thickness: 2px; }

/* ==========================================================================
   Decorative orbs
   ========================================================================== */

.hero-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle at 30% 30%, var(--accent), var(--accent-deep));
  animation: orb-in 700ms ease-out;
  will-change: transform;
}

.orb-accent {
  width: clamp(260px, 42vw, 640px);
  aspect-ratio: 1;
  top: -12%;
  right: -10%;
}

.orb-accent.orb-small {
  width: clamp(160px, 25vw, 340px);
  top: auto;
  bottom: -14%;
  right: -8%;
  left: auto;
}

.orb-violet {
  width: clamp(200px, 30vw, 420px);
  aspect-ratio: 1;
  bottom: -16%;
  left: -12%;
  background: var(--violet);
  filter: blur(40px);
}

/* ASCII particle field — replaces the solid gradient fill on specific orbs (hero + CTA),
   see web-style-guide.md "ASCII-декор (частицы)". Position/size/clip stay the orb's. */
.ascii-field {
  background: none;
  font: 8px/1 var(--font-mono);
  white-space: pre;
  color: var(--accent);
  text-align: left;
}

.hero .orb-accent {
  animation: orb-in 700ms ease-out, orb-drift 11s ease-in-out 700ms infinite;
}

.hero .orb-violet {
  animation: orb-in 700ms ease-out, orb-drift-reverse 13s ease-in-out 700ms infinite;
}

@keyframes orb-drift {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-3%, 3%); }
}

@keyframes orb-drift-reverse {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(3%, -3%); }
}

@keyframes orb-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* Watermark orbs — restrained parallax decor allowed in light sections, see web-style-guide.md */
.has-orb { position: relative; overflow: hidden; }
.has-orb > .container { position: relative; z-index: 1; }

.section-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.orb-watermark {
  width: clamp(220px, 30vw, 420px);
  aspect-ratio: 1;
  top: -10%;
  right: -8%;
  opacity: 0.08;
}

.orb-watermark.orb-watermark-left {
  top: auto;
  right: auto;
  bottom: -12%;
  left: -10%;
}

/* ==========================================================================
   Header
   ========================================================================== */

.site-header {
  position: relative;
  z-index: 10;
  background: var(--bg-dark);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding-block: 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
}

.brand-name {
  font: 700 0.8125rem / 1 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-on-dark);
}

.nav {
  display: flex;
  align-items: center;
  gap: clamp(1.25rem, 2vw, 2.5rem);
}

.nav a {
  position: relative;
  font: 500 0.9375rem / 1 var(--font-sans);
  color: var(--text-on-dark);
  transition: color 150ms ease;
}

.nav a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 100%;
  bottom: -4px;
  height: 1px;
  background: var(--accent);
  transition: right 150ms ease;
}

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

.nav a:hover::after,
.nav a:focus-visible::after { right: 0; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.lang-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lang-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.375rem;
  font: 700 0.75rem / 1 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted-on-dark);
  transition: color 150ms ease;
}

.lang-btn.is-active { color: var(--accent); }
.lang-btn:not(.is-active):hover { color: var(--text-on-dark); }

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-on-dark);
  transition: transform 150ms ease, opacity 150ms ease;
}

.menu-toggle.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.is-open span:nth-child(2) { opacity: 0; }
.menu-toggle.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ==========================================================================
   Hero
   ========================================================================== */

.hero {
  position: relative;
  overflow: hidden;
  background: var(--bg-dark);
  min-height: 90svh;
  display: flex;
  align-items: center;
}

.hero-inner {
  position: relative;
  z-index: 1;
  padding-block: clamp(3rem, 8vw, 6rem);
}

.badge {
  display: inline-block;
  font: 700 0.6875rem / 1 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 4px;
  padding: 0.5rem 0.875rem;
  margin-bottom: 1.5rem;
}

.hero h1 {
  color: #FFFFFF;
  max-width: 18ch;
  margin-bottom: 1.5rem;
  text-wrap: balance;
}

.hero .lead {
  color: var(--text-on-dark);
  margin-bottom: 2.5rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

/* ==========================================================================
   About — layout + portrait swap (ASCII portrait, crossfades to photo on hover)
   ========================================================================== */

.about-layout {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: clamp(2rem, 5vw, 4rem);
}

.about-text { flex: 1 1 420px; }
.about-text .lead { margin-bottom: 0; }

.portrait-swap {
  position: relative;
  flex: 0 0 auto;
  width: clamp(260px, 32vw, 380px);
  aspect-ratio: 1;
  -webkit-mask-image:
    linear-gradient(to right, transparent, #000 22%, #000 78%, transparent),
    linear-gradient(to bottom, transparent, #000 22%, #000 78%, transparent);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, transparent, #000 22%, #000 78%, transparent),
    linear-gradient(to bottom, transparent, #000 22%, #000 78%, transparent);
  mask-composite: intersect;
}

.portrait-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 300ms ease;
}

.portrait-ascii { opacity: 1; }
.portrait-photo { opacity: 0; }

.portrait-swap:hover .portrait-ascii { opacity: 0; }
.portrait-swap:hover .portrait-photo { opacity: 1; }

/* ==========================================================================
   About — feature list
   ========================================================================== */

.feature-list { max-width: 65ch; }

.feature-item {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding-block: 1.5rem;
  border-top: 1px solid var(--divider);
  transition: transform 150ms ease;
}

.feature-item:last-child { border-bottom: 1px solid var(--divider); }

.feature-item:hover { transform: translateX(4px); }

.feature-check {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 0.2rem;
  border: 1.5px solid var(--text-dark);
  border-radius: 3px;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.feature-item:hover .feature-check {
  border-color: var(--accent);
  background: var(--accent);
}

.feature-item h3 { margin-bottom: 0.375rem; }
.feature-item p { color: var(--text-body); }

/* ==========================================================================
   Skills
   ========================================================================== */

.skills-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  max-width: 65ch;
}

.skills-group .label {
  display: block;
  color: var(--text-muted);
  margin-bottom: 0.625rem;
}

.skills-group p {
  font-size: 1.0625rem;
  color: var(--text-body);
}

.tag {
  transition: color 150ms ease;
  cursor: default;
}

.tag:hover { color: var(--accent-ink); }

/* ==========================================================================
   Projects
   ========================================================================== */

.project-list { max-width: 65ch; }

.project-item {
  position: relative;
  padding-block: 2rem;
  border-top: 1px solid var(--divider);
  transition: transform 150ms ease;
}

.project-item:last-child { border-bottom: 1px solid var(--divider); }

.project-item::before {
  content: '';
  position: absolute;
  left: -1rem;
  top: 2rem;
  bottom: 2rem;
  width: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 150ms ease;
}

.project-item:hover,
.project-item:focus-within { transform: translateX(6px); }

.project-item:hover::before,
.project-item:focus-within::before { opacity: 1; }

.project-item h3 { margin-bottom: 0.5rem; transition: color 150ms ease; }
.project-item:hover h3,
.project-item:focus-within h3 { color: var(--accent-ink); }

.project-item p:not(.project-stack) { color: var(--text-body); margin-bottom: 0.75rem; }

.project-stack {
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.projects-all { margin-top: 2.5rem; }

/* ==========================================================================
   Contact
   ========================================================================== */

#contact { text-align: left; }
#contact h2 { max-width: 16ch; margin-bottom: 1.25rem; }
#contact .lead { margin-bottom: 1.5rem; }

.contact-email {
  color: var(--muted-on-dark);
  margin-bottom: 1.5rem;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  background: var(--bg-dark);
  border-top: 1px solid var(--divider-dark);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding-block: 2.5rem;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
}

.footer-links a {
  position: relative;
  font: 500 0.9375rem / 1 var(--font-sans);
  color: var(--muted-on-dark);
  transition: color 150ms ease;
}

.footer-links a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 100%;
  bottom: -4px;
  height: 1px;
  background: var(--accent);
  transition: right 150ms ease;
}

.footer-links a:hover,
.footer-links a:focus-visible { color: var(--accent); }

.footer-links a:hover::after,
.footer-links a:focus-visible::after { right: 0; }

.footer-copy { color: var(--muted-on-dark); }

/* ==========================================================================
   Sub-pages — project.html, blog.html, blog-post.html
   ========================================================================== */

.page-header {
  position: relative;
  overflow: hidden;
  background: var(--bg-dark);
  padding-block: clamp(3rem, 8vw, 5rem);
}

.page-header .label { color: var(--muted-on-dark); }

.page-header h1 {
  color: #FFFFFF;
  margin-top: 1rem;
  max-width: 22ch;
  text-wrap: balance;
}

.page-header .lead {
  color: var(--text-on-dark);
  margin-top: 1rem;
}

.page-header .tag-list { margin-top: 1.5rem; }
.page-header .tag { color: var(--muted-on-dark); }
.page-header .tag:hover { color: var(--accent); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 2rem;
  color: var(--accent);
  font: 700 0.75rem / 1 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  transition: gap 150ms ease;
}

.back-link:hover { gap: 0.75rem; }

.case-section {
  padding-block: 2rem;
  border-top: 1px solid var(--divider);
  max-width: 65ch;
}

.case-section:last-child { border-bottom: 1px solid var(--divider); }
.case-section h3 { margin-bottom: 0.75rem; }
.case-section p { color: var(--text-body); }
.case-section p + p,
.case-section p + .case-list { margin-top: 0.75rem; }

.case-list li {
  position: relative;
  padding-left: 1.25rem;
  color: var(--text-body);
}
.case-list li + li { margin-top: 0.75rem; }
.case-list li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--text-muted);
}
.case-list strong { color: var(--text-dark); font-weight: 600; }

.case-demo { max-width: none; }
.case-demo p { max-width: 65ch; }

.demo-body > * + * { margin-top: 1.5rem; }

.demo-actions,
.demo-telegram {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
}

.demo-prompts .label { color: var(--text-muted); }
.demo-prompts ul { margin-top: 0.5rem; }
.demo-prompts li {
  position: relative;
  padding-left: 1.25rem;
  color: var(--text-body);
}
.demo-prompts li + li { margin-top: 0.375rem; }
.demo-prompts li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

.demo-frame {
  display: block;
  width: 100%;
  max-height: 80svh;
  border: 1px solid var(--divider);
  border-radius: 4px;
  background: var(--surface);
}

.demo-qr {
  display: block;
  width: 160px;
  height: 160px;
  padding: 0.5rem;
  background: var(--bg-light);
  border: 1px solid var(--divider);
  border-radius: 4px;
}

.article-meta {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.page-header .article-meta {
  color: var(--muted-on-dark);
  margin-top: 0.75rem;
  margin-bottom: 0;
}

.article-body { max-width: 65ch; }
.article-body p { color: var(--text-body); margin-bottom: 1.25rem; }
.article-body p:last-child { margin-bottom: 0; }

/* ==========================================================================
   Responsive — mobile-first, breakpoints at 640 / 960 / 1280
   ========================================================================== */

@media (max-width: 959px) {
  .nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    background: var(--bg-dark);
    border-top: 0 solid var(--divider-dark);
    padding-inline: clamp(1.25rem, 5vw, 4rem);
    padding-block: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 200ms ease, padding-block 200ms ease;
  }

  .nav.is-open {
    max-height: 320px;
    border-top-width: 1px;
    padding-block: 0.5rem 1rem;
  }

  .nav a {
    width: 100%;
    padding-block: 0.75rem;
    border-bottom: 1px solid var(--divider-dark);
  }

  .menu-toggle { display: flex; }
}

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

@media (max-width: 639px) {
  .orb-accent { width: 210px; right: -18%; }
  .orb-violet { display: none; }
  .orb-accent.orb-small { width: 140px; }
  .orb-watermark { width: 140px; }

  .hero-actions { flex-direction: column; align-items: stretch; }
  .hero-actions .btn { width: 100%; }

  .demo-qr { display: none; }
}
