:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: rgba(0, 0, 0, 0.06);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.1);
  --green: #34c759;
  --green-soft: rgba(52, 199, 89, 0.12);
  --orange: #ff9500;
  --red: #ff3b30;
  --red-soft: rgba(255, 59, 48, 0.1);
  --radius: 20px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  --topbar-h: 56px;
  --keyboard-h: 200px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --border: rgba(255, 255, 255, 0.08);
    --text: #f5f5f7;
    --text-secondary: #aeaeb2;
    --text-tertiary: #8e8e93;
    --accent-soft: rgba(0, 122, 255, 0.2);
    --green-soft: rgba(52, 199, 89, 0.2);
    --red-soft: rgba(255, 59, 48, 0.15);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  animation: fadeUp 0.4s ease both;
}

.screen.active {
  display: flex;
}

.screen[hidden] {
  display: none !important;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake { animation: shake 0.35s ease; }

@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

.pop { animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

@keyframes starPop {
  0% { transform: scale(0) rotate(-20deg); }
  70% { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

.star-pop { animation: starPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

.topbar {
  display: flex;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.glass {
  background: rgba(245, 245, 247, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

@media (prefers-color-scheme: dark) {
  .glass { background: rgba(0, 0, 0, 0.72); }
}

.topbar-title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.02em;
}

.topbar-meta {
  flex: 1;
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
}

.topbar-spacer { width: 40px; }

.back-btn,
.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: background 0.15s;
}

.back-btn:hover,
.icon-btn:hover { background: var(--accent-soft); }

.star-badge {
  font-size: 14px;
  font-weight: 600;
  color: var(--orange);
  min-width: 40px;
  text-align: right;
}

.screen-body {
  flex: 1;
  padding: 24px 24px 32px;
}

.home-body {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.hero { text-align: center; padding-top: 12px; }

.hero-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  margin-bottom: 16px;
}

.hero-heading {
  margin: 0 0 12px;
  font-size: clamp(32px, 5vw, 44px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.hero-sub {
  margin: 0;
  color: var(--text-secondary);
  font-size: 16px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-pill {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-val {
  display: block;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.section-label {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.level-tabs {
  display: flex;
  gap: 8px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.level-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  border-radius: var(--radius-xs);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.level-tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 24px;
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  transition: transform 0.2s, box-shadow 0.2s;
}

.mode-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.mode-card:active { transform: scale(0.98); }

.mode-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mode-icon.en {
  background: var(--green-soft);
  color: var(--green);
}

.mode-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.mode-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

.lessons-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lesson-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  border: none;
  width: 100%;
  font-family: var(--font);
  text-align: left;
  transition: transform 0.15s, box-shadow 0.15s;
}

.lesson-item:hover:not(:disabled) {
  transform: translateX(4px);
  box-shadow: var(--shadow);
}

.lesson-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.lesson-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lesson-item.completed .lesson-num {
  background: var(--green-soft);
  color: var(--green);
}

.lesson-info { flex: 1; min-width: 0; }

.lesson-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.lesson-meta {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-tertiary);
}

.lesson-stars {
  font-size: 16px;
  letter-spacing: 2px;
  color: var(--orange);
  flex-shrink: 0;
}

.lesson-lock { font-size: 18px; flex-shrink: 0; }

.practice-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: calc(var(--keyboard-h) + 24px);
}

.progress-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.question-counter {
  margin: 0;
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
}

.prompt-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.prompt-emoji { font-size: 48px; line-height: 1; }

.prompt-hanzi {
  margin: 0;
  font-size: clamp(48px, 8vw, 64px);
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.2;
}

.prompt-hint {
  margin: 0;
  font-size: 15px;
  color: var(--text-secondary);
}

.prompt-english {
  margin: 0;
  font-size: clamp(28px, 4vw, 36px);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.typing-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.english-display {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: clamp(22px, 3vw, 28px);
  line-height: 1.8;
  padding: 20px 24px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  word-break: break-all;
  min-height: 80px;
}

.char { transition: color 0.1s; }
.char.correct { color: var(--text-tertiary); }
.char.current {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 3px;
  padding: 0 1px;
  border-bottom: 2px solid var(--accent);
}
.char.error {
  color: var(--red);
  background: var(--red-soft);
  border-radius: 3px;
}
.char.pending { color: var(--text); }

.pinyin-input-wrap { position: relative; }

.pinyin-preview {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 28px;
  letter-spacing: 0.15em;
  padding: 16px 20px;
  background: var(--surface-2);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  min-height: 56px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
}

.pinyin-char { display: inline-block; }
.pinyin-char.matched { color: var(--green); }
.pinyin-char.pending { color: var(--text-tertiary); }
.pinyin-char.cursor {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

.pinyin-input {
  width: 100%;
  padding: 16px 20px;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 24px;
  letter-spacing: 0.1em;
  border: 2px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.pinyin-input:focus { border-color: var(--accent); }
.pinyin-input.correct-flash { border-color: var(--green); }
.pinyin-input.error-flash { border-color: var(--red); }

.typing-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
}

.live-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  flex-wrap: wrap;
}

.live-stat { text-align: center; }

.live-stat-val {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.live-stat-label {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.encourage-msg {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--green);
  min-height: 28px;
}

.keyboard-wrap {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 1080px;
  padding: 12px 16px 20px;
  background: rgba(245, 245, 247, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}

@media (prefers-color-scheme: dark) {
  .keyboard-wrap { background: rgba(28, 28, 30, 0.92); }
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.keyboard-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.key {
  min-width: 36px;
  height: 40px;
  padding: 0 8px;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15), var(--shadow-sm);
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}

.key.wide { min-width: 56px; }
.key.space { min-width: 200px; }

.key.highlight {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 2px var(--accent), 0 4px 12px rgba(0, 122, 255, 0.4);
  transform: translateY(-2px);
}

.key.error-flash {
  background: var(--red);
  color: #fff;
  animation: shake 0.3s ease;
}

.key.shift-hint {
  background: var(--orange);
  color: #fff;
}

.result-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-h));
}

.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 480px;
  width: 100%;
}

.result-emoji { font-size: 64px; margin: 0 0 8px; }

.result-title {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.result-sub {
  margin: 0 0 24px;
  color: var(--text-secondary);
  font-size: 15px;
}

.result-stars {
  font-size: 40px;
  letter-spacing: 8px;
  color: var(--orange);
  margin-bottom: 28px;
  min-height: 48px;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 32px;
}

.result-stat-val {
  display: block;
  font-size: 24px;
  font-weight: 700;
}

.result-stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  width: 100%;
}

.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--text-secondary); }
.btn.warn { background: var(--red-soft); color: var(--red); }

.parent-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 28px;
  max-width: 400px;
  width: calc(100% - 48px);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-family: var(--font);
  color: var(--text);
}

.parent-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

.parent-dialog h2 {
  margin: 0 0 20px;
  font-size: 20px;
  font-weight: 700;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  cursor: pointer;
  font-size: 15px;
}

.switch-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.dialog-info {
  margin: 8px 0 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.parent-dialog .btn { margin-top: 8px; }

@media (max-width: 640px) {
  .mode-cards { grid-template-columns: 1fr; }
  .screen-body { padding: 16px; }
  .key { min-width: 28px; height: 34px; font-size: 11px; }
  .key.space { min-width: 140px; }
}

@media (min-width: 960px) {
  .practice-body { padding-left: 48px; padding-right: 48px; }
}
