:root {
  color-scheme: light dark;
  --paper: #f9f4e9;
  --pink: #f8dce1;
  --pink-ink: #84354b;
  --orange: #f9e4c2;
  --orange-ink: #895116;
  --shadow: 0 2px 0 #5339200a, 0 8px 24px #4933140a;
  --book-type: "Songti SC", "Noto Serif CJK SC", SimSun, serif;
  --surface: #fffcf4;
  --ink: #242c28;
  --muted: #535d55;
  --rule: #cfcbbd;
  --accent: #245747;
  --accent-text: #fffdf5;
  --tint: #e4ede2;
  --trace: #a4a7a1;
  --jp: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", "PingFang SC", sans-serif;
  --reading-size: 1.25rem;
  --bottom-height: calc(4.25rem + env(safe-area-inset-bottom, 0px));
  font: 100%/1.65 system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #20241f;
    --pink: #513542;
    --pink-ink: #ffc3d0;
    --orange: #493822;
    --orange-ink: #ffd397;
    --shadow: 0 2px 0 #0003, 0 8px 24px #0002;
    --surface: #292e28;
    --ink: #f2eddf;
    --muted: #c2c8b9;
    --rule: #626e60;
    --accent: #a1d0b8;
    --accent-text: #152e24;
    --tint: #303e34;
    --trace: #777e74;
  }
}

:root[data-font="large"] { font-size: 112.5%; }
:root[data-font="largest"] { font-size: 125%; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.site-width {
  width: min(100% - 2rem, 760px);
  margin-inline: auto;
}

.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  padding-top: env(safe-area-inset-top, 0px);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-height: 3.5rem;
  gap: .58rem;
  color: var(--accent);
  font-family: var(--book-type);
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-decoration: none;
}

main {
  padding-block: 1.5rem calc(var(--bottom-height) + 2rem);
}

