:root {
  --reader-bg: #f6f6f8;
  --reader-panel: #ffffff;
  --reader-border: #d8dbe3;
  --reader-text: #1f2937;
  --reader-muted: #596579;
}

html[data-reader-theme="dark"] {
  --reader-bg: #0f1116;
  --reader-panel: #161c27;
  --reader-border: #2a3447;
  --reader-text: #e5edf8;
  --reader-muted: #9fb0c9;
}

.reader-shell {
  background: radial-gradient(circle at top right, rgba(255, 82, 82, 0.15), transparent 34%), var(--reader-bg);
  color: var(--reader-text);
  height: calc(100dvh - 13rem);
  padding-top: 6rem;
  padding-bottom: 0.75rem;
  overflow: hidden;
}

.reader-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1rem;
  height: 100%;
}

.reader-layout.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.reader-sidebar,
.reader-main {
  background: var(--reader-panel);
  border: 1px solid var(--reader-border);
  border-radius: 1rem;
}

.reader-sidebar {
  padding: 1rem;
  height: 100%;
  overflow: auto;
  transition: width 0.25s ease, opacity 0.25s ease, padding 0.25s ease, border-width 0.25s ease;
}

.reader-layout.sidebar-collapsed .reader-sidebar {
  padding: 0;
  overflow: hidden;
  border-width: 0;
  opacity: 0;
  pointer-events: none;
  width: 0;
  min-width: 0;
}

.reader-back {
  color: var(--reader-muted);
  font-size: 0.9rem;
}

.reader-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 0.8rem;
}

.reader-meta {
  color: var(--reader-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.reader-chapter-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chapter-card {
  border: 1px solid var(--reader-border);
  border-radius: 0.75rem;
  padding: 0.7rem;
}

.chapter-title {
  font-weight: 600;
}

.chapter-items {
  margin-top: 0.55rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chapter-item-btn {
  border: 1px solid var(--reader-border);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  color: var(--reader-muted);
  background: transparent;
}

.chapter-item-btn.is-active {
  color: #ffffff;
  background: #dc2626;
  border-color: #dc2626;
}

.reader-main {
  padding: 1rem;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.reader-toolbar {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.reader-current-title {
  font-weight: 700;
  font-size: 1.4rem;
}

.reader-current-meta {
  color: var(--reader-muted);
  font-size: 0.9rem;
}

.reader-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.reader-icon-btn {
  height: 2.25rem;
  min-width: 2.25rem;
  padding: 0 0.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid var(--reader-border);
  border-radius: 0.65rem;
  color: var(--reader-text);
  background: transparent;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.reader-icon-btn:hover {
  background: rgba(220, 38, 38, 0.12);
  border-color: #dc2626;
}

.reader-icon-btn:active {
  transform: translateY(1px);
}

.reader-icon-btn svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.reader-icon-btn-small {
  height: 2rem;
  min-width: 2rem;
  padding: 0;
}

.reader-lock-panel {
  border: 1px dashed var(--reader-border);
  border-radius: 1rem;
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.03);
}

.reader-stage {
  margin-top: 1rem;
  border: 1px solid var(--reader-border);
  border-radius: 1rem;
  min-height: 0;
  flex: 1;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.05);
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.reader-content-mount {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader-boundary {
  position: absolute;
  top: 0.6rem;
  bottom: 0.6rem;
  width: clamp(50px, 9%, 92px);
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
}

.reader-boundary-prev {
  left: 0.35rem;
  justify-content: flex-start;
}

.reader-boundary-next {
  right: 0.35rem;
  justify-content: flex-end;
}

.reader-boundary-overlay {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  border: 1px solid var(--reader-border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--reader-panel) 88%, transparent);
  color: var(--reader-text);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.28rem 0.55rem;
}

.reader-boundary-overlay svg {
  width: 0.95rem;
  height: 0.95rem;
}

.reader-boundary-prev .reader-boundary-overlay {
  transform: translateX(-6px);
}

.reader-boundary-next .reader-boundary-overlay {
  transform: translateX(6px);
}

.reader-boundary:hover .reader-boundary-overlay,
.reader-boundary:focus-visible .reader-boundary-overlay,
.reader-stage:hover .reader-boundary-overlay {
  opacity: 1;
  transform: translateX(0);
}

.reader-boundary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.reader-boundary:disabled .reader-boundary-overlay {
  opacity: 0.25;
}

.reader-image {
  max-width: 100%;
  max-height: 100%;
  display: block;
  margin: 0 auto;
  border-radius: 0.8rem;
  object-fit: contain;
}

.reader-image.webtoon {
  width: min(900px, 100%);
}

.reader-image.manga {
  width: min(1200px, 100%);
}

.reader-text {
  max-width: 920px;
  margin: 0 auto;
  line-height: 1.8;
  font-size: 1.05rem;
  width: 100%;
  align-self: flex-start;
}

.reader-text.rtl {
  direction: rtl;
  text-align: right;
}

.reader-scroll-stack {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  align-self: flex-start;
}

@media (max-width: 1024px) {
  .reader-layout {
    grid-template-columns: 1fr;
  }

  .reader-shell {
    height: calc(100dvh - 11.5rem);
    padding-top: 4.75rem;
  }

  .reader-sidebar {
    height: 32dvh;
  }

  .reader-main {
    height: auto;
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .reader-shell {
    height: calc(100dvh - 10.75rem);
    padding-top: 4rem;
    padding-bottom: 0.5rem;
  }

  .reader-icon-btn {
    height: 2.1rem;
    min-width: 2.1rem;
    padding: 0 0.55rem;
  }

  .reader-icon-btn span {
    display: none;
  }

  .reader-boundary {
    width: clamp(42px, 12%, 68px);
  }

  .reader-sidebar {
    height: 28dvh;
  }

  .reader-layout.sidebar-collapsed {
    grid-template-columns: 1fr;
  }
}
