:root {
  color-scheme: dark;

  --bg: #15132a;
  --bg-alt: #1c1937;
  --surface: #221f40;
  --ink: #f4efe6;
  --ink-soft: #b3aecb;
  --line: #34305a;
  --accent: #ff7e5f;
  --accent-ink: #ffffff;
  --night: #0e0c20;
  --night-soft: #2a2654;
  --gold: #ffc857;
  --mint: #7fd1b9;

  --radius: 20px;
  --maxw: 1120px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--serif);
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 0;
}

a { color: inherit; }

/* ---------- NAV ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 14px max(16px, calc((100% - var(--maxw)) / 2));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--serif);
  font-weight: 800;
  font-size: 1.2rem;
  text-decoration: none;
}
.brand .dot { color: var(--accent); }

.language-switcher { display: flex; gap: 6px; margin-left: auto; flex-shrink: 0; }
.language-switcher button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 7px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}
.language-switcher svg { display: block; width: 26px; height: 18px; border-radius: 2px; }
.language-switcher button:hover { background: var(--surface); }
.language-switcher button[aria-pressed="true"] { border-color: var(--accent); background: var(--surface); }
.language-switcher button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

@media (min-width: 761px) and (max-width: 1250px) {
  .nav { flex-wrap: wrap; }
  .nav nav { order: 1; width: 100%; justify-content: center; flex-wrap: wrap; }
}

.nav nav { display: flex; align-items: center; gap: 1.5rem; }
.nav nav a {
  text-decoration: none;
  font-size: 0.95rem;
  color: var(--ink-soft);
  transition: color .2s;
}
.nav nav a:hover { color: var(--ink); }
.nav .nav-cta {
  color: var(--ink);
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

@media (max-width: 760px) {
  /* Telegram's in-app browser can keep sticky/backdrop-filter layers
     composited above the page while scrolling. Keep the mobile header in
     the normal document flow instead. */
  .nav {
    position: relative;
    top: auto;
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .nav nav { display: none; }
  .nav { gap: 8px; }
  .brand { font-size: clamp(.8rem, 3.4vw, 1.2rem); }
}

/* ---------- COMMON ---------- */
.section {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 96px 16px;
}

.section-head { max-width: 680px; margin-bottom: 48px; }
.section-head h2 { font-size: clamp(2rem, 4.5vw, 3rem); }
.section-sub { color: var(--ink-soft); margin: 16px 0 0; }

.eyebrow {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
}

.btn {
  display: inline-block;
  padding: 14px 26px;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  transition: transform .2s, box-shadow .2s, background .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 24px -10px var(--accent);
}
.btn-ghost { border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg-alt); }

/* ---------- HERO ---------- */
.hero {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 72px 16px 56px;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  align-items: center;
  gap: 48px;
}

.hero h1 {
  font-size: clamp(2.6rem, 6.5vw, 4.8rem);
  font-weight: 800;
}
.hero h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}

.lead {
  font-size: 1.15rem;
  color: var(--ink-soft);
  max-width: 34em;
  margin: 24px 0 32px;
}

.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }

