:root {
  --primary: #7c3aed;
  --primary-strong: #6d28d9;
  --primary-soft: #ede9fe;
  --primary-softer: #f5f3ff;
  --bg: #f7f7fb;
  --card: #ffffff;
  --text: #1f2333;
  --text-2: #5b6172;
  --text-3: #9aa0b0;
  --border: #e8e9f0;
  --green: #10b981;
  --green-soft: #d1fae5;
  --red: #ef4444;
  --red-soft: #fee2e2;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .05);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 980px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand-logo { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .5px; }
.brand-sub { font-size: 12px; color: var(--text-3); }

.nav { display: flex; gap: 4px; flex: 1; justify-content: center; }
.nav-item {
  border: none; background: transparent; cursor: pointer;
  padding: 7px 14px; border-radius: 10px; font-size: 14px;
  color: var(--text-2); font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--primary-softer); color: var(--primary); }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 600; }
.badge {
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn {
  border: 1px solid var(--border); background: var(--card); cursor: pointer;
  width: 36px; height: 36px; border-radius: 10px; font-size: 16px;
}

/* ---------- Layout ---------- */
.app { max-width: 980px; margin: 0 auto; padding: 24px 20px 60px; }

.page-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--text-2); font-size: 14px; margin-bottom: 20px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 14px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.btn {
  border: none; cursor: pointer; border-radius: 11px;
  padding: 10px 18px; font-size: 14px; font-weight: 600;
  background: var(--primary); color: #fff;
  transition: transform .06s, background .15s, opacity .15s;
}
.btn:hover { background: var(--primary-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--primary-soft); color: var(--primary-strong); }
.btn.secondary:hover { background: #e4dcff; }
.btn.ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f0f1f5; }
.btn.danger { background: var(--red-soft); color: #b91c1c; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; font-size: 13px; }

/* ---------- Practice home / course cards ---------- */
.course-card { cursor: pointer; display: flex; flex-direction: column; gap: 8px; transition: transform .1s, box-shadow .1s; }
.course-card:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(16,24,40,.1); }
.course-name { font-weight: 700; font-size: 16px; }
.course-desc { color: var(--text-2); font-size: 13px; flex: 1; }
.course-meta { display: flex; gap: 8px; font-size: 12px; color: var(--text-3); }
.pill { background: var(--primary-softer); color: var(--primary-strong); border-radius: 8px; padding: 1px 8px; font-size: 12px; font-weight: 600; }

/* ---------- Practice card ---------- */
.practice-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.progress-track { height: 8px; background: var(--primary-softer); border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 5px; transition: width .25s ease; }

.zh-prompt { font-size: 24px; font-weight: 700; text-align: center; padding: 8px 0 4px; }
.zh-prompt .zh-note { display: block; font-size: 12px; font-weight: 500; color: var(--text-3); margin-top: 2px; }

