/* BopoType 樣式 */
:root {
  --bg: #121316;
  --bg-2: #1a1b1f;
  --card: #1f2126;
  --card-2: #26282f;
  --text: #eceef1;
  --text-dim: #9aa0ab;
  --text-muted: #5d6370;
  --accent: #e2b714;
  --accent-ink: #121316;
  --ok: #3ddc84;
  --bad: #ff6b6b;
  --bad-bg: rgba(255, 107, 107, 0.14);
  --line: #2d3139;
  --focus: rgba(226, 183, 20, 0.45);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  --radius: 14px;
  --font-sans: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-2: #ffffff;
  --card: #ffffff;
  --card-2: #f0f2f5;
  --text: #1d2127;
  --text-dim: #5b6270;
  --text-muted: #a4aab5;
  --accent: #b7860b;
  --accent-ink: #ffffff;
  --ok: #138a4b;
  --bad: #d62f2f;
  --bad-bg: rgba(214, 47, 47, 0.1);
  --line: #e2e5ea;
  --focus: rgba(183, 134, 11, 0.4);
  --shadow: 0 8px 24px rgba(20, 30, 50, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
a { color: var(--accent); }
img { max-width: 100%; height: auto; }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 768px) { .container { padding: 0 24px; } }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* ---------- 頁首 ---------- */
.site-header { border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 20; }
.header-row { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.logo { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 800; font-size: 1.15rem; white-space: nowrap; }
.logo img { width: 30px; height: 30px; }
.logo small { color: var(--text-dim); font-weight: 400; font-size: 0.8rem; }
.site-nav { flex: 1; min-width: 0; }
.site-nav ul { display: flex; gap: 2px; list-style: none; margin: 0; padding: 0; overflow-x: auto; scrollbar-width: none; }
.site-nav ul::-webkit-scrollbar { display: none; }
.site-nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text-dim); text-decoration: none; font-size: 0.92rem; white-space: nowrap; }
.site-nav a:hover { color: var(--text); background: var(--card-2); }
.site-nav a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.btn-theme { flex: none; background: none; border: 1px solid var(--line); color: var(--text-dim); border-radius: 8px; width: 40px; height: 40px; cursor: pointer; }
.btn-theme:hover { color: var(--text); }
@media (max-width: 767px) {
  .header-row { flex-wrap: wrap; row-gap: 0; padding-top: 8px; }
  .logo small { display: none; }
  .site-nav { order: 3; flex-basis: 100%; margin: 0 -16px; }
  .site-nav ul { padding: 0 10px 6px; }
  .btn-theme { margin-left: auto; }
}

/* ---------- 麵包屑 / 標題 ---------- */
.breadcrumb { font-size: 0.82rem; color: var(--text-muted); margin: 16px 0 0; }
.breadcrumb ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.breadcrumb li + li::before { content: "›"; margin-right: 6px; }
.breadcrumb a { color: var(--text-dim); text-decoration: none; }
.page-head { margin: 14px 0 18px; }
.page-head h1 { font-size: clamp(1.45rem, 3.4vw, 2rem); line-height: 1.3; margin: 0 0 6px; }
.page-head p { margin: 0; color: var(--text-dim); max-width: 760px; }

/* ---------- 工具卡 ---------- */
.tool { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
@media (min-width: 768px) { .tool { padding: 20px 24px; } }
.controls { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 14px; }
.ctrl-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.ctrl-label { font-size: 0.78rem; color: var(--text-muted); margin-right: 4px; }
.pill { border: 1px solid transparent; background: var(--card-2); color: var(--text-dim); border-radius: 999px; padding: 6px 12px; min-height: 36px; cursor: pointer; font-size: 0.88rem; }
.pill:hover { color: var(--text); }
.pill[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--text-dim); cursor: pointer; min-height: 36px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.stats { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px; margin-bottom: 10px; font-size: 0.92rem; color: var(--text-dim); }
.stats .timer { font-family: var(--font-mono); font-size: 2rem; font-weight: 800; color: var(--accent); line-height: 1; min-width: 3ch; }
.stats strong { color: var(--text); font-family: var(--font-mono); font-size: 1.15rem; }
.stats .restart { margin-left: auto; }

.passage-title { font-size: 0.9rem; color: var(--text-dim); margin: 0 0 4px; }
.text-view {
  position: relative;
  height: calc(3 * 2.4em);
  overflow: hidden;
  font-size: 1.6rem;
  cursor: text;
  user-select: none;
  -webkit-user-select: none;
}
.text-view.with-hint { height: calc(3 * 2.9em); }
.tx-inner { line-height: 2.4em; transition: transform 0.15s ease; word-break: break-all; }
.text-view.with-hint .tx-inner { line-height: 2.9em; }
[data-mode="en"] .text-view { font-family: var(--font-mono); font-size: 1.45rem; }
[data-mode="en"] .tx-inner { word-break: normal; overflow-wrap: normal; }
.ch.sp { white-space: pre-wrap; }
.ch { position: relative; color: var(--text-muted); border-radius: 4px; }
.ch.gap { margin-right: 0.45em; }
.ch.ok { color: var(--ok); }
.ch.bad { color: var(--bad); background: var(--bad-bg); }
.ch.cur { color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); animation: caret 1.1s ease-in-out infinite; }
@keyframes caret { 50% { box-shadow: inset 0 -3px 0 transparent; } }
.ch .zy { display: none; }
.with-hint .ch { display: inline-flex; flex-direction: column; align-items: center; vertical-align: bottom; line-height: 1.25; margin: 0 0.06em; }
.with-hint .ch .zy {
  display: block; font-size: 0.46em; line-height: 1.25; white-space: nowrap; color: var(--text-dim);
  letter-spacing: 0; min-height: 1.3em; order: -1;
}
.with-hint .ch:not(:has(.zy))::before { content: ""; display: block; height: 0.52em; }
.ch.ok .zy, .ch.bad .zy { opacity: 0.45; }
@media (max-width: 767px) {
  .text-view { font-size: 1.3rem; }
  [data-mode="en"] .text-view { font-size: 1.15rem; }
}

