:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0b100f;
  --bg-soft: #101715;
  --panel: #151d1a;
  --panel-strong: #1b2522;
  --field: #0f1513;
  --border: #2b3a35;
  --border-strong: #3e514b;
  --text: #f0f5f3;
  --muted: #a6b6b1;
  --muted-soft: #7f918b;
  --primary: #4ed0b0;
  --primary-hover: #68dfc3;
  --primary-text: #061310;
  --link: #9ee4ee;
  --warning: #f4c76f;
  --danger: #ff9f9f;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(78, 208, 176, 0.1), rgba(11, 16, 15, 0) 280px),
    var(--bg);
  color: var(--text);
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 14px 42px;
}

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

a:hover {
  text-decoration: underline;
}

button,
.button-link {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
  cursor: pointer;
  font: inherit;
  font-weight: 850;
}

button:hover {
  background: var(--primary-hover);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid rgba(78, 208, 176, 0.45);
  outline-offset: 2px;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -18px -14px 18px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(62, 81, 75, 0.55);
  background: rgba(11, 16, 15, 0.9);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 18px;
  font-weight: 950;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 14px;
}

.top-actions {
  display: flex;
  min-width: 0;
  gap: 8px;
}

.badge-button {
  position: relative;
  gap: 8px;
}

.nav-badge {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  place-items: center;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 12px;
  line-height: 1;
}

.nav-badge[hidden] {
  display: none;
}

.soft-button,
.icon-button,
.bookmark-button,
.secondary-button,
.text-button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  text-decoration: none;
}

.soft-button,
.button-link {
  padding: 0 14px;
}

.soft-button:hover,
.icon-button:hover,
.bookmark-button:hover,
.secondary-button:hover,
.button-link:hover {
  border-color: var(--primary);
  background: rgba(78, 208, 176, 0.1);
  text-decoration: none;
}

.text-button {
  min-height: 36px;
  padding: 0 6px;
  border-color: transparent;
  background: transparent;
  color: var(--link);
}

.hero-search {
  display: grid;
  gap: 16px;
  margin: 20px 0 16px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(78, 208, 176, 0.12), rgba(244, 199, 111, 0.055)), var(--panel);
  box-shadow: var(--shadow);
}

.hero-search h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(28px, 5vw, 46px);
  line-height: 1.05;
  letter-spacing: 0;
}

.hero-search form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.search-field {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.search-field input {
  width: 100%;
  min-height: 54px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}

.search-field input::placeholder {
  color: var(--muted-soft);
}

.hero-search button[type="submit"] {
  align-self: end;
  min-width: 112px;
  padding: 0 18px;
}

.library-summary,
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 12px 0;
  color: var(--muted);
  font-weight: 750;
}

.library-summary {
  justify-content: space-between;
}

.pagination {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.pagination span {
  color: var(--muted-soft);
}

.error,
.warning,
.muted {
  overflow-wrap: anywhere;
}

.error,
.warning {
  color: var(--warning);
}

.error {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid rgba(255, 159, 159, 0.4);
  border-radius: 8px;
  background: rgba(88, 27, 32, 0.35);
  color: var(--danger);
}

.muted {
  color: var(--muted);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  align-items: start;
}

.book-card {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
  min-width: 0;
  min-height: 286px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.018)), var(--panel);
}

.book-card:hover {
  border-color: var(--border-strong);
  background: linear-gradient(180deg, rgba(78, 208, 176, 0.075), rgba(255, 255, 255, 0.02)), var(--panel);
}

.book-card.is-working {
  border-color: rgba(78, 208, 176, 0.5);
}

.book-pages {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  min-height: 212px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.book-pages::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(47.5% - 1px);
  width: 2px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.5) 16%, rgba(0, 0, 0, 0.62) 50%, rgba(255, 255, 255, 0.08) 84%, transparent);
}

.book-cover-page,
.book-info {
  min-width: 0;
  padding: 12px;
}

.book-cover-page {
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.055), rgba(0, 0, 0, 0.05)),
    #18211e;
}

.cover {
  width: min(100%, 128px);
  max-height: 188px;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #26302d;
  object-fit: cover;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.38);
}

.book-info {
  display: grid;
  min-width: 0;
  gap: 8px;
  align-content: start;
  background:
    linear-gradient(270deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.018)),
    #17201d;
}

.book-info h2 {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.icon-button,
.bookmark-button {
  min-height: 44px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button.is-active,
.bookmark-button.is-active {
  border-color: rgba(244, 199, 111, 0.48);
  background: rgba(244, 199, 111, 0.12);
  color: var(--warning);
}

.book-meta {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.book-footer {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 10px;
  align-items: stretch;
}

.book-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.book-actions button {
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  font-size: 13px;
}

.torrent-button {
  grid-column: 1 / -1;
}

.bookmark-button {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
}

.secondary-button {
  color: var(--link);
}

.action-progress {
  display: grid;
  gap: 7px;
  margin-top: 2px;
  font-size: 12px;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
}

.progress-row strong {
  color: var(--text);
}

.progress-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(166, 182, 177, 0.16);
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--warning));
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.52);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  width: min(460px, 100vw);
  height: 100dvh;
  padding: 18px;
  overflow: auto;
  border-left: 1px solid var(--border);
  background: #101614;
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.45);
}

.drawer[hidden],
.drawer-backdrop[hidden] {
  display: none;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.drawer-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.drawer-header p,
.folder-status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.drawer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

.downloads-list,
.favorites-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.download-job,
.favorite-row {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  font-size: 13px;
}

.download-job > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.download-job strong,
.download-job span,
.download-job code,
.favorite-row span,
.favorite-row small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.download-job code,
.favorite-row small {
  color: var(--muted);
}

.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.job-actions button,
.job-actions .button-link {
  min-height: 38px;
  padding: 0 12px;
  font-size: 12px;
}

.danger-button {
  border-color: rgba(255, 159, 159, 0.42);
  color: var(--danger);
}

.favorite-row:hover {
  border-color: var(--primary);
  text-decoration: none;
}

@media (max-width: 760px) {
  main {
    padding: 14px 10px 32px;
  }

  .top-bar {
    margin: -14px -10px 14px;
  }

  .hero-search {
    margin-top: 14px;
    padding: 16px;
  }

  .hero-search form,
  .drawer-actions {
    grid-template-columns: 1fr;
  }

  .hero-search button[type="submit"],
  .drawer-actions button {
    width: 100%;
  }

  .library-summary {
    display: grid;
    gap: 4px;
    justify-content: stretch;
  }

  .book-grid {
    grid-template-columns: 1fr;
  }

  .book-card {
    min-height: 278px;
  }

  .cover {
    width: min(100%, 118px);
  }
}

@media (max-width: 430px) {
  .brand span:last-child {
    display: none;
  }

  .top-actions {
    gap: 6px;
  }

  .top-actions .soft-button {
    min-height: 44px;
    padding: 0 10px;
    font-size: 13px;
  }

  .book-card {
    min-height: 264px;
    padding: 10px;
  }

  .book-pages {
    min-height: 196px;
  }

  .book-cover-page,
  .book-info {
    padding: 10px;
  }

  .cover {
    width: min(100%, 104px);
    max-height: 166px;
  }

  .book-info h2 {
    font-size: 15px;
    -webkit-line-clamp: 4;
  }

  .book-meta {
    font-size: 12px;
  }

  .book-footer {
    gap: 8px;
  }

}
