:root {
  --paper: #f3efe6;
  --card: #fffcf7;
  --ink: #221e1a;
  --muted: #5e574e;
  --line: #e2d9cc;
  --green: #1e4d3a;
  --green-soft: #e7f2eb;
  --red: #8a3d36;
  --red-soft: #f8ece9;
  --gold: #8a6a32;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

html.restoring body { visibility: hidden; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  line-height: 1.65;
  font-size: 17px;
  overflow-x: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

.top, main {
  width: min(44rem, calc(100% - 1.25rem));
  margin-left: auto;
  margin-right: auto;
}

.top { padding: 1.15rem 0 0.25rem; }

.back-row { margin: 0 0 0.55rem; }

.back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--green);
  text-decoration: none;
  font-size: 0.98rem;
}

.catalog {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0.9rem;
  margin: 0.9rem 0 1.4rem;
}

.lesson-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.15rem 1.1rem 1.2rem;
  color: inherit;
  text-decoration: none;
  min-height: 9.5rem;
}

.lesson-card:focus {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.card-index {
  margin: 0;
  color: var(--green);
  font-size: 0.86rem;
  letter-spacing: 0.06em;
}

.lesson-card h2 {
  margin: 0.35rem 0 0.3rem;
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 1.45rem;
  line-height: 1.25;
}

.card-zh { margin: 0; font-size: 1.05rem; }

.card-hint {
  margin: 0.7rem 0 0;
  color: var(--muted);
}

.records-entry { margin: 0.85rem 0 0; }

.record-list {
  list-style: none;
  margin: 0.4rem 0 1.2rem;
  padding: 0;
}

.record-list > li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.95rem 1rem 1rem;
  margin: 0.75rem 0;
}

.record-time { margin: 0; color: var(--muted); font-size: 0.92rem; }

.record-title {
  margin: 0.2rem 0 0;
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.3;
}

.record-zh { margin: 0.15rem 0 0; }

.record-score {
  margin: 0.45rem 0 0;
  color: var(--green);
  font-weight: 650;
}

.record-list details { margin-top: 0.7rem; }

.record-list summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--green);
}

.wrong-block { margin-top: 0.6rem; }

.wrong-block h3 { margin: 0.4rem 0; }

.wrong-block li {
  border-top: 1px solid var(--line);
  padding: 0.65rem 0;
  list-style: none;
}

.wrong-block ul { margin: 0; padding: 0; }

.wrong-stem { margin: 0.15rem 0 0.35rem; }

.kicker {
  margin: 0;
  color: var(--green);
  font-size: 0.86rem;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0.25rem 0 0.4rem;
  font-size: 1.7rem;
  font-weight: 650;
  line-height: 1.25;
}

h2 {
  margin: 0 0 0.4rem;
  font-size: 1.2rem;
}

h3 {
  margin: 1.1rem 0 0.35rem;
  font-size: 1rem;
}

.lead, .note, .optional {
  color: var(--muted);
}

.lead { margin: 0; }

.optional {
  font-weight: 450;
  font-size: 0.85rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.05rem 1.2rem;
  margin: 0.9rem 0;
}

.note { margin: 0.2rem 0 0.8rem; font-size: 0.95rem; }

.player {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0.4rem auto 0.7rem;
  background: #141210;
  border-radius: 12px;
  overflow: hidden;
}

.player video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 78dvh;
  aspect-ratio: 720 / 980;
  object-fit: contain;
  background: #141210;
}

.caption-overlay {
  position: absolute;
  left: 0.45rem;
  right: 0.45rem;
  bottom: 4.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  pointer-events: none;
  text-align: center;
}

.caption-overlay[hidden] { display: none; }

