:root {
  color-scheme: light;
  --bg: #fbfaf7;
  --fg: #24211d;
  --muted: #6f685e;
  --line: #e3ded4;
  --accent: #8a5a3b;
  --card: #ffffff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171613;
  --fg: #ece7de;
  --muted: #a49c90;
  --line: #33302a;
  --accent: #d8a27c;
  --card: #201e1a;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"],
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #171613;
    --fg: #ece7de;
    --muted: #a49c90;
    --line: #33302a;
    --accent: #d8a27c;
    --card: #201e1a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.75;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.site-header,
main,
.site-footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.site-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.site-nav { display: flex; gap: 18px; font-size: 0.95rem; }

main { padding-top: 36px; padding-bottom: 64px; min-height: 60vh; }

.page-title {
  font-size: 1.8rem;
  line-height: 1.25;
  margin: 0 0 28px;
  letter-spacing: -0.02em;
}

.story-list { display: grid; gap: 24px; }

.story-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}

.story-cover-link { display: block; margin-bottom: 14px; }

img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}

.story-cover { width: 100%; }

.story-title { font-size: 1.3rem; line-height: 1.4; margin: 0 0 6px; }
.story-title a { color: var(--fg); }

.story-meta { color: var(--muted); font-size: 0.9rem; margin: 0; }

.story > .story-title { font-size: 2rem; line-height: 1.25; margin-bottom: 10px; }
.story > .story-meta { margin-bottom: 24px; }
.story > .story-cover { margin-bottom: 28px; }

.part { margin: 0 0 32px; }
.part-image { width: 100%; margin: 0 0 14px; }
.part-text { margin: 0; font-size: 1.08rem; }

.story-source { font-size: 0.9rem; color: var(--muted); margin-top: 40px; }
.back-link { margin-top: 32px; font-size: 0.95rem; }

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

/* Card reader — no JS: cards stay a readable vertical stack. */
.reader-deck { margin: 24px 0; }
.reader-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 18px;
}
.card-media { display: flex; align-items: center; justify-content: center; }
.card-media img { width: 100%; }
.card-body { padding: 24px 22px 12px; }
.card-text { margin: 0 auto; max-width: 62ch; text-align: left; line-height: 1.8; }
.sentence { display: block; margin: 0 0 0.6em; border-left: 3px solid transparent; }
.sentence.playing { background: rgba(127, 127, 127, 0.16); border-left-color: var(--accent); }
.reader-dots { display: none; }

