/* ===========================================================
   HSK 汉字输入训练 — 样式
   =========================================================== */

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

:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --bg-glow-a: #fdf8ef;
  --bg-glow-b: #f7ede0;
  --panel: #fffdf8;
  --panel-2: #faf6ee;
  --ink: #211f1b;
  --ink-soft: #4c473f;
  --muted: #8b8477;
  --line: #e6dfd1;
  --line-strong: #d6ccb8;
  --accent: #a52a1f;
  --accent-ink: #fffdf8;
  --accent-soft: #f8e9e5;
  --accent-ring: rgba(165, 42, 31, 0.14);
  --ok: #1a7a4c;
  --ok-soft: #e7f4ec;
  --bad: #c22a26;
  --bad-soft: #fbeae8;
  --field: #fffefa;
  --shadow: 0 18px 40px -26px rgba(53, 42, 25, 0.38), 0 2px 6px rgba(53, 42, 25, 0.05);
  --radius: 20px;
  --font-zh: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --font-en: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151412;
  --bg-glow-a: #2a2521;
  --bg-glow-b: #221f1b;
  --panel: #1e1c19;
  --panel-2: #262320;
  --ink: #efe9dd;
  --ink-soft: #c9c2b4;
  --muted: #968c7d;
  --line: #35312b;
  --line-strong: #46413a;
  --accent: #e0705f;
  --accent-ink: #1b1512;
  --accent-soft: #3a221d;
  --accent-ring: rgba(224, 112, 95, 0.18);
  --ok: #6ccf9b;
  --ok-soft: rgba(108, 207, 155, 0.13);
  --bad: #ff8577;
  --bad-soft: rgba(255, 133, 119, 0.15);
  --field: #191816;
  --shadow: 0 26px 55px -30px rgba(0, 0, 0, 0.85), 0 2px 8px rgba(0, 0, 0, 0.35);
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 560px at 86% -12%, var(--bg-glow-a) 0%, transparent 62%),
    radial-gradient(820px 480px at -8% -6%, var(--bg-glow-b) 0%, transparent 58%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-zh);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 34px 22px 64px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- 中英对照的次要英文标签 ---------- */

.en {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.82;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.logo {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(160deg, var(--accent), #7d1f16);
  color: #fffdf8;
  font-size: 24px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 10px 20px -12px rgba(122, 28, 19, 0.9);
}

.brand-text h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.top-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* 返回首页（试用版/练习页都靠它回得去） */
.home-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.home-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 640px) {
  .home-link { padding: 6px 9px; font-size: 11.5px; }
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 13px;
  overflow-x: auto;
  min-width: 0;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  padding: 6px 11px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: var(--panel-2); color: var(--ink); }
.tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: 0 4px 10px -6px rgba(0, 0, 0, 0.55);
}

.icon-btn {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }
.icon-btn:active { transform: scale(0.94); }

/* ---------- 进度 HUD ---------- */

.hud {
  position: relative;
  overflow: hidden;
  padding: 14px 18px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat { display: flex; flex-direction: column; gap: 3px; padding: 0 14px; border-left: 1px solid var(--line); min-width: 0; }
.stat:first-child { border-left: 0; padding-left: 2px; }

.stat-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 11.5px;
  line-height: 1.25;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.stat-label .en { font-size: 9px; letter-spacing: 0.12em; }

.stat strong {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.hud-bar {
  grid-column: 1 / -1;
  height: 4px;
  margin-top: 12px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.hud-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--ok), #37a06c);
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- 主卡片 ---------- */

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 26px 28px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.25s, box-shadow 0.25s;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, var(--accent), transparent 62%);
  opacity: 0.85;
  transition: background 0.25s;
}

.card.solved { border-color: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft), var(--shadow); }
.card.solved::before { background: linear-gradient(90deg, var(--ok), transparent 62%); }

.card-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 9px;
  border-radius: 7px;
}

.counter { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
  letter-spacing: 0.02em;
}
.status-pill[hidden] { display: none; }
.status-pill[data-kind="ok"] { color: var(--ok); background: var(--ok-soft); }
.status-pill[data-kind="warn"] { color: var(--accent); background: var(--accent-soft); }
.status-pill[data-kind="muted"] { color: var(--muted); background: var(--panel-2); }

.spacer { flex: 1 1 12px; }

.ghost-select,
.ghost-btn {
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 9px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.ghost-btn {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}
.ghost-btn .en { font-size: 8.5px; letter-spacing: 0.08em; }

.ghost-select:hover,
.ghost-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.ghost-select:focus-visible,
.ghost-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 提示区 ---------- */

.prompt {
  margin: 6px 0 0;
  font-family: var(--font-en);
  font-size: clamp(22px, 3.4vw, 29px);
  line-height: 1.38;
  letter-spacing: 0.005em;
  color: var(--ink);
  min-height: 1.4em;
}

.hint-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 26px; }