h1, h2, h3 { line-height: 1.35; margin: 0 0 .6em; }
h1, h2 { font-family: var(--book-type); }
h1 { font-size: clamp(1.65rem, 5vw, 2.2rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.12rem; }
p, ul, ol { margin: 0 0 .85rem; }
p:last-child, ul:last-child, ol:last-child { margin-bottom: 0; }
a { color: var(--accent); text-underline-offset: .2em; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
/* 换页时焦点会移到正文，不给整块正文画框 */
main:focus, main:focus-visible { outline: none; }

.bottom-nav {
  position: fixed;
  z-index: 2;
  inset: auto 0 0;
  min-height: var(--bottom-height);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border-top: 1px solid var(--rule);
  background: var(--surface);
}

.nav-inner { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.nav-inner a {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: .18rem;
  min-height: 4.25rem;
  padding: .3rem .15rem;
  color: var(--muted);
  font-size: .83rem;
  line-height: 1.35;
  text-decoration: none;
}
.nav-inner svg, .brand-mark {
  width: 1.35rem;
  height: 1.35rem;
}
.nav-inner svg {
  box-sizing: content-box;
  padding: .2rem .6rem;
  border-radius: 2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.nav-inner a[aria-current] { color: var(--accent); font-weight: 700; }
.nav-inner a[aria-current] svg { background: var(--tint); }
.brand-mark {
  box-sizing: content-box;
  border-radius: .6rem;
  background: var(--tint);
  padding: .35rem;
}

.skip-link {
  position: absolute;
  z-index: 3;
  top: .5rem;
  left: .5rem;
  padding: .6rem;
  background: var(--surface);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.stack { display: grid; gap: 1rem; }
.stack > * { min-width: 0; }
.stack > p, .stack > h2 { margin: 0; }
.panel {
  padding: clamp(.8rem, 4vw, 1.4rem);
  border: 1px solid var(--rule);
  border-radius: 1.05rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.measure { max-width: 62ch; }
.muted { color: var(--muted); }
.prose { white-space: pre-line; }
.steps {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  border: 1px solid var(--rule);
  border-radius: .55rem;
  background: var(--surface);
}
.steps a {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: .25rem .12rem;
  color: var(--ink);
  text-align: center;
  text-decoration: none;
  font-size: .85rem;
}
.steps a + a { border-left: 1px solid var(--rule); }
.steps a[aria-current] { background: var(--tint); color: var(--accent); font-weight: 700; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions + *, * + .actions { margin-top: .75rem; }
.stack > .actions { margin-top: 0; }
button, .button, select, input[type="text"], textarea { font: inherit; }
button, .button, select {
  min-height: 44px;
  min-width: 44px;
  padding: .45rem .75rem;
  border: 1px solid var(--rule);
  border-radius: .65rem;
  background: var(--surface);
  color: var(--ink);
}
button, select { cursor: pointer; }
.button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.primary, .selected, button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--tint);
  color: var(--accent);
  font-weight: 700;
}
.primary { background: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .57; cursor: default; }
input[type="text"], textarea {
  display: block;
  width: 100%;
  margin-top: .35rem;
  padding: .65rem;
  border: 1px solid var(--rule);
  border-radius: .65rem;
  background: var(--paper);
  color: var(--ink);
}
textarea { min-height: 8rem; resize: vertical; }
input[type="text"] { min-height: 44px; }
label { display: block; }
.setting-toggle { display: flex; align-items: center; gap: .6rem; min-height: 44px; }
.setting-toggle input { width: 1.35rem; height: 1.35rem; accent-color: var(--accent); }

.jp, input[type="text"].jp { font-family: var(--jp); font-size: var(--reading-size); }
h1 .jp { font-size: 1em; }
.jp-line { line-height: 2; }
ruby { ruby-align: center; }
rt { font-size: .62em; line-height: 1.15; color: var(--muted); }
.speak {
  display: inline-grid;
  place-items: center;
  vertical-align: middle;
  margin-inline-start: .15rem;
  padding: 0;
  line-height: 1;
  font-size: 1rem;
}

.kana-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: .45rem; }
.kana-key { display: grid; justify-items: center; line-height: 1.35; padding: .45rem .15rem; }
.kana-key small { color: var(--muted); }
.example + .example, .text-paragraph + .text-paragraph { margin-top: .85rem; }
.text-paragraph + .text-paragraph { padding-top: .85rem; border-top: 1px solid var(--rule); }

.trace-sheet {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 21rem);
  aspect-ratio: 1;
  margin: .75rem auto;
  border: 2px solid var(--pink-ink);
  background: var(--surface);
}
.trace-sheet::before, .trace-sheet::after {
  position: absolute;
  content: "";
  pointer-events: none;
}
.trace-sheet::before { inset: 50% 0 auto; border-top: 1px dashed var(--pink-ink); opacity: .55; }
.trace-sheet::after { inset: 0 auto 0 50%; border-left: 1px dashed var(--pink-ink); opacity: .55; }
.trace-sheet { container-type: inline-size; }
.trace-glyph {
  color: var(--trace);
  font-family: "Klee", "Hiragino Mincho ProN", "Yu Mincho", var(--jp);
  font-size: clamp(6rem, 58vw, 15rem);
  font-size: 70cqi;
  line-height: 1;
  white-space: nowrap;
}
.trace-pair { font-size: clamp(3rem, 31vw, 8rem); font-size: 38cqi; }
.trace-sheet canvas { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; touch-action: none; }

fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { padding: 0; }
.options { display: grid; gap: .5rem; margin-top: .55rem; }
.option-row { display: flex; gap: .35rem; align-items: center; }
.option-row label {
  flex: 1;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: .6rem;
  min-height: 44px;
  padding: .35rem .55rem;
  border: 1px solid var(--rule);
  border-radius: .65rem;
  cursor: pointer;
}
.option-row input { flex: none; margin: 0; width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }
.option-row label:has(input:checked) { border-color: var(--accent); background: var(--tint); }
.tokens { min-height: 54px; margin-block: .35rem .75rem; padding: .35rem; border: 1px solid var(--rule); border-radius: .4rem; }
.tokens .actions { margin: 0; }

.score { color: var(--accent); font-size: 1.5rem; font-weight: 700; }

.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.question-map { display: flex; flex-wrap: wrap; gap: .35rem; }
.question-map button { padding-inline: .45rem; }
.question-map button[aria-current] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.exam-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; }
.exam-jump summary { min-height: 44px; padding-block: .5rem; cursor: pointer; }
.separator { margin-block: 1.1rem; border: 0; border-top: 1px solid var(--rule); }

.notice {
  position: fixed;
  z-index: 3;
  right: 0;
  left: 0;
  bottom: calc(var(--bottom-height) + .5rem);
  padding: .65rem .85rem;
  border: 1px solid var(--rule);
  border-radius: .65rem;
  background: var(--surface);
}

@media (min-width: 560px) {
  main { padding-top: 2rem; }
  .options.columns { grid-template-columns: 1fr 1fr; }
}

/* The cover and the trail through the book. */
.hero {
  position: relative;
  isolation: isolate;
  display: grid;
  align-items: end;
  min-height: 9rem;
  overflow: hidden;
  border-radius: 1.25rem;
  background: repeating-linear-gradient(135deg, transparent 0 24px, #fff1 24px 25px), var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow);
}
.hero:has(.hero-image:not([hidden]), .hero-video.is-playing) { aspect-ratio: 16 / 9; }
.hero-image, .hero-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hero-video { opacity: 0; z-index: 1; }
.hero-video.is-playing { opacity: 1; }
.hero-copy {
  position: relative;
  z-index: 1;
  padding: clamp(1.05rem, 4vw, 2rem);
}
.hero:has(.hero-image:not([hidden]), .hero-video.is-playing) .hero-copy {
  color: #fffdf5;
  background: linear-gradient(0deg, #142d24ef, #142d2400);
  text-shadow: 0 1px 8px #10231d;
}
.hero h1 { margin: 0; }
.hero h1 .jp {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", var(--jp);
  font-size: clamp(2.15rem, 8vw, 3.3rem);
  font-weight: 700;
}
.hero-copy p { font-size: .95rem; margin-top: .2rem; }
.home-today {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: .25rem .8rem;
  border-inline-start: .35rem solid var(--accent);
}
.home-today h2 { grid-column: 1 / -1; margin-bottom: 0; }
.home-today p { margin: 0; }
.home-today .button { justify-content: center; white-space: nowrap; }
.home-next { font-size: 1.1rem; font-weight: 600; }
.daily-summary, .daily-progress, .task-link, .quiz-result, .empty-state {
  display: flex;
  align-items: center;
  gap: .65rem;
}
.daily-summary { justify-content: space-between; }
.daily-summary h2 { margin-bottom: .4rem; }
.daily-progress { flex-direction: column; gap: .15rem; font-size: .8rem; text-align: center; }
.streak {
  width: fit-content;
  padding: .2rem .55rem;
  border-radius: .6rem;
  background: var(--orange);
  color: var(--orange-ink);
  font-size: .85rem;
}
.daily-tasks {
  padding: 0;
  margin: .75rem 0 0;
  list-style: none;
}
.daily-tasks li { border-top: 1px solid var(--rule); }
.task-link { min-height: 44px; color: var(--ink); text-decoration: none; }
.task-name { flex: 1; }
.task-count { font-size: .85rem; color: var(--muted); }
.task-check { color: var(--muted); text-align: center; width: 1.35rem; }
.task-check.done { color: var(--accent); font-weight: 800; }
.task-link:hover .task-name { color: var(--accent); text-decoration: underline; }
.unit-image, .lesson-image, .course-thumbnail {
  display: block;
  object-fit: cover;
  background: var(--tint);
}
.unit-image, .lesson-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: .7rem;
}
.unit-image { margin-bottom: .8rem; }
.lesson-image { box-shadow: var(--shadow); }
.course-thumbnail {
  width: clamp(2.2rem, 11vw, 3.25rem);
  aspect-ratio: 1;
  border-radius: .45rem;
}
.course-list {
  position: relative;
  padding: 0;
  margin: .3rem 0 0;
  list-style: none;
}
.course-list::before {
  content: "";
  position: absolute;
  inset: 1.6rem auto 1.6rem .71rem;
  border-left: 2px dashed var(--rule);
}
.course-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 3.5rem;
  padding: .3rem .45rem .3rem 0;
  border-radius: .55rem;
  color: var(--ink);
  text-decoration: none;
}
.course-name { flex: 1; min-width: 0; }
.course-status { display: block; color: var(--muted); font-size: .8rem; }
.course-link:hover .course-name { color: var(--accent); text-decoration: underline; }
.station {
  display: grid;
  place-items: center;
  flex: 0 0 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--muted);
  line-height: 1;
  font-weight: 800;
}
.station-upcoming .course-name { color: var(--muted); }
.station-current .course-link { background: var(--tint); }
.station-current .station {
  background: var(--pink);
  border-color: var(--pink-ink);
  color: var(--pink-ink);
  animation: station-hop 1.8s ease-in-out 2;
}
.station-done .station { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
@keyframes station-hop {
  0%, 60%, 100% { transform: translateY(0); }
  25% { transform: translateY(-.23rem); }
}

/* Study cards and the reading page. */
.kana-key[aria-expanded="true"] { background: var(--pink); border-color: var(--pink-ink); color: var(--pink-ink); }
.kana-detail {
  margin-top: .8rem;
  padding: .75rem;
  border-radius: .75rem;
  background: var(--tint);
  animation: kana-open .24s ease-out both;
}
.kana-spotlight {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-bottom: .4rem;
}
.kana-spotlight h3 { margin: 0; }
.kana-spotlight .jp { font-size: clamp(2.65rem, 12vw, 4.8rem); }
@keyframes kana-open {
  from { opacity: 0; transform: scale(.94); }
  to { opacity: 1; transform: scale(1); }
}
.flip-card { perspective: 68rem; margin-block: .55rem; }
.flip-inner {
  display: grid;
  transform-style: preserve-3d;
  transition: transform .48s cubic-bezier(.2, .65, .2, 1);
}
.flip-card.is-flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  align-content: center;
  min-width: 0;
  min-height: 10rem;
  padding: .85rem;
  border: 1px solid var(--rule);
  border-radius: .9rem;
  background: var(--tint);
  backface-visibility: hidden;
  overflow-wrap: anywhere;
  text-align: center;
}
.flip-face .jp { font-size: 1.6rem; }
.flip-face .actions { justify-content: center; }
.flip-face[inert] { pointer-events: none; }
.flip-back {
  background: var(--orange);
  transform: rotateY(180deg);
}
.vocab-revealed { min-width: 0; max-width: 100%; }
.text-paragraph { padding: .55rem .65rem; border-radius: .55rem; }
.text-paragraph.is-reading {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--tint);
}
.reading-passage {
  margin-block: .75rem;
  padding: .15rem .75rem .45rem;
  border: 1px solid var(--rule);
  border-inline-start: .25rem solid var(--orange-ink);
  border-radius: .65rem;
  background: var(--paper);
}
.reading-passage summary { min-height: 44px; padding-block: .5rem; font-weight: 700; cursor: pointer; }
.passage-copy { padding-bottom: .35rem; }
.result-question { padding-top: .85rem; }
.result-question + .result-question { margin-top: 1rem; border-top: 1px solid var(--rule); }

