/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4f8ef7;
  --primary-dark: #3a72d8;
  --secondary: #ff8c42;
  --success: #2ec97a;
  --danger: #f25c5c;
  --warning: #f7c948;
  --bg: #f0f4ff;
  --card: #ffffff;
  --text: #2d3142;
  --text-muted: #7a8098;
  --border: #dce3f5;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(79,142,247,.12);
  --shadow-lg: 0 8px 40px rgba(79,142,247,.18);
  --font: 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --lv1: #2ec97a; --lv1-bg: #eafff4;
  --lv2: #f7c948; --lv2-bg: #fffae8;
  --lv3: #f25c5c; --lv3-bg: #fff0f0;
  --gradient: linear-gradient(135deg, #4f8ef7 0%, #6a5af9 100%);
  --hover-bg: #f5f8ff;
  --active-bg: #eef4ff;
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.site-footer {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  background: #f7f9ff;
}

.site-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ===== Header ===== */
.header {
  background: var(--gradient);
  box-shadow: 0 2px 16px rgba(79,142,247,.3);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 0 24px;
  display: flex; align-items: center; gap: 16px;
  height: 64px;
}
.logo {
  font-size: 1.4rem; font-weight: 800; color: #fff;
  letter-spacing: 0.5px; white-space: nowrap;
}
.nav { display: flex; gap: 4px; flex: 1; justify-content: center; }
.nav-btn {
  background: transparent; border: none; cursor: pointer;
  color: rgba(255,255,255,.8); font-size: 0.95rem; font-weight: 600;
  padding: 8px 16px; border-radius: 10px; transition: all .2s;
}
.nav-btn:hover, .nav-btn.active {
  background: rgba(255,255,255,.2); color: #fff;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 22px; border-radius: 10px; border: none;
  font-family: var(--font); font-size: 0.95rem; font-weight: 700;
  cursor: pointer; transition: all .2s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,142,247,.4); }
.btn-outline { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-hero {
  background: #fff; color: var(--primary);
  font-size: 1.1rem; padding: 14px 32px; border-radius: 14px;
  box-shadow: var(--shadow-lg);
}
.btn-hero:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(79,142,247,.3); }
.btn-hero-outline {
  background: transparent; color: #fff; border: 2px solid rgba(255,255,255,.7);
  font-size: 1.1rem; padding: 14px 32px; border-radius: 14px;
}
.btn-hero-outline:hover { background: rgba(255,255,255,.15); }
.btn-full { width: 100%; justify-content: center; padding: 14px; font-size: 1rem; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }

