:root {
  --bg: #f6efe2;
  --surface: #fffaf0;
  --text: #3b2a2f;
  --muted: #76606a;
  --accent: #a8483a;
  --border: #e6d9c3;
  --shadow: 0 2px 10px rgba(80, 50, 30, 0.08);
  --story-size: 1.25rem;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1a24;
    --surface: #2a2330;
    --text: #f1e7da;
    --muted: #b8a9b0;
    --accent: #f0a08b;
    --border: #3d3345;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #1f1a24;
  --surface: #2a2330;
  --text: #f1e7da;
  --muted: #b8a9b0;
  --accent: #f0a08b;
  --border: #3d3345;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  line-height: 1.6;
}

a { color: var(--accent); }
a:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.page {
  max-width: 44rem;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.page > main { flex: 1; }

.hero { text-align: center; padding: 40px 0 24px; }
.hero h1 { font-size: clamp(2rem, 8vw, 3rem); margin: 0; line-height: 1.15; letter-spacing: 0.01em; }
.tagline { margin: 8px 0 0; color: var(--muted); font-size: 1.1rem; font-style: italic; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.card {
  display: flex;
  gap: 16px;
  align-items: stretch;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-img { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; flex: none; }
.card-text { min-width: 0; }
.card h2 { margin: 0 0 6px; font-size: 1.4rem; line-height: 1.25; color: var(--accent); overflow-wrap: anywhere; }
.summary { margin: 0 0 10px; }

.meta { margin: 0; color: var(--muted); font-family: var(--sans); font-size: 0.875rem; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.dot { opacity: 0.6; }
.badge { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 1px 10px; }

.empty { text-align: center; color: var(--muted); font-style: italic; padding: 40px 0; }

.back { margin: 20px 0 0; font-family: var(--sans); font-size: 0.95rem; }

.story header { padding: 16px 0 8px; }
.story h1 { font-size: clamp(1.9rem, 7vw, 2.6rem); line-height: 1.2; margin: 0 0 10px; overflow-wrap: anywhere; }

.reader-controls { margin-top: 12px; display: flex; gap: 8px; }
.reader-controls button {
  font: 600 1rem var(--sans);
  min-width: 48px;
  min-height: 44px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.reader-controls button:hover { border-color: var(--accent); }

.story-img {
  display: block;
  width: 100%;
  height: auto;
  margin: 12px 0 8px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.audio {
  margin: 16px 0 8px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.audio p { margin: 0 0 8px; font-family: var(--sans); font-weight: 600; }
.audio audio { width: 100%; }

.story-text { font-size: var(--story-size); line-height: 1.75; padding: 8px 0 24px; }
.story-text p { margin: 0 0 1.1em; }
.story-text h2, .story-text h3 { line-height: 1.3; margin: 1.6em 0 0.6em; color: var(--accent); }
.story-text blockquote { margin: 1.2em 0; padding: 4px 0 4px 18px; border-left: 4px solid var(--accent); font-style: italic; }
.story-text blockquote p { margin: 0; }
.story-text ul { margin: 0 0 1.1em; padding-left: 1.3em; }
.story-text li { margin-bottom: 0.5em; }
.story-text .verse { margin: 1.2em 0; padding: 4px 0 4px 18px; border-left: 4px solid var(--accent); font-style: italic; }
.story-figure { margin: 1.6em 0; }
.story-figure img { display: block; width: 100%; height: auto; border-radius: 16px; box-shadow: var(--shadow); }
.story-figure figcaption { margin-top: 8px; font-family: var(--sans); font-size: 0.875rem; font-style: italic; color: var(--muted); text-align: center; }
.story-text hr { border: 0; text-align: center; margin: 1.8em 0; }
.story-text hr::before { content: "✦ ✦ ✦"; color: var(--muted); letter-spacing: 0.5em; }

.story-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 8px 0 32px; font-family: var(--sans); }
.story-nav a {
  display: block;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.story-nav a span { display: block; color: var(--muted); font-size: 0.8rem; margin-bottom: 2px; }
.story-nav .next { text-align: right; grid-column: 2; }
.story-nav .prev { grid-column: 1; }

.not-found { text-align: center; padding: 64px 0; }

.footer { text-align: center; padding: 24px 0 32px; font-family: var(--sans); font-size: 0.875rem; color: var(--muted); }
.footer a { color: var(--muted); }

@media (max-width: 420px) {
  .card { flex-direction: column; }
  .card-img { width: 100%; height: 160px; }
  .story-nav { grid-template-columns: 1fr; }
  .story-nav .next, .story-nav .prev { grid-column: 1; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card:hover { transform: none; }
}
