:root {
  color-scheme: light;
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  --word-font: "Century Gothic", Futura, "Avenir Next", "Trebuchet MS", sans-serif;
  --bg: #edf8f5;
  --panel: #fbfdf8;
  --surface: #f3fbf3;
  --control: #fffdf7;
  --ink: #20343a;
  --muted: #61747a;
  --line: #cfe1da;
  --blue: #4f87a3;
  --green: #4f9378;
  --red: #b56560;
  --amber: #c8963f;
  --peach: #efaa90;
  --mint: #a7dbbd;
  --sky: #a8d8ef;
  --lemon: #efd665;
  --soft-blue: #e6f4fb;
  --soft-green: #e5f6ec;
  --soft-red: #f7e7e2;
  --shadow: 0 12px 28px rgba(32, 52, 58, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  touch-action: pan-x pan-y;
}

body {
  background:
    linear-gradient(90deg, rgba(79, 135, 163, 0.045) 1px, transparent 1px),
    linear-gradient(180deg, rgba(79, 147, 120, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, #fffdf5 0, #f4fbf7 280px, var(--bg) 100%),
    var(--bg);
  background-size: 28px 28px, 28px 28px, auto, auto;
  color: var(--ink);
  font-family: var(--ui-font);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app {
  width: min(980px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 20px 0 28px;
}

.topbar,
.parent-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.94);
  padding: 12px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--sky) 0 48%, var(--lemon) 48% 82%, var(--peach) 82% 100%);
  color: #2f3f3c;
  font-weight: 800;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.42);
}

.brand h1 {
  font-size: 24px;
  line-height: 1.1;
}

#progressText,
.muted-text,
.field span,
.word-cn,
.quiz-meta,
.done-copy {
  color: var(--muted);
}

.child-view {
  display: grid;
  gap: 16px;
}

.hero-panel,
.panel,
.quiz-card,
.study-card,
.write-card,
.done-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-panel {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.compact-hero {
  position: relative;
  overflow: hidden;
  padding: 14px 16px;
  box-shadow: none;
}

.compact-hero::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: linear-gradient(180deg, var(--peach), var(--lemon), var(--mint), var(--sky));
}

.hero-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.hero-title {
  overflow-wrap: anywhere;
  font-size: clamp(30px, 6vw, 64px);
  line-height: 1.06;
  font-weight: 850;
}

.compact-hero .hero-title {
  font-size: 22px;
}

.hero-subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-size: 18px;
}

.compact-hero .hero-subtitle {
  margin-top: 4px;
  font-size: 15px;
}

.word-progress {
  display: flex;
  gap: 7px;
  margin-top: 10px;
}

.word-dot {
  width: 12px;
  height: 12px;
  border: 1px solid rgba(79, 135, 163, 0.28);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.9);
}

.word-dot.done {
  border-color: rgba(79, 147, 120, 0.34);
  background: var(--mint);
}

.word-dot.active {
  border-color: rgba(200, 150, 63, 0.46);
  background: var(--lemon);
  box-shadow: 0 0 0 4px rgba(239, 214, 101, 0.24);
}

.word-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.word-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  min-height: 92px;
}

.word-tile strong,
.record-card strong {
  display: block;
  overflow-wrap: anywhere;
}

.word-tile strong,
.masked-word,
.choice-button,
.study-word,
.single-write-word,
.write-word,
.image-card strong {
  font-family: var(--word-font);
  font-variant-ligatures: none;
}

.word-cn {
  display: block;
  margin-top: 6px;
  font-size: 14px;
}

.step-indicator {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.step-pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.8);
  padding: 0 12px;
  color: var(--muted);
  font-weight: 700;
}

.step-pill.active {
  border-color: rgba(200, 150, 63, 0.58);
  background: #fff3bf;
  color: #51472b;
}

.step-pill:nth-child(1) {
  border-color: rgba(232, 180, 158, 0.62);
}

