:root {
  --bg: #f7f5f0; --card: #ffffff; --ink: #1d2430; --muted: #687385; --line: #e3dfd6;
  --accent: #0f7b6c; --accent-soft: #e2f2ee; --warn: #c4502f; --warn-soft: #fbe8e1;
  --gold: #b7791f; --gold-soft: #fbf0dc; --blue: #2f5fb3; --blue-soft: #e5edfa;
  --pad: #fffdf8; --grid: #eadfca; --shadow: 0 1px 2px rgba(20,25,35,.06), 0 4px 14px rgba(20,25,35,.05);
  --zh: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  --kai: "LXGW WenKai TC", "DFKai-SB", "BiauKai", "Kaiti TC", "Microsoft JhengHei", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c; --card: #1c2027; --ink: #e8eaee; --muted: #9aa3b2; --line: #2c323c;
    --accent: #3fc1a9; --accent-soft: #173a35; --warn: #ff8a66; --warn-soft: #3d241c;
    --gold: #e2b04f; --gold-soft: #3a2f19; --blue: #7ea6f2; --blue-soft: #1d2a42;
    --pad: #1f232a; --grid: #3a3528; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c; --card: #1c2027; --ink: #e8eaee; --muted: #9aa3b2; --line: #2c323c;
  --accent: #3fc1a9; --accent-soft: #173a35; --warn: #ff8a66; --warn-soft: #3d241c;
  --gold: #e2b04f; --gold-soft: #3a2f19; --blue: #7ea6f2; --blue-soft: #1d2a42;
  --pad: #1f232a; --grid: #3a3528; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.5 system-ui, "Segoe UI", var(--zh); }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.zh { font-family: var(--zh); }
.kai { font-family: var(--kai); }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--zh); font-weight: 700; font-size: 20px; text-decoration: none; color: var(--ink); }
.brand span { font-family: system-ui; font-weight: 500; font-size: 14px; color: var(--muted); margin-left: 6px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 500; }
nav a.on, nav a:hover { background: var(--accent-soft); color: var(--accent); }
.menu-btn { display: none; margin-left: auto; border: 1px solid var(--line); background: none; border-radius: 8px; padding: 4px 10px; font-size: 18px; }
@media (max-width: 860px) {
  .menu-btn { display: block; }
  nav { display: none; width: 100%; }
  nav.open { display: flex; }
}

main { max-width: 1120px; margin: 0 auto; padding: 24px 20px 80px; }
h1 { font-size: 28px; margin: 4px 0 6px; }
h2 { font-size: 20px; margin: 28px 0 10px; }
h3 { font-size: 17px; margin: 0 0 6px; }
.lead { color: var(--muted); margin: 0 0 18px; max-width: 760px; }
.crumb { font-size: 14px; color: var(--muted); }
.crumb a { text-decoration: none; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
a.card { display: block; text-decoration: none; color: inherit; transition: transform .12s, border-color .12s; }
a.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .big { font-family: var(--zh); font-size: 30px; font-weight: 700; }
.card p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.meta { font-size: 13px; color: var(--muted); }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.phase { border-left: 4px solid var(--accent); padding: 2px 0 2px 16px; margin: 26px 0 12px; }
.phase.p2 { border-color: var(--blue); } .phase.p3 { border-color: var(--gold); } .phase.p4 { border-color: var(--muted); } .phase.p5 { border-color: var(--warn); }
.phase h2 { margin: 0; }
.phase .when { font-size: 14px; color: var(--muted); }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0 6px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; min-width: 140px; }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 13px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; padding: 8px 14px; font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; color: var(--ink); min-height: 42px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.tabs { display: flex; gap: 6px; margin: 14px 0 18px; flex-wrap: wrap; }

