:root {
  color-scheme: dark light;
  --bg: #10131a;
  --panel: #181d27;
  --panel-2: #202737;
  --text: #f4f1ea;
  --muted: #aeb6c4;
  --line: rgba(255,255,255,.12);
  --accent: #e76f51;
  --accent-2: #4db6ac;
  --danger: #ef476f;
  --shadow: 0 18px 36px rgba(0,0,0,.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
a {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.loading {
  min-height: 80vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
}

.loading-mark {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  padding: 8px 0 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
}

.icon-button[disabled] {
  opacity: .35;
  cursor: default;
}

.top-title {
  min-width: 0;
}

.top-title strong,
.top-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-title strong {
  font-size: 15px;
}

.top-title span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.hero {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.hero-cover {
  position: relative;
  min-height: 210px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-cover img {
  width: 100%;
  height: 100%;
  min-height: 210px;
  object-fit: cover;
  display: block;
}

.hero-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.05), rgba(0,0,0,.72));
}

.hero-copy {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 8vw, 48px);
  line-height: 1.04;
}

.hero-desc {
  margin: 8px 0 0;
  max-width: 40rem;
  color: rgba(255,255,255,.82);
  font-size: 14px;
  line-height: 1.5;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.action {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 800;
}

.action.primary {
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 70%, white);
  color: #fff;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
}

.chapter-list {
  display: grid;
  gap: 10px;
}

.chapter-item {
  display: grid;
  gap: 4px;
}

.chapter-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  min-height: 104px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
}

.chapter-card img {
  width: 92px;
  height: 88px;
  object-fit: cover;
  border-radius: 6px;
  background: #0b0d10;
}

.chapter-card h3 {
  margin: 2px 0 6px;
  font-size: 16px;
  line-height: 1.25;
}

.chapter-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.chapter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
}

.reader-head {
  display: grid;
  gap: 8px;
  margin: 4px 0 12px;
}

.reader-head h1 {
  font-size: clamp(24px, 7vw, 42px);
}

.reader-tools {
  position: sticky;
  top: 58px;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 0 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}

.reader-tools button {
  min-height: 40px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 800;
}

.reader-tools button.primary {
  background: var(--accent);
  color: #fff;
}

.panel-stack {
  display: grid;
  gap: 12px;
}

figure {
  margin: 0;
  background: #090b0f;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

figure img {
  width: 100%;
  height: auto;
  display: block;
}

.pdf-panel {
  display: grid;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.pdf-panel img {
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: 6px;
  background: #090b0f;
}

.chapter-channel-link {
  display: block;
  width: fit-content;
  margin: 12px auto 0;
  padding: 4px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chapter-channel-link.inline {
  margin: 0 0 2px 112px;
  text-align: left;
}

@media (max-width: 380px) {
  .chapter-channel-link.inline {
    margin-left: 0;
  }
}

.reader-bottom {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.reader-bottom.single {
  grid-template-columns: minmax(0, 1fr);
}

.notice {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent-2) 16%, transparent);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f2ee;
    --panel: #ffffff;
    --panel-2: #eef1f6;
    --text: #151920;
    --muted: #626b78;
    --line: rgba(20,24,32,.14);
    --shadow: 0 16px 32px rgba(31,35,44,.14);
  }

  .hero-desc {
    color: rgba(255,255,255,.86);
  }
}
