:root {
  --bg: #f7f3e9;
  --bg-card: #ffffff;
  --ink: #2c3a2e;
  --ink-soft: #5f6f62;
  --accent: #5b8c5a;
  --accent-2: #c4a35a;
  --accent-3: #7a9e7e;
  --earth: #a67c52;
  --leaf: #6b9b6e;
  --sky: #dceee0;
  --line: #e6ddd0;
  --shadow: 0 8px 24px rgba(44, 58, 46, 0.08);
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, "Nunito", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 380px at 8% -8%, #e8f0d8 0%, transparent 55%),
    radial-gradient(900px 320px at 100% 0%, #f0e6d4 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 17px;
}

.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 14px 24px;
}

.topbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 14px 0 10px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}
.brand-emoji {
  font-size: 1.55rem;
  background: #fff;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 0.98rem; }
.brand-text small { color: var(--ink-soft); font-size: 0.72rem; }

.nav {
  width: 100%;
  display: flex;
  gap: 6px;
  justify-content: flex-start;
  flex-wrap: wrap;
}
.nav a {
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 999px;
}
.nav a.active, .nav a:hover {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.main { flex: 1; padding-bottom: 12px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

h1 { font-size: 1.5rem; margin: 0 0 8px; letter-spacing: -0.02em; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 8px; line-height: 1.3; }
p { margin: 0 0 10px; }
.muted { color: var(--ink-soft); font-size: 0.95rem; }

.intro {
  background: linear-gradient(135deg, #eef5e8, #f8f0e4);
  border-left: 4px solid var(--accent);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.98rem;
  margin: 10px 0 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  border-radius: 999px;
  padding: 13px 18px;
  text-decoration: none;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 0 #3f6640;
  transition: transform 0.08s ease;
  text-align: center;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #3f6640; }
.btn.secondary {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  box-shadow: none;
}
.btn.earth {
  background: var(--earth);
  box-shadow: 0 4px 0 #7a5a3a;
}
.btn.earth:active { box-shadow: 0 2px 0 #7a5a3a; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-block { width: 100%; }

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.choice-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.35;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--line);
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.08s ease;
}
.choice-btn:hover, .choice-btn:focus-visible {
  border-color: var(--accent);
  background: #f3f8f2;
  outline: none;
}
.choice-btn:active { transform: translateY(1px); box-shadow: none; }

.pill {
  display: inline-block;
  background: #e8f0d8;
  color: #3d5c3a;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-right: 4px;
  margin-bottom: 4px;
}
.pill.gold {
  background: #f5ecd8;
  color: #7a5e28;
}

.story-card {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.story-card:active { transform: scale(0.99); }
.story-card .story-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0 4px;
}
.story-card .done-note {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
  margin-top: 6px;
}

.art-wrap {
  background: linear-gradient(180deg, #eaf3e6 0%, #f7f3e9 100%);
  border-radius: 14px;
  border: 1px solid var(--line);
  margin: 4px 0 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
}
.art-wrap svg {
  width: 100%;
  height: auto;
  max-height: 220px;
  display: block;
}

.scene-text {
  font-size: 1.08rem;
  line-height: 1.55;
  margin: 0 0 4px;
}

.ending-box {
  background: linear-gradient(135deg, #eef5e8, #f8f0e4);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 12px 0;
  border: 1px solid var(--line);
}
.ending-box .label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 6px;
}
.ending-box .realisation {
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 0;
}

.progress-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-3);
  margin-right: 4px;
  opacity: 0.45;
}
.progress-dot.on { opacity: 1; background: var(--accent); }

.finished-list { list-style: none; padding: 0; margin: 0; }
.finished-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.finished-list li:last-child { border-bottom: none; }
.finished-list .when { color: var(--ink-soft); font-size: 0.85rem; white-space: nowrap; }

.footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.78rem;
  padding: 16px 0 8px;
}
.footer p { margin: 0; }

.empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--ink-soft);
}

.loading {
  text-align: center;
  padding: 40px 12px;
  color: var(--ink-soft);
}

@media (min-width: 480px) {
  body { font-size: 18px; }
  .app { padding: 0 18px 28px; }
}

.origin { font-size: 0.82rem; margin: 6px 0 8px; line-height: 1.35; }
.origin-line { font-size: 0.8rem; margin: 0 0 8px; line-height: 1.35; }


.brand-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}
.audio-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  border: 2px solid var(--accent); background: #fff;
  border-radius: 999px; padding: 7px 10px; cursor: pointer;
  font: inherit; font-size: 0.8rem; font-weight: 750; color: var(--accent);
  box-shadow: var(--shadow); flex-shrink: 0;
  white-space: nowrap;
}
.audio-toggle.on, .audio-toggle.mini.on {
  background: var(--accent); color: #fff;
}
.audio-toggle.mini { padding: 5px 10px; font-size: 0.75rem; border-width: 1.5px; opacity: 0.95; }
.audio-toggle .audio-icon { font-size: 1rem; line-height: 1; }
.audio-toggle:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.talk-card { background: linear-gradient(180deg, #fff 0%, #f3f8ef 100%); }
.talk-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.talk-kicker { margin: 0; font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }
.talk-row { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; }
.narrator { flex-shrink: 0; text-align: center; width: 76px; }
.narrator-name { font-size: 0.75rem; font-weight: 700; color: var(--accent); margin-top: 2px; }
.narrator-avatar { filter: drop-shadow(0 4px 8px rgba(0,0,0,.08)); }
.narrator.talking .mouth { animation: talk 0.28s ease-in-out infinite alternate; }
@keyframes talk { from { ry: 3; } to { ry: 7; } }
.speech-bubble {
  flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 14px; position: relative; box-shadow: var(--shadow);
}
.speech-bubble::before {
  content: ""; position: absolute; left: -8px; top: 18px;
  border: 8px solid transparent; border-right-color: #fff; filter: drop-shadow(-1px 0 0 var(--line));
}
.speech-bubble .scene-text { margin: 0; font-size: 1.05rem; }
.listening-hint { margin: 8px 0 0; font-size: 0.88rem; }
.linkish {
  background: none; border: 0; color: var(--accent); font: inherit; font-weight: 700;
  text-decoration: underline; cursor: pointer; padding: 0;
}
.choice-stage { margin-top: 14px; }
.choice-stage.in { animation: rise 0.35s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
body.listen-mode .topbar .audio-toggle { box-shadow: 0 0 0 3px rgba(91,140,90,.25); }

.nav a { padding: 7px 9px; font-size: 0.82rem; }

.narrator { cursor: pointer; border-radius: 12px; }
.narrator:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.narrator-tap {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.2;
  margin-top: 1px;
}

.voice-list { display: flex; flex-direction: column; gap: 10px; }
.voice-card {
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}
.voice-card.selected {
  border-color: var(--accent);
  background: linear-gradient(180deg, #fff 0%, #f3f8ef 100%);
  box-shadow: 0 0 0 3px rgba(91, 140, 90, 0.18), var(--shadow);
}
.voice-select {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0 0 10px;
  margin: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: inherit;
}
.voice-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.voice-name { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.voice-vibe { font-size: 0.92rem; color: var(--ink-soft); font-weight: 600; }
.voice-hint {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ink-soft);
  opacity: 0.8;
  line-height: 1.3;
}
.voice-picked {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  background: #f3eee4;
  border-radius: 999px;
  padding: 5px 9px;
}
.voice-card.selected .voice-picked {
  background: #e8f0d8;
  color: #3d5c3a;
}
.voice-preview {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.92rem;
}
.speed-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.speed-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 28px;
  cursor: pointer;
}
