:root {
  --paper: #f3eadb;
  --ink: #243027;
  --muted: #5c6a61;
  --card: #fffaf2;
  --line: #e3d5c0;
  --red: #b84332;
  --good: #1f6b45;
  --bad: #9d341f;
  --amber: #a56b12;
  --sans: "Nunito", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  --serif: "Fraunces", "Iowan Old Style", Palatino, "Palatino Linotype", "Songti SC", serif;
  --cjk: "Songti SC", "Noto Serif SC", "STSong", "PMingLiU", serif;
  --shadow: 0 14px 34px rgba(72, 42, 12, 0.08);
  --cat: #243027;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  background:
    linear-gradient(90deg, var(--red) 0 18px, transparent 18px),
    radial-gradient(rgba(90, 55, 20, 0.045) 0.7px, transparent 0.7px),
    var(--paper);
  background-size: auto, 3px 3px, auto;
  padding: 28px 20px 64px 36px;
}
.spine {
  position: fixed;
  z-index: 3;
  left: 7px;
  top: 22px;
  bottom: 22px;
  width: 8px;
  background: radial-gradient(circle at 50% 8px, var(--paper) 4.5px, transparent 5px);
  background-size: 8px 52px;
  pointer-events: none;
}
button, input, a { font: inherit; color: inherit; }
button { cursor: pointer; }
a { text-decoration: none; }
:focus-visible {
  outline: 3px solid #e2a23a;
  outline-offset: 2px;
}

.wrap { max-width: 1080px; margin: 0 auto; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 22px;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 220px;
}
.mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #fffaf2;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 22px;
  box-shadow: 4px 4px 0 #e7c2a4;
}
.brand small {
  display: block;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.08em;
}
.brand strong { display: block; font-size: 18px; letter-spacing: -0.02em; }
.top-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  min-width: min(320px, 70vw);
}
.search input {
  border: 0;
  background: transparent;
  width: 100%;
  outline: none;
  font-weight: 700;
}
.chip, .btn, .modes a, .seg button {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 800;
  background: var(--card);
  box-shadow: inset 0 0 0 1.5px var(--line);
}
.chip[aria-pressed="true"], .seg button[aria-pressed="true"] {
  background: var(--ink);
  color: #fffaf2;
  box-shadow: none;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--ink);
  color: #fffaf2;
  box-shadow: none;
  min-height: 46px;
  padding: 12px 18px;
}
.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}
.btn.good { background: var(--good); }
.btn.warn { background: var(--bad); }
.btn:active, .chip:active { transform: translateY(1px); }
.review-link { color: var(--bad); }

.hero {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 18px;
  margin-bottom: 18px;
}
.hero-copy, .progress-card, .cat-card, .panel, .flash .face, .prompt, .choice, .tile, .word-row {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 24px;
}
.hero-copy, .progress-card { padding: 22px 24px; box-shadow: var(--shadow); }
.lede {
  margin: 0 0 18px;
  font-family: var(--cjk);
  font-size: 28px;
  line-height: 1.45;
}
.hero-actions, .result-actions, .flash-actions, .row-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.progress-card { display: flex; gap: 16px; align-items: center; }
.ring { width: 92px; height: 92px; flex: none; }
.ring circle { fill: none; stroke-width: 3.2; }
.ring .track { stroke: #efe2d0; }
.ring .value { stroke: var(--red); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 18px 18px; }
.progress-card p { margin: 4px 0 0; color: var(--muted); font-weight: 700; }
.progress-card strong { font-family: var(--serif); font-size: 28px; }
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
}
.steps li {
  background: transparent;
  border-radius: 16px;
  padding: 10px 12px;
  font-weight: 800;
  color: var(--muted);
}
.steps b {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ink);
  color: #fffaf2;
  font-family: var(--cjk);
}