.cap-en, .cap-zh {
  margin: 0;
  max-width: 100%;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  background: rgba(12, 10, 8, 0.78);
  color: #fff;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 0.95rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.cap-zh { font-size: 0.9rem; }

.caption-modes {
  display: flex;
  gap: 0.4rem;
  width: 100%;
  margin: 0 0 0.45rem;
}

.mode, .submit {
  appearance: none;
  border: 1px solid var(--green);
  background: var(--green);
  color: #f7f4ee;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.98rem;
  text-decoration: none;
  display: inline-block;
  cursor: pointer;
}

.mode {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  background: #f7f4ee;
  color: var(--green);
  padding: 0.4rem 0.3rem;
  font-size: 0.92rem;
  line-height: 1.2;
  white-space: normal;
}

.mode[aria-checked="true"] {
  background: var(--green);
  color: #f7f4ee;
}

.mode:disabled,
.mode[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.missing {
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}

.missing p { margin: 0.25rem 0; }

code {
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.88em;
}

.warmup {
  margin: 0.2rem 0 0;
  padding-left: 1.2rem;
}

.warmup-q { margin: 0; }

.warmup-start {
  margin: 0.15rem 0 0.55rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.passage {
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", "Songti SC", Georgia, serif;
  font-size: 1.08rem;
  line-height: 1.85;
}

.passage-title {
  margin: 0 0 0.55rem;
  font-size: 1.25rem;
  font-weight: 650;
}

.para {
  display: block;
  height: 0.85rem;
}

.blank {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem;
  max-width: 100%;
  margin: 0 0.1rem;
  vertical-align: baseline;
}

.blank input {
  width: 7.6rem;
  max-width: 100%;
  min-width: 4.5rem;
  font: inherit;
  font-size: 1rem;
  color: inherit;
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--ink);
  border-radius: 0;
  padding: 0.15rem 0.15rem 0.1rem;
}

.blank input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.hint { color: var(--muted); font-size: 0.92em; }

.blank.is-right input { border-bottom-color: var(--green); background: var(--green-soft); }
.blank.is-wrong input { border-bottom-color: var(--red); background: var(--red-soft); }

.mark {
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 0 0.4rem;
}

.is-right .mark { color: var(--green); background: var(--green-soft); }
.is-wrong .mark { color: var(--red); background: var(--red-soft); }

.question {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0.75rem 0;
  padding: 0.75rem 0.8rem 0.55rem;
  min-width: 0;
  max-width: 100%;
}

.question.is-right { border-color: #b7d4c4; background: #f7fbf8; }
.question.is-wrong { border-color: #e4c6c1; background: #fdf8f7; }

legend {
  font-family: Palatino, "Palatino Linotype", Georgia, serif;
  padding: 0 0.2rem;
  max-width: calc(100% - 1.2rem);
  white-space: pre-line;
}

#intro .lead { color: var(--ink); margin: 0; }

.restore-box { margin: 0.2rem 0 0.8rem; }

.restore-box .choice.is-used {
  opacity: 0.38;
}

.restore-slot {
  display: inline;
}

.restore-line {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  cursor: pointer;
  vertical-align: baseline;
}

.restore-rule {
  display: inline-block;
  width: 8em;
  height: 0;
  border-bottom: 1.5px solid var(--ink);
  vertical-align: baseline;
  position: relative;
}

.restore-rule::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -1.05em;
  height: 1.75em;
}

.restore-line.is-filled .restore-rule { display: none; }

.restore-line.is-filled .restore-letter,
.restore-filled .letter {
  display: inline-grid;
  vertical-align: -0.2em;
  margin-right: 0.28em;
}

.restore-line.is-filled .restore-sentence {
  border-bottom: 1.5px solid var(--ink);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.restore-filled {
  display: inline;
  margin: 0;
  padding: 0 0.08em 0.02em;
  border-bottom: 1.5px solid var(--ink);
  line-height: inherit;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.restore-filled.is-right {
  border-bottom-color: var(--green);
  background: var(--green-soft);
}

.restore-filled.is-wrong {
  border-bottom-color: var(--red);
  background: var(--red-soft);
}

.restore-line .letter[hidden] { display: none !important; }

.restore-pop {
  position: fixed;
  z-index: 40;
  box-sizing: border-box;
  width: min(36rem, calc(100vw - 1.5rem));
  max-height: min(70dvh, 32rem);
  overflow: auto;
  padding: 0.45rem 0.7rem 0.65rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(34, 30, 26, 0.16);
}

.restore-pop .restore-opt {
  width: 100%;
  box-sizing: border-box;
  align-items: flex-start;
}

.restore-pop .restore-opt-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  overflow-wrap: break-word;
}

.restore-pop[hidden] { display: none; }

.restore-clear {
  appearance: none;
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0 0 0.25rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f4ee;
  color: var(--green);
  font: inherit;
  cursor: pointer;
}

.restore-opt.is-taken {
  opacity: 0.38;
  pointer-events: none;
}

@media (max-width: 800px) {
  .restore-pop {
    left: 0.6rem !important;
    right: 0.6rem !important;
    bottom: max(0.6rem, env(safe-area-inset-bottom)) !important;
    top: auto !important;
    width: auto !important;
    max-height: 70dvh;
  }
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.55rem 0.15rem;
  cursor: pointer;
}

.choice input {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.2rem;
  accent-color: var(--green);
  flex: 0 0 auto;
}

.letter {
  flex: 0 0 auto;
  width: 1.6rem;
  height: 1.6rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  background: #fff;
}

.choice-text { font-family: Palatino, "Palatino Linotype", Georgia, serif; }

.mark-line { margin: 0.35rem 0 0.2rem; color: var(--muted); font-size: 0.92rem; }

.actions { margin-top: 0.6rem; }

.submit { min-height: 48px; touch-action: manipulation; }

.mode, .choice, .blank input { touch-action: manipulation; }

.score {
  margin: 0.2rem 0 0;
  font-size: 2.4rem;
  line-height: 1;
  color: var(--green);
}

.score span { font-size: 1.1rem; color: var(--muted); }

.split { margin-top: 0.35rem; }

.review { list-style: none; margin: 0; padding: 0; }

.review li {
  border-top: 1px solid var(--line);
  padding: 0.7rem 0;
}

.review p { margin: 0.1rem 0; }

.review-head { font-weight: 650; }

.review .is-right .review-head { color: var(--green); }
.review .is-wrong .review-head { color: var(--red); }

.explain { color: var(--muted); overflow-wrap: anywhere; }

.review, .passage, .choice-text, legend, .guide-en, .guide-zh, .key-en, .key-hint { overflow-wrap: break-word; }

.guide h2 { margin-bottom: 0.2rem; }

.guide h3 { margin-top: 1.15rem; }

.guide-title {
  margin: 0.2rem 0 0.7rem;
  font-size: 1.15rem;
  font-weight: 650;
}

.guide-en {
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
  font-size: 1.05rem;
  line-height: 1.75;
}

.guide-zh {
  font-size: 1.02rem;
  line-height: 1.8;
}

.guide-en p, .guide-zh p { margin: 0.7rem 0; }

.key-sentences {
  list-style: none;
  margin: 0.3rem 0 0;
  padding: 0;
}

.key-sentences li {
  border-top: 1px solid var(--line);
  padding: 0.75rem 0;
}

.key-en {
  margin: 0 0 0.3rem;
  font-weight: 650;
  line-height: 1.45;
}

.key-hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.writing-prompt { font-size: 1.05rem; }

.prompt-label { font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif; }

#writing-box {
  display: block;
  width: 100%;
  min-height: 8.5rem;
  margin: 0.4rem 0 0.8rem;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-size: 1rem;
  line-height: 1.55;
  resize: vertical;
}

#writing-box:focus {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.writing-starts { margin: 0.2rem 0 0.8rem; padding-left: 1.2rem; }

.vocab-list {
  list-style: none;
  margin: 0.2rem 0 0;
  padding: 0;
}

.vocab-list li {
  border-top: 1px solid var(--line);
  padding: 0.75rem 0;
}

.vocab-en {
  margin: 0;
  font-weight: 650;
  line-height: 1.4;
}

.vocab-en span {
  margin-left: 0.4rem;
  color: var(--muted);
  font-weight: 450;
  font-size: 0.86rem;
}

.vocab-list p { margin: 0.15rem 0; }

.vocab-use { color: var(--muted); }

.retry-end { margin: 0.2rem 0 1.2rem; }

@media (max-width: 700px) {
  body { font-size: 16.5px; }
  h1 { font-size: 1.45rem; }
  .top { padding-top: 1.1rem; }
  .card { padding: 0.95rem 0.8rem 1rem; }
  .submit { display: block; width: 100%; text-align: center; }
  .cap-en, .cap-zh { font-size: 0.82rem; }
  .caption-overlay { bottom: 4.4rem; }
}

@media (min-width: 768px) {
  .top, main { width: min(46rem, calc(100% - 2.5rem)); }
  body { font-size: 18px; }
  .card { padding: 1.25rem 1.3rem 1.35rem; }
}

@media (min-width: 1024px) {
  .top, main { width: min(48rem, calc(100% - 4rem)); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .player video { max-height: 68dvh; }
  .top { padding-top: 0.6rem; }
}
