/* ── 组件层 ──────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
}

/* ── 顶栏 ────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: .01em;
  flex: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 2px;
  margin-right: auto;
  padding: 3px;
  background: var(--bg-inset);
  border-radius: var(--radius);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 6px 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] {
  background: var(--bg-elev-2);
  color: var(--text);
  box-shadow: var(--shadow);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  transition: color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

.theme-icon::before { content: "◐"; font-size: 16px; }

/* ── 主视图 ──────────────────────────────────────────────────────────── */

.view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.view:focus { outline: none; }

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.page-head { margin-bottom: 22px; }
.page-title { font-size: 22px; }
.page-sub { margin-top: 6px; color: var(--text-dim); font-size: 14px; }

/* ── 卡片 ────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px;
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: var(--text);
  transition: border-color .15s, transform .15s, background .15s;
}
.mode-card:hover {
  border-color: var(--accent);
  background: var(--bg-elev-2);
  transform: translateY(-1px);
}
.mode-card .mc-title { font-weight: 620; font-size: 15px; }
.mode-card .mc-desc { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.mode-card .mc-meta {
  margin-top: 4px;
  color: var(--text-faint);
  font-size: 12px;
  font-family: var(--mono);
}

/* ── 按钮 ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s, background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost { background: transparent; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ── 表单 ────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--text-dim); }

select, input[type="text"], input[type="number"], textarea {
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-inset);
  color: var(--text);
  font-size: 14px;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); outline: none; }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }

.chip {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-inset);
  color: var(--text-dim);
  font-size: 13px;
  transition: all .15s;
}
.chip:hover { color: var(--text); border-color: var(--text-faint); }
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* ── 统计条 ──────────────────────────────────────────────────────────── */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}

.metric {
  padding: 11px 13px;
  background: var(--bg-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.metric-label { font-size: 11px; color: var(--text-faint); letter-spacing: .04em; }
.metric-value {
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}
.metric-value.good { color: var(--correct); }
.metric-value.bad { color: var(--wrong); }

/* ── 屏幕键盘 ────────────────────────────────────────────────────────── */

.keyboard {
  --key-w: 52px;
  --key-h: 54px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  user-select: none;
}

.kb-row { display: flex; gap: 7px; justify-content: center; }

.key {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: var(--key-w);
  height: var(--key-h);
  padding: 0;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 9px;
  background: var(--bg-elev-2);
  color: var(--text);
  transition: background .1s, border-color .1s, transform .1s;
}
.key:hover { background: var(--bg-elev); }

.key-letter {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.1;
}

.key-tags {
  display: flex;
  gap: 3px;
  font-size: 10px;
  line-height: 1.1;
  min-height: 11px;
  color: var(--text-faint);
  font-family: var(--mono);
}
.key-tags .tag-init { color: var(--info); }
.key-tags .tag-fin { color: var(--accent); }

.key.is-next {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--bg-elev-2));
  box-shadow: 0 0 0 1px var(--accent), 0 0 18px -4px var(--accent);
}
.key.is-next .key-letter { color: var(--accent); }

.key.is-ok {
  background: var(--correct-bg);
  border-color: var(--correct);
}
.key.is-bad {
  background: var(--wrong-bg);
  border-color: var(--wrong);
  animation: shake .22s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.key.is-weak { border-color: var(--wrong); }
.key.is-weak::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--wrong);
}

.key-small { width: var(--key-w); }

/* ── 键位表页 ────────────────────────────────────────────────────────── */

.layout-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.layout-table th, .layout-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
}
.layout-table th { color: var(--text-faint); font-weight: 500; font-size: 12px; }
.layout-table td.mono { font-family: var(--mono); }
.layout-table tr:last-child td { border-bottom: 0; }

.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .cols-2 { grid-template-columns: 1fr; } }

.mnemonic {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
}
.mnemonic-item {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 9px;
  background: var(--bg-inset);
  border: 1px solid var(--line-soft);
  border-radius: 7px;
}
.mnemonic-item b { font-weight: 600; }
.mnemonic-item span { color: var(--text-faint); font-family: var(--mono); font-size: 11px; }

/* ── 练习页 ──────────────────────────────────────────────────────────── */

.practice { display: flex; flex-direction: column; gap: 14px; min-height: 100%; }

.practice-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.progress {
  flex: 1;
  min-width: 120px;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-inset);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .25s ease;
}

.prompt-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 20px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.prompt-hanzi {
  font-size: 52px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: .04em;
}
.prompt-hanzi.small { font-size: 26px; line-height: 1.7; }