.cats, .hits { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cat-card {
  position: relative;
  display: block;
  padding: 16px 16px 14px;
  min-height: 148px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.cat-card::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 7px;
  background: var(--tint);
}
.cat-card:hover { transform: translateY(-3px); }
.cat-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.cat-icon {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: color-mix(in srgb, var(--tint) 16%, white);
  font-size: 24px;
}
.cat-card .en {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 12px;
}
.cat-card h2 {
  margin: 2px 0 10px;
  font-family: var(--cjk);
  font-size: 28px;
  font-weight: 700;
}
.bar { height: 6px; border-radius: 99px; background: #f0e4d2; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--tint); }
.meta { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-weight: 800; font-size: 13px; }
.seal {
  position: absolute;
  right: 14px;
  top: 18px;
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border: 2px solid var(--red);
  color: var(--red);
  border-radius: 50%;
  font-family: var(--cjk);
  font-weight: 700;
  transform: rotate(-12deg);
  background: rgba(255, 250, 242, 0.85);
}
.hits { margin-bottom: 14px; }
.hit {
  text-align: left;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1.5px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hit b { font-family: var(--serif); font-size: 22px; }
.hit span { font-family: var(--cjk); font-size: 16px; }
.hit em { color: var(--muted); font-style: normal; font-weight: 800; font-size: 13px; }
.section-label { margin: 8px 0; color: var(--muted); font-weight: 800; }

.cat-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.cat-head h1 { margin: 0; font-family: var(--cjk); font-size: 40px; line-height: 1; }
.cat-head p { margin: 4px 0 0; color: var(--muted); font-weight: 800; }
.back { font-weight: 800; color: var(--muted); display: inline-block; margin-bottom: 10px; }
.modes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.modes a[aria-current="page"] { background: var(--cat); color: #fffaf2; box-shadow: none; }
.stage { --cat: var(--ink); }

.panel { padding: 22px; box-shadow: var(--shadow); }
.panel h2 { font-family: var(--cjk); margin: 0 0 8px; font-size: 32px; }
.flash-wrap { max-width: 640px; margin: 0 auto; }
.flash { perspective: 1200px; min-height: 340px; }
.flash-inner {
  position: relative;
  min-height: 340px;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(.2,.7,.2,1);
}
.flash.is-flipped .flash-inner { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px 22px;
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.back {
  transform: rotateY(180deg);
  background: var(--ink);
  color: #fffaf2;
  border-color: var(--ink);
}
.no-num { color: var(--muted); font-weight: 800; letter-spacing: 0.08em; font-size: 13px; }
.face.back .no-num { color: #d9c7ae; }
.word {
  margin: 8px 0;
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.word.lg { font-size: clamp(42px, 7vw, 76px); }
.word.md { font-size: clamp(32px, 5vw, 52px); }
.word.sm { font-size: clamp(26px, 3.4vw, 38px); }
.ipa { margin: 0; color: var(--amber); font-weight: 800; font-size: 20px; }
.zh-huge {
  margin: 8px 0;
  font-family: var(--cjk);
  font-size: clamp(36px, 5vw, 60px);
  line-height: 1.25;
}
.note, .alt, .kbd, .judge { margin: 6px 0 0; }
.note, .alt { color: #d9c7ae; font-weight: 700; }
.kbd { color: var(--muted); font-weight: 800; font-size: 13px; text-align: center; }
.flash-actions { justify-content: center; margin-top: 14px; }
.badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e7f5ec;
  color: var(--good);
  font-weight: 800;
  font-size: 13px;
}
.badge.shaky { background: #fdecea; color: var(--bad); }
.face.back .badge { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }

.prompt { padding: 22px; text-align: center; box-shadow: var(--shadow); margin-bottom: 12px; }
.prompt .word { margin-bottom: 0; }
.listen-btn {
  width: 96px; height: 96px;
  border-radius: 50%;
  border: 0;
  background: var(--cat);
  color: white;
  font-weight: 900;
  font-size: 18px;
}
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  text-align: left;
  min-height: 74px;
  padding: 14px 16px;
  font-weight: 800;
  font-size: 20px;
  display: flex;
  gap: 10px;
  align-items: center;
  box-shadow: var(--shadow);
}
.choice .keycap {
  width: 28px; height: 28px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 8px;
  background: #f3e7d6;
  font-size: 14px;
}
.choice.correct { background: #e7f5ec; border-color: var(--good); }
.choice.wrong { background: #fdecea; border-color: var(--bad); }
.choice:disabled { cursor: default; }
.judge.ok { color: var(--good); font-weight: 900; }
.judge.bad { color: var(--bad); font-weight: 900; }
.quiz-top, .spell-top, .match-top {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px;
  font-weight: 800; color: var(--muted);
}
.quiz-top > span, .spell-top > span, .match-top > span { white-space: nowrap; }
.flash-wrap .quiz-top { width: 100%; }
.feedback { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 12px; }
.cat-card .en, .word, .zh-huge, .choice span { overflow-wrap: anywhere; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }

.match-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tile {
  min-height: 96px;
  padding: 10px;
  font-weight: 800;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
}
.tile small { color: var(--muted); font-weight: 900; letter-spacing: 0.08em; }
.tile b { overflow-wrap: anywhere; }
.tile.en b { font-family: var(--serif); font-size: 20px; }
.tile.zh b { font-family: var(--cjk); font-size: 18px; }
.tile.on { border-color: var(--cat); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cat) 28%, transparent); }
.tile.matched { background: #e7f5ec; border-color: var(--good); }
.tile.bad { border-color: var(--bad); background: #fdecea; animation: shake 0.45s ease; }
@keyframes shake {
  20% { transform: translateX(-3px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

.spell-box {
  width: 100%;
  margin-top: 12px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: #fff;
  padding: 14px 16px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 700;
}
.mask { font-family: var(--serif); font-size: 28px; letter-spacing: 0.04em; margin: 8px 0 0; }
.stars { font-size: 32px; letter-spacing: 4px; color: var(--amber); margin: 0; }

.list-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.list-tools input {
  flex: 1;
  min-width: 180px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--card);
  padding: 10px 14px;
  font-weight: 800;
}
.word-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.word-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
}
.word-row b { font-family: var(--serif); font-size: 22px; }
.word-row .ipa { font-size: 14px; }
.word-row .zh { font-family: var(--cjk); }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: #fff;
  font-weight: 900;
}
.foot {
  margin-top: 28px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.linkish { background: none; border: 0; padding: 0; color: var(--muted); font-weight: 800; text-decoration: underline; }

.confetti { position: relative; height: 0; }
.confetti i {
  position: absolute;
  left: calc(8% + var(--i) * 5%);
  top: -10px;
  width: 8px; height: 14px;
  border-radius: 2px;
  background: hsl(calc(var(--i) * 24), 70%, 48%);
  animation: fall 900ms ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(70px) rotate(180deg); opacity: 0; }
}

@media (max-width: 800px) {
  body { padding: 18px 14px 48px 28px; }
  .hero, .steps, .choices, .match-grid { grid-template-columns: 1fr 1fr; }
  .hero { grid-template-columns: 1fr; }
  .lede { font-size: 24px; }
  .cat-head h1 { font-size: 32px; }
  .top { flex-direction: column; }
}
@media (max-width: 560px) {
  .steps, .choices, .match-grid { grid-template-columns: 1fr; }
  .match-grid { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
