/* 拼音：Andika 子集（OFL，改名为 PinyinSubset）；汉字：霞鹜文楷子集（OFL）。许可证见 fonts/OFL-*.txt */
@font-face {
  font-family: "PinyinFont";
  src: url("fonts/pinyin-subset.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "KaiFont";
  src: url("fonts/lxgwwenkai-subset.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #fbf8f1;
  --card: #ffffff;
  --ink: #2b2a28;
  --muted: #7a756c;
  --line: #e6e0d3;
  --accent: #2f6fbd;
  --accent-soft: #e5eefa;
  --right: #2e9e6a;
  --right-soft: #e2f4ea;
  --wrong: #d9583f;
  --wrong-soft: #fbe7e2;
  --radius: 16px;
  --py: "PinyinFont", "Andika", "Century Gothic", system-ui, sans-serif;
  --hz: "KaiFont", "Kaiti SC", "STKaiti", "KaiTi", "楷体", serif;
  --ui: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 18px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

/* 连续快速点按时不触发双击放大 */
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

.screen {
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* 设置页 */
.setup {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 { margin: 8px 0 0; font-size: 28px; }
h2 { margin: 0 0 12px; font-size: 18px; }
.hint { margin: 0; color: var(--muted); }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.unit + .unit { margin-top: 16px; }

.unit-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
  cursor: pointer;
}

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

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }

.chip span {
  display: inline-block;
  min-height: 44px;
  padding: 8px 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-family: var(--py);
  font-size: 18px;
  cursor: pointer;
  user-select: none;
}

.chip span.cn { font-family: var(--ui); }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.count-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.count-row h2 { margin: 0; }

.stepper { display: flex; align-items: center; gap: 8px; }

.stepper button {
  width: 48px;
  height: 48px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  font-size: 24px;
}

.stepper input {
  width: 72px;
  height: 48px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  text-align: center;
  font-size: 22px;
  font-family: var(--ui);
  background: var(--card);
  color: var(--ink);
}

.big-btn {
  min-height: 60px;
  border: none;
  border-radius: var(--radius);
  font-size: 22px;
  font-weight: 600;
}

.primary { background: var(--accent); color: #fff; }
.primary:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }
.secondary { background: var(--card); border: 1.5px solid var(--line); }

/* 答题页 */
.quiz {
  /* 答题时长按不弹出选字和菜单，像原生 App */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
}

.quiz-head { display: flex; justify-content: space-between; align-items: center; font-size: 20px; color: var(--muted); }

.link-btn {
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 16px;
}

.link-btn.armed { border-color: var(--wrong); background: var(--wrong-soft); color: var(--wrong); }

.progress-bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.question {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2vmin;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 16px;
  overflow: hidden;
  transition: background .15s;
}

.question.flash-right { background: var(--right-soft); }
.question.flash-wrong { background: var(--wrong-soft); }

.q-type { font-size: 16px; color: var(--muted); }

/* 字号随屏幕变化：--len 是拼音字符数，保证长词也不超出宽度 */
.py {
  font-family: var(--py);
  line-height: 1.2;
  white-space: nowrap;
  font-size: min(var(--max, 30vmin), calc(150vw / var(--len, 1)));
}

.py .dash { color: var(--muted); padding: 0 .25em; }

.py.wrap {
  white-space: normal;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.py.wrap .part { white-space: nowrap; }

.hz {
  font-family: var(--hz);
  line-height: 1.2;
  letter-spacing: .1em;
  font-size: min(16vmin, calc(70vw / var(--len, 1)));
}

.answer-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.answer {
  min-height: 72px;
  border: none;
  border-radius: var(--radius);
  font-size: 24px;
  font-weight: 700;
  color: #fff;
}

.answer.right { background: var(--right); }
.answer.wrong { background: var(--wrong); }
.answer:disabled { opacity: .6; }

/* 结果页 */
.result {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  text-align: center;
}

.score-line { margin: 24px 0 0; font-size: 22px; color: var(--muted); }
.score { margin: 0; font-size: 96px; font-weight: 700; line-height: 1.1; color: var(--accent); }

.wrong-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.wrong-list li {
  padding: 6px 14px;
  border-radius: 12px;
  background: var(--wrong-soft);
  font-family: var(--py);
  font-size: 26px;
}

.wrong-list .hz-small { font-family: var(--hz); font-size: 22px; margin-left: .3em; }

.result-actions { display: grid; gap: 12px; }

@media (min-width: 768px) {
  .result-actions { grid-template-columns: 1fr 1fr; }
  .answer { min-height: 88px; font-size: 28px; }
}
