/* =========================================================
   Читалка — оформление
   Светлая тема, сепия и тёмная; масштаб текста через --scale
   ========================================================= */

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

:root {
  --scale: 1;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "PT Serif", Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f6f1e8;
  --bg-soft: #efe7da;
  --surface: #fffdf8;
  --ink: #241f1b;
  --muted: #71675a;
  --line: #e0d5c4;
  --accent: #9a4f2e;
  --accent-quiet: #c0805c;

  --topbar-h: 4.25rem;
  --measure: 38rem;

  color-scheme: light;
}

html[data-theme="sepia"] {
  --bg: #eee1c9;
  --bg-soft: #e6d6b8;
  --surface: #f7eeda;
  --ink: #3a2c1d;
  --muted: #7a6749;
  --line: #d8c5a3;
  --accent: #8a4b22;
  --accent-quiet: #b5855a;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #151517;
  --bg-soft: #1b1b1f;
  --surface: #1e1e23;
  --ink: #e9e4da;
  --muted: #a1988b;
  --line: #2e2e35;
  --accent: #e0a273;
  --accent-quiet: #9c7554;
  color-scheme: dark;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 18% -5%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 55%),
    radial-gradient(circle at 88% 105%, color-mix(in srgb, var(--ink) 5%, transparent), transparent 50%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color 0.35s ease, color 0.35s ease;
}

::selection {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
}

main {
  min-height: 55vh;
}

a {
  color: inherit;
}

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

/* ---------- служебное ---------- */

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  padding: 0.6rem 0.9rem;
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.85rem;
  text-decoration: none;
  box-shadow: 0 4px 18px rgb(0 0 0 / 0.12);
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0.75rem;
}

.progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 60;
  pointer-events: none;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.12s linear;
}

/* ---------- шапка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  width: min(100% - 2rem, 70rem);
  margin-inline: auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink);
  transition: color 0.2s ease;
}

.brand::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

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

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

.ctl {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.78rem;
  line-height: 1;
  padding: 0.55rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
}

.ctl:hover {
  color: var(--ink);
  border-color: var(--accent-quiet);
}

.fontsize {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.fontsize button {
  border: 0;
  border-radius: 0;
  padding: 0.55rem 0.7rem;
  font-size: 0.8rem;
}

.fontsize button + button {
  border-left: 1px solid var(--line);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  width: 2.2rem;
  height: 2.2rem;
}

.theme-toggle .icon {
  width: 1.05rem;
  height: 1.05rem;
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-sun,
html[data-theme="sepia"] .theme-toggle .icon-sepia,
html[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* ---------- главная ---------- */

.wrap {
  width: min(100% - 2.5rem, 46rem);
  margin-inline: auto;
}

