:root {
  --paper: #f3eee6;
  --card: #fffdf9;
  --ink: #221c18;
  --muted: #6d6258;
  --line: #e4d7c8;
  --brick: #9a3f32;
  --brick-dark: #7c3128;
  --moss: #234237;
  --tint: #f8ece8;
  --shadow: 0 10px 30px rgba(60, 40, 20, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
}

button, input { font: inherit; }

button {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--brick);
  outline-offset: 2px;
}

.wrap {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 20px 16px calc(230px + env(safe-area-inset-bottom));
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brick);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Songti SC", "STSong", serif;
  font-size: 1.85rem;
  font-weight: 650;
  line-height: 1.25;
}

.en-title, .setup, .meta, .lead, .hint, .foot, .note {
  color: var(--muted);
}

.en-title { margin: 8px 0 0; }

.setup { margin: 14px 0 0; color: var(--ink); white-space: pre-line; }

.meta { margin: 10px 0 0; font-size: 0.92rem; }

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 18px;
}

.primary, .secondary, .ghost, .chip, .line button, .mode button {
  min-height: 44px;
  border-radius: 999px;
  padding: 10px 16px;
}

.primary {
  background: var(--brick);
  color: #fffdf9;
}

.primary:active { background: var(--brick-dark); }

.secondary, .ghost, .mode button, .line button, .chip {
  background: var(--card);
  border: 1px solid var(--line);
}

.mode {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.mode button { flex: 1; }

.mode button[aria-pressed="true"] {
  background: var(--ink);
  color: #fffdf9;
  border-color: var(--ink);
}

.panel, .line, .banner, details {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.panel, details { margin-top: 16px; padding: 14px; }

.panel h2, details summary {
  margin: 0;
  font-size: 1rem;
}

.lead { margin: 8px 0 0; }

.lines { display: grid; gap: 10px; margin-top: 12px; }

.line {
  padding: 12px;
  text-align: left;
  box-shadow: none;
}

.line.active {
  border-color: var(--brick);
  box-shadow: inset 3px 0 0 var(--brick);
}

.line, .chip, .actions { scroll-margin-bottom: 240px; }

.en {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.zh, .note { margin: 8px 0 0; }

.zh { color: var(--moss); }

.note {
  padding: 8px 10px;
  background: #f7f3ec;
  border-radius: 10px;
  font-size: 0.92rem;
}

.line .row, .done-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chapters { display: grid; gap: 8px; margin-top: 12px; }

.chip {
  display: grid;
  grid-template-columns: 4.2rem 1fr;
  gap: 8px;
  width: 100%;
  border-radius: 14px;
  text-align: left;
  align-items: center;
}

.chip[aria-current="true"] {
  border-color: var(--brick);
}

.chip small { display: block; color: var(--muted); }

.banner {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--tint);
  border-color: #efcfc8;
}

.banner strong { color: var(--brick-dark); }

.banner p { margin: 6px 0 0; }

.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  background: #fffdf9;
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
}

.player-inner { width: min(720px, 100%); margin: 0 auto; }

.now-label {
  margin: 0 0 2px;
  min-height: 1.3em;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.time {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--brick);
}

.transport, .rates {
  display: flex;
  gap: 8px;
  align-items: center;
}

.transport { margin-top: 2px; }

.play {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 50%;
  background: var(--brick);
  color: white;
  font-size: 1.15rem;
}

.transport .secondary, .rates button { flex: 1; }

.rates { margin-top: 6px; }

.transport .secondary, .rates button { min-height: 40px; padding: 6px 8px; }

.rates button[aria-pressed="true"] {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.foot { margin: 16px 0 0; font-size: 0.85rem; }

body.view-hall #storyView { display: none; }
body.view-story #hallView { display: none; }
body.view-hall:not(.has-audio) .player { display: none; }
body.view-hall:not(.has-audio) .wrap { padding-bottom: 28px; }

#backHall, #backPractice, #backPracticeStory { margin-bottom: 12px; }

.cards { display: grid; gap: 12px; margin-top: 16px; }

.story-card {
  width: 100%;
  text-align: left;
  padding: 16px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
}

.story-card strong { display: block; font-size: 1.15rem; }
.story-card p { margin: 8px 0 0; }

.scene-layer {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(34, 28, 24, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

.scene-layer video {
  width: min(100%, 420px);
  max-height: 70vh;
  background: #000;
}

#notice { margin: 0 auto; width: min(720px, 100%); }

details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }

details ol { margin: 8px 0 0; padding-left: 1.2rem; }

.hidden { display: none !important; }

.help-copy p { margin: 10px 0 0; }

.help-copy a,
.source-page a { color: var(--brick-dark); }

a.secondary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-decoration: none;
}

.source-page { padding-bottom: 28px; }

@media (max-width: 420px) {
  .player { padding: 4px 12px calc(4px + env(safe-area-inset-bottom)); }
  .now-label { margin-bottom: 0; }
  .play { width: 44px; height: 44px; flex-basis: 44px; }
  .rates { flex-wrap: nowrap; }
  .rates button,
  #back15 {
    min-width: 0;
    min-height: 44px;
    padding-left: 4px;
    padding-right: 4px;
  }
  #back15 { flex: 1.4 1 0; font-size: 0.86rem; }
  body.view-story .wrap,
  body.view-hall.has-audio .wrap {
    padding-bottom: calc(250px + env(safe-area-inset-bottom));
  }
  .line, .chip, .actions { scroll-margin-bottom: 270px; }
}

@media (min-width: 800px) {
  .wrap { padding-top: 32px; }
}