.hint-btn {
  font: inherit;
  font-size: 12px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 1.3;
  color: var(--muted);
  background: transparent;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.hint-btn .en { font-size: 8.5px; letter-spacing: 0.08em; }
.hint-btn:hover { color: var(--ink); border-color: var(--muted); background: var(--panel-2); }
.hint-btn[aria-pressed="true"] { color: var(--accent); border-style: solid; border-color: var(--accent); background: var(--accent-soft); }

.pinyin {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
}

/* ---------- 填空区（每个汉字一格下划线，标点直接给出） ---------- */

.input-wrap {
  position: relative;
  padding: 18px 18px 16px;
  border: 1.5px solid var(--line);
  border-radius: 15px;
  background: var(--field);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}
.card.solved .input-wrap { border-color: var(--ok); }
.card.solved .input-wrap:focus-within { border-color: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }

.worksheet {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.42em 0.3em;
  font-size: clamp(18px, 2.9vw, 22px);
  line-height: 1.4;
}

/* 一个字 + 紧跟其后的标点作为整体换行 */
.group {
  display: inline-flex;
  align-items: flex-end;
  gap: 0.05em;
}

.slot {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0.06em 0.04em 0.05em;
  border-bottom: 2px solid var(--muted);
  border-radius: 3px 3px 0 0;
  transition: border-color 0.15s, background 0.15s;
}

/* 每个字上方的拼音：HSK1–2 的学生靠它认字，跟着「拼音提示」开关一起出现 */
.cell-pinyin {
  display: none;
  font-size: 0.7em;
  line-height: 1.15;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.01em;
  white-space: nowrap;
  padding: 0 0.05em 0.05em;
}

.worksheet.pinyin-on .cell-pinyin { display: block; }
.worksheet.pinyin-on { row-gap: 0.5em; }

.cell {
  display: block;
  width: 1.15em;
  height: 1.55em;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-family: var(--font-zh);
  font-size: 1em;
  line-height: 1.55em;
  text-align: center;
  color: var(--ink);
  caret-color: var(--accent);
}

.cell::selection { background: var(--accent-ring); color: var(--ink); }

.slot:focus-within { border-color: var(--ink); background: var(--panel-2); }
.slot.ok { border-color: var(--ok); background: transparent; }
.slot.ok .cell { color: var(--ok); }
.slot.ok:focus-within { border-color: var(--ok); background: transparent; }
.slot.bad { border-color: var(--bad); }
.slot.bad .cell { color: var(--bad); background: var(--bad-soft); border-radius: 3px; }

.punct {
  color: var(--muted);
  font-size: 0.95em;
  padding: 0 0.02em 0.1em;
  user-select: none;
}

/* ---------- 输入区下方信息 ---------- */

.input-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: -4px;
}

.legend { display: inline-flex; align-items: center; gap: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend .en { font-size: 9px; letter-spacing: 0.05em; }

.lg { width: 9px; height: 9px; border-radius: 2.5px; display: inline-block; }
.lg.ok { background: var(--ok); }
.lg.bad { background: var(--bad); }

/* ---------- 按钮 ---------- */

.actions { display: flex; justify-content: flex-end; gap: 9px; flex-wrap: wrap; margin-top: 2px; }

.btn {
  font: inherit;
  font-size: 14px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 8px 18px;
  border-radius: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.btn .zh { line-height: 1.25; }
.btn .en { font-size: 8.5px; letter-spacing: 0.09em; }
.btn.primary .en { opacity: 0.85; }
.btn:active { transform: translateY(1px); }

.btn.ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-soft); }
.btn.ghost:hover { background: var(--panel-2); border-color: var(--muted); color: var(--ink); }

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  box-shadow: 0 10px 20px -14px var(--accent);
}
.btn.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 14px 24px -14px var(--accent); }
.btn.primary:disabled { opacity: 0.38; cursor: not-allowed; box-shadow: none; }

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 页脚 ---------- */

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px 16px;
  flex-wrap: wrap;
  padding: 0 4px;
  font-size: 12px;
  color: var(--muted);
}

.foot-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* 内容来源声明：练习页页脚（中文加粗，英文次要） */
.foot-note {
  flex: 1 0 100%;
  margin: 8px 0 0;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.65;
  color: var(--ink-soft);
}

.foot-note .en { display: block; margin-top: 2px; font-weight: 700; color: var(--ink-soft); }
.foot-note-sub { display: block; margin-top: 3px; font-weight: 600; font-size: 0.92em; color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); margin: 0; cursor: pointer; }
.switch-text { display: inline-flex; flex-direction: column; line-height: 1.2; }
.switch-text .en { font-size: 8.5px; letter-spacing: 0.08em; }

.link {
  font: inherit;
  font-size: 12px;
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--bad); text-decoration-color: var(--bad); }
.link .en { font-size: 8.5px; letter-spacing: 0.08em; text-decoration: none; }

.tip { display: flex; flex-direction: column; gap: 2px; line-height: 1.45; }
.tip .en {
  font-size: 10px;
  letter-spacing: 0.02em;
  text-transform: none;
  font-weight: 400;
  opacity: 0.75;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  z-index: 50;
  max-width: min(90vw, 460px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--panel);
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 16px 34px -18px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="ok"] { background: var(--ok); color: #fff; }
.toast[data-kind="warn"] { background: var(--accent); color: var(--accent-ink); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 响应式 ---------- */

@media (max-width: 640px) {
  .app { padding: 20px 14px 44px; gap: 14px; }
  .card { padding: 20px 16px 18px; border-radius: 16px; }
  .top-actions { width: 100%; }
  .tabs { flex: 1; }
  .hud { padding: 12px 14px 10px; }
  .stat { padding: 0 10px; }
  .stat strong { font-size: 16px; }
  .prompt { font-size: 20px; }
  .input-wrap { padding: 15px 14px 13px; }
  .actions .btn { flex: 1 1 auto; }
  .foot { justify-content: flex-start; }
}

@media (max-width: 420px) {
  .brand-text h1 { font-size: 16.5px; }
  .tagline { font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
