:root {
  --color-text: #18181b;
  --color-muted: #71717a;
  --color-link: #c41e3a;
  --color-link-hover: #9a1830;
  --color-heading: #18181b;
  --color-bg: #f4f4f5;
  --color-surface: #fff;
  --color-border: #e4e4e7;
  --color-header: #0b4278;
  --color-header-text: #fafafa;
  --color-nav: #093664;
  --color-nav-hover: #0e5294;
  --color-accent: #c41e3a;
  --color-series: #f4f4f5;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --max-width: 1800px;
  --gutter: clamp(1rem, 2.5vw, 2rem);
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: clamp(14px, 1.5vw, 16px);
  line-height: 1.65;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}

a {
  color: var(--color-link);
  text-decoration: none;
}
a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

h1, h2, h3, h4 {
  color: var(--color-heading);
  font-weight: 600;
  line-height: 1.3;
}
h1 { font-size: clamp(1.25rem, 2vw, 1.75rem); }
h2 { font-size: clamp(1.05rem, 1.8vw, 1.25rem); margin-top: 1.5rem; margin-bottom: .5rem; }
h3 { font-size: 1rem; }

strong, b { color: inherit; font-weight: 600; }

.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

/* Header */
.site-header {
  background: var(--color-header);
  color: var(--color-header-text);
  border-bottom: none;
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.logo {
  display: block;
  flex: 0 0 auto;
  text-decoration: none !important;
  line-height: 0;
}
.logo:hover { opacity: .92; text-decoration: none !important; }
.logo img {
  display: block;
  height: clamp(90px, 14vw, 180px);
  width: auto;
  max-width: min(640px, 90vw);
}

.logo__text {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1.2;
}

.header-banners {
  flex: 1 1 420px;
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  justify-content: flex-end;
  align-items: stretch;
  min-width: 0;
}
.header-banners .ad-slot {
  flex: 1 1 240px;
  max-width: 400px;
  min-width: 0;
}
.header-banners img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 90px;
  object-fit: contain;
}

.demo-banner {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .2rem;
  width: 100%;
  min-height: 72px;
  padding: .65rem 1rem;
  background: #0e5294;
  border: 1px solid rgba(255, 255, 255, .2);
  color: #fff;
  text-decoration: none !important;
  line-height: 1.3;
}
.demo-banner:hover {
  background: #1268b8;
  text-decoration: none !important;
  color: #fff;
}
.demo-banner--b {
  background: #8b1530;
  border-color: rgba(255, 255, 255, .15);
}
.demo-banner--b:hover {
  background: #a61a3a;
}
.demo-banner__tag {
  font-size: .625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  opacity: .75;
}
.demo-banner__head {
  font-size: 1rem;
  font-weight: 700;
}
.demo-banner__sub {
  font-size: .8125rem;
  opacity: .9;
}

.nav-toggle {
  display: none;
  flex: 0 0 auto;
  margin-left: auto;
  background: transparent;
  color: var(--color-header-text);
  border: 1px solid rgba(255, 255, 255, .25);
  padding: .5rem .85rem;
  cursor: pointer;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
}
.nav-toggle:hover { background: var(--color-nav-hover); }

.main-nav {
  background: var(--color-nav);
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.main-nav .container {
  padding-top: 0;
  padding-bottom: 0;
}

.main-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
}

.main-nav a {
  display: block;
  padding: .85rem 1.15rem;
  color: #e4e4e7;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: .01em;
  text-transform: lowercase;
  border-bottom: none;
}
.main-nav a:hover {
  color: #fff;
  background: var(--color-nav-hover);
  text-decoration: none;
}
.main-nav a.is-active {
  color: #fff;
  background: rgba(255, 255, 255, .12);
  box-shadow: inset 0 -3px 0 #fff;
}

/* Layout */
.site-layout {
  display: grid;
  grid-template-columns: minmax(200px, 240px) minmax(0, 1fr) minmax(200px, 260px);
  gap: clamp(1rem, 2vw, 1.5rem);
  padding-top: clamp(1rem, 2vw, 1.5rem);
  padding-bottom: clamp(1rem, 2vw, 1.5rem);
  align-items: start;
}

.sidebar, .content, .aside { min-width: 0; }

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  margin-bottom: 1rem;
}

.panel__title {
  background: var(--color-header);
  color: var(--color-header-text);
  font-size: .9375rem;
  font-weight: 600;
  padding: .65rem .9rem;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: .04em;
  line-height: 1.35;
}

.panel__body { padding: 1rem; }

.genre-list, .alpha-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.genre-list li, .alpha-list li { margin-bottom: .35rem; }
.genre-list a { font-size: .9375rem; line-height: 1.45; }

