:root {
  --desk: #e9e2d2;
  --paper: #fbf8f1;
  --ink: #26282c;
  --muted: #74706a;
  --rule: #e2dacb;
  --rail: #2f8a5a;
  --rail-soft: #e3f1e8;
  --on-rail: #fff;
  --a: #c4612c;
  --a-soft: #f8e9df;
  --b: #2f68a8;
  --b-soft: #e4edf7;
  --right: #2f8a5a;
  --wrong: #c0453a;
  --shadow: 0 1px 2px rgb(60 45 20 / 0.08), 0 12px 32px -12px rgb(60 45 20 / 0.25);
  --serif: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  --sans: "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #15181c;
    --paper: #1f2328;
    --ink: #ece7dc;
    --muted: #9c978e;
    --rule: #343941;
    --rail: #5cbf8a;
    --rail-soft: #213b2d;
    --on-rail: #10241a;
    --a: #e8925f;
    --a-soft: #3a2a21;
    --b: #7fb0e6;
    --b-soft: #22303f;
    --right: #5cbf8a;
    --wrong: #ec7b70;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 12px 32px -12px rgb(0 0 0 / 0.6);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--desk);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [role="button"]:focus-visible { outline: 2px solid var(--rail); outline-offset: 2px; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
}

/* ---------- top bar ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}

.bar-title {
  margin: 0;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-title [lang="ja"] { font-family: var(--serif); font-weight: 700; }
.bar-page { color: var(--muted); margin-left: 8px; }
.shelf-link { margin-right: 10px; color: var(--rail); text-decoration: none; font-weight: 500; }
.shelf-link:hover { text-decoration: underline; }

/* ---------- home contents ---------- */

.shelf-mode .toggles, .shelf-mode .route { display: none; }

.toggles { display: flex; gap: 4px; flex-shrink: 0; }

.toggle {
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--muted);
}
.toggle[aria-pressed="true"] { background: var(--rail); border-color: var(--rail); color: var(--on-rail); }

/* ---------- page ---------- */

.stage {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 24px;
  outline: none;
}

.page {
  background: var(--paper);
  border-radius: 6px;
  box-shadow: var(--shadow);
  min-height: 100%;
  padding: 28px clamp(16px, 5vw, 44px) 40px;
}
.from-right { animation: from-right 0.32s ease-out; }
.from-left { animation: from-left 0.32s ease-out; }
@keyframes from-right { from { opacity: 0; transform: translateX(28px); } }
@keyframes from-left { from { opacity: 0; transform: translateX(-28px); } }
@media (prefers-reduced-motion: reduce) {
  .from-right, .from-left { animation: none; }
}

.muted { color: var(--muted); font-size: 13px; }

.pill {
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
}
.pill:hover { border-color: var(--rail); color: var(--rail); }
.pill.playing { background: var(--rail); border-color: var(--rail); color: var(--on-rail); }

.primary {
  border: 0;
  background: var(--rail);
  color: var(--on-rail);
  border-radius: 999px;
  padding: 10px 24px;
  font-size: 15px;
  font-weight: 500;
}
.primary:hover { filter: brightness(1.08); }

/* ---------- cover ---------- */

.cover { padding: 0; overflow: hidden; }
.cover-art img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.cover-body { padding: 24px clamp(16px, 5vw, 44px) 36px; }
.kicker { margin: 0; color: var(--rail); font-size: 13px; letter-spacing: 0.1em; }
.cover-title { margin: 4px 0 0; font-family: var(--serif); font-size: clamp(34px, 8vw, 48px); line-height: 1.2; }
.cover-sub { margin: 6px 0 20px; color: var(--muted); }
.cover-summary { margin: 0 0 6px; font-size: 16px; }
.cover-summary.ja { font-family: var(--serif); color: var(--muted); font-size: 15px; }