/* Progress and answer feedback. */
.question-progress {
  display: block;
  width: 100%;
  height: .55rem;
  margin-block: .55rem .95rem;
  overflow: hidden;
  border: 0;
  border-radius: 2rem;
  background: var(--tint);
  accent-color: var(--accent);
  appearance: none;
}
.question-progress::-webkit-progress-bar { background: var(--tint); }
.question-progress::-webkit-progress-value { background: var(--accent); border-radius: 2rem; }
.question-progress::-moz-progress-bar { background: var(--accent); border-radius: 2rem; }

.feedback {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  margin-top: .85rem;
  padding: .8rem;
  border-inline-start: .25rem solid var(--accent);
  border-radius: .65rem;
  background: var(--tint);
}
.feedback-copy { flex: 1; min-width: 0; }
.feedback-copy p { margin-bottom: .4rem; }
.feedback-copy p:last-child { margin-bottom: 0; }
.feedback-wrong { border-color: var(--pink-ink); background: var(--pink); }
.feedback.answer-flash { animation: answer-flash .5s ease-out; }
.feedback.answer-shake { animation: answer-shake .34s ease-in-out; }
.coach { color: var(--muted); font-size: .9rem; }
.feedback-wrong .coach { color: var(--pink-ink); }
.mascot { display: block; width: clamp(3rem, 14vw, 5.2rem); aspect-ratio: 1; object-fit: contain; border-radius: 22%; }
.empty-state .mascot { width: 4.5rem; }
.empty-state p { margin: 0; }