.prompt-pinyin {
  font-family: var(--mono);
  font-size: 20px;
  color: var(--accent);
  letter-spacing: .04em;
}

.prompt-split {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}
.prompt-split .ps-part {
  padding: 3px 10px;
  background: var(--bg-inset);
  border: 1px solid var(--line-soft);
  border-radius: 7px;
}
.prompt-split .ps-part b { color: var(--text); font-weight: 600; }
.prompt-split .ps-arrow { color: var(--text-faint); }

.slots {
  display: flex;
  gap: 10px;
  align-items: center;
}
.slot {
  display: grid;
  place-items: center;
  width: 46px;
  height: 54px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 10px;
  background: var(--bg-inset);
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-faint);
  transition: all .12s;
}
.slot.filled { color: var(--text); background: var(--bg-elev-2); }
.slot.current {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 16px -5px var(--accent);
}
.slot.alt-hint { border-style: dashed; }

.feedback {
  min-height: 22px;
  font-size: 13px;
  color: var(--text-dim);
}
.feedback.good { color: var(--correct); }
.feedback.bad { color: var(--wrong); }

/* 句子练习：整句逐字显示 */
.sentence {
  font-size: 24px;
  line-height: 1.9;
  letter-spacing: .02em;
  text-align: center;
}
.sentence .s-char {
  padding: 1px 2px;
  border-radius: 5px;
  transition: background .15s, color .15s;
}
.sentence .s-char.done { color: var(--text-faint); }
.sentence .s-char.active {
  background: var(--accent);
  color: var(--accent-ink);
}
.sentence .s-char.missed { color: var(--wrong); }

/* ── 结果页 ──────────────────────────────────────────────────────────── */

.result-hero { text-align: center; padding: 12px 0 4px; }
.result-title { font-size: 26px; }
.result-title.good { color: var(--correct); }
.result-title.bad { color: var(--warn); }

.weak-list { display: flex; flex-wrap: wrap; gap: 7px; }
.weak-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-inset);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  font-size: 13px;
}
.weak-item .wi-key {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--wrong);
  text-transform: uppercase;
}
.weak-item .wi-n { color: var(--text-faint); font-size: 11px; }

/* ── 错题本 ──────────────────────────────────────────────────────────── */

.mistake-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line-soft);
}
.mistake-row:last-child { border-bottom: 0; }
.mistake-hanzi { font-size: 19px; min-width: 30px; text-align: center; }
.mistake-syl { font-family: var(--mono); color: var(--text-dim); font-size: 13px; }
.mistake-code { font-family: var(--mono); color: var(--accent); font-size: 13px; }
.mistake-n {
  margin-left: auto;
  padding: 2px 9px;
  background: var(--wrong-bg);
  color: var(--wrong);
  border-radius: 999px;
  font-size: 12px;
  font-family: var(--mono);
}

/* ── 历史表 ──────────────────────────────────────────────────────────── */

.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th, .history-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
}
.history-table th { color: var(--text-faint); font-weight: 500; font-size: 12px; }
.history-table td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── 状态栏 ──────────────────────────────────────────────────────────── */

.statusbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 7px 20px;
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: 12px;
  color: var(--text-dim);
}
.statusbar .sb-item { display: flex; align-items: center; gap: 5px; }
.statusbar .sb-item b {
  font-family: var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.statusbar .sb-spacer { margin-left: auto; }
.statusbar kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-elev-2);
  font-family: var(--mono);
  font-size: 11px;
}

/* ── 空状态 ──────────────────────────────────────────────────────────── */

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-faint);
}
.empty .empty-title { font-size: 15px; color: var(--text-dim); margin-bottom: 6px; }

/* ── 弹层 ────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .55);
  z-index: 50;
}
.modal {
  width: min(520px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .7);
  padding: 20px 22px;
}
.modal h3 { font-size: 17px; margin-bottom: 14px; }
.modal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}
.modal-row:last-of-type { border-bottom: 0; }
.modal-row .mr-label { font-size: 14px; }
.modal-row .mr-desc { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

.switch {
  position: relative;
  width: 40px;
  height: 23px;
  border: 0;
  border-radius: 999px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  transition: background .15s;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform .15s, background .15s;
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(17px); background: var(--accent-ink); }

/* ── 响应式 ──────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .keyboard { --key-w: 32px; --key-h: 44px; gap: 5px; }
  .kb-row { gap: 5px; }
  .key-letter { font-size: 13px; }
  .key-tags { font-size: 8px; }
  .topbar { padding: 8px 12px; gap: 10px; }
  .brand-name { display: none; }
  .page { padding: 18px 14px 36px; }
  .prompt-hanzi { font-size: 42px; }
}
