/* ============================================================
   common.css — Excel 快捷键学习站 · 全局样式
   ============================================================ */

/* ============================================
   CSS 变量
   ============================================ */
:root {
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --border: #e5e7eb;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --hover-bg: rgba(37, 99, 235, 0.04);
  --nav-bg: rgba(255, 255, 255, 0.85);
  --nav-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
  --kbd-bg: #f9fafb;
  --correct: #16a34a;
  --wrong: #dc2626;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --card-bg: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent: #60a5fa;
  --accent-light: #1e3a5f;
  --border: #334155;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --hover-bg: rgba(96, 165, 250, 0.08);
  --nav-bg: rgba(15, 23, 42, 0.9);
  --nav-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
  --kbd-bg: #1e293b;
  --correct: #4ade80;
  --wrong: #f87171;
}

/* ============================================
   全局基础
   ============================================ */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
  padding-top: 110px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================
   顶部导航栏
   ============================================ */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--nav-shadow);
  z-index: 1000;
  display: flex;
  align-items: center;
  transition: background 0.3s;
}

.top-nav-inner {
  width: 100%; max-width: 1260px;
  margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 16px;
}

.nav-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px;
  color: var(--text); text-decoration: none; white-space: nowrap;
}

.nav-brand-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, #217346, #2ecc71);
  color: #fff; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px;
}

.nav-search {
  flex: 1; max-width: 360px; position: relative;
}

.nav-search-icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); font-size: 14px; pointer-events: none;
}

.nav-search input {
  width: 100%; height: 36px;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0 12px 0 32px; font-size: 13px;
  background: var(--bg); color: var(--text);
  outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}

.nav-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.nav-actions { display: flex; align-items: center; gap: 8px; }

.nav-btn {
  display: inline-flex; align-items: center; gap: 4px;
  height: 34px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card-bg); color: var(--text);
  font-size: 13px; cursor: pointer;
  transition: background 0.2s, border-color 0.2s; white-space: nowrap;
}

.nav-btn:hover {
  background: var(--hover-bg); border-color: var(--accent);
}

/* ============================================
   分类标签栏
   ============================================ */
.category-bar {
  position: fixed; top: 56px; left: 0; right: 0;
  height: 46px;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 999;
  display: flex; align-items: center; overflow-x: auto;
}

.category-bar-inner {
  width: 100%; max-width: 1260px;
  margin: 0 auto; padding: 0 20px;
  display: flex; gap: 4px;
}

.category-tab {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  color: var(--text-secondary); white-space: nowrap;
  transition: background 0.2s, color 0.2s; text-decoration: none;
}

.category-tab:hover {
  background: var(--hover-bg); color: var(--accent); text-decoration: none;
}

.category-tab.active {
  background: var(--accent-light); color: var(--accent); font-weight: 600;
}

/* ============================================
   主内容区
   ============================================ */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px 40px;
  display: flex;
  flex-direction: column;
}

/* ============================================
   页头
   ============================================ */
.page-header { margin-bottom: 24px; order: 0; }

.page-title { font-size: 28px; font-weight: 800; margin-bottom: 8px; }

.page-desc {
  font-size: 15px; color: var(--text-secondary); margin-bottom: 12px;
}

.page-stats { display: flex; gap: 10px; }

.stat-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px;
  background: var(--accent-light); color: var(--accent);
  border-radius: 20px; font-size: 13px; font-weight: 500;
}

/* ============================================
   子分类筛选
   ============================================ */
.sub-filter {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 20px; order: 0;
}

.sub-filter-btn {
  padding: 6px 16px;
  border: 1px solid var(--border); border-radius: 20px;
  background: var(--card-bg); color: var(--text-secondary);
  font-size: 13px; cursor: pointer; transition: all 0.2s;
}

.sub-filter-btn:hover {
  border-color: var(--accent); color: var(--accent);
}

.sub-filter-btn.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

/* ============================================
   虚拟键盘 — 经典87键TKL布局
   ============================================ */
.keyboard-section {
  order: 1;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px 16px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 110px;
  z-index: 50;
  transition: background 0.3s;
  overflow-x: auto;
}

.keyboard-title {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.keyboard-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 880px; /* 防止挤压 */
}

.keyboard-row {
  display: flex;
  gap: 4px;
  justify-content: flex-start;
}