.input-wrap { margin-top: 10px; }
.type-input {
  width: 100%; font: inherit; font-size: 1.25rem; padding: 12px 14px; min-height: 52px;
  background: var(--bg-2); color: var(--text); border: 2px solid var(--line); border-radius: 10px; outline: none;
}
.type-input:focus { border-color: var(--focus); }
.type-input::placeholder { color: var(--text-muted); font-size: 0.95rem; }
.tool:focus-within { border-color: var(--focus); }
[data-mode="key"] .tool-focus-ring, [data-mode="key"]:focus-within .text-view { background: color-mix(in srgb, var(--accent) 4%, transparent); border-radius: 8px; }

.notice { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; font-size: 0.88rem; background: var(--card-2); color: var(--text-dim); }
.notice[data-kind="warn"] { background: var(--bad-bg); color: var(--bad); }

.kb-wrap { margin-top: 16px; }
.kb-hint { min-height: 1.6em; font-size: 0.92rem; color: var(--text-dim); text-align: center; margin-bottom: 6px; }
.keyboard { display: flex; flex-direction: column; gap: 5px; align-items: center; }
.kb-row { display: flex; gap: 5px; justify-content: center; width: 100%; }
.kb-row-1 { padding-left: 2.2%; }
.kb-row-2 { padding-left: 4.4%; }
.kb-row-3 { padding-left: 6.6%; }
.kb-key {
  flex: 0 1 56px; aspect-ratio: 1 / 1; max-width: 56px; min-width: 0; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card-2); border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 8px;
  color: var(--text); cursor: pointer; transition: background 0.1s, transform 0.05s;
}
.kb-key .kb-zy { font-size: 1.05rem; line-height: 1.1; }
.kb-key .kb-en { font-size: 0.62rem; color: var(--text-muted); font-family: var(--font-mono); }
.kb-home .kb-en { text-decoration: underline; }
.kb-space { flex-basis: 330px; max-width: 330px; aspect-ratio: auto; height: 44px; flex-direction: row; gap: 8px; }
.kb-key.kb-seq { background: color-mix(in srgb, var(--accent) 18%, var(--card-2)); }
.kb-key.kb-next { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kb-key.kb-next .kb-en { color: var(--accent-ink); }
.kb-key.kb-press { animation: press 0.18s ease; }
@keyframes press { 40% { transform: translateY(2px); filter: brightness(1.3); } }
@media (max-width: 520px) {
  .kb-row { gap: 3px; }
  .kb-key { border-radius: 6px; }
  .kb-key .kb-zy { font-size: 0.9rem; }
  .kb-key .kb-en { display: none; }
}

.tool-foot { margin-top: 12px; font-size: 0.82rem; color: var(--text-muted); text-align: center; }
kbd { font-family: var(--font-mono); font-size: 0.8em; background: var(--card-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; color: var(--text-dim); }

/* ---------- 按鈕 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); font-weight: 700; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--card-2); color: var(--text); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; font-weight: 600; }

/* ---------- 結果視窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(8, 9, 11, 0.72); display: flex; align-items: center; justify-content: center; padding: 16px; opacity: 0; transition: opacity 0.2s; }
.modal.open { opacity: 1; }
.result-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px 24px; width: 100%; max-width: 440px; text-align: center; box-shadow: var(--shadow); }
.result-rank { display: inline-block; background: var(--card-2); color: var(--accent); border-radius: 999px; padding: 6px 14px; font-weight: 700; }
.result-speed { font-family: var(--font-mono); font-size: 4.2rem; font-weight: 800; color: var(--accent); line-height: 1.1; margin-top: 12px; }
.result-unit { color: var(--text-dim); font-size: 0.9rem; }
.result-pb { min-height: 1.4em; margin: 6px 0 0; font-size: 0.9rem; color: var(--ok); }
.result-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 18px 0; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-grid b { display: block; font-family: var(--font-mono); font-size: 1.2rem; }
.result-grid span { font-size: 0.75rem; color: var(--text-dim); }
.result-actions { display: flex; gap: 10px; }
.result-actions .btn { flex: 1; }
.result-tip { margin: 12px 0 0; font-size: 0.8rem; color: var(--text-muted); }

/* ---------- 文章 ---------- */
.content { max-width: 780px; margin: 40px auto 0; }
.prose h2 { font-size: 1.4rem; margin: 2.2em 0 0.6em; line-height: 1.4; }
.prose h3 { font-size: 1.12rem; margin: 1.6em 0 0.4em; }
.prose p, .prose li { color: var(--text-dim); }
.prose strong { color: var(--text); }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 0.35em 0; }
.table-wrap { overflow-x: auto; margin: 1em 0; border: 1px solid var(--line); border-radius: 10px; }
.prose table { width: 100%; border-collapse: collapse; font-size: 0.92rem; min-width: 480px; }
.prose th, .prose td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { background: var(--card-2); color: var(--text); white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }
.prose .callout { background: var(--card); border-left: 3px solid var(--accent); padding: 12px 16px; border-radius: 0 10px 10px 0; }

.faq details { border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; background: var(--card); }
.faq summary { cursor: pointer; padding: 14px 16px; font-weight: 700; list-style: none; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; float: right; color: var(--text-muted); }
.faq details[open] summary::after { content: "−"; }
.faq details p { margin: 0; padding: 0 16px 14px; color: var(--text-dim); }

.related { margin: 48px 0 0; }
.related h2 { font-size: 1.2rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.link-card { display: block; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); text-decoration: none; }
.link-card:hover { border-color: var(--accent); }
.link-card b { display: block; margin-bottom: 4px; }
.link-card span { font-size: 0.86rem; color: var(--text-dim); }

/* ---------- 遊戲 ---------- */
.game-hud { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 0.92rem; color: var(--text-dim); margin-bottom: 10px; }
.game-hud strong { color: var(--text); font-family: var(--font-mono); }
.game-hud .lives { color: var(--bad); letter-spacing: 2px; }
.arena { position: relative; height: 420px; overflow: hidden; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; outline: none; }
.arena:focus { border-color: var(--focus); }
.arena::after { content: ""; position: absolute; left: 0; right: 0; bottom: 30px; border-top: 2px dashed var(--bad); opacity: 0.5; }
.arena.g-miss { animation: miss 0.3s; }
@keyframes miss { 30% { background: var(--bad-bg); } }
.g-item { position: absolute; top: 0; padding: 4px 12px; border-radius: 8px; background: var(--card-2); border: 1px solid var(--line); font-size: 1.25rem; font-weight: 700; white-space: nowrap; will-change: transform; }
.g-item.g-target { border-color: var(--accent); color: var(--accent); }
.g-item.g-pop { animation: pop 0.22s forwards; }
@keyframes pop { to { opacity: 0; transform: scale(1.6); } }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; background: color-mix(in srgb, var(--bg-2) 88%, transparent); z-index: 2; }
.overlay h2 { margin: 0 0 8px; }
.overlay p { margin: 0 0 10px; color: var(--text-dim); max-width: 420px; }
.overlay .go-score { font-size: 2.6rem; font-weight: 800; color: var(--accent); font-family: var(--font-mono); margin: 0; }
.game-input { margin-top: 10px; }
[data-game-mode="zhuyin"] .game-input { display: none; }
.g-shake { animation: shake 0.25s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@media (max-width: 767px) { .arena { height: 340px; } }

/* ---------- 頁尾 ---------- */
.site-footer { margin-top: 64px; border-top: 1px solid var(--line); padding: 32px 0 40px; font-size: 0.86rem; color: var(--text-dim); }
.footer-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 20px; }
.site-footer h2 { font-size: 0.9rem; color: var(--text); margin: 0 0 8px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin: 4px 0; }
.site-footer a { color: var(--text-dim); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.footer-note { margin-top: 24px; color: var(--text-muted); font-size: 0.8rem; }

/* ---------- 404 ---------- */
.error-page { text-align: center; padding: 80px 0 40px; }
.error-page .code { font-size: 5rem; font-weight: 900; color: var(--accent); font-family: var(--font-mono); line-height: 1; }

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

.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; }
.tool { position: relative; }
.key-focus { position: absolute; top: 0; left: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; }

@media (max-width: 767px) {
  .page-head { margin: 10px 0 12px; }
  .page-head p { font-size: 0.9rem; }
  .controls { gap: 8px 12px; margin-bottom: 10px; }
  .ctrl-group[aria-label="按鍵音效"] { display: none; }
  .pill { padding: 4px 10px; min-height: 34px; font-size: 0.84rem; }
  .stats { gap: 4px 14px; }
  .stats .timer { font-size: 1.6rem; }
}