.genre-list--sections a {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.0625rem;
  line-height: 1.4;
  color: var(--color-text);
}
.genre-list--sections a:hover {
  color: var(--color-link);
}
.genre-list--sections a:hover .genre-list__icon {
  color: var(--color-link);
}
.genre-list__icon {
  flex-shrink: 0;
  color: var(--color-header);
}
.genre-list--sections a.is-active {
  color: var(--color-link);
  font-weight: 600;
}
.genre-list--sections a.is-active .genre-list__icon {
  color: var(--color-link);
}

.alpha-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(1.75rem, 1fr));
  gap: 3px;
}
.alpha-list a {
  display: block;
  text-align: center;
  padding: .3rem .2rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  font-size: .8125rem;
  font-weight: 500;
  color: var(--color-heading);
}
.alpha-list a:hover {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
  text-decoration: none;
}

.search-form input[type="text"],
.search-form input[type="email"],
.search-form input[type="password"],
.search-form select,
.search-form textarea {
  width: 100%;
  padding: .7rem .8rem;
  border: 1px solid var(--color-border);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  margin-bottom: .65rem;
  background: var(--color-surface);
  color: var(--color-text);
}
.search-form input[type="text"]:focus,
.search-form input[type="email"]:focus,
.search-form input[type="password"]:focus,
.search-form select:focus,
.search-form textarea:focus {
  outline: 2px solid var(--color-header);
  outline-offset: 0;
  border-color: var(--color-header);
}

.btn {
  display: inline-block;
  padding: .55rem 1.1rem;
  background: var(--color-header);
  color: #fff !important;
  border: 1px solid var(--color-header);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none !important;
}
.btn:hover {
  background: var(--color-nav-hover);
  border-color: var(--color-nav-hover);
  text-decoration: none !important;
}
.btn--secondary {
  background: var(--color-accent);
  border-color: var(--color-accent);
}
.btn--secondary:hover {
  background: var(--color-link-hover);
  border-color: var(--color-link-hover);
}
.btn--small { padding: .4rem .7rem; font-size: .9375rem; }

.content .text {
  background: var(--color-surface);
  padding: clamp(1.25rem, 2.5vw, 2rem);
  border: 1px solid var(--color-border);
  font-size: 1rem;
  line-height: 1.7;
}
.content .text h1 {
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  margin-top: 0;
  margin-bottom: 1rem;
}
.content .text h2 {
  font-size: clamp(1.25rem, 2vw, 1.5rem);
  margin-top: 1.75rem;
  margin-bottom: .75rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--color-border);
}
.content .text h2:first-child { margin-top: 0; }
.content .text h3 {
  font-size: 1.125rem;
  margin-top: 1.25rem;
  margin-bottom: .5rem;
}
.content .text p { margin: 0 0 1rem; }
.content .text ul,
.content .text ol {
  margin: 0 0 1.25rem;
  padding-left: 1.75rem;
}
.content .text ul { list-style: disc; }
.content .text ol { list-style: decimal; }
.content .text li {
  margin-bottom: .45rem;
  padding-left: .25rem;
}
.content .text li::marker {
  color: var(--color-header);
}
.content .text ul ul,
.content .text ol ol {
  margin-top: .45rem;
  margin-bottom: .45rem;
}