@property --ring-value {
  syntax: "<percentage>";
  initial-value: 0%;
  inherits: false;
}
.score-ring {
  --ring-value: var(--target);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 3.7rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--ring-value), var(--tint) 0);
  color: var(--accent);
}
.score-ring strong {
  display: grid;
  place-items: center;
  width: 77%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface);
  font-size: .95em;
  font-variant-numeric: tabular-nums;
}
.quiz-result { flex-wrap: wrap; }
.quiz-result .score-ring { width: clamp(4.25rem, 20vw, 5.5rem); font-size: 1.15rem; }
.result-copy { flex: 1 1 8rem; }
.result-copy .score { margin-bottom: .2rem; }
.ring-animate { animation: fill-ring .85s ease-out both; }
.stars {
  display: inline-flex;
  gap: .1em;
  align-items: center;
  color: var(--muted);
  white-space: nowrap;
}
.star-earned { color: var(--orange-ink); }
.result-copy .stars { font-size: 1.65rem; }
.stars-animate .star-earned { animation: star-light .4s ease-out .25s both; }
.stars-animate .star-earned:nth-child(2) { animation-delay: .48s; }
.stars-animate .star-earned:nth-child(3) { animation-delay: .71s; }
.medal { font-size: 1.7rem; line-height: 1.2; }