.builder { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; padding: 18px 4px; }
.chip {
  padding: 8px 12px; border-radius: 9px; font-size: 18px; font-weight: 600;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  min-width: 28px; text-align: center; transition: all .12s;
}
.chip.done { background: var(--green-soft); color: #065f46; }
.chip.current { background: var(--primary-soft); color: var(--primary-strong); box-shadow: 0 0 0 2px var(--primary) inset; animation: pulse 1.2s infinite; }
.chip.todo { background: #f1f2f6; color: #c3c7d2; }
.chip.wrong { background: var(--red-soft); color: #b91c1c; animation: shake .3s; }

@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 2px var(--primary) inset; } 50% { box-shadow: 0 0 0 4px #c4b5fd inset; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
@keyframes floatUp { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(-26px); opacity: 0; } }

.combo-float { position: fixed; pointer-events: none; font-weight: 800; color: var(--primary); z-index: 100; animation: floatUp .7s ease forwards; }
.rating-float { position: fixed; pointer-events: none; font-size: 46px; font-weight: 800; z-index: 100; animation: pop .5s ease forwards; }

.input-row { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.word-input {
  font-size: 20px; padding: 10px 14px; border: 2px solid var(--border); border-radius: 11px;
  outline: none; text-align: center; min-width: 180px; font-family: inherit; font-weight: 600;
}
.word-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.word-input.is-wrong { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.full-input { width: 100%; text-align: left; font-size: 18px; min-width: 0; }

.feedback { text-align: center; min-height: 24px; font-weight: 700; font-size: 15px; margin-top: 6px; }
.feedback.ok { color: var(--green); }
.feedback.err { color: var(--red); }

.combo-banner { text-align: center; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.combo-banner b { color: var(--primary); font-size: 15px; }

/* ---------- Result / rating ---------- */
.rating-box { text-align: center; padding: 10px; }
.rating-letter { font-size: 60px; font-weight: 800; line-height: 1; }
.rating-SSS { color: #7c3aed; }
.rating-SS { color: #9333ea; }
.rating-S { color: #0891b2; }
.rating-A { color: #10b981; }
.rating-B { color: #f59e0b; }
.rating-C { color: #ef4444; }
.rating-detail { color: var(--text-2); font-size: 13px; margin-top: 6px; }

/* ---------- Lists ---------- */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-main { flex: 1; min-width: 0; }
.list-en { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; font-weight: 600; word-break: break-word; }
.list-zh { color: var(--text-2); font-size: 13px; }

.empty { text-align: center; color: var(--text-3); padding: 40px 10px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* ---------- Stats ---------- */
.stat-card { text-align: center; padding: 16px; }
.stat-num { font-size: 30px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.heatmap { display: flex; flex-wrap: wrap; gap: 4px; }
.heat-cell { width: 14px; height: 14px; border-radius: 3px; background: #eef0f4; }
.heat-cell.l1 { background: #ddd6fe; }
.heat-cell.l2 { background: #c4b5fd; }
.heat-cell.l3 { background: #a78bfa; }
.heat-cell.l4 { background: #7c3aed; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; outline: none; font-family: inherit; background: #fff;
}
.field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field textarea { resize: vertical; min-height: 70px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #1f2333; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 200; max-width: 90vw;
}
.toast.show { animation: pop .25s ease; }

/* ---------- Settings rows ---------- */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: none; }
.row .row-label { font-weight: 600; font-size: 14px; }
.row .row-desc { font-size: 12px; color: var(--text-3); }
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #d6d9e0; border-radius: 24px; cursor: pointer; transition: .2s; }
.switch .slider:before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* =========================================================================
 * 深色模式
 * ========================================================================= */
[data-theme="dark"] {
  --primary: #a78bfa;
  --primary-strong: #8b5cf6;
  --primary-soft: #2b2350;
  --primary-softer: #221c42;
  --bg: #0e1016;
  --card: #191c25;
  --text: #e7eaf0;
  --text-2: #aab1c0;
  --text-3: #6d7484;
  --border: #2a2f3c;
  --green: #34d399;
  --green-soft: #123528;
  --red: #f87171;
  --red-soft: #3c1e1e;
  --amber: #fbbf24;
  --amber-soft: #3b2f10;
  --shadow: 0 1px 3px rgba(0,0,0,.45), 0 6px 20px rgba(0,0,0,.4);
}
[data-theme="dark"] .topbar { background: rgba(20, 23, 32, .85); }
[data-theme="dark"] .word-input,
[data-theme="dark"] .field input,
[data-theme="dark"] .field textarea,
[data-theme="dark"] .field select { background: #141720; color: var(--text); }
[data-theme="dark"] .btn.ghost:hover { background: #242938; }
[data-theme="dark"] .chip.todo { background: #232733; color: #4a5164; }
[data-theme="dark"] .chip.done { background: #123528; color: #6ee7b7; }
[data-theme="dark"] .chip.current { background: #2b2350; color: #c4b5fd; }
[data-theme="dark"] .heat-cell { background: #232733; }
[data-theme="dark"] .switch .slider { background: #3a4152; }
[data-theme="dark"] .rating-SSS { color: #a78bfa; }
[data-theme="dark"] .rating-SS { color: #c084fc; }
[data-theme="dark"] .rating-S { color: #22d3ee; }
[data-theme="dark"] .rating-A { color: #34d399; }
[data-theme="dark"] .rating-B { color: #fbbf24; }
[data-theme="dark"] .rating-C { color: #f87171; }
