/* ============================================================ 
   CRITICAL-BOOK.CSS — только первый экран book.php
   (навбар + обложка + кнопки + базовые стили)
   ============================================================ */

@font-face {
  font-family: 'Playfair Display';
  font-style: normal;
  font-weight: 900;
  font-display: optional;
  src: url('/assets/fonts/playfair-display-v40-cyrillic_latin-900.woff2') format('woff2');
  size-adjust: 100%;
  ascent-override: 95%;
  descent-override: 25%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'Playfair Display';
  font-style: normal;
  font-weight: 700;
  font-display: optional;
  src: url('/assets/fonts/playfair-display-v40-cyrillic_latin-700.woff2') format('woff2');
  size-adjust: 100%;
  ascent-override: 95%;
  descent-override: 25%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'Playfair Display';
  font-style: normal;
  font-weight: 400;
  font-display: optional;
  src: url('/assets/fonts/playfair-display-v40-cyrillic_latin-regular.woff2') format('woff2');
  size-adjust: 100%;
  ascent-override: 95%;
  descent-override: 25%;
  line-gap-override: 0%;
}
@font-face {
  font-family: 'Playfair Fallback';
  src: local('Georgia'), local('Times New Roman');
  size-adjust: 107%;
  ascent-override: 95%;
  descent-override: 25%;
  line-gap-override: 0%;
}

*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}
html{scroll-behavior:smooth}
html,body{width:100%;overflow-x:clip;max-width:100vw}
body{
  font-family: 'Playfair Display', 'Playfair Fallback', Georgia, 'Times New Roman', serif;
  background:#0a0a1a;
  color:#f0ebe3;
  line-height:1.6;
}
img{max-width:100%;display:block}
a{text-decoration:none;color:inherit}
button{font:inherit;color:inherit}
.container{max-width:1200px;margin:0 auto;padding:0 20px;width:100%}

/* ============================================================
   NAVBAR (фиксированные размеры → CLS 0)
   ============================================================ */
.navbar{
  position:fixed;top:0;left:0;right:0;height:75px;
  background:rgba(8,11,24,.98);
  z-index:1100;
  border-bottom:1px solid rgba(240,235,227,.09);
  transition:background .28s ease, box-shadow .28s ease, border-color .28s ease;
}
.navbar.scrolled{
  background:rgba(8,11,24,.99);
  box-shadow:0 8px 24px rgba(0,0,0,.35);
}
.navbar .container{
  display:flex;justify-content:flex-start;align-items:center;
  height:100%;position:relative;max-width:1200px;gap:16px;
}

