:root {
  --navy: #174f83;
  --navy-dark: #103957;
  --wine: #9f1f50;
  --teal: #258f91;
  --green: #3c8b61;
  --gold: #dca53a;
  --ink: #263746;
  --muted: #687c8f;
  --line: #dce5ec;
  --surface: #ffffff;
  --bg: #f4f7fa;
  --blue-soft: #e8f0f7;
  --wine-soft: #f7e9ef;
  --teal-soft: #e5f3f2;
  --shadow: 0 12px 32px rgba(22, 54, 81, .10);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { background: var(--bg); overflow-x: hidden; }
body { margin: 0; min-height: 100vh; background: var(--bg); overflow-x: hidden; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 68px;
  display: flex; align-items: center; gap: 12px; padding: 0 max(18px, env(safe-area-inset-left));
  background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; margin-right: auto; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--navy); color: white; font-weight: 800; box-shadow: inset 4px 0 var(--wine); }
.brand strong { display: block; color: var(--navy-dark); font-size: 16px; letter-spacing: .03em; }
.brand small { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 12px; background: var(--blue-soft); color: var(--navy); font-weight: 700; cursor: pointer; }

#main-content { width: min(100%, 980px); margin: 0 auto; padding: 24px 18px 36px; outline: 0; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin: 2px 0 22px; }
.eyebrow { color: var(--wine); text-transform: uppercase; font-size: 11px; font-weight: 800; letter-spacing: .15em; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(27px, 6vw, 38px); line-height: 1.18; color: var(--navy-dark); margin-bottom: 8px; }
h2 { color: var(--navy-dark); font-size: 21px; }
h3 { color: var(--navy-dark); font-size: 16px; }
.subtitle, .muted { color: var(--muted); }