.confetti {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.confetti-full { position: fixed; z-index: 4; }
.confetti i {
  position: absolute;
  top: 35%;
  left: 50%;
  width: .38rem;
  height: .6rem;
  background: #d96a90;
  border-radius: 2px;
  opacity: 0;
  animation: paper-burst .75s ease-out both;
}
.confetti i:nth-child(3n + 2) { background: #e6a747; }
.confetti i:nth-child(3n + 3) { background: #5aaf8a; }
.confetti-full i {
  top: -1rem;
  left: var(--x);
  width: .48rem;
  height: .76rem;
  animation: paper-fall 1.95s ease-in var(--delay) both;
}
.page { animation: page-arrival .2s ease-out; }

@keyframes page-arrival {
  from { opacity: .75; transform: translateY(.25rem); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes answer-flash { from { box-shadow: inset 0 0 0 2px var(--accent); } }
@keyframes answer-shake {
  25%, 65% { transform: translateX(-3px); }
  45%, 85% { transform: translateX(3px); }
}
@keyframes fill-ring { from { --ring-value: 0%; } }
@keyframes star-light {
  0% { opacity: .15; transform: scale(.62); }
  65% { transform: scale(1.18); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes paper-burst {
  0% { opacity: 1; }
  80% { opacity: .9; }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--turn)); }
}
@keyframes paper-fall {
  10%, 80% { opacity: 1; }
  100% { opacity: 0; transform: translate(1.5rem, 100vh) rotate(var(--turn)); }
}

@media (max-width: 480px) {
  .home-today { grid-template-columns: minmax(0, 1fr); }
  .home-today .button { margin-top: .45rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .hero-video, .confetti { display: none !important; }
  .flip-inner, .flip-back, .flip-card.is-flipped .flip-inner { transform: none; }
  .flip-face[inert] { visibility: hidden; }
}