/* ★ ФИКС CLS: жёсткие размеры логотипа */
.logo-wrapper{
  display:flex;flex-direction:column;align-items:center;text-decoration:none;
  text-align:center;position:relative;color:#fff;gap:1px;
  justify-content:center;flex-shrink:0;cursor:pointer;
  width:240px;min-width:240px;max-width:240px;
  height:54px;min-height:54px;max-height:54px;
  overflow:hidden;
  transition:transform .28s cubic-bezier(.2,.8,.2,1);
}
.logo-wrapper:hover{transform:translateY(-1px);}
.logo{
  font-family:'Playfair Display', 'Playfair Fallback', Georgia, 'Times New Roman', serif;
  display:inline-flex;align-items:baseline;gap:.12rem;
  font-size:1.55rem;font-weight:700;color:#fff;
  line-height:1;white-space:nowrap;
  height:1.55rem;min-height:1.55rem;max-height:1.55rem;
  transition:text-shadow .28s ease;
}
.logo-wrapper:hover .logo{ text-shadow:0 0 12px rgba(127,246,247,.35); }
.logo-part{color:#fff;line-height:1;text-shadow:0 0 5px rgba(255,255,255,.8),0 0 10px rgba(255,255,255,.5)}
.logo-tld{
  font-size:.5em;color:#7ff6f7;font-weight:800;margin-left:2px;
  vertical-align:super;letter-spacing:0;line-height:1;
  text-shadow:0 0 6px rgba(0,197,207,.7),0 0 14px rgba(0,183,194,.5);
}
.logo-producer{
  font-size:.42rem;font-weight:800;letter-spacing:.14em;color:#fff;
  text-transform:uppercase;margin-bottom:1px;line-height:1;
  display:inline-flex;align-items:center;padding:.22rem .55rem;
  border:1px solid rgba(127,246,247,.5);border-radius:999px;
  background:linear-gradient(135deg,rgba(0,197,207,.92),rgba(15,76,117,.92));
  white-space:nowrap;
  height:1.1em;min-height:1.1em;max-height:1.1em;
  box-sizing:content-box;
  transition:box-shadow .28s ease, transform .28s ease;
}
.logo-wrapper:hover .logo-producer{ box-shadow:0 4px 16px rgba(0,183,194,.5); }
.logo-name{
  font-size:.56rem;font-weight:400;color:rgba(176,183,195,.75);margin-top:2px;
  letter-spacing:.14em;text-transform:uppercase;line-height:1;white-space:nowrap;
  /* ★ ФИКС CLS: фиксируем высоту, ширину и overflow */
  height:1em;min-height:1em;max-height:1em;
  width:100%;max-width:240px;
  display:block;overflow:hidden;text-overflow:clip;
}

/* Меню */
.nav-menu{display:flex;list-style:none;gap:8px;align-items:center;margin:0;padding:0;flex-shrink:0}
.nav-menu>li{flex:0 0 138px;width:138px;min-width:138px}
.nav-menu>li>a{
  box-sizing:border-box;width:138px;min-width:138px;height:42px;margin:0;padding:0 10px;
  display:flex;align-items:center;justify-content:center;gap:6px;border-radius:11px;
  white-space:nowrap;text-decoration:none;font-weight:600;font-size:.86rem;color:#fff;
  border:1px solid rgba(240,235,227,.30);
  background:rgba(240,235,227,.025);
  box-shadow:0 6px 20px rgba(0,0,0,.18),inset 0 1px 0 rgba(255,255,255,.08);
  transition:background .24s ease, border-color .24s ease, box-shadow .24s ease, transform .24s ease, color .24s ease;
}
.nav-menu>li>a:hover,
.nav-menu>li>a:focus-visible{
  background:rgba(79,179,189,.12);
  border-color:rgba(127,246,247,.55);
  box-shadow:0 8px 24px rgba(0,0,0,.24), 0 0 18px rgba(79,179,189,.18), inset 0 1px 0 rgba(255,255,255,.12);
  transform:translateY(-1px);
  outline:none;
}
.nav-menu>li>a.nav-book.active{
  background:radial-gradient(circle at 30% 20%, rgba(255,217,102,.32), transparent 60%),
             linear-gradient(135deg, rgba(215,184,90,.42), rgba(184,134,11,.32));
  border-color:rgba(255,217,102,.85);
  color:#fff;
}
.nav-menu>li>a.nav-book.active:hover{ filter:brightness(1.05); }
.nav-about-avatar{
  display:inline-flex;align-items:center;justify-content:center;
  width:28px;height:28px;min-width:28px;border-radius:50%;overflow:hidden;
  border:1.5px solid rgba(143,214,221,.6);background:#0a0f19;
  transition:border-color .24s ease, box-shadow .24s ease;
}
.nav-menu>li>a:hover .nav-about-avatar{
  border-color:rgba(180,250,255,.95);
  box-shadow:0 0 10px rgba(0,197,207,.35);
}
.nav-about-avatar img{width:100%;height:100%;object-fit:cover;display:block;border-radius:50%}

.nav-toggle{
  display:none;
  background:none;border:none;cursor:pointer;
  width:42px;height:42px;border-radius:11px;
  align-items:center;justify-content:center;flex-direction:column;gap:5px;
  padding:0;
  transition:background .24s ease;
}
.nav-toggle:hover{background:rgba(240,235,227,.06);}
.nav-toggle span{
  display:block;width:22px;height:2px;background:#fff;border-radius:2px;
  transition:transform .3s cubic-bezier(.2,.8,.2,1), opacity .3s ease;
}
.nav-toggle[aria-expanded="true"] span:nth-child(1){transform:translateY(7px) rotate(45deg);}
.nav-toggle[aria-expanded="true"] span:nth-child(2){opacity:0;}
.nav-toggle[aria-expanded="true"] span:nth-child(3){transform:translateY(-7px) rotate(-45deg);}

@media (max-width: 1024px) { .nav-toggle { display: flex; } .nav-menu { display: none; } }

/* ============================================================
   HERO (обложка) — с жёсткими размерами для CLS 0
   ============================================================ */
.hero {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: radial-gradient(120% 80% at 50% 0%, #12122a 0%, #05050a 70%);
    margin-top: 75px;
    padding: 16px 16px 28px;
    overflow: hidden;
}
.hero__media {
    position: relative;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    background: #0a0a1a;
    border-radius: 24px;
    overflow: hidden;
    isolation: isolate;
    box-shadow:
        0 30px 60px rgba(0,0,0,.6),
        0 0 44px rgba(212,175,55,.10),
        inset 0 0 0 1px rgba(255,217,102,.08);
    aspect-ratio: 1000 / 1345;
    transition:box-shadow .3s ease;
}
.hero__media:hover{
    box-shadow:
        0 34px 70px rgba(0,0,0,.65),
        0 0 60px rgba(212,175,55,.16),
        inset 0 0 0 1px rgba(255,217,102,.14);
}
.hero__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 22%;
    display: block;
}
.hero__overlay {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to bottom,
            rgba(5,5,10,.72) 0%,
            rgba(5,5,10,.30) 25%,
            rgba(5,5,10,.15) 50%,
            rgba(5,5,10,.45) 75%,
            rgba(5,5,10,.92) 100%);
    pointer-events: none;
    z-index: 1;
}
.hero__content {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    text-align: center;
    padding: 22px 22px 80px;
    gap: 12px;
}
.hero__top,
.hero__bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
}
.hero__title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 2rem;
    font-weight: 900;
    color: #FFD966;
    line-height: 1.06;
    letter-spacing: .3px;
    margin: 0;
    text-shadow: 0 4px 18px rgba(0,0,0,.9), 0 0 40px rgba(212,175,55,.35);
    /* ★ ФИКС CLS */
    height: 2.12rem;min-height: 2.12rem;max-height: 2.12rem;
    overflow: hidden;
}
.hero__subtitle-top {
    font-family: 'Playfair Display', Georgia, serif;
    font-style: italic;
    font-size: 1rem;
    color: #f5efd6;
    margin: 0;
    text-shadow: 0 2px 8px rgba(0,0,0,.95);
    /* ★ ФИКС CLS */
    height: 1.3em;min-height: 1.3em;max-height: 1.3em;
    overflow: hidden;
}
.hero__subtitle {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1rem;
    font-weight: 400;
    font-style: italic;
    color: rgba(245, 239, 214, 0.95);
    line-height: 1.5;
    max-width: 48ch;
    margin: 0;
    text-shadow: 0 2px 8px rgba(0,0,0,.95);
    letter-spacing: 0.2px;
    /* ★ ФИКС CLS */
    min-height: calc(1.5em * 3);
    overflow: hidden;
}