.hero-art {
  background: linear-gradient(170deg, #ffb07a, #b86bb0 45%, #3a3570 85%);
  border-radius: 32px;
  overflow: hidden;
  aspect-ratio: 10 / 9;
  box-shadow: 0 30px 60px -30px rgba(36, 32, 74, .6);
}
.hero-art svg { width: 100%; height: 100%; display: block; }
.hero-art img { width: 100%; height: 100%; display: block; object-fit: contain; }

.sun { fill: var(--gold); }
.mountains { fill: var(--night); opacity: .55; }
.stars path { fill: #fff; opacity: .9; animation: twinkle 3s ease-in-out infinite; }
.stars path:nth-child(2) { animation-delay: .6s; }
.stars path:nth-child(3) { animation-delay: 1.2s; }
.stars path:nth-child(4) { animation-delay: 1.8s; }

.book { transform-origin: 200px 230px; animation: float 6s ease-in-out infinite; }
.page-l { fill: #fff7ea; }
.page-r { fill: #fffdf8; }
.spine { stroke: #e0cfb4; stroke-width: 3; }
.lines path { fill: none; stroke: #d8c7ab; stroke-width: 4; stroke-linecap: round; }

.code-float {
  font-family: var(--mono);
  font-size: 26px;
  fill: var(--mint);
  text-anchor: middle;
  animation: rise 4s ease-in-out infinite;
}

@keyframes twinkle { 50% { opacity: .3; } }
@keyframes float { 50% { transform: translateY(-8px); } }
@keyframes rise {
  0%, 100% { transform: translateY(6px); opacity: .5; }
  50% { transform: translateY(-6px); opacity: 1; }
}

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; padding-top: 48px; }
  .hero-art { max-width: 460px; width: 100%; }
}

/* ---------- ABOUT ---------- */
.about-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  align-items: start;
}
.about-text p { margin: 0 0 1.1em; }
.about-text strong { color: var(--ink); }

.code-card {
  background: var(--night);
  color: #e9e6ff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 24px 50px -28px rgba(20, 16, 50, .7);
}
.code-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .05);
}
.code-bar span { width: 11px; height: 11px; border-radius: 50%; background: #ff6b4a; }
.code-bar span:nth-child(2) { background: var(--gold); }
.code-bar span:nth-child(3) { background: var(--mint); }
.code-bar em {
  margin-left: 10px;
  font-family: var(--mono);
  font-size: .8rem;
  font-style: normal;
  opacity: .6;
}
.code-card pre {
  margin: 0;
  padding: 20px 22px 24px;
  font-family: var(--mono);
  font-size: .9rem;
  line-height: 1.7;
  overflow-x: auto;
}
.code-card .k { color: #c792ea; }
.code-card .f { color: var(--mint); }
.code-card .s { color: var(--gold); }
.code-card .c { color: #8a86ad; font-style: italic; }

.stats {
  list-style: none;
  padding: 0;
  margin: 64px 0 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}
.stats li { padding: 28px 8px 0; }
.stats strong {
  display: block;
  font-family: var(--serif);
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  color: var(--accent);
  line-height: 1;
}
.stats span { color: var(--ink-soft); font-size: .95rem; }

@media (max-width: 860px) {
  .about-grid { grid-template-columns: 1fr; }
}

/* ---------- AI ---------- */
.ai-section { padding-top: 24px; }
.ai-content {
  max-width: 680px;
}
.ai-content p { margin: 0 0 1.1em; }
.ai-content p:last-child { margin-bottom: 0; }

/* ---------- PROCESS ---------- */
.process { position: relative; }
.steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}
.steps li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  transition: transform .25s, box-shadow .25s;
}
.steps li:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 40px -24px rgba(31, 27, 46, .35);
}
.step-n {
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--accent);
}
.steps h3 { font-size: 1.35rem; margin: 10px 0 8px; }
.steps p { margin: 0; color: var(--ink-soft); font-size: .97rem; }

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

/* ---------- BOOK STATES ---------- */
.book-states { padding-top: 24px; }
.states {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}
.states li {
  position: relative;
  padding: 24px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-alt);
}
.state-n {
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--mint);
}
.states h3 { font-size: 1.3rem; margin: 10px 0 8px; }
.states p { margin: 0; color: var(--ink-soft); font-size: .97rem; }

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

/* ---------- BOOKS ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 28px;
}
.book-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .25s;
}
.book-card:hover { transform: translateY(-4px); }

.cover {
  background: linear-gradient(135deg, #2c2a6b, #6b4fbf 60%, #ff9a6b);
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 1.5rem;
  line-height: 1.15;
  color: #fff;
}
.cover span { max-width: 12em; text-shadow: 0 2px 12px rgba(0, 0, 0, .15); }
.cover-img { position: relative; }
.cover-img img {
  position: absolute;
  inset: 16px;
  width: calc(100% - 32px);
  height: calc(100% - 32px);
  object-fit: contain;
}
.cover-3 {
  color: var(--ink-soft);
  font-size: 3.5rem;
}

.book-meta { padding: 22px 24px 26px; }
.book-meta h3 { font-size: 1.3rem; margin: 10px 0 6px; }
.book-meta p { margin: 0; color: var(--ink-soft); font-size: .97rem; }
.book-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}
.tag-published { background: #dcfce7; color: #166534; }
.tag-action { background: var(--accent); color: var(--accent-ink); text-decoration: none; }
.tag-action:hover { text-decoration: underline; }
.tag-action:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.tag-soft {
  background: color-mix(in srgb, var(--ink-soft) 14%, transparent);
  color: var(--ink-soft);
}

@media (max-width: 860px) { .book-grid { grid-template-columns: 1fr; max-width: 460px; } }

/* ---------- CTA ---------- */
.cta-box {
  background: radial-gradient(circle at 85% 15%, var(--night-soft), var(--night));
  color: #f4efe6;
  border-radius: 32px;
  padding: clamp(40px, 7vw, 72px);
  text-align: center;
}
.cta-box h2 { font-size: clamp(1.8rem, 4vw, 2.6rem); max-width: 18em; margin: 0 auto; }
.cta-box p { color: #c9c4e6; max-width: 32em; margin: 16px auto 32px; }

/* ---------- FOOTER ---------- */
.footer {
  border-top: 1px solid var(--line);
  padding: 32px 16px;
  text-align: center;
  color: var(--ink-soft);
  font-size: .9rem;
}

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