.keyboard-spacer {
  flex-shrink: 0;
}

.keyboard-key {
  width: 48px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  font-family: 'Segoe UI', 'Consolas', monospace;
  background: var(--bg);
  color: var(--text);
  transition: all 0.15s ease;
  cursor: default;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 2px 0 var(--border);
}

.keyboard-key:hover {
  background: var(--hover-bg);
}

.keyboard-key.space-key {
  /* width set by JS inline */
}

/* 按键按下的3D效果 */
.keyboard-key.active {
  background: var(--accent) !important;
  color: #fff !important;
  transform: translateY(2px);
  box-shadow: 0 0 0 2px var(--accent), 0 0 12px rgba(37, 99, 235, 0.4);
  z-index: 10;
  border-color: var(--accent) !important;
  font-weight: 700;
}

[data-theme="dark"] .keyboard-key.active {
  box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(96, 165, 250, 0.5);
}

/* ============================================
   快捷键卡片
   ============================================ */
.cards-grid {
  order: 2;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 30px;
}

.shortcut-card {
  position: relative;
  background: var(--card-bg);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 18px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.shortcut-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .shortcut-card:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

/* 选中锁定 */
.shortcut-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15), 0 6px 20px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
  background: var(--hover-bg);
}

[data-theme="dark"] .shortcut-card.selected {
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.25), 0 6px 20px rgba(0, 0, 0, 0.3);
  background: rgba(96, 165, 250, 0.08);
}

.shortcut-card.selected .key-badge {
  background: var(--accent); color: #fff;
}

.shortcut-card.selected::after {
  content: '📌';
  position: absolute; top: 8px; right: 10px; font-size: 14px;
}

.card-keys {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 4px; margin-bottom: 10px;
}

.key-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 28px; padding: 0 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; font-weight: 600;
  font-family: 'Segoe UI', monospace; color: var(--text);
  transition: background 0.2s, color 0.2s;
}

.key-plus {
  color: var(--text-secondary); font-size: 14px; margin: 0 2px;
}

.card-desc {
  font-size: 14px; color: var(--text);
  line-height: 1.5; margin-bottom: 8px;
}

.card-sub {
  font-size: 12px; color: var(--text-secondary);
  background: var(--bg); display: inline-block;
  padding: 2px 8px; border-radius: 10px;
}

/* ============================================
   无结果
   ============================================ */
.no-results {
  order: 3;
  display: none;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.no-results-icon { font-size: 48px; margin-bottom: 12px; }

/* ============================================
   测验弹窗
   ============================================ */
.quiz-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}

.quiz-overlay.active { opacity: 1; pointer-events: auto; }

.quiz-panel {
  background: var(--card-bg);
  border-radius: 16px; padding: 36px 32px;
  max-width: 480px; width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.quiz-question {
  font-size: 18px; font-weight: 700; margin-bottom: 8px; color: var(--text);
}

.quiz-desc {
  font-size: 14px; color: var(--text-secondary); margin-bottom: 20px;
}

.quiz-input {
  width: 100%; height: 44px;
  border: 2px solid var(--border); border-radius: 10px;
  padding: 0 14px; font-size: 16px; text-align: center;
  background: var(--bg); color: var(--text);
  outline: none; transition: border-color 0.2s; margin-bottom: 16px;
}

.quiz-input:focus { border-color: var(--accent); }

.quiz-feedback {
  min-height: 24px; font-size: 15px; font-weight: 600; margin-bottom: 16px;
}

.quiz-feedback.correct { color: var(--correct); }
.quiz-feedback.wrong { color: var(--wrong); }

.quiz-actions {
  display: flex; gap: 10px; justify-content: center; margin-bottom: 16px;
}

.quiz-btn {
  padding: 8px 20px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.quiz-btn:active { transform: scale(0.97); }

.quiz-btn-primary { background: var(--accent); color: #fff; }
.quiz-btn-primary:hover { background: #1d4ed8; }
[data-theme="dark"] .quiz-btn-primary:hover { background: #3b82f6; }

.quiz-btn-secondary {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
}

.quiz-btn-secondary:hover { background: var(--hover-bg); }

.quiz-score { font-size: 14px; color: var(--text-secondary); }

/* ============================================
   底部导航
   ============================================ */
.page-footer {
  max-width: 1200px; margin: 0 auto; padding: 20px;
  display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid var(--border);
}

.footer-nav-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 16px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text);
  background: var(--card-bg); text-decoration: none;
  transition: border-color 0.2s, background 0.2s;
}

.footer-nav-btn:hover {
  border-color: var(--accent); background: var(--hover-bg); text-decoration: none;
}

.footer-page-info { font-size: 13px; color: var(--text-secondary); }

/* ============================================
   首页专用样式
   ============================================ */

/* 英雄区域 */
.hero { text-align: center; padding: 40px 20px 30px; }
.hero-icon { font-size: 56px; margin-bottom: 12px; }
.hero h1 { font-size: 32px; font-weight: 800; margin-bottom: 8px; }
.hero p {
  font-size: 16px; color: var(--text-secondary);
  max-width: 520px; margin: 0 auto;
}

/* 统计概览 */
.overview-stats {
  display: flex; justify-content: center; flex-wrap: wrap;
  gap: 16px; margin: 24px 0 36px;
}

.overview-stat-card {
  background: var(--card-bg); border-radius: 12px;
  padding: 20px 28px; box-shadow: var(--shadow);
  text-align: center; min-width: 140px;
}

.overview-stat-number {
  font-size: 32px; font-weight: 800; color: var(--accent);
}

.overview-stat-label {
  font-size: 13px; color: var(--text-secondary); margin-top: 4px;
}

/* 分类卡片导航 — 修正布局 */
.category-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
  padding: 0;
}

.category-link-card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 2px solid transparent;
  min-height: 160px;
}

.category-link-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  border-color: var(--accent);
  text-decoration: none;
}

