/* ============================================================
   Демократия и диктатура — reading site
   Visual identity: two buildings, one floor plan.
   Navy #1A2238 / Gold #C9A227 / warm paper, carried over from
   the book's own print design and chapter illustrations.
   ============================================================ */

:root {
  --navy: #1A2238;
  --navy-2: #232C49;
  --gold: #C9A227;
  --gold-light: #E6C84A;
  --ink: #242424;
  --muted: #5A6472;
  --paper: #F7F5EF;
  --paper-card: #FFFFFF;
  --rule: #E3E0D6;

  --serif: ui-serif, Cambria, Georgia, "Times New Roman", "Noto Serif", serif;

  --measure: 34rem;
  --radius: 3px;
  --speed: 180ms;
}

/* ---------- Theme variants (light / sepia / dark) ---------- */
body.theme-paper {
  --bg: var(--paper);
  --surface: var(--paper-card);
  --text: var(--ink);
  --text-muted: var(--muted);
  --hairline: var(--rule);
  --accent: var(--gold);
  --nav-bg: var(--navy);
  --nav-text: #EDEBE3;
  --nav-text-dim: #9AA2B8;
}
body.theme-sepia {
  --bg: #F1E6D2;
  --surface: #F8EFDF;
  --text: #3A2E1F;
  --text-muted: #7A6A50;
  --hairline: #E0CFA9;
  --accent: #9C6B1F;
  --nav-bg: #2B2116;
  --nav-text: #EFE3CC;
  --nav-text-dim: #B8A583;
}
body.theme-dark {
  --bg: #14161F;
  --surface: #1B1E2B;
  --text: #E7E5DD;
  --text-muted: #9AA0B4;
  --hairline: #2A2E40;
  --accent: var(--gold-light);
  --nav-bg: #0F1119;
  --nav-text: #E7E5DD;
  --nav-text-dim: #767C94;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  transition: background var(--speed) ease, color var(--speed) ease;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--navy);
  color: #fff;
  padding: 0.6rem 1rem;
  z-index: 200;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

a { color: inherit; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* ================= App shell (reading pages) ================= */
.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Directory (left nav) ---------- */
.directory {
  width: 300px;
  flex-shrink: 0;
  background: var(--nav-bg);
  color: var(--nav-text);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,0.06);
}
.directory-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1.5rem 1.5rem 1rem;
}
.directory-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
  color: var(--nav-text);
}
.directory-close {
  display: none;
  background: none;
  border: none;
  color: var(--nav-text-dim);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

.directory-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0 2.5rem;
}
.directory-list > li > a {
  display: block;
  padding: 0.55rem 1.5rem;
  text-decoration: none;
  color: var(--nav-text-dim);
  font-size: 0.92rem;
  border-left: 2px solid transparent;
}
.directory-list > li > a:hover { color: var(--nav-text); }
.directory-list > li > a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(201,162,39,0.08);
}

.directory-part {
  margin-top: 0.9rem;
  padding: 0 1.5rem;
}
.directory-part-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 0.1rem;
}
.directory-part-title {
  display: block;
  font-size: 0.86rem;
  color: var(--nav-text);
  margin-bottom: 0.4rem;
  line-height: 1.3;
}
.directory-sublist {
  list-style: none;
  margin: 0 0 0.4rem;
  padding: 0;
}
.directory-sublist a {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.4rem 0.4rem 0.4rem 0.2rem;
  text-decoration: none;
  color: var(--nav-text-dim);
  font-size: 0.88rem;
  border-left: 2px solid transparent;
  border-radius: 2px;
}
.directory-sublist a:hover { color: var(--nav-text); }
.directory-sublist a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(201,162,39,0.08);
}
.directory-num {
  color: var(--nav-text-dim);
  font-variant-numeric: oldstyle-nums;
  min-width: 1.4rem;
}
.directory-sublist a.is-active .directory-num { color: var(--accent); }

.scrim {
  display: none;
}