.step-pill:nth-child(2) {
  border-color: rgba(184, 206, 216, 0.78);
}

.step-pill:nth-child(3) {
  border-color: rgba(185, 215, 189, 0.78);
}

.quiz-card,
.study-card,
.write-card,
.done-card {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.focus-card {
  position: relative;
  overflow: hidden;
  min-height: min(560px, calc(100vh - 210px));
  align-content: center;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.9), rgba(243, 251, 243, 0.84)),
    var(--panel);
  transition: border-color 120ms ease, background-color 120ms ease, transform 120ms ease;
}

.focus-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 10px;
  background: linear-gradient(90deg, var(--peach), var(--lemon), var(--mint), var(--sky));
}

.focus-card.ok {
  border-color: rgba(93, 127, 108, 0.55);
  background: var(--panel);
}

.focus-card.no {
  border-color: rgba(166, 107, 97, 0.5);
  background: var(--panel);
}

.quiz-top,
.write-top,
.panel-head {
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
  text-align: center;
}

.quiz-top h2,
.write-top h2 {
  font-size: clamp(34px, 5.4vw, 56px);
  line-height: 1.08;
}

.study-card {
  text-align: center;
}

.study-card .submit-strip {
  justify-content: center;
  text-align: center;
}

.study-card .write-actions {
  justify-content: center;
}

.study-word {
  overflow-wrap: anywhere;
  font-size: clamp(46px, 10vw, 92px);
  line-height: 1.04;
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
}

.study-cn {
  color: #9d6058;
  font-size: clamp(24px, 5vw, 44px);
  font-weight: 800;
}

.study-example {
  color: var(--muted);
  font-size: 20px;
  line-height: 1.45;
}

.study-example-row {
  display: inline-flex;
  max-width: min(680px, 100%);
  justify-content: center;
  align-items: center;
  gap: 10px;
  justify-self: center;
  flex-wrap: wrap;
}

.sound-button {
  justify-self: center;
  min-width: min(260px, 100%);
  min-height: 58px;
  border: 1px solid rgba(79, 147, 120, 0.38);
  border-radius: 8px;
  background: linear-gradient(180deg, #effbef, #dff4e6);
  color: #2f654f;
  font-weight: 850;
  box-shadow: 0 3px 0 rgba(79, 147, 120, 0.16);
}

.mini-sound-button {
  min-height: 34px;
  border: 1px solid rgba(79, 135, 163, 0.28);
  border-radius: 8px;
  background: var(--soft-blue);
  color: #4f7182;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 800;
}

.quiz-sound-button {
  min-width: min(320px, 100%);
  min-height: 66px;
  font-size: 22px;
}

.dictation-hint {
  color: var(--muted);
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}

.quiz-meta {
  font-weight: 700;
}

.masked-word {
  overflow-wrap: anywhere;
  font-size: clamp(44px, 8vw, 76px);
  line-height: 1.15;
  font-weight: 850;
  letter-spacing: 0;
  white-space: pre-wrap;
  text-align: center;
}

.choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 14px;
  width: min(520px, 100%);
  justify-self: center;
}

.choice-button {
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
  font-size: 34px;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(79, 135, 163, 0.08);
}

.remember-button {
  justify-self: center;
  min-width: min(260px, 100%);
  min-height: 62px;
}

.choice-button:active,
.choice-button:hover,
.plain-button:hover,
.quiet-button:hover,
.icon-button:hover {
  border-color: var(--blue);
  background: var(--soft-blue);
}

.feedback {
  min-height: 28px;
  text-align: center;
  font-weight: 800;
}

.feedback.no {
  display: inline-flex;
  justify-self: center;
  min-height: 34px;
  align-items: center;
  border-radius: 8px;
  background: var(--soft-red);
  padding: 0 14px;
}

.feedback.ok {
  color: var(--green);
}

.feedback.no {
  color: var(--red);
}