.cast { list-style: none; padding: 0; margin: 24px 0 0; display: flex; gap: 20px; flex-wrap: wrap; }
.cast li { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.cast b { color: var(--ink); margin-right: 6px; }

.how { margin: 24px 0 28px; padding-left: 20px; color: var(--muted); font-size: 14px; }
.cover-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* ---------- contents ---------- */

.toc-head { text-align: center; margin-bottom: 8px; }
.toc-head h1 { margin: 4px 0; font-family: var(--serif); font-size: clamp(32px, 8vw, 44px); letter-spacing: 0.4em; padding-left: 0.4em; }
.toc-head p { margin: 0; }
.epub-download { margin-top: 16px !important; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 12px; }
.epub-download .pill { color: var(--rail); border-color: var(--rail); text-decoration: none; font-weight: 500; }
.epub-download .pill:hover { background: var(--rail); color: var(--on-rail); }
.toc-chapter { margin-top: 32px; }
.toc-chapter-head {
  display: flex;
  gap: 16px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--ink);
  color: inherit;
  text-decoration: none;
}
a.toc-chapter-head:hover b { color: var(--rail); }
.toc-chapter-head img { width: 120px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.toc-chapter-text { display: flex; flex-direction: column; min-width: 0; }
.toc-chapter-text b { font-family: var(--serif); font-size: 26px; line-height: 1.3; }
.toc-chapter-zh { color: var(--muted); font-size: 14px; }
.toc-chapter-summary { margin-top: 4px; font-size: 14px; }
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--rule);
  color: inherit;
  text-decoration: none;
}
.toc-row:hover { background: var(--rail-soft); }
.toc-no { width: 1.6em; flex-shrink: 0; color: var(--rail); font-weight: 700; text-align: center; }
.toc-title { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 10px; min-width: 0; }
.toc-title [lang="ja"] { font-family: var(--serif); font-size: 17px; }
.toc-title small { color: var(--muted); font-size: 13px; }
.toc-leader { flex: 1; min-width: 16px; border-bottom: 2px dotted var(--rule); transform: translateY(-4px); }
.toc-num { flex-shrink: 0; font-variant-numeric: tabular-nums; color: var(--muted); }
.toc-practice .toc-no { color: var(--muted); font-weight: 500; }
.toc-practice .toc-title [lang="ja"] { font-size: 15px; }
@media (max-width: 480px) {
  .toc-chapter-head img { width: 88px; }
  .toc-chapter-text b { font-size: 22px; }
}

/* ---------- avatars ---------- */

.avatar {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}
.speaker-A .avatar { background: var(--a); }
.speaker-B .avatar { background: var(--b); }

/* ---------- scene: station sign header ---------- */

.ekimei {
  text-align: center;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 18px;
}
.ekimei-no { margin: 12px 0 0; font-size: 12px; color: var(--muted); letter-spacing: 0.15em; }
.ekimei h2 { margin: 2px 12px 0; font-family: var(--serif); font-size: clamp(24px, 6vw, 32px); line-height: 1.3; }
.ekimei-zh { margin: 2px 0 12px; color: var(--muted); font-size: 14px; }
.ekimei-band {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 12px;
  background: var(--rail);
  color: var(--on-rail);
  font-family: var(--serif);
  font-size: 13px;
}

.scene-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.scene-tools > .muted:not(.listen-hint) { margin-left: auto; }
.listen-hint { flex-basis: 100%; margin: 0; }

.pill:disabled { opacity: 0.45; cursor: default; color: inherit; border-color: var(--rule); }
.primary.small { padding: 6px 16px; font-size: 14px; }
.link { border: 0; background: none; padding: 6px 4px; font-size: 13px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- role play ---------- */

.role-panel {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--rail-soft);
}
.role-panel p { margin: 0 0 4px; }
.role-title { font-weight: 700; }
.role-pick { display: flex; gap: 10px; margin: 10px 0 4px; flex-wrap: wrap; }
.role-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 8px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper);
  text-align: left;
}
.role-choice:hover { border-color: var(--rail); }
.role-choice b { display: block; line-height: 1.2; }
.role-choice small { color: var(--muted); }
.role-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }

