:root {
  --accent: #4f7cff;
  --accent2: #ff9f43;
  --good: #2ecc71;
  --bad: #ff5b5b;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #8892a6;
  --page-bg: #f4f6fb;
  --border: #e7e9f2;
  --active-bg: #eef2ff;
}

html.dark {
  --card: #1c2030;
  --text: #e7e9f2;
  --muted: #8b90a3;
  --page-bg: #12141f;
  --border: #2a2f45;
  --active-bg: #232842;
}

html[data-theme="blue"] { --accent: #4f7cff; }
html[data-theme="green"] { --accent: #2ecc71; }
html[data-theme="orange"] { --accent: #ff9f43; }
html[data-theme="pink"] { --accent: #ff6b9f; }
html[data-theme="purple"] { --accent: #8b5cf6; }
html[data-theme="teal"] { --accent: #14b8a6; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--page-bg);
  color: var(--text);
}

.btn { padding: 12px; border: none; border-radius: 12px; font-size: 14px; font-weight: 700; cursor: pointer; }
.btn.secondary { background: #f1f3f8; color: var(--text); }
html.dark .btn.secondary { background: #262b40; color: var(--text); }
.btn.primary { background: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }

.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.85); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.3s, top 0.3s; z-index: 100;
}
.toast.show { opacity: 1; top: 34px; }

.overlay { position: fixed; inset: 0; background: rgba(15,20,35,0.55); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 40; }
.overlay.show { display: flex; }
.panel { background: var(--card); color: var(--text); border-radius: 18px; padding: 20px; width: 100%; max-width: 420px; max-height: 80vh; overflow-y: auto; }
.panel h3 { margin-top: 0; }
.list-item { padding: 12px; border-radius: 10px; background: var(--page-bg); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.list-item .en { font-weight: 600; color: var(--text); font-size: 14px; }
.list-item .zh { color: var(--muted); font-size: 12px; margin-top: 4px; }
.panel-actions { display: flex; gap: 10px; margin-top: 14px; }
.empty-tip { text-align: center; color: var(--muted); padding: 30px 0; font-size: 14px; }
.list-item-action {
  border: none; background: var(--card); color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 6px 10px; border-radius: 8px; cursor: pointer; flex-shrink: 0; white-space: nowrap;
}
.list-item-action:hover { background: var(--active-bg); color: var(--accent); }
.list-item .word-chip { font-weight: 700; color: var(--accent); font-size: 15px; }

.form-field { margin-bottom: 12px; }
.form-field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.form-field input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 14px;
  background: var(--card); color: var(--text);
}
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tabs button { flex: 1; padding: 8px; border: none; border-radius: 10px; background: #f1f3f8; font-weight: 700; cursor: pointer; color: var(--muted); }
.auth-tabs button.active { background: var(--accent); color: #fff; }
.auth-error { color: var(--bad); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.lb-rank { width: 24px; display: inline-block; color: var(--muted); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 8px 30px rgba(20,25,45,0.06); padding: 24px; position: relative; overflow: hidden; }

.timer-track { height: 6px; background: #eef0f4; border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
html.dark .timer-track { background: #232842; }
.timer-fill { height: 100%; width: 100%; background: var(--accent); transition: width 0.2s linear, background 0.3s; border-radius: 999px; }
.timer-fill.low { background: var(--bad); }

.stopwatch-inline {
  text-align: right; font-family: "SF Mono", Menlo, monospace; font-size: 13px; color: var(--muted); margin-bottom: 10px;
}

/* ---- floating audio player widget (common.js speakText/speakWordByWord) ---- */
.audio-player {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(20px);
  display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 18px 8px 8px; box-shadow: 0 10px 30px rgba(20,25,45,0.15);
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 90;
}
.audio-player.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.audio-player-toggle {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--accent); color: #fff;
  font-size: 14px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.audio-player-body { display: flex; flex-direction: column; gap: 6px; }
.audio-player-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); font-weight: 600; white-space: nowrap; }
.audio-player-wave { display: flex; align-items: flex-end; gap: 2px; height: 14px; }
.audio-player-wave span { width: 3px; background: var(--accent); border-radius: 2px; animation: audio-wave 0.9s ease-in-out infinite; }
.audio-player-wave span:nth-child(1) { animation-delay: 0s; }
.audio-player-wave span:nth-child(2) { animation-delay: 0.1s; }
.audio-player-wave span:nth-child(3) { animation-delay: 0.2s; }
.audio-player-wave span:nth-child(4) { animation-delay: 0.3s; }
.audio-player-wave span:nth-child(5) { animation-delay: 0.4s; }
.audio-player.paused .audio-player-wave span { animation-play-state: paused; height: 30%; }
@keyframes audio-wave { 0%, 100% { height: 30%; } 50% { height: 100%; } }
.audio-player-track { width: 160px; height: 4px; background: var(--border); border-radius: 999px; overflow: hidden; }
.audio-player-fill { height: 100%; background: var(--accent); width: 0%; }
.audio-player-close {
  width: 26px; height: 26px; border-radius: 50%; border: none; background: var(--page-bg); color: var(--muted);
  cursor: pointer; font-size: 14px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}

.zh-hint { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 14px; min-height: 20px; }

.feedback { text-align: center; font-size: 14px; font-weight: 700; min-height: 20px; margin-top: 10px; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

/* ---- top bar shared by game pages ---- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 24px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar .back-link {
  width: 34px; height: 34px; border-radius: 10px; background: var(--page-bg); color: var(--text);
  display: flex; align-items: center; justify-content: center; text-decoration: none; font-size: 16px; flex-shrink: 0;
}
.topbar .title-wrap { flex: 1; min-width: 0; }
.topbar .title-wrap .lesson-title { font-weight: 700; font-size: 15px; color: var(--text); }
.topbar .title-wrap .counter { color: var(--muted); font-size: 12px; margin-left: 6px; }
.topbar .progress-track { height: 4px; background: var(--border); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.topbar .progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.2s; }
.topbar .right-cluster { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar .stopwatch { font-family: "SF Mono", Menlo, monospace; font-size: 14px; color: var(--muted); min-width: 48px; text-align: right; }
.topbar .icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: none; background: var(--page-bg); color: var(--text);
  cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center; position: relative;
}
.topbar .icon-btn:hover { background: var(--active-bg); }
.topbar .icon-btn.active { background: var(--active-bg); color: var(--accent); }
.topbar .score-inline { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.topbar .score-inline b { color: var(--text); }

.theme-popover {
  position: absolute; top: 40px; right: 0; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.15); display: none; z-index: 60; width: 200px;
}
.theme-popover.show { display: block; }
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.theme-swatch { width: 26px; height: 26px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.theme-swatch.active { border-color: var(--text); }
