:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #132018;
  --muted: #647067;
  --line: #deeadf;
  --green: #16a34a;
  --green-dark: #15803d;
  --green-soft: #dcfce7;
  --amber: #f59e0b;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  width: min(480px, 100%);
  margin: 0 auto;
  padding: 14px 14px 84px;
}

.topbar {
  display: block;
  margin-bottom: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(135deg, #ffffff 0%, #eaf8ef 100%);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.05);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.hero-copy {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.top-actions,
.controls,
.after-reading,
.speech-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 800;
  text-align: center;
}

.primary-button {
  background: var(--green);
  color: #ffffff;
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  border: 1px solid #e4e7ec;
  background: #f2f4f7;
  color: #98a2b3;
}

.secondary-button {
  border: 1px solid #cfdad2;
  background: #ffffff;
  color: #1d2939;
}

.ghost-button {
  background: var(--green-soft);
  color: var(--green-dark);
}

.danger-button {
  background: var(--red-soft);
  color: #991b1b;
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  border: 1px solid #e4e7ec;
  background: #f2f4f7;
  color: #98a2b3;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.05);
}

.metric-card {
  padding: 14px 10px;
  text-align: center;
}

.metric-value {
  display: block;
  font-size: 28px;
  font-weight: 900;
}

.metric-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view-panel[hidden] {
  display: none;
}

.panel {
  padding: 18px;
}

.section-head {
  margin-bottom: 14px;
}

.section-head p,
.reader-head p,
.hint {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

.lesson-list,
.mistake-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lesson-card {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto 24px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 82px;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdfb;
  color: inherit;
  text-align: left;
}

.lesson-card.active {
  border-color: var(--green);
  background: #f0fdf4;
}

.lesson-card.locked {
  background: #ffffff;
  color: #98a2b3;
  opacity: 0.78;
}

.lesson-no {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 11px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-weight: 900;
}

.lesson-card.locked .lesson-no {
  background: #f2f4f7;
  color: #c0c8d2;
}

.lesson-main {
  min-width: 0;
}

.lesson-status {
  display: block;
  width: max-content;
  max-width: 100%;
  margin-bottom: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.5;
}

.lesson-card.locked .lesson-status {
  background: #f2f4f7;
  color: #98a2b3;
}

.lesson-grade {
  align-self: start;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.lesson-lock {
  color: #c0c8d2;
  font-size: 20px;
  font-weight: 900;
  text-align: right;
}

.lesson-title {
  display: block;
  font-weight: 850;
  line-height: 1.35;
}

.lesson-desc {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.lesson-card.locked .lesson-desc {
  color: #b8c0cc;
}

.reader-panel {
  order: 1;
}

.lesson-list-panel {
  order: 2;
}

.mistake-panel {
  order: 3;
}

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

.score-pill {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #475467;
  font-weight: 850;
}

.score-pill.good {
  background: var(--green-soft);
  color: var(--green-dark);
}

.score-pill.warn {
  background: #fef3c7;
  color: #92400e;
}

.result-score {
  justify-self: start;
  border-radius: 14px;
}

.target-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.target-card,
.mistake-card {
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdfb;
  text-align: center;
}

.target-card.marked {
  border-color: #fca5a5;
  background: #fff1f2;
}

.target-char,
.mistake-char {
  display: block;
  font-size: 34px;
  font-weight: 900;
  line-height: 1.1;
}

.target-pinyin,
.mistake-pinyin {
  display: block;
  margin-top: 6px;
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 800;
}

.story-box {
  min-height: 220px;
  margin: 14px 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffefb;
  font-size: 26px;
  line-height: 2;
}

.story-char {
  display: inline-flex;
  min-width: 1em;
  justify-content: center;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  vertical-align: baseline;
}

.story-char:hover {
  background: var(--green-soft);
}

.story-char.marked {
  background: var(--red-soft);
  color: #991b1b;
  font-weight: 900;
}

.char-help {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px;
  margin: -4px 0 14px;
  padding: 12px 14px;
  border: 1px solid #bbf7d0;
  border-radius: 14px;
  background: #f0fdf4;
}

.char-help-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.char-help-char {
  color: var(--ink);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}

.char-help-pinyin {
  color: var(--green-dark);
  font-size: 20px;
  font-weight: 900;
}

.speech-panel {
  display: grid;
  gap: 14px;
  margin: 14px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f8fbf9;
}

.result-panel {
  background: #ffffff;
}

.speech-result {
  padding: 14px;
  border-radius: 8px;
  background: #ffffff;
}

.result-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

#recognizedText {
  color: #1d2939;
  line-height: 1.7;
}

.wrong-chars {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  max-height: 260px;
  overflow: auto;
}

.wrong-note {
  grid-column: 1 / -1;
  padding: 14px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  line-height: 1.55;
}

.wrong-summary {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.punctuation {
  color: #758177;
}

.mistake-card {
  position: relative;
}

.mistake-source {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.remove-mistake {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #f2f4f7;
  color: #667085;
  font-size: 14px;
}

.empty-note {
  padding: 16px;
  border-radius: 14px;
  background: #f8fbf9;
  color: var(--muted);
  line-height: 1.55;
}

.bottom-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(480px, 100%);
  margin: 0 auto;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.tab-button {
  padding: 10px 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 850;
  text-align: center;
  text-decoration: none;
}

.tab-button:focus,
.tab-button:hover,
.tab-button.active {
  background: var(--green-soft);
  color: var(--green-dark);
}

.top-actions {
  margin-top: 18px;
}

.top-actions button,
.controls button,
.after-reading button,
.speech-actions button {
  flex: 1 1 calc(50% - 8px);
}

.speech-actions .primary-button {
  flex-basis: 100%;
}

@media (min-width: 760px) {
  body {
    background:
      linear-gradient(90deg, rgba(15, 23, 42, 0.04), transparent 24%, transparent 76%, rgba(15, 23, 42, 0.04)),
      var(--bg);
  }
}