/* See-all tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tiles.wide { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.tile { position: relative; perspective: 800px; min-height: 150px; cursor: pointer; }
.tile .in { position: absolute; inset: 0; transition: transform .35s; transform-style: preserve-3d; }
.tile.flip .in { transform: rotateY(180deg); }
.tile .face { position: absolute; inset: 0; backface-visibility: hidden; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; box-shadow: var(--shadow); }
.tile .back { transform: rotateY(180deg); background: var(--gold-soft); }
.tile .sym { font-family: var(--zh); font-size: 44px; line-height: 1.1; font-weight: 500; }
.tiles.wide .sym { font-size: 30px; }
.tile .zy { font-family: var(--zh); font-size: 15px; color: var(--accent); }
.tile .py { font-size: 15px; color: var(--ink); font-weight: 600; }
.tile .en { font-size: 13px; color: var(--muted); }
.tile .q { font-size: 28px; }
.tile .hint { font-size: 12px; color: var(--muted); position: absolute; bottom: 6px; }
.group-title { margin: 18px 0 8px; font-weight: 700; color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .04em; }

/* Practice */
.practice { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.practice > #rateBox { grid-column: 1 / -1; }
@media (min-width: 900px) { .practice.two { grid-template-columns: minmax(0, 1fr) auto; } }
.prompt { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; text-align: center; box-shadow: var(--shadow); }
.prompt .en { font-size: 22px; font-weight: 600; }
.prompt .py { font-size: 20px; }
.prompt .zy { font-family: var(--zh); font-size: 20px; color: var(--accent); }
.prompt .count { font-size: 13px; color: var(--muted); }
.answer { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.answer .sym { font-family: var(--kai); font-size: 64px; line-height: 1.15; }
.answer .note { font-size: 14px; color: var(--muted); max-width: 640px; margin: 6px auto 0; }
.pads { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.padwrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
canvas.pad { background: var(--pad); border: 2px solid var(--line); border-radius: 14px; touch-action: none; user-select: none;
  -webkit-user-select: none; cursor: crosshair; display: block; }
canvas.pad.done { cursor: default; }
.score { font-weight: 700; font-size: 15px; }
.score.good { color: var(--accent); } .score.ok { color: var(--gold); } .score.bad { color: var(--warn); }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 620px; margin: 0 auto; }
.rate .btn { flex-direction: column; gap: 0; min-height: 58px; }
.rate .btn small { font-weight: 400; font-size: 12px; color: var(--muted); }
.rate .btn.sug { outline: 3px solid var(--accent); outline-offset: 1px; }
.r-again { border-color: var(--warn) !important; } .r-hard { border-color: var(--gold) !important; } .r-good { border-color: var(--accent) !important; } .r-easy { border-color: var(--blue) !important; }
.kbd { font-size: 12px; color: var(--muted); text-align: center; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.settings { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 14px; color: var(--muted); }
.settings label { display: flex; align-items: center; gap: 6px; }
select, input[type=number] { font: inherit; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }

/* lists & dialogs */
.list { display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; align-items: center; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.item .h { font-family: var(--zh); font-size: 20px; font-weight: 500; }
.item .z { font-family: var(--zh); font-size: 14px; color: var(--accent); }
.item .p { font-size: 14px; }
.item .e { font-size: 14px; color: var(--muted); }
.item .n { font-size: 13px; color: var(--gold); }
.play { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--accent-soft); color: var(--accent);
  cursor: pointer; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.play:disabled { background: var(--line); color: var(--muted); cursor: default; }
.play.playing { background: var(--accent); color: #fff; }
.dialog { display: grid; gap: 8px; }
.line { display: flex; gap: 10px; align-items: flex-start; }
.line.B { flex-direction: row-reverse; }
.bubble { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; max-width: 75%; }
.line.B .bubble { background: var(--blue-soft); }
.line.now .bubble { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.bubble .h { font-family: var(--zh); font-size: 19px; }
.bubble .p, .bubble .e { font-size: 13px; color: var(--muted); }
.hide-py .p, .hide-py .z { display: none; } .hide-en .e { display: none; } .hide-zh .bubble .h { filter: blur(6px); }
.prose { max-width: 760px; }
.tw-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.tw-table td, .tw-table th { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; font-size: 14px; }
.tw-table th { background: var(--accent-soft); color: var(--accent); font-size: 13px; }
.tw-table .h { font-family: var(--zh); font-size: 18px; }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--gold-soft); color: var(--gold); font-weight: 600; }
.tone-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 520px; margin: 14px auto; }
.tone-btns .btn { font-size: 22px; min-height: 70px; flex-direction: column; gap: 0; }
.tone-btns .btn small { font-size: 12px; font-weight: 400; color: var(--muted); }
.tone-btns .btn.right { background: var(--accent-soft); border-color: var(--accent); }
.tone-btns .btn.wrong { background: var(--warn-soft); border-color: var(--warn); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 50; }
footer.note { margin-top: 40px; font-size: 13px; color: var(--muted); }