.take-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.take-btn {
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 13px;
}
.take-btn:hover { border-color: var(--rail); }
.take-btn.playing { background: var(--rail); border-color: var(--rail); color: var(--on-rail); }
.take-btn.record.on { background: var(--wrong); border-color: var(--wrong); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
.turn-hint { display: none; font-size: 13px; font-weight: 700; color: var(--rail); }
.your-turn .turn-hint { display: inline; }
.your-turn .take-btn.record:not(.on) { background: var(--rail); border-color: var(--rail); color: var(--on-rail); animation: pulse 1.2s ease-in-out infinite; }
.your-turn .bubble { box-shadow: 0 0 0 2px var(--rail); }
.speaker-A.mine .bubble { outline: 2px dashed var(--a); outline-offset: -2px; }
.speaker-B.mine .bubble { outline: 2px dashed var(--b); outline-offset: -2px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgb(47 138 90 / 0); } 0%, 100% { box-shadow: 0 0 0 0 rgb(47 138 90 / 0.45); } }
@media (prefers-reduced-motion: reduce) {
  .take-btn.record.on, .your-turn .take-btn.record:not(.on) { animation: none; }
}

/* 先聽再看: text stays blurred until the line has been heard */
.listen-first .turn:not(.seen):not(.mine) .ja { filter: blur(7px); user-select: none; }
.listen-first .turn:not(.seen):not(.mine) .word { pointer-events: none; }
.listen-first .turn:not(.seen):not(.mine) .zh { display: none; }
.listen-first .turn .ja { transition: filter 0.5s; }

/* ---------- dialogue ---------- */

.dialogue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }

.turn { display: flex; align-items: flex-start; gap: 8px; scroll-margin: 24px; }
.turn.speaker-B { flex-direction: row-reverse; }

.turn-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
  max-width: min(88%, 520px);
}
.speaker-B .turn-body { align-items: flex-end; }

.bubble {
  position: relative;
  padding: 10px 14px 12px;
  border-radius: 14px;
  cursor: pointer;
  overflow: hidden;
  transition: box-shadow 0.15s;
}
.speaker-A .bubble { background: var(--a-soft); border-top-left-radius: 4px; }
.speaker-B .bubble { background: var(--b-soft); border-top-right-radius: 4px; }
.speaker-A.playing .bubble { box-shadow: 0 0 0 2px var(--a); }
.speaker-B.playing .bubble { box-shadow: 0 0 0 2px var(--b); }

.ja { margin: 0; font-family: var(--serif); font-size: 18px; line-height: 2; }
.zh { display: none; margin: 4px 0 0; font-size: 14px; color: var(--muted); line-height: 1.6; }
.show-zh .zh, .reveal .zh { display: block; }

.progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: calc(var(--p, 0) * 100%);
  opacity: 0;
}
.playing .progress { opacity: 1; }
.speaker-A .progress { background: var(--a); }
.speaker-B .progress { background: var(--b); }