/* Кнопки */
.hero .btn-primary,
.hero .btn-install {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 0 0 auto;
    height: 46px;min-height: 46px;max-height: 46px;
    padding: 0 18px;
    border-radius: 13px;
    font: 700 .88rem/1 system-ui, -apple-system, 'Segoe UI', sans-serif;
    letter-spacing: .2px;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    /* ★ ФИКС CLS */
    min-width: 140px;
    box-sizing: border-box;
    transition: transform .24s cubic-bezier(.2,.8,.2,1), box-shadow .24s ease, filter .24s ease, background .24s ease, border-color .24s ease;
}
.hero .btn-primary {
    color: #0a0a1a;
    background: linear-gradient(135deg, #FFD966 0%, #E8B923 55%, #C99A0E 100%);
    border: 1px solid rgba(255,255,255,.35);
    box-shadow: 0 10px 24px rgba(255,217,102,.28), inset 0 1px 0 rgba(255,255,255,.5);
}
.hero .btn-primary:hover,
.hero .btn-primary:focus-visible {
    filter: brightness(1.06);
    transform: translateY(-2px);
    box-shadow: 0 16px 34px rgba(255,217,102,.42), inset 0 1px 0 rgba(255,255,255,.55);
    outline:none;
}
.hero .btn-install {
    color: #f0ebe3;
    background: rgba(12,16,26,.6);
    border: 1px solid rgba(127,246,247,.45);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.hero .btn-install:hover,
.hero .btn-install:focus-visible {
    background: rgba(0,183,194,.18);
    border-color: rgba(127,246,247,.85);
    transform: translateY(-2px);
    box-shadow:0 10px 24px rgba(0,183,194,.22);
    outline:none;
}
.hero .btn-install[hidden] { display: none; }

.hero__actions {
    position: relative;
    z-index: 3;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px;
    width: 100%;
    padding: 0 16px;
    margin-top: -70px;
    /* ★ ФИКС CLS */
    min-height: 46px;height: 46px;max-height: 46px;
    box-sizing: border-box;
}
@media (min-width: 768px) {
    .hero__actions {
        margin-top: 24px;
        max-width: 1280px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Адаптив для планшетов и десктопа (только hero) */
@media (min-width: 768px) and (max-width: 1024px) {
    .hero__media { aspect-ratio: 16 / 9; border-radius: 28px; }
    .hero__img { object-position: center 35%; }
    .hero__overlay {
        background:
            radial-gradient(75% 95% at 50% 50%,
                rgba(5,5,10,.80) 0%,
                rgba(5,5,10,.60) 45%,
                rgba(5,5,10,.18) 78%,
                rgba(5,5,10,0) 100%),
            linear-gradient(to bottom,
                rgba(5,5,10,.10) 0%,
                rgba(5,5,10,.45) 100%);
    }
    .hero__content { justify-content: center; padding: 32px 20px; gap: 16px; }
    .hero__top, .hero__bottom { gap: 10px; }
    .hero__title { font-size: clamp(1.8rem, 8vw, 2.5rem); height: auto;min-height: auto;max-height: none; }
    .hero__subtitle-top { font-size: clamp(1.1rem, 2.5vw, 1.5rem); height: auto;min-height: auto;max-height: none; }
    .hero__subtitle { font-size: clamp(.9rem, 2vw, 1.1rem); max-width: 56ch; min-height: auto; }
    .hero__actions {
        position: relative; bottom: auto; left: auto; right: auto;
        flex-direction: row; justify-content: center; flex-wrap: nowrap;
        gap: 14px; width: 100%; max-width: 1280px; margin: 18px auto 0; padding: 0;
        min-height: 52px;height: 52px;max-height: 52px;
    }
    .hero .btn-primary, .hero .btn-install { height: 52px;min-height: 52px;max-height: 52px; padding: 0 24px; border-radius: 15px; font-size: .95rem; }
}
@media (min-width: 1025px) {
    .hero { padding: 24px 20px 36px; }
    .hero__media { aspect-ratio: 16 / 7; border-radius: 28px; max-height: 78vh; }
    .hero__img { object-position: center 35%; }
    .hero__overlay {
        background:
            radial-gradient(75% 95% at 50% 50%,
                rgba(5,5,10,.80) 0%,
                rgba(5,5,10,.60) 45%,
                rgba(5,5,10,.18) 78%,
                rgba(5,5,10,0) 100%),
            linear-gradient(to bottom,
                rgba(5,5,10,.10) 0%,
                rgba(5,5,10,.45) 100%);
    }
    .hero__content { justify-content: center; padding: 32px clamp(32px, 5vw, 88px); gap: 18px; inset: 0; max-width: none; width: 100%; }
    .hero__top, .hero__bottom { gap: 10px; }
    .hero__title { font-size: clamp(2.6rem, 5.2vw, 5.2rem); line-height: 1; letter-spacing: .5px; white-space: nowrap; height: auto;min-height: auto;max-height: none; }
    .hero__subtitle-top { font-size: clamp(1.25rem, 2.2vw, 1.9rem); letter-spacing: .3px; height: auto;min-height: auto;max-height: none; }
    .hero__subtitle { font-size: clamp(1.1rem, 1.5vw, 1.4rem); max-width: 64ch; line-height: 1.6; font-style: italic; min-height: auto; }
    .hero__actions {
        position: relative; bottom: auto; left: auto; right: auto;
        flex-direction: row; justify-content: center; flex-wrap: nowrap;
        gap: 14px; width: 100%; max-width: 1280px; margin: 24px auto 0; padding: 0;
        min-height: 54px;height: 54px;max-height: 54px;
    }
    .hero .btn-primary, .hero .btn-install { height: 54px;min-height: 54px;max-height: 54px; padding: 0 28px; border-radius: 16px; font-size: 1rem; }
}

/* ★ ФИКС CLS: кнопка поиска вырвана из потока */
.search-float-btn{
  position:fixed !important;
  bottom:calc(110px + env(safe-area-inset-bottom, 0px));
  right:24px;
  width:50px;height:50px;border-radius:50%;
  background:linear-gradient(135deg,#FFD966,#C99A0E);color:#0a0a1a;border:none;
  display:none;align-items:center;justify-content:center;
  box-shadow:0 6px 20px rgba(0,0,0,0.4);z-index:1040;cursor:pointer;
  contain: strict;
  will-change: transform;
  transition:transform .24s cubic-bezier(.2,.8,.2,1), box-shadow .24s ease, filter .24s ease;
}
@media (max-width:1024px){ .search-float-btn{display:flex !important;} }

/* ★ Кнопка "наверх" — тоже fixed */
.toc-float-btn {
    display: none;
    position: fixed !important;
    bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.6rem;
    cursor: pointer;
    z-index: 3000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--highlight, #4fb3bd), #0f4c75);
    contain: strict;
    will-change: transform;
}
.toc-float-btn:hover { transform: scale(1.05); }
@media (max-width: 1024px) { .toc-float-btn { display: flex; } }

/* ★ ФИКС: скрываем сайдбар на мобильных ДО загрузки reader.css */
@media (max-width: 1024px) {
  .reader-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(90%, 340px);
    max-width: 340px;
    max-height: 100dvh;
    z-index: 2000;
    background: rgba(12, 12, 26, 0.99);
    border-radius: 0 20px 20px 0;
    border-left: 0;
    padding-top: 26px;
    padding-bottom: 40px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain;
    transform: translateX(-100%);
    transition: transform 0.34s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 30px 0 70px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    -webkit-overflow-scrolling: touch;
    visibility: hidden; /* ★ скрываем до открытия */
  }
  .reader-sidebar.is-open,
  .reader-sidebar.open {
    transform: translateX(0);
    pointer-events: auto;
    visibility: visible;
  }
}