:root {
  --bg: #eef3f8;
  --card: #ffffff;
  --ink: #1c2434;
  --blue: #2f6fe0;
  --blue-dark: #1e5bc4;
  --blue-text: #2a5fbe;
  --blue-soft: #e8f1fc;
  --line: #d5e3f5;
  --green: #178a48;
  --green-bg: #d8f6e4;
  --red: #e14b4b;
  --red-line: #f3b7b7;
  --hint: #1d5fbf;
  --hint-bg: #e7f1fd;
  --muted: #5c6b82;
  --shadow: 0 10px 28px rgba(36, 74, 130, 0.08);
  --radius: 18px;
  --sans: "PingFang HK", "PingFang TC", "Noto Sans CJK TC", "Noto Sans TC",
    "Microsoft JhengHei", "Microsoft JhengHei UI", "Segoe UI",
    "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

button, input { font-family: inherit; }

button { cursor: pointer; }

button:focus-visible {
  outline: 3px solid #8eb4f5;
  outline-offset: 2px;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  color: var(--blue-text);
  letter-spacing: 0.01em;
}

.top-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--blue-text);
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}

.top-stats .sep,
.shortcut-bar .sep {
  width: 1px;
  height: 18px;
  background: #c5d6ee;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 18px;
  align-items: stretch;
}

.left-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.practice {
  flex: 1;
  padding: 36px 36px 28px;
  text-align: center;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.loading, .muted { color: var(--muted); }

.hanzi {
  margin: 0;
  font-size: 104px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #161b26;
}

.prompt {
  margin: 22px 0 0;
  font-size: 22px;
  font-weight: 800;
}

.hint-line {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
}

#question,
#summary-host { width: 100%; }

.answer-wrap {
  display: flex;
  justify-content: center;
  margin-top: 22px;
}

.answer {
  width: clamp(120px, 28vw, 168px);
  height: clamp(96px, 18vw, 120px);
  border: 3px solid #3b78e7;
  border-radius: 16px;
  background: #fff;
  color: #161b26;
  font-family: inherit;
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  padding: 0;
}

.answer:focus {
  outline: 3px solid #8eb4f5;
  outline-offset: 3px;
}

.answer.bad { border-color: var(--red); color: var(--red); }
.answer.good { border-color: var(--green); color: var(--green); }
.answer:disabled { opacity: 1; -webkit-text-fill-color: var(--green); }

.feedback {
  align-self: stretch;
  margin-top: 22px;
  min-height: 52px;
}

.summary { width: 100%; }

.banner {
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.5;
}

.banner.ok { background: var(--green-bg); color: var(--green); }
.banner.hint, .banner.revealed { background: var(--hint-bg); color: var(--hint); }
.banner.note { background: #f4f7fb; color: #415068; font-size: 16px; }

.retry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--red-line);
  background: #fff;
  color: var(--red);
  font-size: 16px;
  font-weight: 800;
}

.retry:hover { background: #fff6f6; }

.summary-next {
  margin: 14px 0 0;
  color: var(--blue-text);
  font-weight: 800;
}

.summary h3 {
  margin: 0 0 8px;
  font-size: 32px;
  color: var(--blue-text);
}

.summary-score {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
}

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

.missed-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.missed-chip {
  min-width: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #f6f8fb;
  font-size: 22px;
  font-weight: 800;
}

.shortcut-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 14px 18px;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  color: #31445f;
  font-weight: 700;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  margin-right: 6px;
  padding: 2px 8px;
  border: 1.5px solid #9eb6e0;
  border-bottom-width: 3px;
  border-radius: 8px;
  background: #f8fbff;
  color: var(--blue-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
}

.side {
  padding: 26px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.side h2 {
  margin: 0 0 18px;
  text-align: center;
  color: var(--blue-text);
  font-size: 26px;
  font-weight: 800;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #e6ebf2;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: #3b82f6;
  border-radius: inherit;
  width: 0;
}

.progress-label {
  margin: 12px 0 4px;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
}

.band {
  margin: 0 0 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  border-radius: 12px;
  min-height: 48px;
  padding: 10px 14px;
  font-size: 18px;
  font-weight: 800;
  border: 1.5px solid transparent;
}

.btn-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--blue-soft);
  color: #2a64d6;
  border-color: #c5daf6;
}