/* ---------- Reader column ---------- */
.reader {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 2rem;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
}
.topbar-title {
  flex: 1;
  font-size: 0.86rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.menu-btn span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

.theme-toggle {
  display: flex;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0.2rem;
}
.theme-btn {
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--serif);
  font-size: 0.85rem;
  cursor: pointer;
}
.theme-btn:nth-child(1) { color: #6b6b6b; }
.theme-btn:nth-child(2) { color: #9c6b1f; }
.theme-btn:nth-child(3) { color: #2b2116; background: #1c1c22; color: #eee; }
.theme-btn.is-active {
  outline: 1.5px solid var(--accent);
}

.content {
  flex: 1;
  padding: 2.5rem 2rem 4rem;
  outline: none;
}

.part-banner {
  max-width: var(--measure);
  margin: 0 auto 2.5rem;
  padding-top: 0.5rem;
  text-align: center;
}
.part-label {
  display: block;
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
}
.part-title {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
}

.chapter {
  max-width: var(--measure);
  margin: 0 auto;
}
.chapter-kicker {
  color: var(--accent);
  font-size: 0.85rem;
  margin: 0 0 0.2rem;
}
.chapter h1 {
  font-size: 1.9rem;
  line-height: 1.25;
  margin: 0 0 1.5rem;
}

.chapter-figure {
  margin: 0 auto 2rem;
  text-align: center;
}
.chapter-figure img {
  width: 132px;
  height: 132px;
  border-radius: 50%;
}
.chapter-figure figcaption {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-muted);
}

.prose p {
  font-size: 1.08rem;
  line-height: 1.75;
  margin: 0 0 1.2rem;
  text-align: justify;
  hyphens: auto;
}
.prose p.lede::first-letter {
  font-size: 3.4rem;
  line-height: 0.8;
  float: left;
  padding: 0.1rem 0.35rem 0 0;
  color: var(--accent);
  font-weight: 700;
}

.chapter-appendix .appendix-list {
  max-width: var(--measure);
  padding-left: 1.2rem;
}
.chapter-appendix .appendix-list li {
  font-size: 1.02rem;
  line-height: 1.65;
  margin-bottom: 0.7rem;
}

.pager {
  max-width: var(--measure);
  margin: 3.5rem auto 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--hairline);
  padding-top: 1.5rem;
}
.pager-link {
  flex: 1;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.pager-link:hover { border-color: var(--accent); }
.pager-next { text-align: right; align-items: flex-end; }
.pager-dir {
  font-size: 0.72rem;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.pager-title {
  font-size: 0.92rem;
  line-height: 1.3;
}
.pager-empty { visibility: hidden; }

.page-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--hairline);
}

/* ================= Cover / landing page ================= */
.cover-body { background: var(--navy); }
.cover {
  min-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem 2rem;
  color: #EDEBE3;
}
.buildings-svg {
  width: min(560px, 88vw);
  height: auto;
  margin-bottom: 1rem;
}
.buildings-svg .building polygon,
.buildings-svg .building rect:not(.window):not(.door) {
  fill: #232C49;
  stroke: #C9A227;
  stroke-width: 1.2;
  stroke-opacity: 0.55;
}
.buildings-svg .window { fill: rgba(230,200,74,0.18); }
.buildings-svg .door { fill: #14161F; }
.buildings-svg .badge { fill: #C9A227; }
.buildings-svg .ground-line { stroke: #C9A227; stroke-width: 1.5; opacity: 0.6; }

.cover-kicker {
  color: var(--gold);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  margin: 0 0 0.6rem;
}
.cover-title {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  line-height: 1.1;
  margin: 0 0 0.6rem;
  font-weight: 700;
}
.cover-subtitle {
  color: var(--gold-light);
  font-size: clamp(1.05rem, 2.4vw, 1.35rem);
  font-style: italic;
  margin: 0 0 1rem;
  max-width: 40rem;
}
.cover-tagline {
  color: #B7BCCC;
  font-size: 1rem;
  max-width: 32rem;
  margin: 0 0 2rem;
}
.cover-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 2.5rem;
}
.btn-primary, .btn-secondary {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border-radius: 2px;
  text-decoration: none;
  font-size: 0.95rem;
}
.btn-primary {
  background: var(--gold);
  color: #1A2238;
  font-weight: 700;
}
.btn-secondary {
  border: 1px solid rgba(230,200,74,0.4);
  color: #EDEBE3;
}
.btn-primary:hover { background: var(--gold-light); }
.btn-secondary:hover { border-color: var(--gold); }

.cover-epigraph {
  max-width: 34rem;
  margin: 0;
  padding-top: 1.8rem;
  border-top: 1px solid rgba(230,200,74,0.25);
}
.cover-epigraph p {
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.6;
  color: #D7DAE3;
  margin: 0 0 0.5rem;
}
.cover-epigraph cite {
  font-style: normal;
  font-size: 0.85rem;
  color: var(--gold);
}

.toc-page {
  max-width: 46rem;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
  color: #D7DAE3;
}
.toc-page h2 {
  color: #EDEBE3;
  font-size: 1.2rem;
  margin-bottom: 1.2rem;
  text-align: center;
}
.toc-flat {
  list-style: none;
  padding: 0;
  margin: 0 0 1.2rem;
  text-align: center;
}
.toc-flat a {
  text-decoration: none;
  color: #D7DAE3;
  font-size: 1rem;
}
.toc-flat a:hover { color: var(--gold); }
.toc-group { margin-bottom: 1.6rem; }
.toc-part {
  color: var(--gold);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  margin: 0 0 0.5rem;
  text-align: center;
}
.toc-sublist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.35rem;
}
.toc-sublist a {
  display: flex;
  gap: 0.7rem;
  text-decoration: none;
  color: #D7DAE3;
  padding: 0.45rem 0.8rem;
  border-radius: 2px;
}
.toc-sublist a:hover { background: rgba(201,162,39,0.1); color: var(--gold); }
.toc-num { color: var(--gold); font-variant-numeric: oldstyle-nums; min-width: 1.3rem; }

.cover-footer {
  text-align: center;
  padding: 1.5rem;
  color: #767C94;
  font-size: 0.78rem;
  border-top: 1px solid rgba(230,200,74,0.15);
}

/* ================= Responsive ================= */
@media (max-width: 880px) {
  .directory {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--speed) ease;
    width: 82vw;
    max-width: 320px;
  }
  body.nav-open .directory { transform: translateX(0); }
  .directory-close { display: block; }
  body.nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(10,10,14,0.45);
    z-index: 90;
  }
  .menu-btn { display: flex; }
  .content { padding: 1.6rem 1.1rem 3rem; }
  .topbar { padding: 0.8rem 1.1rem; }
  .chapter h1 { font-size: 1.55rem; }
  .prose p { font-size: 1.02rem; text-align: left; }
  .pager { flex-direction: column; }
}

@media (min-width: 881px) {
  .menu-btn { display: none; }
}