.hero-card { position: relative; overflow: hidden; color: white; padding: 26px; border-radius: 28px; background: linear-gradient(135deg, var(--navy) 0%, #246b9f 100%); box-shadow: var(--shadow); }
.hero-card::after { content: ""; position: absolute; width: 180px; height: 180px; border-radius: 50%; right: -46px; top: -54px; background: rgba(255,255,255,.09); }
.hero-card .eyebrow { color: #bed7ec; }
.hero-card h1, .hero-card h2 { color: white; }
.hero-card p { color: rgba(255,255,255,.82); line-height: 1.7; max-width: 620px; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 18px; }

.btn { border: 0; border-radius: 14px; min-height: 44px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 750; cursor: pointer; text-decoration: none; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--wine); color: white; box-shadow: 0 8px 18px rgba(159,31,80,.2); }
.btn-light { background: white; color: var(--navy); }
.btn-outline { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn-soft { background: var(--blue-soft); color: var(--navy); }
.btn-success { background: var(--green); color: white; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.section { margin-top: 28px; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 13px; }
.section-title h2 { margin: 0; }
.text-link { border: 0; background: none; color: var(--navy); font-weight: 700; cursor: pointer; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 6px 20px rgba(29,58,83,.05); }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: white; border: 1px solid var(--line); border-radius: 18px; padding: 15px; }
.stat b { display: block; color: var(--navy); font-size: 24px; margin-bottom: 3px; }
.stat span { color: var(--muted); font-size: 12px; }

.progress-row { display: flex; align-items: center; gap: 12px; }
.progress-track { flex: 1; height: 8px; background: rgba(255,255,255,.24); border-radius: 99px; overflow: hidden; }
.progress-track.light { background: var(--line); }
.progress-fill { height: 100%; background: #fff; border-radius: inherit; transition: width .3s ease; }
.progress-track.light .progress-fill { background: linear-gradient(90deg, var(--navy), var(--teal)); }
.progress-label { min-width: 42px; font-size: 12px; font-weight: 700; }

.topic-card { display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center; cursor: pointer; transition: .18s ease; }
.topic-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.topic-number { width: 56px; height: 56px; border-radius: 17px; display: grid; place-items: center; background: var(--blue-soft); color: var(--navy); font-weight: 850; }
.topic-card:nth-child(even) .topic-number { background: var(--wine-soft); color: var(--wine); }
.topic-card h3 { margin: 0 0 4px; }
.topic-card p { margin: 0; font-size: 12px; color: var(--muted); }
.topic-meta { text-align: right; color: var(--muted); font-size: 11px; }
.mini-progress { width: 54px; height: 5px; margin-top: 7px; border-radius: 99px; background: var(--line); overflow: hidden; }
.mini-progress i { display: block; height: 100%; background: var(--teal); }

.bottom-nav { position: fixed; z-index: 40; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 760px); height: calc(72px + env(safe-area-inset-bottom)); padding: 6px 10px env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4,1fr); background: rgba(255,255,255,.96); border: 1px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0; box-shadow: 0 -10px 32px rgba(25,54,79,.09); backdrop-filter: blur(18px); }
.bottom-nav button { position: relative; border: 0; background: transparent; color: var(--muted); border-radius: 16px; display: grid; place-content: center; gap: 2px; cursor: pointer; }
.bottom-nav button span { font-size: 21px; line-height: 1; }
.bottom-nav button b { font-size: 11px; }
.bottom-nav button.active { color: var(--navy); background: var(--blue-soft); }
.nav-badge { position: absolute; top: 4px; right: calc(50% - 25px); min-width: 17px; height: 17px; padding: 0 4px; display: grid; place-items: center; border-radius: 99px; background: var(--wine); color: white; font-size: 9px; font-style: normal; }

.lesson-head { background: linear-gradient(145deg, #f8fbfd, #e8f0f7); border: 1px solid var(--line); border-radius: 26px; padding: 22px; }
.lesson-title-row { display: flex; align-items: center; gap: 14px; }
.lesson-title-row .topic-number { flex: 0 0 auto; }
.lesson-title-row h1 { font-size: 28px; margin-bottom: 3px; }
.lesson-title-row p { margin: 0; color: var(--muted); }
.stepper { display: grid; grid-template-columns: repeat(9,minmax(0,1fr)); gap: 7px; margin-top: 20px; }
.step-pill { min-width: 0; border: 0; border-radius: 14px; padding: 10px 4px; background: white; color: var(--muted); cursor: pointer; border: 1px solid var(--line); }
.step-pill b { display: grid; place-items: center; margin: 0 auto 5px; width: 24px; height: 24px; border-radius: 50%; background: var(--line); font-size: 11px; }
.step-pill span { font-size: 11px; font-weight: 700; }
.step-pill.active { border-color: var(--navy); color: var(--navy); background: var(--blue-soft); }
.step-pill.active b { background: var(--navy); color: white; }
.step-pill.done b { background: var(--green); color: white; }

.lesson-panel { min-width: 0; max-width: 100%; margin-top: 18px; background: white; border-radius: 24px; border: 1px solid var(--line); padding: clamp(18px,4vw,28px); }
.lesson-panel .lead-en { font-family: Georgia, "Times New Roman", serif; font-size: 19px; line-height: 1.75; color: var(--navy-dark); }
.lesson-panel .lead-zh { line-height: 1.9; color: var(--muted); border-top: 1px solid var(--line); padding-top: 17px; }
.audio-box { display: flex; align-items: center; gap: 14px; background: var(--navy); color: white; padding: 14px; border-radius: 18px; margin-bottom: 20px; }
.audio-box button { width: 46px; height: 46px; border: 0; border-radius: 50%; background: white; color: var(--navy); font-size: 20px; cursor: pointer; flex: 0 0 auto; }
.audio-box div { min-width: 0; flex: 1; }
.audio-box strong, .audio-box small { display: block; }
.audio-box small { opacity: .7; margin-top: 3px; }

.chunk-list { display: grid; gap: 10px; }
.chunk-groups { display: grid; gap: 10px; }
.chunk-group { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); overflow: hidden; }
.chunk-group summary { min-height: 58px; padding: 12px 14px; display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; cursor: pointer; list-style: none; color: var(--navy-dark); }
.chunk-group summary::-webkit-details-marker { display: none; }
.chunk-group summary > span { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 10px; background: var(--blue-soft); color: var(--navy); font-size: 12px; font-weight: 850; }
.chunk-group summary > small { color: var(--muted); font-size: 10px; }
.chunk-group[open] summary { background: var(--blue-soft); }
.chunk-group[open] summary > span { background: var(--navy); color: white; }
.chunk-group .chunk-list { padding: 10px; }
.chunk-group .chunk-card { box-shadow: none; }
.chunk-card { position: relative; border: 1px solid var(--line); border-radius: 18px; padding: 17px 88px 17px 17px; background: var(--surface); }
.chunk-card.favorite { border-color: #d8abc0; background: var(--wine-soft); }
.chunk-card .en { font-weight: 780; color: var(--navy-dark); line-height: 1.5; }
.chunk-card .zh { color: var(--muted); font-size: 13px; margin-top: 5px; }
.chunk-actions { position: absolute; top: 13px; right: 12px; display: flex; gap: 7px; }
.round-button { width: 32px; height: 32px; border: 0; border-radius: 10px; background: var(--blue-soft); color: var(--navy); cursor: pointer; }
.favorite .fav-button { background: var(--wine); color: white; }

.rhythm-card { border-left: 4px solid var(--wine); }
.rhythm-line { font-size: 18px; line-height: 1.6; color: var(--navy-dark); margin: 10px 0; }
.rhythm-line strong { color: var(--wine); }
.inline-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.frame-card { margin-bottom: 12px; }
.frame-card label { display: block; color: var(--wine); font-size: 12px; font-weight: 800; margin-bottom: 9px; }
.frame-pattern { color: var(--navy-dark); font-family: Georgia, serif; font-size: 17px; font-weight: 750; line-height: 1.55; }
.frame-example { margin: 9px 0; padding: 10px 12px; border-radius: 12px; background: var(--blue-soft); color: var(--navy-dark); line-height: 1.5; }
.frame-example small { display: block; color: var(--muted); font-size: 10px; font-weight: 800; margin-bottom: 3px; }
.frame-answer { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; color: var(--navy-dark); outline: none; }
.frame-answer:focus { border-color: var(--navy); box-shadow: 0 0 0 3px var(--blue-soft); }
.frame-builder { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; line-height: 1.7; }
.frame-builder input { flex: 1 1 220px; min-height: 42px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; color: var(--navy-dark); outline: none; }
.frame-builder input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px var(--blue-soft); }
.personal-output { padding: 17px; border-radius: 16px; background: var(--teal-soft); color: #155c5d; line-height: 1.7; }
.subsection-heading { margin-top: 34px; padding-top: 24px; border-top: 1px solid var(--line); }
.subsection-heading h2 { margin-bottom: 6px; }
.substitution-list { display: grid; gap: 11px; }
.substitution-card { border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: #fff; }
.substitution-slot { color: var(--wine); font-size: 12px; font-weight: 800; margin-bottom: 9px; }
.substitution-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sub-option { min-height: 64px; text-align: left; border: 1px solid var(--line); border-radius: 13px; padding: 9px 11px; background: var(--bg); color: var(--navy-dark); cursor: pointer; line-height: 1.4; }
.sub-option small { display: block; color: var(--muted); font-size: 10px; margin-bottom: 4px; }
.sub-option.selected { border-color: var(--navy); background: var(--blue-soft); box-shadow: 0 0 0 2px rgba(23,79,131,.08); }
.sub-custom { width: 100%; min-height: 42px; margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 0 11px; outline: none; }
.sub-custom:focus { border-color: var(--navy); box-shadow: 0 0 0 3px var(--blue-soft); }
.ladder-list { display: grid; gap: 8px; }
.ladder-item { width: 100%; display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; text-align: left; border: 1px solid var(--line); border-radius: 15px; padding: 11px; background: #fff; cursor: pointer; }
.ladder-item > b { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--navy); color: white; }
.ladder-item span { color: var(--navy-dark); line-height: 1.45; }
.ladder-item small { display: block; color: var(--wine); font-weight: 800; margin-bottom: 2px; }
.ladder-item i { color: var(--navy); font-size: 11px; font-style: normal; font-weight: 800; white-space: nowrap; }
.ladder-item:nth-child(n+5) > b { background: var(--wine); }
.ladder-task { margin-top: 12px; padding: 14px; border-radius: 14px; background: var(--wine-soft); color: var(--wine); line-height: 1.6; }
.highlight-legend { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; margin: 8px 0; }
.highlight-legend span { width: 20px; height: 10px; background: #fff19b; border-radius: 3px; }
.chunk-highlight { background: #fff19b; color: inherit; padding: 1px 2px; border-radius: 3px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }

.word-bank-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 11px; }
.word-card { position: relative; min-width: 0; display: grid; grid-template-columns: 36px 1fr 34px; gap: 11px; align-items: start; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(145deg,#fff,#f7fafc); }
.word-index { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: var(--navy); color: white; font-size: 11px; font-weight: 850; }
.word-copy { min-width: 0; }
.word-copy h3 { margin: 0 0 3px; color: var(--navy); font-size: 17px; }
.word-copy p { margin: 0 0 9px; color: var(--wine); font-size: 12px; font-weight: 750; }
.word-copy div { color: var(--ink); font-family: Georgia,"Times New Roman",serif; line-height: 1.55; }
.learning-tip { margin-top: 16px; padding: 15px 17px; border-radius: 15px; background: var(--wine-soft); color: var(--wine); line-height: 1.7; }
.level-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 13px 15px; border-left: 4px solid var(--navy); border-radius: 4px 14px 14px 4px; background: var(--blue-soft); color: var(--navy); }
.level-meta span { color: var(--muted); font-size: 13px; line-height: 1.55; }
.vocab-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; margin-top: 16px; }
.vocab-card { min-width: 0; padding: 17px; border: 1px solid var(--line); border-left: 4px solid var(--navy); border-radius: 17px; background: var(--blue-soft); }
.vocab-card.level-A2,.vocab-card.level-B2,.vocab-card.level-C2 { border-left-color: var(--wine); background: var(--wine-soft); }
.vocab-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 5px 10px; }
.vocab-head h3 { margin: 0; color: var(--navy); font-size: 18px; }
.vocab-card.level-A2 .vocab-head h3,.vocab-card.level-B2 .vocab-head h3,.vocab-card.level-C2 .vocab-head h3 { color: var(--wine); }
.vocab-head span { color: var(--muted); font-size: 10px; }
.ipa { margin-top: 5px; color: var(--muted); font-family: "Arial Unicode MS","Noto Sans",sans-serif; font-size: 12px; overflow-wrap: anywhere; }
.vocab-meaning { margin-top: 9px; color: var(--ink); font-weight: 750; }
.vocab-example { margin: 9px 0 13px; color: var(--navy-dark); font-family: Georgia,"Times New Roman",serif; line-height: 1.55; }
.vocab-example small { display: block; margin-top: 4px; color: var(--muted); font-family: Inter,-apple-system,"PingFang SC",sans-serif; }

.level-tabs { display: flex; gap: 7px; overflow-x: auto; margin-bottom: 14px; }
.level-tabs button { min-width: 58px; border: 1px solid var(--line); background: white; border-radius: 12px; padding: 9px; font-weight: 750; cursor: pointer; }
.level-tabs button.active { color: white; background: var(--navy); border-color: var(--navy); }
.script-box { max-width: 100%; overflow-wrap: anywhere; background: var(--blue-soft); padding: 18px; border-radius: 17px; font-family: Georgia, serif; color: var(--navy-dark); line-height: 1.75; }
.prompt-chain { display: flex; flex-wrap: wrap; gap: 7px; margin: 16px 0; }
.prompt-chain span { padding: 7px 10px; border-radius: 99px; background: var(--wine-soft); color: var(--wine); font-size: 11px; font-weight: 800; }
.recorder { border: 1px dashed #adc0cf; border-radius: 20px; padding: 20px; text-align: center; }
.record-button { width: 72px; height: 72px; border-radius: 50%; border: 7px solid var(--wine-soft); background: var(--wine); color: white; font-size: 22px; cursor: pointer; }
.record-button.recording { animation: pulse 1.2s infinite; }
.replay-button { margin-top: 8px; min-width: 138px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 16px rgba(159,31,80,.12); } }
.record-time { font-variant-numeric: tabular-nums; font-size: 26px; color: var(--navy); font-weight: 800; margin: 10px 0 4px; }

.lesson-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }
.review-card { min-height: 230px; display: grid; place-content: center; text-align: center; }
.review-card .question { color: var(--muted); margin-bottom: 15px; }
.review-answer { font-size: 23px; line-height: 1.4; color: var(--navy-dark); font-weight: 780; }
.review-controls { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; margin-top: 15px; }

.works-list { display: grid; gap: 10px; }
.work-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; }
.work-row p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty b { display: block; font-size: 18px; color: var(--navy); margin-bottom: 6px; }
.toast { position: fixed; z-index: 90; left: 50%; bottom: 96px; transform: translate(-50%, 18px); background: var(--navy-dark); color: white; padding: 11px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .22s ease; box-shadow: var(--shadow); font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.install-sheet { position: fixed; z-index: 120; inset: 0; display: grid; place-items: end center; padding: 18px; background: rgba(10,34,51,.46); backdrop-filter: blur(6px); }
.install-card { position: relative; width: min(100%, 460px); padding: 26px; border-radius: 26px; background: white; box-shadow: 0 24px 60px rgba(10,34,51,.28); }
.install-close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--bg); color: var(--muted); font-size: 22px; cursor: pointer; }
.install-icon { width: 68px; height: 68px; margin-bottom: 16px; border-radius: 17px; overflow: hidden; box-shadow: var(--shadow); }
.install-icon img { width: 100%; height: 100%; display: block; }
.install-card h2 { margin: 6px 0 12px; }
.install-card p { color: var(--muted); line-height: 1.7; }
.install-steps { margin: 14px 0 20px; padding-left: 24px; color: var(--navy-dark); line-height: 1.9; }
.install-steps b { color: var(--wine); }
.install-done { width: 100%; }

@media (max-width: 680px) {
  #main-content { width: 100vw; max-width: 100vw; padding: 18px 14px 28px; overflow: hidden; }
  .lesson-head, .lesson-panel { width: 100%; max-width: 100%; overflow: hidden; }
  .stepper, .level-tabs, .script-box, .prompt-chain, .recorder, .lesson-footer { min-width: 0; max-width: 100%; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero-card { padding: 22px; }
  .stat-grid { grid-template-columns: repeat(3,1fr); }
  .stat { padding: 12px 10px; }
  .stat b { font-size: 20px; }
  .topic-card { grid-template-columns: 48px 1fr; }
  .topic-number { width: 48px; height: 48px; }
  .topic-meta { grid-column: 2; text-align: left; }
  .stepper { display: flex; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 4px; }
  .step-pill { flex: 0 0 68px; scroll-snap-align: start; padding: 8px 2px; }
  .step-pill span { font-size: 9px; }
  .lesson-footer .btn { flex: 1; min-width: 0; padding: 0 10px; }
  .substitution-options { grid-template-columns: 1fr; }
  .word-bank-grid, .vocab-grid { grid-template-columns: 1fr; }
  .ladder-item { grid-template-columns: 30px 1fr; }
  .ladder-item i { grid-column: 2; }
}

@media (min-width: 900px) {
  .app-shell { padding-bottom: 96px; }
  .topbar { padding-left: calc((100vw - 980px)/2 + 18px); padding-right: calc((100vw - 980px)/2 + 18px); }
}