.turn-tools { align-self: center; flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; }
.line-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: transparent;
  font-size: 12px;
  color: var(--muted);
  padding: 0;
}
.line-play::before { content: "▶"; font-size: 10px; padding-left: 2px; }
.playing .line-play::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 10px;
  padding: 0;
  background: linear-gradient(90deg, currentColor 0 3px, transparent 3px 5px, currentColor 5px 8px);
}
.playing.paused .line-play::before { content: "▶"; display: inline; width: auto; height: auto; padding-left: 2px; background: none; }
.speaker-A.playing .line-play { background: var(--a); border-color: var(--a); color: #fff; }
.speaker-B.playing .line-play { background: var(--b); border-color: var(--b); color: #fff; }
.show-zh .zh-btn { visibility: hidden; }
.reveal .zh-btn { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.word {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  border-bottom: 2px dotted var(--rail);
  line-height: inherit;
}
.word:hover { background: var(--rail-soft); }
.word + .word { margin-left: 3px; }
rt { font-family: var(--sans); font-size: 0.5em; color: var(--rail); letter-spacing: 0; }
body:not(.show-furigana) rt { display: none; }

/* ---------- fact card ---------- */

.fact {
  margin-top: 28px;
  padding: 16px 18px;
  border: 1px dashed var(--rail);
  border-radius: 8px;
  background: var(--rail-soft);
}
.fact p { margin: 0; }
.fact-title { font-weight: 700; margin-bottom: 14px !important; }
.fact-line { display: flex; align-items: center; gap: 8px; }
.fact-rail { flex: 1; height: 4px; border-radius: 2px; background: repeating-linear-gradient(90deg, var(--rail) 0 14px, transparent 14px 20px); }
.fact-station {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  padding: 4px 6px;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
}
.fact-station .dot { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--rail); background: var(--paper); }
.fact-station.on .dot { background: var(--rail); }
.fact-detail { margin-top: 12px !important; min-height: 1.6em; font-size: 15px; }

/* ---------- light-up card ---------- */

.lightup { margin-top: 28px; padding: 16px 18px; border: 1px dashed var(--rail); border-radius: 8px; background: var(--rail-soft); }
.lightup .fact-title { margin: 0 0 12px; }
.lightup-frame { border-radius: 8px; overflow: hidden; background: #0c0d12; }
.lightup-frame img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: 30% 30%;
  filter: brightness(0.32) saturate(0.25) contrast(1.1);
  transition: filter 1.4s ease-out;
}
.lit .lightup-frame img { filter: none; }
.lit .lightup-frame { box-shadow: 0 0 32px -4px rgb(255 170 60 / 0.55); transition: box-shadow 1.4s; }
.lightup-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.lightup-caption { margin: 0; font-size: 15px; }
.lightup-row .primary { flex-shrink: 0; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .lightup-frame img { transition: none; } }

/* ---------- trivia cards ---------- */

.trivia { margin-top: 16px; border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
.trivia-q {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: var(--paper);
  padding: 12px 14px;
  text-align: left;
  font-weight: 500;
}
.trivia-q:hover { background: var(--rail-soft); }
.trivia-icon { font-size: 26px; line-height: 1; }
.trivia-text { flex: 1; }
.trivia-text small { display: block; color: var(--rail); font-size: 12px; font-weight: 700; }
.trivia-chev::before { content: "+"; font-size: 20px; color: var(--muted); }
.trivia-q[aria-expanded="true"] .trivia-chev::before { content: "−"; }
.trivia-a { margin: 0; padding: 0 14px 14px 52px; color: var(--ink); font-size: 15px; animation: fade-in 0.25s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- other pages ---------- */

.page-head h2 { margin: 0; font-family: var(--serif); font-size: clamp(26px, 6vw, 32px); }
.page-head p { margin: 0; color: var(--muted); }
.tip { margin: 8px 0 20px; }

/* word cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.card-wrap { display: flex; flex-direction: column; gap: 4px; }
.card { display: grid; perspective: 600px; cursor: pointer; }
.card-face {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 104px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--paper);
  text-align: center;
  backface-visibility: hidden;
  transition: transform 0.4s;
}
.card-front b { font-family: var(--serif); font-size: 22px; }
.card-reading { font-size: 12px; color: var(--rail); }
body:not(.show-furigana) .card-reading { visibility: hidden; }
.card-back { transform: rotateY(180deg); background: var(--rail-soft); border-color: var(--rail); font-size: 14px; }
.card-back p { margin: 0; }
.card-back .en { color: var(--muted); font-size: 12px; margin-top: 4px; }
.card.flipped .card-front { transform: rotateY(-180deg); }
.card.flipped .card-back { transform: rotateY(0); }
@media (prefers-reduced-motion: reduce) { .card-face { transition: none; } }

.card-actions { display: flex; justify-content: center; gap: 6px; }
.icon {
  width: 32px;
  height: 28px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  font-size: 13px;
  padding: 0;
}
.icon.playing { background: var(--rail); border-color: var(--rail); color: var(--on-rail); }

/* quiz */
.questions { display: flex; flex-direction: column; gap: 22px; }
.q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.q-no { font-weight: 700; color: var(--rail); }
.q-options { display: flex; flex-direction: column; gap: 8px; }
.q-option {
  text-align: left;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  padding: 10px 14px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.7;
}
.q-option:not(:disabled):hover { border-color: var(--rail); }
.q-option:disabled { cursor: default; opacity: 0.6; }
.q-option.right { opacity: 1; border-color: var(--right); box-shadow: inset 4px 0 0 var(--right); }
.q-option.wrong { opacity: 1; border-color: var(--wrong); box-shadow: inset 4px 0 0 var(--wrong); }
.q-zh { display: block; font-family: var(--sans); font-size: 13px; color: var(--muted); }

/* cloze */
.cloze-line { margin: 0 0 6px; font-family: var(--serif); font-size: 18px; line-height: 2; }
.cloze-gap {
  display: inline-block;
  min-width: calc(var(--len, 2) * 1em + 0.6em);
  margin: 0 2px;
  border-bottom: 2px solid var(--rail);
  color: var(--rail);
  text-align: center;
  line-height: 1.4;
}
.cloze-fill { padding: 0 3px; border-radius: 4px; font-weight: 700; color: var(--right); background: var(--rail-soft); }
.cloze .q-zh { margin: 0 0 10px; }
.cloze-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 6px; }
.cloze-option { text-align: center; }

.score.done { margin-top: 28px; text-align: center; padding: 20px; border-radius: 10px; background: var(--rail-soft); }
.score p { margin: 0 0 12px; }
.score-num { font-size: 32px; font-weight: 700; color: var(--rail); margin-bottom: 4px !important; }

.missing { text-align: center; padding: 40px; }

/* ---------- route map footer ---------- */

.route {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.nav {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--paper);
  font-size: 22px;
  line-height: 1;
  padding: 0 0 3px;
}
.nav:disabled { opacity: 0.35; cursor: default; }

.stops-wrap { position: relative; flex: 1; }
.stops {
  position: relative;
  display: flex;
  justify-content: space-between;
  list-style: none;
  margin: 0;
  padding: 0;
}
.stops::before {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 13px;
  height: 4px;
  border-radius: 2px;
  background: var(--rule);
}
.stops button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 0;
  background: none;
  padding: 6px 0 0;
  min-width: 20px;
}
.stops .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--rule);
  background: var(--paper);
}
.stops .passed .dot { border-color: var(--rail); }
.stops .here .dot { border-color: var(--rail); background: var(--rail); transform: scale(1.25); }
.stop-label { font-size: 11px; color: var(--muted); }
.stops .here .stop-label { color: var(--rail); font-weight: 700; }