/* Enhanced by assets/reader.js */
.reader-deck.reader-ready {
  position: relative;
  height: calc(100dvh - 190px);
  min-height: 400px;
  margin: 16px 0;
  overflow: hidden;
  touch-action: pan-y;
}
.reader-deck.reader-ready .reader-track {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform 260ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.reader-deck.reader-ready .reader-card {
  flex: 0 0 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  margin: 0;
  overflow: hidden;
}
.reader-deck.reader-ready .card-media {
  flex: 0 0 46%;
  overflow: hidden;
  border-radius: 10px;
  background: var(--line);
}
.reader-deck.reader-ready .card-media:empty { display: none; }
.reader-deck.reader-ready .card-media img {
  max-height: 100%;
  width: auto;
  object-fit: contain;
}
.reader-deck.reader-ready .card-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y; /* own scroll container: needs pan-y or it eats horizontal swipes */
  padding: 24px 22px 120px;
}
.reader-deck.reader-ready .reader-dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  z-index: 2;
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 2px;
  padding: 8px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0));
  touch-action: manipulation;
}
.reader-dots .reader-dot {
  position: relative;
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
}
.reader-dots .reader-dot::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}
.reader-dots .reader-dot[aria-current="true"]::after { background: var(--accent); }
.reader-dots .reader-dot:focus-visible { outline: 2px solid #fff; outline-offset: 1px; border-radius: 50%; }

.reader-next-post {
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
  color: var(--fg);
  text-decoration: none;
}
.next-post-label {
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.next-post-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.next-post-arrow { font-size: 1.2rem; color: var(--accent); }
.reader-next-post:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

@media (min-width: 720px) {
  .reader-deck.reader-ready {
    height: min(80vh, 760px);
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reader-deck.reader-ready .reader-track { transition: none; }
}

/* Full-page reader on phones */
.reader-topbar { display: none; }
.reader-top-title { margin: 0; font-size: 1rem; }

body.reader-fullscreen {
  overflow: hidden;
  overscroll-behavior: none;
}
body.reader-fullscreen main { max-width: none; min-height: 0; padding: 0; }
body.reader-fullscreen .site-header,
body.reader-fullscreen .site-footer,
body.reader-fullscreen .story > .story-title,
body.reader-fullscreen .story > .story-meta,
body.reader-fullscreen .story > .story-source,
body.reader-fullscreen .back-link { display: none; }
body.reader-fullscreen .story {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
}
body.reader-fullscreen .reader-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 12px 4px;
  border-bottom: 1px solid var(--line);
}
body.reader-fullscreen .reader-back {
  flex: 0 0 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
body.reader-fullscreen .reader-top-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
body.reader-fullscreen .reader-top-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.9rem;
}
body.reader-fullscreen .reader-deck.reader-ready {
  flex: 1;
  height: auto;
  min-height: 0;
  margin: 0;
}
body.reader-fullscreen .reader-next-post {
  width: 100%;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
body.reader-fullscreen .card-media img { -webkit-touch-callout: none; }
body.reader-fullscreen .reader-deck.is-swiping,
body.reader-fullscreen .reader-deck.is-swiping .card-text {
  user-select: none;
  -webkit-user-select: none;
}

/* Image skeletons and scroll hint */
@keyframes skeleton-shimmer {
  from { background-position: -180% 0; }
  to { background-position: 180% 0; }
}
.cover-slide.skeleton,
.reader-card.skeleton .card-media {
  background-image: linear-gradient(100deg, var(--line) 25%, var(--card) 45%, var(--line) 65%);
  background-size: 220% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
}
.cover-image, .card-image { transition: opacity 220ms ease; }
.skeleton .cover-image, .skeleton .card-image { opacity: 0; }
.reader-deck.reader-ready .reader-card { position: relative; }
.scroll-hint { display: none; }
.reader-card.hint-visible .scroll-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 16px;
  bottom: 68px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1rem;
  pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
  .cover-slide.skeleton,
  .reader-card.skeleton .card-media { animation: none; }
  .cover-image, .card-image { transition: none; }
}

/* Home cover feed */
body.home-picker main { max-width: none; padding: 0; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
body.home-picker .empty-state { padding: 24px 20px; }

.feed-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent);
  color: #fff;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}
.feed-brand { font-weight: 700; text-transform: uppercase; }
.feed-count { display: none; opacity: 0.9; }
body.home-picker:has(.cover-feed.feed-ready) .feed-count { display: block; }

.cover-feed { display: block; }
.cover-feed.feed-ready {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scroll-snap-type: y mandatory;
}
.cover-slide {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--line);
}
.feed-ready .cover-slide {
  height: 100vh;
  height: 100dvh;
  scroll-snap-align: start;
}
.cover-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
}
.cover-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.35) 55%, rgba(0, 0, 0, 0.2)),
    rgba(0, 0, 0, 0.25);
}
.cover-content {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 32px 24px calc(110px + env(safe-area-inset-bottom));
  color: #fff;
}
.cover-title {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
  max-width: 18ch;
}
.cover-meta { margin: 0 0 24px; font-size: 0.9rem; opacity: 0.9; }
.cover-read {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 24px;
  border-radius: 999px;
  background: #fff;
  color: #1b1814;
  font-weight: 700;
  text-decoration: none;
  touch-action: manipulation;
}
.cover-read:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.feed-next { display: none; }
body.home-picker:has(.cover-feed.feed-ready) .feed-next {
  display: block;
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 4;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  touch-action: manipulation;
}
.feed-next:disabled { opacity: 0.3; cursor: default; }

.site-footer {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  padding-bottom: 32px;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 480px) {
  body { font-size: 16px; }
  .site-header { padding-top: 20px; }
  .story > .story-title { font-size: 1.6rem; }
}

/* Theme toggle */
.theme-toggle,
.listen-toggle {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
.theme-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: -4px; }
.listen-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: -4px; }
.listen-toggle.listen-on,
.listen-toggle[aria-pressed="true"] { background: rgba(127, 127, 127, 0.18); color: var(--accent); }
.listen-icon { width: 20px; height: 20px; }
.theme-icon { display: none; width: 20px; height: 20px; }
:root[data-theme="light"] .theme-icon[data-mode="light"],
:root[data-theme="dark"] .theme-icon[data-mode="dark"],
:root:not([data-theme="light"]):not([data-theme="dark"]) .theme-icon[data-mode="auto"] {
  display: block;
}

/* Desktop post pages have no reader top bar: keep the theme and listen toggles reachable */
@media (min-width: 720px) {
  .reader-topbar {
    display: flex;
    justify-content: flex-end;
    min-height: 0;
    padding: 0;
  }
  .reader-topbar > :not(.theme-toggle):not(.listen-toggle) { display: none; }
}

/* Topic index page */
.feed-left, .feed-right { display: flex; align-items: center; gap: 10px; }
.feed-link { color: #fff; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.brand-mark { display: inline-block; vertical-align: middle; width: 1.25em; height: 1.25em; border-radius: 6px; }
.topic-title { font-size: 1.25rem; margin: 40px 0 16px; letter-spacing: -0.01em; }
.page-intro { color: var(--muted); margin: -12px 0 8px; }