.write-list {
  display: grid;
  gap: 14px;
}

.write-item {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.write-prompt {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.write-word {
  overflow-wrap: anywhere;
  font-size: clamp(24px, 5vw, 42px);
  line-height: 1.08;
  font-weight: 850;
}

.single-write-word {
  overflow-wrap: anywhere;
  text-align: center;
  font-size: clamp(38px, 8vw, 82px);
  line-height: 1.05;
  font-weight: 900;
}

.single-write-item {
  background: transparent;
  border: 0;
  padding: 0;
}

.single-canvas {
  height: min(470px, 52vh);
}

.writing-canvas {
  display: block;
  width: 100%;
  height: 210px;
  border: 1px solid #cfd8cf;
  border-radius: 8px;
  background:
    linear-gradient(0deg, transparent 31px, rgba(184, 206, 216, 0.22) 32px),
    #f2f6ea;
  background-size: 100% 32px, auto;
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.32),
    inset 12px 0 0 rgba(232, 180, 158, 0.16);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.write-actions,
.dialog-actions,
.stack-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.submit-strip {
  position: static;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  border: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.done-card {
  min-height: 420px;
  place-items: center;
  text-align: center;
}

.done-title {
  color: #557765;
  font-size: clamp(40px, 8vw, 76px);
  line-height: 1;
  font-weight: 900;
}

.done-actions {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

.primary-button,
.plain-button,
.quiet-button,
.icon-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  background: var(--control);
  color: var(--ink);
}

.primary-button {
  border-color: rgba(79, 135, 163, 0.56);
  background: linear-gradient(180deg, #5d97b2, #4f7f99);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(42, 86, 103, 0.18);
}

.quiet-button {
  color: var(--muted);
}

.icon-button {
  display: inline-grid;
  width: 42px;
  padding: 0;
  place-items: center;
  font-weight: 900;
}

.danger-button {
  color: var(--red);
}

.dialog {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
}

.dialog::backdrop {
  background: rgba(24, 32, 51, 0.38);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field input,
.field select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
  padding: 0 12px;
}

.error-text {
  min-height: 22px;
  color: var(--red);
  font-weight: 700;
}

.parent-view {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: auto;
  background:
    linear-gradient(180deg, #f5f7f1 0, var(--bg) 280px),
    var(--bg);
  padding: 20px;
}

.parent-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.parent-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}

.panel {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
}

.records-panel,
.handwriting-panel {
  grid-column: span 1;
}

.status-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.status-card,
.record-card,
.image-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.status-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(18px, 2.2vw, 24px);
  line-height: 1.18;
}

.status-card span {
  color: var(--muted);
  font-size: 14px;
}

.status-card.wide {
  grid-column: 1 / -1;
}

.records-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
}

.record-card {
  width: 100%;
  text-align: left;
}

.record-card.active {
  border-color: var(--blue);
  background: var(--soft-blue);
}

.record-detail {
  display: grid;
  gap: 12px;
}

.image-card img {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf2;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  transform: translateX(-50%) translateY(18px);
  max-width: min(520px, calc(100vw - 32px));
  border-radius: 8px;
  background: #3f5551;
  color: #fff;
  padding: 12px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%);
}

.update-banner {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 52;
  transform: translateX(-50%) translateY(18px);
  width: min(620px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  background: #fffdf9;
  color: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.update-banner.show {
  opacity: 1;
  transform: translateX(-50%);
  pointer-events: auto;
}

.update-banner[hidden] {
  display: none;
}

.update-banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .app,
  .parent-view {
    width: 100%;
  }

  .app {
    padding: 12px 10px 24px;
  }

  .topbar,
  .hero-head,
  .submit-strip,
  .parent-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .word-strip,
  .choices,
  .status-cards,
  .parent-grid {
    grid-template-columns: 1fr;
  }

  .writing-canvas {
    height: 190px;
  }
}
