:root {
  --bg: #000;
  --panel: rgba(18, 18, 20, 0.84);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #f3f3f3;
  --muted: #a1a1aa;
  --accent: #60a5fa;
  --danger: #f87171;
  --success: #22c55e;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

body.light {
  --bg: #f5f5f7;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-border: rgba(0, 0, 0, 0.08);
  --text: #121212;
  --muted: #5f6368;
  --accent: #2563eb;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
  min-height: 100%;
}

body {
  background: var(--bg);
}

body.reader-mode {
  background: var(--bg);
}

body.reader-mode.lock-scroll {
  overflow: hidden;
}

button:focus,
select:focus,
button:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: none;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.page-topbar {
  position: sticky;
}

body.page-topbar-hidden .page-topbar {
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
}

.overlay-topbar {
  position: fixed;
  left: 0;
  right: 0;
}

body.ui-hidden .overlay-topbar {
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
}

.brand-button {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 28px;
  font-weight: 700;
  padding: 8px 10px;
  cursor: pointer;
  line-height: 1;
}

.topbar-actions,
.reader-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1 1 auto;
}

button,
select {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  min-height: 42px;
  transition:
    transform 0.12s ease,
    border-color 0.12s ease,
    opacity 0.12s ease,
    background-color 0.12s ease;
}

button:hover,
select:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.status {
  margin-left: auto;
  color: var(--muted);
  font-size: 14px;
  padding: 8px 4px;
  white-space: nowrap;
}

.page {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 12px 40px;
  min-height: calc(100vh - 72px);
  background: var(--bg);
}

.catalog-block h1,
.catalog-block h2 {
  margin: 0 0 12px;
}

.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 280px));
  gap: 14px;
  margin-top: 14px;
}

.work-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.work-card-cover-wrap {
  width: 100%;
  height: min(40vh, 420px);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
}

.work-card-cover,
.work-header-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.work-card-cover-placeholder {
  color: var(--muted);
  font-size: 14px;
  padding: 16px;
  text-align: center;
}

.work-card-body {
  padding: 14px;
}

.work-card-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.work-card-sub {
  color: var(--muted);
  font-size: 14px;
}

.work-header {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  margin-bottom: 20px;
  align-items: start;
}

.work-header-cover-wrap {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
}

.work-header-meta h1 {
  margin: 0 0 10px;
}

.work-header-meta p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.work-description {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.7;
  white-space: pre-line;
}

.back-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.chapters-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.narrow-chapters {
  max-width: 900px;
}

.chapter-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.chapter-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.chapter-sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 10px;
}

.chapter-actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

.preload-wrap {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.preload-bar-wrap {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.preload-bar-wrap.show {
  opacity: 1;
}

.preload-bar {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.18s linear;
}

.preload-btn.done {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
  color: var(--success);
  opacity: 1;
}

.done-mark {
  display: inline-block;
  margin-left: 6px;
  animation: popIn 0.25s ease;
}

.chapter-note {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.message {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 18px;
  line-height: 1.6;
  box-shadow: var(--shadow);
}

.error {
  color: var(--danger);
}

.reader-page {
  min-height: 100vh;
  background: var(--bg);
}

.reader-container {
  width: 100%;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: center;
}

.single-page {
  width: 100%;
  min-height: 100vh;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.single-page img {
  display: block;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.single-page.desktop-fit-height img {
  height: 100vh;
  width: auto;
  max-width: none;
  max-height: none;
  object-fit: contain;
}

.single-page.mobile-fit-width img {
  width: 100vw;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: contain;
}

.page-tap-zones {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 42% 16% 42%;
  z-index: 3;
}

.page-tap-zone {
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  min-height: 0;
  border-radius: 0;
}

.strip-pages {
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  padding: 88px 0 96px;
}

.strip-pages img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  transform: translateY(0);
  opacity: 1;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

body.ui-hidden .overlay-bottom {
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
}

.hint {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 53;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

body.light .hint {
  background: rgba(255, 255, 255, 0.75);
}

body.ui-hidden .hint,
.hint.hint-faded {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  pointer-events: none;
}

.overlay-side {
  position: fixed;
  left: 16px;
  top: 96px;
  z-index: 54;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.overlay-side a {
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.5;
}

.overlay-side a:hover {
  color: var(--accent);
}

body.ui-hidden .overlay-side {
  transform: translateX(-120%);
  opacity: 0;
  pointer-events: none;
}

@keyframes popIn {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 1100px) {
  .overlay-side {
    width: 220px;
  }
}

@media (max-width: 900px) {
  .status {
    width: 100%;
    margin-left: 0;
  }

  .work-header {
    grid-template-columns: 1fr;
  }

  .work-card-cover-wrap {
    height: min(38vh, 360px);
  }

  .single-page {
    min-height: 100vh;
    height: auto;
    overflow: visible;
    align-items: center;
    justify-content: center;
    padding-top: 88px;
    padding-bottom: 96px;
  }

  body.ui-hidden .single-page {
    padding-top: 0;
    padding-bottom: 0;
    min-height: 100vh;
  }

  .single-page.mobile-fit-width img {
    width: 100%;
    height: auto;
  }

  .page-tap-zones {
    position: fixed;
    inset: 0;
    grid-template-columns: 44% 12% 44%;
  }

  .overlay-side {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: calc(104px + env(safe-area-inset-bottom));
    width: auto;
  }

  .hint {
    bottom: calc(180px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 680px) {
  .topbar {
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .brand-button {
    width: 100%;
    text-align: left;
    padding-bottom: 2px;
    font-size: 24px;
  }

  .topbar-actions,
  .reader-controls {
    width: 100%;
  }

  button,
  select {
    font-size: 13px;
    padding: 9px 10px;
    min-height: 40px;
  }

  .page {
    padding-left: 8px;
    padding-right: 8px;
  }

  .works-grid {
    grid-template-columns: 1fr;
  }

  .work-card-cover-wrap {
    height: min(36vh, 320px);
  }

  .chapter-actions {
    grid-template-columns: 1fr;
  }

  .preload-wrap {
    grid-template-columns: auto 1fr;
    width: 100%;
  }

  .overlay-side {
    gap: 8px;
    padding: 10px 12px;
  }

  .overlay-side a {
    font-size: 13px;
  }

  .hint {
    font-size: 12px;
  }
}