/* the little train that rides to the current page */
.train {
  position: absolute;
  left: 0;
  top: -4px;
  pointer-events: none;
  transition-property: transform;
  transition-timing-function: cubic-bezier(0.45, 0, 0.25, 1);
}
.train svg { display: block; filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.2)); }
.train.backward svg { transform: scaleX(-1); }
.train.running svg { animation: rattle 0.18s linear 4; }
@keyframes rattle { 50% { translate: 0 -1px; } }
@media (prefers-reduced-motion: reduce) {
  .train { transition-duration: 0s !important; }
  .train.running svg { animation: none; }
}
.stops .here .dot { visibility: hidden; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 20;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }

/* ---------- word sheet ---------- */

.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(20 18 14 / 0.35); }
.sheet-card {
  position: relative;
  width: min(100%, 480px);
  margin: 0 auto;
  padding: 24px 24px max(24px, env(safe-area-inset-bottom));
  background: var(--paper);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  text-align: center;
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 600px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 16px; }
}
.sheet-x { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 24px; color: var(--muted); }
.sheet-reading { margin: 0; color: var(--rail); min-height: 1.6em; }
.sheet-word { margin: 0; font-family: var(--serif); font-size: 34px; }
.sheet-zh { margin: 10px 0 0; font-size: 16px; }
.sheet-en { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.sheet-actions { display: flex; justify-content: center; gap: 8px; margin-top: 18px; }
.sheet-note { margin: 14px 0 0; font-size: 12px; color: var(--muted); }

@media (max-width: 420px) {
  .bar { flex-wrap: wrap; }
  .toggle { padding: 3px 8px; }
  .ja { font-size: 17px; }
  .avatar { width: 28px; height: 28px; font-size: 12px; }
}
