:root {
  --bg1: #eef4ff;
  --bg2: #f8fafc;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(30, 41, 59, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 45%);
  min-height: 100vh;
}

.app { max-width: 980px; margin: 0 auto; padding: 20px 16px 60px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 34px; line-height: 1; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.5px; }
.brand .sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.server-badge {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: 6px 14px; font-size: 12px; cursor: default;
}
.server-badge.ok { color: var(--green); border-color: #bbf7d0; background: #f0fdf4; }
.server-badge.bad { color: var(--red); border-color: #fecaca; background: #fef2f2; }

.tabs {
  display: flex; gap: 6px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 6px; overflow-x: auto; margin-bottom: 16px;
  position: sticky; top: 8px; z-index: 10; box-shadow: var(--shadow);
}
.tabs button {
  border: 0; background: transparent; padding: 9px 18px; border-radius: 10px;
  font-size: 14px; color: var(--muted); cursor: pointer; white-space: nowrap; font-weight: 600;
}
.tabs button.active { background: var(--primary); color: #fff; }
.tabs button:hover:not(.active) { background: var(--primary-soft); color: var(--primary); }

.tab { display: none; }
.tab.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 17px; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.row-end { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 12px; padding: 10px 18px; font-size: 14px; cursor: pointer;
  font-weight: 600; transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.btn:hover { box-shadow: 0 4px 12px rgba(79, 70, 229, 0.18); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); border: 0; color: #fff; }
.btn.secondary { background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.lg { padding: 13px 26px; font-size: 15px; }
.btn.small { padding: 6px 12px; font-size: 12px; border-radius: 9px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.mode-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.mode-pills button {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: 8px 18px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.mode-pills button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.notice-bar {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 12px; padding: 10px 14px; font-size: 13px; margin-bottom: 12px;
}

.practice-card { padding: 20px; }
.practice-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.target-box { text-align: center; flex: 1; min-width: 180px; }
.target-char {
  font-size: 64px; font-weight: 800; line-height: 1.1; color: var(--primary-dark);
  word-break: break-all; white-space: pre-wrap;
}
.target-pinyin { font-size: 22px; color: var(--primary); font-weight: 700; margin-top: 2px; }
.target-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.target-actions { display: flex; flex-direction: column; gap: 10px; }

.tips-box {
  background: var(--primary-soft); border-radius: 12px; padding: 12px 14px;
  font-size: 13.5px; line-height: 1.7; margin: 14px 0;
}
.tips-box b { color: var(--primary-dark); }

.recorder-area { text-align: center; }
.meter-wrap { max-width: 560px; margin: 0 auto 12px; }
.meter-wrap canvas { width: 100%; height: 48px; border-radius: 12px; background: #f1f5f9; display: block; }
.rec-controls { display: flex; align-items: center; justify-content: center; gap: 18px; }
.rec-btn {
  width: 92px; height: 92px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(135deg, #ef4444, #b91c1c); color: #fff; font-size: 30px;
  box-shadow: 0 8px 20px rgba(220, 38, 38, 0.35); transition: transform 0.1s ease;
}
.rec-btn:hover { transform: scale(1.05); }
.rec-btn:active { transform: scale(0.95); }
.rec-btn.recording { animation: pulse 1.2s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
  50% { box-shadow: 0 0 0 18px rgba(220, 38, 38, 0); }
}
.rec-time { font-size: 15px; font-weight: 700; color: var(--muted); min-width: 56px; }
.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.result-area { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 16px; }
.result-grid { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.score-wrap { position: relative; width: 120px; height: 120px; flex: 0 0 auto; }
.score-ring { width: 120px; height: 120px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #e2e8f0; stroke-width: 10; }
.ring-fg {
  fill: none; stroke: var(--primary); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset 0.6s ease, stroke 0.4s ease;
}
.score-num {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 26px; font-weight: 800;
}
.score-num small { font-size: 11px; color: var(--muted); font-weight: 500; }
.result-info { flex: 1; min-width: 260px; }
.grade { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.recog-line { font-size: 14px; margin-bottom: 6px; }
.char-match { font-size: 15px; letter-spacing: 2px; line-height: 1.8; margin-bottom: 8px; }
.char-match .ok { color: var(--green); }
.char-match .bad { color: var(--red); text-decoration: underline wavy; }
.char-match .conf { color: var(--amber); text-decoration: underline wavy; }
.feedback { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.8; color: #334155; }
.feedback li::marker { color: var(--primary); }

.pitch-wrap { margin-top: 16px; }
.pitch-wrap h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); }
.pitch-wrap canvas { width: 100%; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; }

.ai-panel {
  margin-top: 14px; background: linear-gradient(135deg, #f5f3ff, #eef2ff);
  border: 1px solid #ddd6fe; border-radius: 12px; padding: 14px; font-size: 13.5px; line-height: 1.8;
}
.ai-panel h4 { margin: 0 0 8px; color: var(--primary-dark); font-size: 14px; }
.ai-panel table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.ai-panel th, .ai-panel td { border: 1px solid #ddd6fe; padding: 6px 8px; text-align: left; font-size: 12.5px; }

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.self-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.self-check .btn.selected { background: var(--primary); color: #fff; border-color: var(--primary); }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 22px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: 0 10px 28px rgba(15, 23, 42, 0.35);
  z-index: 100; max-width: 90vw; text-align: center;
  animation: toastIn 0.25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.eb-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; flex-wrap: wrap;
}
.eb-item .eb-text { font-size: 16px; font-weight: 800; color: var(--red); }
.eb-item .eb-info { font-size: 12px; color: var(--muted); }
.eb-item .btn { flex-shrink: 0; }

.phoneme-groups { display: flex; flex-direction: column; gap: 12px; }
.pgroup h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); }
.pgroup .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pchip {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px;
  cursor: pointer; text-align: center; min-width: 74px; transition: all 0.12s ease;
}
.pchip:hover { border-color: var(--primary); box-shadow: 0 4px 10px rgba(79, 70, 229, 0.16); }
.pchip .p { font-size: 18px; font-weight: 800; color: var(--primary-dark); }
.pchip .w { font-size: 11px; color: var(--muted); margin-top: 2px; }

.tone-diagram { max-width: 560px; margin: 0 auto 12px; }
.tone-diagram svg { width: 100%; height: auto; }
.tone-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tone-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.tone-card .tn { font-size: 15px; font-weight: 800; color: var(--primary-dark); }
.tone-card .tc { font-size: 26px; font-weight: 800; margin: 4px 0; }
.tone-card .tp { color: var(--primary); font-weight: 700; font-size: 15px; }
.tone-card .td { font-size: 12px; color: var(--muted); }

.mp-cat { margin-bottom: 14px; }
.mp-cat h4 { margin: 0 0 4px; font-size: 14px; color: var(--primary-dark); }
.mp-cat p { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.mp-pairs { display: flex; flex-wrap: wrap; gap: 8px; }
.mp-pair {
  border: 1px solid var(--line); background: #f8fafc; border-radius: 10px;
  padding: 7px 12px; font-size: 13.5px; font-weight: 600;
}
.mp-pair .vs { color: var(--muted); font-weight: 400; margin: 0 4px; }

.twister-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.twister-card .tt { font-size: 16px; font-weight: 800; color: var(--primary-dark); }
.twister-card .tt-focus { display: inline-block; font-size: 11px; background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 2px 10px; margin-left: 8px; }
.twister-card .tt-content { font-size: 14px; line-height: 1.9; margin: 8px 0; white-space: pre-wrap; }
.twister-card .tt-tip { font-size: 12px; color: var(--muted); }
.twister-card .row-between { margin-top: 6px; }

#weakList .weak-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; flex-wrap: wrap;
}
.weak-item .wp { font-size: 18px; font-weight: 800; color: var(--red); }
.weak-item .ws { font-size: 12px; color: var(--muted); }
.weak-actions { margin-top: 14px; }
.empty-tip { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { text-align: center; margin-bottom: 0; }
.stat-num { font-size: 30px; font-weight: 800; color: var(--primary-dark); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td .score-badge { font-weight: 800; }
.score-badge.high { color: var(--green); }
.score-badge.mid { color: var(--amber); }
.score-badge.low { color: var(--red); }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #334155; }
.form-row input[type="text"], .form-row input[type="password"], .form-row select {
  width: 100%; max-width: 480px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; background: #fff;
}
.form-row input[type="range"] { width: 100%; max-width: 480px; }
.radio-group { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.radio-group label { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 0; }
.switch-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 14px; cursor: pointer; }
.cat-checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.cat-checks label {
  display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; font-size: 13px; cursor: pointer; line-height: 1.5;
}
.cat-checks .cat-name { font-weight: 700; }
.cat-checks .cat-desc { font-size: 11px; color: var(--muted); }
.docs { font-size: 13px; line-height: 1.9; padding-left: 20px; color: #334155; }
#aiTestResult { margin-top: 10px; }

footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }

@media (max-width: 640px) {
  .app { padding: 12px 10px 40px; }
  .target-char { font-size: 48px; }
  .practice-top { flex-direction: column; }
  .result-grid { justify-content: center; }
  .tabs { top: 4px; }
}