/* ===== User area ===== */
.user-area, .user-info {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.avatar { font-size: 1.4rem; }
.username { color: #fff; font-weight: 700; font-size: 0.95rem; }
.hidden { display: none !important; }

/* ===== Main / Pages ===== */
.main { max-width: 1200px; margin: 0 auto; padding: 40px 24px; }
.page { display: none; }
.page.active { display: block; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ===== Hero ===== */
.hero {
  background: var(--gradient);
  border-radius: var(--radius);
  padding: 60px 48px;
  display: flex; align-items: center; justify-content: space-between; gap: 32px;
  margin-bottom: 40px;
  box-shadow: var(--shadow-lg);
}
.hero-title { font-size: 2.2rem; font-weight: 900; color: #fff; margin-bottom: 12px; }
.hero-sub { font-size: 1.1rem; color: rgba(255,255,255,.85); margin-bottom: 28px; line-height: 1.8; }
.hero-sub strong { color: #fff; }
.hero-actions { display: flex; gap: 14px; flex-wrap: wrap; }
.hero-img { font-size: 8rem; opacity: .85; user-select: none; flex-shrink: 0; }

/* ===== Feature Cards ===== */
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.feature-card {
  background: var(--card); border-radius: var(--radius);
  padding: 28px 24px; text-align: center;
  box-shadow: var(--shadow); transition: transform .2s;
}
.feature-card:hover { transform: translateY(-4px); }
.feature-icon { font-size: 2.4rem; margin-bottom: 12px; }
.feature-card h3 { font-size: 1.05rem; margin-bottom: 8px; }
.feature-card p { color: var(--text-muted); font-size: 0.9rem; }

/* ===== Section Title ===== */
.section-title { margin-bottom: 28px; }
.section-title h2 { font-size: 1.7rem; font-weight: 800; margin-bottom: 6px; }
.section-title p { color: var(--text-muted); }

/* ===== Level Filter ===== */
.level-filter { display: flex; gap: 10px; margin-bottom: 28px; flex-wrap: wrap; }
.filter-btn {
  padding: 8px 20px; border-radius: 20px; border: 2px solid var(--border);
  background: var(--card); font-family: var(--font); font-size: 0.9rem;
  font-weight: 700; cursor: pointer; transition: all .2s; color: var(--text-muted);
}
.filter-btn.active, .filter-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--active-bg); }
.filter-btn.level-1.active { border-color: var(--lv1); color: var(--lv1); background: var(--lv1-bg); }
.filter-btn.level-2.active { border-color: var(--lv2); color: #b8861a; background: var(--lv2-bg); }
.filter-btn.level-3.active { border-color: var(--lv3); color: var(--lv3); background: var(--lv3-bg); }

/* ===== Article Grid ===== */
.article-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.article-card {
  background: var(--card); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow); cursor: pointer; transition: all .2s;
  border: 2px solid transparent; position: relative; overflow: hidden;
}
.article-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.article-card-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.article-card h3 { font-size: 1.1rem; font-weight: 800; }
.level-badge {
  padding: 3px 12px; border-radius: 20px; font-size: 0.78rem; font-weight: 700;
  white-space: nowrap; flex-shrink: 0; margin-left: 8px;
}
.badge-1 { background: var(--lv1-bg); color: var(--lv1); }
.badge-2 { background: var(--lv2-bg); color: #b8861a; }
.badge-3 { background: var(--lv3-bg); color: var(--lv3); }
.article-preview { color: var(--text-muted); font-size: 0.88rem; line-height: 1.7; margin-bottom: 16px; }
.article-card-footer { display: flex; justify-content: space-between; align-items: center; }
.article-char-count { font-size: 0.82rem; color: var(--text-muted); }
.btn-start {
  padding: 7px 18px; border-radius: 8px; font-size: 0.88rem;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  font-weight: 700; transition: all .2s;
}
.btn-start:hover { background: var(--primary-dark); }

/* ===== Typing Page ===== */
.typing-header {
  background: var(--card); border-radius: var(--radius);
  padding: 20px 24px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.typing-info { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.info-label { color: var(--text-muted); font-size: 0.9rem; }
.info-value { font-weight: 800; font-size: 1rem; }
.info-badge { padding: 2px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 700; }
.stats-bar { display: flex; gap: 24px; flex-wrap: wrap; }
.stat-item { text-align: center; min-width: 80px; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 2px; }
.stat-value { font-size: 1.4rem; font-weight: 900; color: var(--primary); }
.typing-settings { margin-top: 12px; display: flex; justify-content: flex-end; }
.timer-value { color: var(--secondary) !important; }
.timer-danger { color: var(--danger) !important; animation: pulse .6s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: .5; } }

/* Progress Bar */
.progress-bar-wrap {
  height: 6px; background: var(--border); border-radius: 6px;
  margin-bottom: 16px; overflow: hidden;
}
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 6px; transition: width .3s; }

/* Article Display */
.article-display {
  background: var(--card); border-radius: var(--radius);
  padding: 24px 28px; margin-bottom: 16px;
  font-size: 1.15rem; line-height: 2.2; letter-spacing: 1px;
  box-shadow: var(--shadow); min-height: 120px;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
.char-correct { color: var(--success); }
.char-wrong { color: var(--danger); text-decoration: underline; background: #ffe8e8; border-radius: 2px; }
.char-current {
  background: var(--primary); color: #fff;
  border-radius: 3px; animation: blink .8s infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.char-pending { color: var(--text-muted); }

/* Typing Input */
.input-area { margin-bottom: 16px; }
.typing-textarea {
  width: 100%; height: 120px;
  border: 2px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; font-size: 1.05rem; font-family: var(--font);
  resize: none; outline: none; transition: border-color .2s;
  line-height: 1.8; background: var(--card);
}
.typing-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79,142,247,.1); }
.typing-textarea:disabled { background: #f5f5f5; cursor: not-allowed; }

.typing-actions { display: flex; justify-content: space-between; align-items: center; }

/* ===== Result Page ===== */
.result-container {
  max-width: 600px; margin: 0 auto;
  background: var(--card); border-radius: var(--radius);
  padding: 48px 40px; text-align: center;
  box-shadow: var(--shadow-lg);
}
.result-emoji { font-size: 5rem; margin-bottom: 12px; }
.result-header h2 { font-size: 2rem; margin-bottom: 8px; }
.result-header p { color: var(--text-muted); margin-bottom: 32px; }
.result-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 24px; }
.result-stat {
  background: var(--bg); border-radius: 12px; padding: 20px;
}
.result-stat-value { font-size: 2.2rem; font-weight: 900; color: var(--primary); }
.result-stat-label { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }
.result-rank-info {
  background: linear-gradient(135deg, #fff7e6, #fff0f0);
  border-radius: 12px; padding: 14px 20px; margin-bottom: 24px;
  font-weight: 700; font-size: 1rem; color: var(--secondary);
  border: 2px solid #ffd89b;
  display: none;
}
.result-rank-info.show { display: block; }
.result-actions { display: flex; gap: 14px; justify-content: center; }

/* ===== Leaderboard ===== */
.lb-controls {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.lb-filter { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lb-filter label { font-size: 0.9rem; color: var(--text-muted); font-weight: 600; }
.lb-meta { display: flex; align-items: center; gap: 10px; }
#lbLastUpdate { font-size: 0.82rem; color: var(--text-muted); }

.leaderboard-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table thead th {
  background: var(--gradient);
  color: #fff; padding: 14px 16px;
  font-size: 0.9rem; font-weight: 700; text-align: center;
}
.leaderboard-table tbody tr { border-bottom: 1px solid var(--border); transition: background .15s; }
.leaderboard-table tbody tr:hover { background: var(--hover-bg); }
.leaderboard-table tbody td { padding: 13px 16px; text-align: center; font-size: 0.92rem; }
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  font-weight: 900; font-size: 0.9rem;
}
.rank-1 { background: #ffd700; color: #7a5c00; font-size: 1.2rem; }
.rank-2 { background: #c0c0c0; color: #555; }
.rank-3 { background: #cd7f32; color: #fff; }
.rank-other { background: var(--bg); color: var(--text-muted); }
.lb-empty { text-align: center; padding: 48px; color: var(--text-muted); font-size: 1.05rem; }
.lb-new-row { animation: highlight 2s ease; }
@keyframes highlight { 0% { background: #fffbe6; } 100% { background: transparent; } }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal {
  background: var(--card); border-radius: 20px;
  padding: 40px 36px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg); position: relative;
  animation: slideUp .3s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: var(--bg); border: none; width: 32px; height: 32px;
  border-radius: 50%; cursor: pointer; font-size: 0.95rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: all .2s;
}
.modal-close:hover { background: #ffe0e0; color: var(--danger); }
.modal-title { font-size: 1.5rem; font-weight: 900; margin-bottom: 28px; text-align: center; }

/* Form */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 0.9rem; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.req { color: var(--danger); }
.form-group input, .form-group select {
  width: 100%; padding: 12px 14px; border: 2px solid var(--border);
  border-radius: 10px; font-family: var(--font); font-size: 0.95rem;
  outline: none; transition: border-color .2s; background: var(--bg);
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); background: #fff; }
.form-error { display: block; color: var(--danger); font-size: 0.8rem; margin-top: 4px; min-height: 18px; }
/* 验证码 */
.captcha-row { display: flex; align-items: center; gap: 10px; }
.captcha-question {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 110px; padding: 9px 14px;
  background: linear-gradient(135deg, #667eea22, #764ba222);
  border: 1.5px solid var(--primary);
  border-radius: 10px; font-size: 1rem; font-weight: 700;
  color: var(--primary); letter-spacing: 1px; user-select: none;
}
.captcha-refresh { padding: 8px 10px !important; }
.captcha-input {
  width: 80px !important; text-align: center;
  font-size: 1.1rem !important; font-weight: 700;
}
.modal-switch { text-align: center; margin-top: 16px; font-size: 0.88rem; color: var(--text-muted); }
.modal-switch a { color: var(--primary); font-weight: 700; text-decoration: none; }
.modal-switch a:hover { text-decoration: underline; }

/* ===== Toast ===== */
.toast-container { position: fixed; bottom: 28px; right: 28px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--text); color: #fff;
  padding: 13px 22px; border-radius: 12px;
  font-size: 0.92rem; font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  animation: toastIn .3s ease;
  max-width: 320px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); color: var(--text); }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }

/* ===== Themes ===== */
[data-theme="green"] {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --bg: #f0fdf4;
  --border: #bbf7d0;
  --shadow: 0 4px 24px rgba(22,163,74,.12);
  --shadow-lg: 0 8px 40px rgba(22,163,74,.18);
  --gradient: linear-gradient(135deg, #16a34a 0%, #0891b2 100%);
  --hover-bg: #dcfce7;
  --active-bg: #dcfce7;
}
[data-theme="dark"] {
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --secondary: #fb923c;
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.5);
  --gradient: linear-gradient(135deg, #1e3a5f 0%, #1e1b4b 100%);
  --hover-bg: #293548;
  --active-bg: #1e2d40;
  --lv1-bg: #14281e;
  --lv2-bg: #282010;
  --lv3-bg: #2a1515;
}
[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group select { background: #0f172a; color: var(--text); }
[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group select:focus { background: var(--card); }
[data-theme="dark"] .typing-textarea { background: var(--card); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .typing-textarea:disabled { background: #141d2b; }
[data-theme="dark"] .char-wrong { background: rgba(242,92,92,.18); }
[data-theme="dark"] .modal-close:hover { background: #3a1f1f; }
[data-theme="dark"] .result-rank-info { background: linear-gradient(135deg, #252010, #251515); border-color: #4a3a10; }
[data-theme="dark"] .btn-hero { background: var(--card); color: var(--primary); }
[data-theme="pink"] {
  --primary: #db2777;
  --primary-dark: #be185d;
  --bg: #fff1f2;
  --border: #fecdd3;
  --shadow: 0 4px 24px rgba(219,39,119,.12);
  --shadow-lg: 0 8px 40px rgba(219,39,119,.18);
  --gradient: linear-gradient(135deg, #db2777 0%, #f472b6 100%);
  --hover-bg: #fce7f3;
  --active-bg: #fce7f3;
}
[data-theme="orange"] {
  --primary: #ea580c;
  --primary-dark: #c2410c;
  --bg: #fff7ed;
  --border: #fed7aa;
  --shadow: 0 4px 24px rgba(234,88,12,.12);
  --shadow-lg: 0 8px 40px rgba(234,88,12,.18);
  --gradient: linear-gradient(135deg, #ea580c 0%, #f59e0b 100%);
  --hover-bg: #ffedd5;
  --active-bg: #ffedd5;
}

/* ===== Theme Picker ===== */
.theme-bar { position: relative; display: flex; align-items: center; }
.theme-toggle-btn {
  background: rgba(255,255,255,.18); border: none; color: #fff;
  font-size: 1.15rem; width: 38px; height: 38px;
  border-radius: 10px; cursor: pointer; transition: all .2s;
  display: flex; align-items: center; justify-content: center;
}
.theme-toggle-btn:hover { background: rgba(255,255,255,.35); }
.theme-picker {
  position: fixed; top: 72px; right: 12px;
  background: var(--card); border-radius: 16px;
  padding: 14px 16px; box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200; min-width: 150px;
  animation: slideUp .2s ease;
}
.theme-picker.hidden { display: none; }
.theme-picker-label {
  font-size: .78rem; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px;
}
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-swatch {
  width: 34px; height: 34px; border-radius: 50%;
  cursor: pointer; transition: all .2s;
  border: 3px solid transparent;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.theme-swatch:hover { transform: scale(1.18); }
.theme-swatch.active {
  box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--primary), 0 2px 8px rgba(0,0,0,.2);
}

/* ===== Language Toggle ===== */
.lang-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.lang-btn {
  padding: 8px 20px; border-radius: 20px;
  border: 2px solid var(--border); background: var(--card);
  font-family: var(--font); font-size: .9rem; font-weight: 700;
  cursor: pointer; transition: all .2s; color: var(--text-muted);
}
.lang-btn.active { border-color: var(--primary); color: var(--primary); background: var(--active-bg); }
.lang-btn:hover { border-color: var(--primary); color: var(--primary); }

/* English article display */
.article-display.lang-en {
  font-family: 'Segoe UI', 'Georgia', serif;
  letter-spacing: .3px; line-height: 2.2; font-size: 1.1rem;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

/* ===== Responsive ===== */
@media (max-width: 700px) {
  .hero { flex-direction: column; padding: 32px 24px; text-align: center; }
  .hero-img { display: none; }
  .hero-actions { justify-content: center; }
  .hero-title { font-size: 1.5rem; }
  .stats-bar { gap: 12px; }
  .stat-value { font-size: 1.1rem; }
  .result-stats { grid-template-columns: 1fr 1fr; }
  .modal { padding: 28px 20px; }
  .header-inner { padding: 0 14px; gap: 8px; }
  .nav-btn { padding: 6px 10px; font-size: 0.85rem; }
  .logo { font-size: 1.1rem; }
  .leaderboard-table { font-size: 0.8rem; }
  .leaderboard-table td, .leaderboard-table th { padding: 10px 8px; }
}