.btn-ghost:hover { background: #dceafb; }

.btn-review {
  background: #fff;
  color: #2a64d6;
  border-color: #c5daf6;
}

.btn-review.has-items {
  background: #fff6e8;
  color: #a15c12;
  border-color: #f0d3a0;
}

.btn-solid {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.btn-solid:hover { background: var(--blue-dark); }

.btn-small {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 16px;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.today {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid #e6eef8;
  text-align: left;
}

.today h3 {
  margin: 16px 0 8px;
  font-size: 15px;
  color: var(--blue-text);
}

.today p { margin: 0 0 6px; font-size: 15px; color: #34445c; }

.today-misses {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.today-misses span {
  background: #f4f7fb;
  border-radius: 8px;
  padding: 2px 8px;
  font-weight: 800;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: auto;
  background: #f7f9fc;
}

.overlay[hidden] { display: none !important; }

.map-page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 8px 20px 36px;
}

.map-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 18px 4px 8px;
  border-top: 6px solid var(--blue);
}

.map-brand {
  color: var(--blue-text);
  font-weight: 800;
  font-size: 18px;
}

.map-top h2 {
  margin: 0;
  text-align: center;
  color: var(--blue-text);
  font-size: 34px;
  font-weight: 800;
}

.map-top .btn { justify-self: end; }

.map-board { margin-top: 18px; overflow-x: auto; }

.map-board-inner { min-width: 760px; }

.key-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.key {
  position: relative;
  width: 68px;
  height: 74px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.key-letter {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 13px;
  font-weight: 800;
  opacity: 0.9;
}

.key-radical {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.key.philosophy { background: #e4f0fc; color: #2f6ed6; }
.key.stroke { background: #e5f6ec; color: #2e9a62; }
.key.body { background: #fdebd9; color: #e07a32; }
.key.shape { background: #f1e8f8; color: #8b62c4; }
.key.special { background: #315dcf; color: #fff; }

.legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.legend-item {
  min-width: 148px;
  padding: 10px 14px 12px;
  border-radius: 12px;
  text-align: center;
}

.legend-item strong { display: block; font-size: 16px; }
.legend-item span { display: block; margin-top: 4px; font-size: 15px; font-weight: 700; letter-spacing: 0.03em; }

.legend-item.philosophy { background: #e4f0fc; color: #2f6ed6; }
.legend-item.stroke { background: #e5f6ec; color: #2e9a62; }
.legend-item.body { background: #fdebd9; color: #e07a32; }
.legend-item.shape { background: #f1e8f8; color: #8b62c4; }
.legend-item.special { background: #315dcf; color: #fff; }

.map-note {
  max-width: 820px;
  margin: 22px auto 0;
  padding: 14px 18px;
  border-radius: 12px;
  background: #e7f1fb;
  color: #2457a8;
  text-align: center;
  font-weight: 800;
  line-height: 1.7;
}

.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;
}

.noscript {
  max-width: 640px;
  margin: 24px auto;
  padding: 16px;
  background: #fff;
  border-radius: 12px;
}

@media (max-width: 860px) {
  .page { padding: 16px 12px 28px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .top-stats { flex-wrap: wrap; white-space: normal; font-size: 16px; }
  .workspace { grid-template-columns: 1fr; }
  .practice { min-height: 0; padding: 28px 16px 20px; }
  .hanzi { font-size: 80px; }
  .prompt { font-size: 18px; }
  .answer { font-size: 48px; }
  .today { margin-top: 20px; }
  .map-top {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .map-top h2 { font-size: 26px; }
  .map-top .btn { justify-self: center; }
  .key { width: 56px; height: 62px; }
  .key-radical { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