[data-theme="dark"] .category-link-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.cat-card-icon { font-size: 32px; margin-bottom: 10px; }

.cat-card-title {
  font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 6px;
}

.cat-card-count {
  font-size: 13px; color: var(--accent); font-weight: 600; margin-bottom: 6px;
}

.cat-card-desc {
  font-size: 13px; color: var(--text-secondary); line-height: 1.4;
  flex: 1;
}

/* ============================================
   Tooltip
   ============================================ */
.tooltip { position: relative; }

.tooltip::before {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  padding: 4px 10px;
  background: #1e293b; color: #f1f5f9;
  font-size: 12px; border-radius: 6px;
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.2s; z-index: 100;
}

.tooltip:hover::before { opacity: 1; }

.btn-text { display: inline; }

/* ============================================
   打印
   ============================================ */
@media print {
  .top-nav, .category-bar, .nav-actions, .sub-filter,
  .keyboard-section, .quiz-overlay, .page-footer, .nav-search {
    display: none !important;
  }
  body { padding-top: 0; background: #fff; color: #000; }
  .shortcut-card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================
   响应式
   ============================================ */
@media (max-width: 768px) {
  body { padding-top: 100px; }

  .top-nav-inner { gap: 8px; padding: 0 12px; }
  .nav-brand span { display: none; }
  .nav-search { max-width: none; }
  .btn-text { display: none; }

  .category-bar { top: 56px; height: 42px; }
  .category-bar-inner { padding: 0 10px; gap: 2px; }
  .category-tab { padding: 5px 10px; font-size: 12px; }

  .page-title { font-size: 22px; }

  .cards-grid { grid-template-columns: 1fr; }

  .keyboard-section {
    position: relative; top: auto; padding: 12px 8px;
  }

  .keyboard-container { min-width: 700px; }

  .keyboard-key {
    width: 36px; height: 30px; font-size: 9px;
  }

  .hero h1 { font-size: 24px; }
  .hero p { font-size: 14px; }

  .overview-stats { gap: 10px; }
  .overview-stat-card { min-width: 100px; padding: 14px 16px; }
  .overview-stat-number { font-size: 24px; }

  .category-cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .category-link-card { min-height: auto; }

  .quiz-panel { padding: 24px 16px; }
}

@media (max-width: 480px) {
  .top-nav { height: 50px; }
  .category-bar { top: 50px; height: 38px; }
  body { padding-top: 88px; }
  .keyboard-section { top: auto; position: relative; }
  .page-stats { flex-direction: column; gap: 6px; }
}

/* ============================================
   滚动条
   ============================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

.category-bar::-webkit-scrollbar { height: 0; }
.category-bar { scrollbar-width: none; -ms-overflow-style: none; }
