/* === ROOT CONFIGURATION === */
:root {
  --font-body: 'Literata', Georgia, 'Times New Roman', serif;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --line-height-body: 1.55;
  --content-max-width: 65ch;

  /* Colors: Light mode */
  --color-bg: #f5f0e6;
  --color-text: #222222;
  --color-text-heading: #111111;
  --color-text-secondary: #555555;
  --color-text-muted: #888888;
  --color-accent: #0066cc;
  --color-border: #e0e0e0;
  --color-nav-bg: #f5f0e6;
}

/* === DARK MODE === */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #121212;
    --color-text: #E0E0E0;
    --color-text-heading: #EBEBEB;
    --color-text-secondary: #A0A0A0;
    --color-text-muted: #707070;
    --color-accent: #66b3ff;
    --color-border: #2a2a2a;
    --color-nav-bg: rgba(18, 18, 18, 0.95);
  }
}

/* === BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background-color: var(--color-bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  line-height: var(--line-height-body);
}

/* === PROGRESS BAR === */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--color-accent);
  z-index: 200;
  width: 0%;
  transition: width 0.15s linear;
}

/* === SITE-WIDE PAGE CONTAINER (стандарт сайта) === */
.page-container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px;
}

/* === TOP GRID: logo + site header === */
.top-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 5px;
}

.top-grid .logo-card {
  z-index: 200;
}

/* === STANDARD SITE HEADER (как на главной insider.pm) === */
header.site-header {
  grid-column: span 11;
  padding: 16px 22px;
  border: 1px solid #dde1e8;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

header.site-header .hcontent {
  flex: 1;
  min-width: 0;
}

header.site-header .hrow {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
}

header.site-header .title {
  font-size: 24px;
  font-weight: 700;
  color: #0c1222;
  text-align: center;
  font-family: var(--font-ui);
}

@media (max-width: 900px) {
  header.site-header {
    grid-column: span 12;
    flex-direction: column;
    text-align: center;
  }
  header.site-header .hrow {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 6px;
  }
}

/* === CHAPTER NAVIGATION BAR (sticky, по главам) === */
.chapter-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-nav-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;
  font-family: var(--font-ui);
  margin-top: 1rem;
}

.chapter-bar-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.chapter-bar a {
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.2s;
}

.chapter-bar a:hover {
  color: var(--color-accent);
}

.chapter-bar nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

/* === ARTICLE CONTAINER === */
.article-body {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 2rem clamp(1rem, 0.5rem + 2vw, 2rem) 4rem;
}

/* === CHAPTER HEADER === */
.chapter-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.chapter-label {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.chapter-title {
  font-size: clamp(2rem, 1.5rem + 2.5vw, 3rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--color-text-heading);
  margin-bottom: 0.75rem;
}

.chapter-meta {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* === BODY TEXT === */
.article-body p {
  font-size: clamp(1.0625rem, 1rem + 0.25vw, 1.3125rem);
  line-height: var(--line-height-body);
  letter-spacing: normal;
  word-spacing: normal;
  text-align: left;
  margin-bottom: 1.25em;
}

/* === DIALOGUE === */
.article-body p em:first-child {
  /* Italic thoughts */
}

/* === SECTION BREAK === */
.section-break {
  text-align: center;
  margin: 2.5rem 0;
  color: var(--color-text-muted);
  font-size: 1.25rem;
  letter-spacing: 0.5em;
}

/* === CHAPTER NAVIGATION === */
.chapter-nav {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--font-ui);
}

.chapter-nav a {
  color: var(--color-accent);
  text-decoration: none;
  font-size: 0.9375rem;
  transition: opacity 0.2s;
}

.chapter-nav a:hover {
  opacity: 0.7;
}

.chapter-nav .nav-label {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.chapter-nav .nav-next {
  text-align: right;
}

/* === COVER PAGE === */
.cover-page {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 2rem;
}

.cover-book-title {
  font-size: clamp(1.5rem, 1rem + 3vw, 2rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--color-text-heading);
  margin-bottom: 0.75rem;
}

.cover-toc {
  list-style: none;
  padding: 0;
  width: 100%;
  max-width: 320px;
}

.cover-toc li {
  margin-bottom: 0.5rem;
}

.cover-toc a {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--color-text);
  text-decoration: none;
  font-size: 1.0625rem;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
  font-family: var(--font-ui);
}

.cover-toc a:hover {
  background: rgba(0, 102, 204, 0.08);
  color: var(--color-accent);
}

.cover-toc .toc-chapter-num {
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  margin-right: 0.5rem;
}

/* === MOBILE === */
@media (max-width: 768px) {
  .article-body p {
    line-height: 1.45;
  }

  .chapter-nav {
    flex-direction: column;
  }

  .chapter-nav .nav-next {
    text-align: left;
  }

  .chapter-bar {
    padding: 0.625rem 1rem;
  }

  .chapter-bar nav {
    gap: 0.75rem;
  }
}