/* Главная: приветствие и авторские права */
.home-intro {
  margin-bottom: 1.75rem;
  padding: 1.25rem 1.35rem 1.35rem;
  background: linear-gradient(135deg, #eef4fb 0%, #f8fafc 100%);
  border: 1px solid #c5d9ef;
  border-left: 4px solid var(--color-header);
}
.home-intro__title {
  margin: 0 0 1.15rem;
  padding: 0;
  border: none;
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
  color: var(--color-header);
  line-height: 1.3;
}
.home-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
  margin-bottom: 1.15rem;
}
.home-stat {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .85rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-header);
}
.home-stat--books {
  border-top-color: var(--color-accent);
}
.home-stat__value {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--color-header);
}
.home-stat--books .home-stat__value {
  color: var(--color-accent);
}
.home-stat__label {
  font-size: .875rem;
  font-weight: 500;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.home-intro__lead {
  margin: 0 0 .75rem;
  font-size: 1.0625rem;
  font-weight: 500;
  color: var(--color-heading);
}
.home-intro__genres {
  margin: 0;
  font-size: .9375rem;
  line-height: 1.65;
  color: var(--color-text);
}
.home-intro__genres strong {
  color: var(--color-header);
  font-weight: 600;
}

.home-notice {
  margin-bottom: 1.75rem;
  padding: 1rem 1.25rem 1.15rem;
  background: #fff5f5;
  border: 1px solid #f0caca;
  border-left: 4px solid var(--color-accent);
}
.home-notice__title {
  margin: 0 0 .65rem;
  padding: 0;
  border: none;
  font-size: 1.125rem;
  color: var(--color-accent);
}
.home-notice p {
  margin: 0;
  font-size: .9375rem;
  line-height: 1.6;
}
.home-notice strong {
  color: var(--color-accent);
}

.home-news > h2 {
  margin-top: 0;
}

@media (max-width: 540px) {
  .home-stats {
    grid-template-columns: 1fr;
  }
  .home-intro,
  .home-notice {
    padding: 1rem;
  }
}

/* Новости библиотеки */
.news-feed {
  margin-top: .75rem;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
}
.news-feed__day + .news-feed__day {
  border-top: 1px solid var(--color-border);
}
.news-feed__date {
  margin: 0;
  padding: .65rem 1rem;
  font-size: .9375rem;
  font-weight: 600;
  color: var(--color-header);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.news-feed--page .news-feed__date {
  font-size: 1.0625rem;
}
.news-feed__list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.news-feed__item {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 1rem;
  line-height: 1.45;
}
.news-feed__item:last-child {
  border-bottom: none;
}
.news-feed__icon {
  flex-shrink: 0;
  margin-top: .15rem;
  color: var(--color-header);
}
.news-feed__genre {
  font-weight: 600;
  color: var(--color-header);
  text-decoration: none;
}
.news-feed__genre:hover {
  color: var(--color-link);
  text-decoration: underline;
}
.news-feed__sep {
  color: var(--color-muted);
  margin: 0 .25rem;
}
.news-feed__author {
  color: var(--color-text);
}
.news-feed__more {
  margin-top: 1rem;
  margin-bottom: 0;
  font-size: 1rem;
}
.news-feed__empty {
  color: var(--color-muted);
  font-style: italic;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9375rem;
  background: var(--color-surface);
}
.data-table th,
.data-table td {
  padding: .75rem 1rem;
  vertical-align: middle;
  text-align: left;
}
.data-table thead th {
  background: var(--color-header);
  color: #fff;
  font-size: .8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  border: none;
}
.data-table tbody td {
  border-bottom: 1px solid var(--color-border);
}
.data-table tbody tr:last-child td {
  border-bottom: none;
}
.data-table tbody tr:hover td {
  background: var(--color-bg);
}
.data-table tbody td:first-child {
  font-size: 1rem;
  line-height: 1.45;
  color: var(--color-text);
}
.data-table tbody td:first-child a {
  font-weight: 500;
  color: var(--color-header);
  text-decoration: none;
}
.data-table tbody td:first-child a:hover {
  color: var(--color-link);
  text-decoration: underline;
}
.data-table tr.series-row td {
  background: var(--color-series);
  font-weight: 600;
  font-size: .875rem;
  color: var(--color-header);
  padding: .55rem 1rem;
  border-bottom: 1px solid var(--color-border);
}
.data-table tr.series-row:hover td {
  background: var(--color-series);
}
.data-table .actions {
  white-space: nowrap;
  text-align: right;
  width: 1%;
}
.data-table .actions a {
  display: inline-block;
  padding: .4rem .75rem;
  margin: .15rem 0 .15rem .35rem;
  font-size: .8125rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none !important;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-header);
}
.data-table .actions a:hover {
  background: var(--color-bg);
  color: var(--color-header);
}
.data-table .actions a[href*="/read/"] {
  background: var(--color-header);
  border-color: var(--color-header);
  color: #fff !important;
}
.data-table .actions a[href*="/read/"]:hover {
  background: var(--color-nav-hover);
  border-color: var(--color-nav-hover);
  color: #fff !important;
}
.data-table .actions a[href*="/download"] {
  border-color: var(--color-accent);
  color: var(--color-accent) !important;
}
.data-table .actions a[href*="/download"]:hover {
  background: var(--color-accent);
  color: #fff !important;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin: 1.25rem 0;
  justify-content: center;
}
.pagination a, .pagination span {
  padding: .35rem .65rem;
  border: 1px solid var(--color-border);
  font-size: .8125rem;
  background: var(--color-surface);
  min-width: 2rem;
  text-align: center;
}
.pagination a:hover {
  background: var(--color-bg);
  text-decoration: none;
}
.pagination .current {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.reader-text {
  background: var(--color-surface);
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid var(--color-border);
  max-width: 72ch;
  margin: 0 auto;
}
.reader-text .reader-author { text-align: right; }
.reader-text .reader-title { text-align: center; margin-bottom: 1.5rem; }
.reader-text .indent { display: inline-block; width: 2rem; }
.reader-text p { margin: 0 0 .75rem; text-align: justify; }

.copyright-notice {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  padding: 1rem;
  margin-bottom: 1rem;
  font-size: .875rem;
}

.book-cover {
  float: left;
  margin: 0 1.25rem 1rem 0;
  max-width: min(200px, 40vw);
  border: 1px solid var(--color-border);
}

.flash {
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  font-size: .875rem;
  border: 1px solid;
}
.flash--error { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }
.flash--success { background: #f0fdf4; border-color: #86efac; color: #166534; }

.auth-form label {
  display: block;
  margin-bottom: .85rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-heading);
}
.auth-form input,
.auth-form select,
.auth-form textarea {
  width: 100%;
  max-width: 100%;
  padding: .7rem .8rem;
  border: 1px solid var(--color-border);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  background: var(--color-surface);
  color: var(--color-text);
  margin-top: .35rem;
}
.auth-form input:focus,
.auth-form select:focus,
.auth-form textarea:focus {
  outline: 2px solid var(--color-header);
  outline-offset: 0;
  border-color: var(--color-header);
}
.auth-form textarea {
  min-height: 8rem;
  resize: vertical;
}
.auth-form .btn {
  margin-top: .25rem;
  font-size: 1rem;
  padding: .55rem 1.15rem;
}

.ad-slot img { max-width: 100%; height: auto; }
.content-ads { margin-top: 1.5rem; }
.content-ads .ad-slot { margin-bottom: 1rem; text-align: center; }

.captcha-code {
  display: inline-block;
  font-family: monospace;
  font-size: 1.1rem;
  letter-spacing: .2em;
  font-weight: 700;
  color: var(--color-heading);
  background: var(--color-bg);
  padding: .25rem .5rem;
  border: 1px dashed var(--color-border);
}

.field-error { color: var(--color-link); font-size: .8125rem; display: block; margin-top: .25rem; }

.site-footer {
  padding-top: 1.25rem;
  padding-bottom: 1.5rem;
  text-align: center;
  font-size: .8125rem;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}
.site-footer p { margin: 0; }

/* Tablet: sidebars below content in grid */
@media (max-width: 1200px) {
  .site-layout {
    grid-template-columns: 1fr;
  }
  .content { order: 1; }
  .sidebar {
    order: 2;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
  }
  .sidebar .panel { margin-bottom: 0; }
  .aside {
    order: 3;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
  }
  .aside .panel { margin-bottom: 0; }
}

/* Header banners: tablet and mobile */
@media (max-width: 1024px) {
  .header-top {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "logo toggle"
      "banners banners";
    align-items: center;
  }

  .logo { grid-area: logo; }
  .nav-toggle { grid-area: toggle; margin-left: 0; }
  .header-banners {
    grid-area: banners;
    flex: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }
  .header-banners .ad-slot {
    flex: none;
    max-width: none;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .header-top {
    padding-top: .65rem;
    padding-bottom: .65rem;
  }

  .nav-toggle { display: block; }

  .main-nav { display: none; }
  .main-nav.is-open { display: block; }

  .main-nav ul { flex-direction: column; }
  .main-nav a {
    border-bottom: 1px solid rgba(255, 255, 255, .12);
    border-left: 3px solid transparent;
  }
  .main-nav a:hover {
    border-left-color: #fff;
    background: var(--color-nav-hover);
  }
  .main-nav a.is-active {
    border-left-color: #fff;
    background: rgba(255, 255, 255, .12);
    box-shadow: none;
  }

  .header-banners {
    grid-template-columns: 1fr;
    gap: .5rem;
  }

  .demo-banner {
    min-height: 64px;
    padding: .55rem .85rem;
  }
  .demo-banner__head { font-size: .9375rem; }
  .demo-banner__sub { font-size: .75rem; }

  .sidebar,
  .aside {
    grid-template-columns: 1fr;
  }

  .book-cover {
    float: none;
    display: block;
    margin: 0 auto 1rem;
    max-width: 160px;
  }

  .content .text { padding: 1rem; }

  .data-table { font-size: .875rem; }
  .data-table th,
  .data-table td { padding: .6rem .75rem; }
  .data-table tbody td:first-child { font-size: .9375rem; }
  .data-table .actions {
    white-space: normal;
    text-align: left;
    width: auto;
  }
  .data-table .actions a {
    margin: .2rem .35rem .2rem 0;
  }
}

@media (max-width: 480px) {
  .logo img { height: clamp(70px, 20vw, 100px); }
  .header-top { gap: .65rem; }
  .demo-banner__tag { display: none; }
  .alpha-list { grid-template-columns: repeat(auto-fill, minmax(1.5rem, 1fr)); }
}