.hero {
  padding: clamp(3rem, 9vw, 6rem) 0 2.4rem;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero-title {
  margin: 0.9rem 0 0;
  font-size: clamp(2.7rem, 9vw, 4.4rem);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.035em;
}

.hero-sub {
  margin: 1.3rem 0 0;
  max-width: 33rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.hero-meta {
  margin: 1.8rem 0 0;
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- список рассказов ---------- */

.story-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.story-item {
  border-bottom: 1px solid var(--line);
}

.card {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr) auto;
  align-items: start;
  gap: 1.4rem;
  padding: 2rem 0.25rem;
  text-decoration: none;
  color: inherit;
}

.card-num {
  padding-top: 0.5rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--accent-quiet);
}

.card-body {
  min-width: 0;
}

.card h2 {
  margin: 0;
  font-size: clamp(1.4rem, 3.6vw, 1.75rem);
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.015em;
  transition: color 0.2s ease;
}

.card-lead {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.97rem;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 0.85rem 0 0;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-arrow {
  align-self: center;
  font-size: 1.15rem;
  color: var(--accent);
  opacity: 0;
  transform: translateX(-0.4rem);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.card:hover h2,
.card:focus-visible h2 {
  color: var(--accent);
}

.card:hover .card-arrow,
.card:focus-visible .card-arrow {
  opacity: 1;
  transform: none;
}

/* ---------- страница рассказа ---------- */

.story-wrap {
  width: min(100% - 2.5rem, var(--measure));
  margin-inline: auto;
  padding: clamp(1.75rem, 5vw, 3rem) 0 0;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.18s ease, gap 0.18s ease;
}

.back:hover {
  color: var(--accent);
  gap: 0.7rem;
}

.story-head {
  margin-top: 1.6rem;
  padding-bottom: 1.9rem;
  border-bottom: 1px solid var(--line);
}

.story-head h1 {
  margin: 0.7rem 0 0;
  font-size: clamp(2rem, 6.4vw, 3rem);
  font-weight: 600;
  line-height: 1.07;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.story-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 1.1rem 0 0;
  font-family: var(--sans);
  font-size: 0.73rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- текст ---------- */

.prose {
  padding-top: 2.1rem;
  font-size: calc(1.09rem * var(--scale));
  line-height: 1.78;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.prose p {
  margin: 0 0 1.05em;
}

.prose p:last-child {
  margin-bottom: 0;
}

.prose em {
  font-style: italic;
}

.prose strong {
  font-weight: 600;
}

.prose h2 {
  margin: 2.2em 0 0.7em;
  font-size: 1.28em;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  text-align: left;
}

.prose blockquote {
  margin: 1.8em 0;
  padding-left: 1.15em;
  border-left: 2px solid var(--accent-quiet);
  color: var(--muted);
  font-style: italic;
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.scene-break {
  margin: 2.3em 0;
  text-align: center;
  color: var(--accent-quiet);
  font-size: 1.05rem;
  line-height: 1;
  text-align: center;
}

@media (min-width: 640px) {
  .prose p.lede::first-letter {
    float: left;
    margin: 0.02em 0.1em 0 0;
    font-size: 3.3em;
    font-weight: 600;
    line-height: 0.82;
    color: var(--accent);
  }
}

/* ---------- навигация между рассказами ---------- */

.story-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 4.5rem;
  padding: 1.6rem 0 0;
  border-top: 1px solid var(--line);
}

.nav-link {
  display: block;
  text-decoration: none;
  color: inherit;
  min-height: 2.6rem;
}

.nav-link span {
  display: block;
  margin-bottom: 0.35rem;
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-link strong {
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.35;
  transition: color 0.18s ease;
}

.nav-link:hover strong {
  color: var(--accent);
}

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

/* ---------- подвал ---------- */

.site-footer {
  margin-top: 5.5rem;
  border-top: 1px solid var(--line);
}

.site-footer .inner {
  width: min(100% - 2.5rem, 70rem);
  margin-inline: auto;
  padding: 2rem 0 3rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem 2rem;
  font-family: var(--sans);
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  color: var(--muted);
}

/* ---------- адаптив ---------- */

@media (max-width: 560px) {
  :root {
    --topbar-h: 3.75rem;
  }

  .topbar-inner {
    width: calc(100% - 1.5rem);
  }

  .brand {
    font-size: 0.85rem;
    letter-spacing: 0.12em;
  }

  .wrap,
  .story-wrap,
  .site-footer .inner {
    width: calc(100% - 2rem);
  }

  .hero {
    padding-top: 2.6rem;
  }

  .card {
    grid-template-columns: 1.6rem minmax(0, 1fr);
    gap: 1rem;
    padding: 1.6rem 0;
  }

  .card-arrow {
    display: none;
  }

  .card-lead {
    -webkit-line-clamp: 3;
  }

  .story-nav {
    grid-template-columns: 1fr;
    gap: 1.1rem;
    margin-top: 3.2rem;
  }

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

  .nav-link.nav-empty {
    display: none;
  }

  .site-footer {
    margin-top: 3.5rem;
  }

  .prose {
    font-size: calc(1.04rem * var(--scale));
    line-height: 1.72;
  }

  .prose p {
    margin-bottom: 1em;
  }
}

/* ---------- доступность и печать ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

@media print {
  .topbar,
  .progress,
  .skip-link,
  .story-nav,
  .site-footer,
  .back {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .prose {
    font-size: 11.5pt;
    line-height: 1.55;
  }

  .story-wrap {
    width: 100%;
  }
}
