/* ============================================
   小学生在线打字练习 - 儿童友好样式表
   ============================================ */

/* ---------- 基础重置 ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6C5CE7;
  --primary-light: #A29BFE;
  --primary-dark: #5A4BD1;
  --accent: #FDCB6E;
  --success: #00B894;
  --success-light: #55EFC4;
  --danger: #FF7675;
  --danger-light: #FAB1A0;
  --warning: #FDCB6E;
  --info: #74B9FF;
  --bg-main: #F8F7FF;
  --bg-card: #FFFFFF;
  --bg-soft: #F0EEFF;
  --text-main: #2D3436;
  --text-soft: #636E72;
  --text-light: #B2BEC3;
  --border: #DFE6E9;
  --shadow-sm: 0 2px 8px rgba(108, 92, 231, 0.08);
  --shadow-md: 0 4px 20px rgba(108, 92, 231, 0.12);
  --shadow-lg: 0 8px 40px rgba(108, 92, 231, 0.16);
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  /* 使用 clip 替代 hidden：clip 不会创建新的滚动容器，
     避免在部分移动设备上导致纵向滚动失灵 */
  overflow-x: clip;
}

/* ---------- 装饰背景 ---------- */
.bg-decoration {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.bg-decoration .blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.15;
  animation: float 20s ease-in-out infinite;
}

.bg-decoration .blob:nth-child(1) {
  width: 400px; height: 400px;
  background: var(--primary);
  top: -100px; left: -100px;
  animation-delay: 0s;
}

.bg-decoration .blob:nth-child(2) {
  width: 300px; height: 300px;
  background: var(--success);
  top: 50%; right: -80px;
  animation-delay: 5s;
}

.bg-decoration .blob:nth-child(3) {
  width: 350px; height: 350px;
  background: var(--accent);
  bottom: -100px; left: 30%;
  animation-delay: 10s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -30px) scale(1.05); }
  66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* ---------- 顶部导航栏 ---------- */
.navbar {
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  padding: 0 clamp(12px, 2.5vw, 32px);
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
}

.navbar .logo .logo-icon {
  font-size: 28px;
}

/* 导航栏 logo 图片（机构品牌图） */
.navbar .logo .logo-img {
  height: 44px;
  width: auto;
  max-width: 140px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  display: block;
}

/* 品牌主名称 */
.navbar .logo .logo-name {
  color: var(--primary);
}

/* 品牌副标语（位于主名称右侧） */
.navbar .logo .logo-slogan {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
  padding-left: 12px;
  border-left: 1px solid var(--border);
  margin-left: 2px;
  white-space: nowrap;
}

.navbar .nav-stats {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-soft);
}

.nav-stat-item .stat-icon {
  font-size: 18px;
}

.nav-stat-item .stat-value {
  font-weight: 700;
  color: var(--primary);
}

/* ---------- 主容器 ---------- */
.container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px clamp(8px, 2vw, 16px);
}

/* ---------- 学科选择 ---------- */
.subject-tabs {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 32px 0;
}

.subject-tab {
  padding: 14px 40px;
  border-radius: var(--radius-xl);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  border: 3px solid transparent;
  background: var(--bg-card);
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.subject-tab:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.subject-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
  box-shadow: 0 4px 20px rgba(108, 92, 231, 0.3);
}

.subject-tab .tab-icon {
  font-size: 22px;
}

/* ---------- 年级卡片 ---------- */
.grade-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.grade-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  border: 3px solid transparent;
  position: relative;
  overflow: hidden;
}

.grade-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 4px;
  background: var(--card-color, var(--primary));
}

.grade-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--card-color, var(--primary));
}

.grade-card.active {
  border-color: var(--card-color, var(--primary));
  background: var(--bg-soft);
}

.grade-card .grade-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.grade-card .grade-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.grade-card .grade-meta {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

/* ---------- 学期选择 ---------- */
.semester-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
}

.semester-btn {
  padding: 10px 32px;
  border-radius: var(--radius-xl);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-soft);
  transition: var(--transition);
}

.semester-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}

.semester-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---------- 内容类型卡片 ---------- */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.category-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  border: 2px solid transparent;
  position: relative;
}

.category-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
}

.category-card .cat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.category-card .cat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: var(--bg-soft);
}

.category-card .cat-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.category-card .cat-desc {
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 12px;
}

.category-card .cat-count {
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
}

/* ---------- 练习项目列表 ---------- */
.practice-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.practice-item {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.practice-item:hover {
  border-color: var(--primary-light);
  transform: translateX(4px);
}

.practice-item .item-info {
  flex: 1;
}

.practice-item .item-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}

.practice-item .item-preview {
  font-size: 13px;
  color: var(--text-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* ★ 固定显示 10 个字符宽度，保证星星对齐 */
  width: 150px;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.practice-item .item-star {
  font-size: 20px;
  display: flex;
  align-items: center;
  gap: 2px;
  margin-right: 12px;
}

.practice-item .item-star-icon {
  color: var(--text-light);
}

.practice-item .item-star-icon.earned {
  color: var(--accent);
  text-shadow: 0 0 4px rgba(253, 203, 110, 0.5);
}

.practice-item .item-arrow {
  color: var(--text-light);
  font-size: 18px;
}

/* ---------- 打字练习界面 ---------- */
.practice-view {
  display: none;
  animation: fadeInUp 0.4s ease;
}

.practice-view.active {
  display: block;
}

/* 练习头部 */
.practice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.practice-header .header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-btn {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-soft);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.back-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.practice-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}

.mode-switcher {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-btn {
  padding: 8px 18px;
  border-radius: var(--radius-xl);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-soft);
  transition: var(--transition);
}

.mode-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* 统计面板 */
.stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 120px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.stat-card .stat-number {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
}

.stat-card .stat-unit {
  font-size: 12px;
  color: var(--text-light);
  margin-left: 2px;
}

.stat-card.success .stat-number { color: var(--success); }
.stat-card.warning .stat-number { color: var(--warning); }
.stat-card.danger .stat-number { color: var(--danger); }

/* 进度条 */
.progress-container {
  margin-bottom: 20px;
}

.progress-bar {
  height: 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-xl);
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success-light), var(--success));
  border-radius: var(--radius-xl);
  transition: width 0.3s ease;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-light);
  margin-top: 6px;
}

/* 打字区域 */
.typing-area {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 3vw, 40px);
  box-shadow: var(--shadow-md);
  min-height: 200px;
  position: relative;
  /* 防止内容溢出导致横向滚动 */
  overflow: hidden;
}

.typing-display {
  font-size: clamp(18px, 2.5vw, 28px);
  line-height: 1.8;
  user-select: none;
  text-align: left;
  /* break-word 比 break-all 更自然：中文整字断行，英文按单词断行 */
  word-break: break-word;
  overflow-wrap: break-word;
  /* overflow:hidden 用于3行滚动视窗；JS 会动态设置 height */
  overflow: hidden;
  position: relative;
  transition: height 0.3s ease;
}

/* 段落首行缩进占位符（空两格） */
.typing-display .para-indent {
  display: inline-block;
  width: 2em;
}

/* 滚动容器 */
.typing-display .typing-scroll-inner {
  position: relative;
  transition: transform 0.35s ease-out;
  will-change: transform;
}

/* 底部渐隐遮罩（仅滚动激活时，只在底部，不遮拼音） */
.typing-display.scroll-active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  pointer-events: none;
  z-index: 2;
  background: linear-gradient(to top, var(--bg-card), transparent);
}

.typing-display .char {
  position: relative;
  display: inline-block;
  padding: 2px 1px;
  border-radius: 4px;
  transition: background 0.15s ease;
}

.typing-display .char.correct {
  color: var(--success);
}

.typing-display .char.incorrect {
  color: #fff;
  background: var(--danger);
  border-radius: 4px;
}

.typing-display .char.current {
  background: var(--primary-light);
  color: #fff;
  animation: pulse 1s infinite;
  border-radius: 4px;
}

.typing-display .char.pending {
  color: var(--text-main);
}

.typing-display .char.skip {
  color: var(--text-light);
  opacity: 0.85;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* 合并的拼音+汉字单元（中文字模式） */
.typing-display .char-cell {
  display: inline-block;
  vertical-align: top;
  width: clamp(28px, 3.2vw, 38px);
  text-align: center;
  margin: 0 1px;
}

.typing-display .char-cell .cell-pinyin {
  display: block;
  font-size: 13px;
  line-height: 1.4;
  height: 20px;
  overflow: visible;
  white-space: nowrap;
  color: var(--text-light);
}

.typing-display .char-cell .cell-char {
  display: block;
  font-size: 28px;
  line-height: 1.6;
  border-radius: 4px;
  transition: background 0.15s ease;
}

/* 状态样式 - 拼音 */
.typing-display .char-cell.correct .cell-pinyin { color: var(--success); }
.typing-display .char-cell.incorrect .cell-pinyin { color: var(--danger); }
.typing-display .char-cell.current .cell-pinyin { color: var(--primary); font-weight: 700; }

/* 状态样式 - 汉字 */
.typing-display .char-cell.correct .cell-char { color: var(--success); }
.typing-display .char-cell.incorrect .cell-char { color: #fff; background: var(--danger); }
.typing-display .char-cell.current .cell-char { background: var(--primary-light); color: #fff; animation: pulse 1s infinite; }
.typing-display .char-cell.pending .cell-char { color: var(--text-main); }

/* 拼音输入模式：汉字在上，已输入拼音在下 */
.typing-display .pinyin-input-cell {
  display: inline-block;
  vertical-align: top;
  width: clamp(28px, 3.2vw, 38px);
  text-align: center;
  margin: 0 1px;
}

.typing-display .pinyin-input-cell .cell-char-top {
  display: block;
  font-size: 28px;
  line-height: 1.6;
  border-radius: 4px;
  transition: background 0.15s ease;
}

.typing-display .pinyin-input-cell .cell-typed-bottom {
  display: block;
  font-size: 13px;
  line-height: 1.4;
  height: 20px;
  overflow: visible;
  white-space: nowrap;
  color: var(--text-light);
}

/* 状态样式 - 汉字 */
.typing-display .pinyin-input-cell.correct .cell-char-top { color: var(--success); }
.typing-display .pinyin-input-cell.incorrect .cell-char-top { color: #fff; background: var(--danger); }
.typing-display .pinyin-input-cell.current .cell-char-top { background: var(--primary-light); color: #fff; animation: pulse 1s infinite; }
.typing-display .pinyin-input-cell.pending .cell-char-top { color: var(--text-main); }

/* 状态样式 - 已输入拼音 */
.typing-display .pinyin-input-cell.correct .cell-typed-bottom { color: var(--success); }
.typing-display .pinyin-input-cell.incorrect .cell-typed-bottom { color: var(--danger); }
.typing-display .pinyin-input-cell.current .cell-typed-bottom { color: var(--primary); font-weight: 700; }

/* 看拼音打字模式：未输入的汉字显示为浅色占位符□ */
.typing-display .p2c-cell[data-chinese="true"].pending .cell-char { color: var(--border); }
/* 看拼音打字模式：拼音更醒目（作为唯一参考） */
.typing-display .p2c-cell[data-chinese="true"].pending .cell-pinyin { color: var(--text-soft); font-weight: 500; }

/* 拼音显示区域（已弃用，保留空壳） */
.pinyin-display { display: none; }

/* 英文释义显示 */
.meaning-display {
  font-size: 14px;
  color: var(--text-soft);
  margin-bottom: 12px;
  padding: 8px 16px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  display: inline-block;
}

/* 输入框 */
.typing-input-wrapper {
  margin-top: 24px;
  position: relative;
}

.typing-input {
  width: 100%;
  padding: 16px 20px;
  font-size: clamp(16px, 2vw, 20px);
  border: 3px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: var(--transition);
  font-family: inherit;
  letter-spacing: 1px;
  background: var(--bg-main);
  /* ★ 防止输入框内容溢出 */
  max-width: 100%;
}

.typing-input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.1);
}

.typing-input::placeholder {
  color: var(--text-light);
}

/* 提示信息 */
.typing-hint {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-light);
}

.typing-hint kbd {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  font-family: monospace;
  color: var(--text-soft);
}

/* ---------- 结果界面 ---------- */
.result-view {
  display: none;
  animation: fadeInUp 0.5s ease;
}

.result-view.active {
  display: block;
}

.result-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 600px;
  margin: 40px auto;
}

.result-card .result-emoji {
  font-size: 72px;
  margin-bottom: 16px;
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.result-card .result-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 8px;
}

.result-card .result-subtitle {
  font-size: 16px;
  color: var(--text-soft);
  margin-bottom: 32px;
}

.result-stars {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
}

/* 异常成绩警告框 */
.result-warning {
  background: #FFF3CD;
  border: 2px solid #FFC107;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
  text-align: center;
}
.result-warning .warning-icon {
  font-size: 32px;
  margin-bottom: 8px;
}
.result-warning .warning-text {
  font-size: 14px;
  color: #856404;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 4px;
}
.result-warning .warning-sub {
  font-size: 12px;
  color: #856404;
  opacity: 0.8;
}

.result-star {
  font-size: 40px;
  color: var(--border);
  transition: var(--transition);
}

.result-star.earned {
  color: var(--accent);
  animation: starPop 0.4s ease;
}

@keyframes starPop {
  0% { transform: scale(0) rotate(-180deg); }
  100% { transform: scale(1) rotate(0); }
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.result-stat {
  text-align: center;
}

.result-stat .rstat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
}

.result-stat .rstat-label {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 4px;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  padding: 12px 32px;
  border-radius: var(--radius-xl);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg-soft);
  color: var(--primary);
}

.btn-secondary:hover {
  background: var(--primary-light);
  color: #fff;
  transform: translateY(-2px);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  background: #00A383;
  transform: translateY(-2px);
}

/* ---------- 面包屑导航 ---------- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text-light);
  flex-wrap: wrap;
}

.breadcrumb .crumb {
  cursor: pointer;
  transition: var(--transition);
}

.breadcrumb .crumb:hover {
  color: var(--primary);
}

.breadcrumb .crumb.current {
  color: var(--text-main);
  font-weight: 600;
}

.breadcrumb .crumb-sep {
  color: var(--text-light);
}

/* ---------- 章节标题 ---------- */
.section-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .title-icon {
  font-size: 24px;
}

/* ---------- 飘星动画 ---------- */
.star-particle {
  position: fixed;
  font-size: 24px;
  pointer-events: none;
  z-index: 9999;
  animation: starFly 1s ease-out forwards;
}

@keyframes starFly {
  0% {
    opacity: 1;
    transform: scale(0) translateY(0);
  }
  50% {
    opacity: 1;
    transform: scale(1.5) translateY(-40px);
  }
  100% {
    opacity: 0;
    transform: scale(0.5) translateY(-80px);
  }
}

/* ---------- 完成动画 ---------- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Toast 提示 ---------- */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-main);
  color: #fff;
  padding: 12px 32px;
  border-radius: var(--radius-xl);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 10000;
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- 首页三列布局 ---------- */
.home-layout {
  display: flex;
  gap: clamp(12px, 2vw, 28px);
  align-items: flex-start;
}

.home-sidebar {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 80px;
  margin-left: -50px;
  /* ★ 限制 sticky 元素最大高度，防止内容超出视口导致滚动卡死 */
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  /* 滚动优化：触摸设备平滑滚动 */
  -webkit-overflow-scrolling: touch;
}

.home-main {
  flex: 1;
  min-width: 0;  /* ★ 关键：防止 flex 子元素撑爆容器 */
}

.home-ad {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 80px;
  margin-right: -50px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* ★ 同上：限制高度防止滚动卡死 */
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- 排行榜 ---------- */
.leaderboard {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.leaderboard-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 20px 20px 14px;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.leaderboard-header .lb-icon {
  font-size: 24px;
}

.leaderboard-subtitle {
  background: var(--primary-dark);
  color: rgba(255, 255, 255, 0.8);
  font-size: 12px;
  padding: 0 20px 12px;
  font-weight: 500;
}

.leaderboard-list {
  /* ★ 响应式高度：根据视口高度自适应，不再固定 600px */
  max-height: calc(100vh - 280px);
  min-height: 200px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

/* 排行榜条目 */
.lb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--bg-soft);
  transition: var(--transition);
}

.lb-item:last-child {
  border-bottom: none;
}

.lb-item:hover {
  background: var(--bg-soft);
}

.lb-item-top {
  background: linear-gradient(90deg, rgba(253, 203, 110, 0.08), transparent);
}

.lb-rank {
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

.lb-rank-medal {
  font-size: 22px;
}

.lb-rank-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-soft);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}

.lb-info {
  flex: 1;
  min-width: 0;
}

.lb-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-meta {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 2px;
}

.lb-stats {
  flex-shrink: 0;
  text-align: right;
}

.lb-speed {
  font-size: 16px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

.lb-unit {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-light);
}

.lb-acc {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 1px;
}

.lb-stars {
  font-size: 10px;
  margin-top: 2px;
  letter-spacing: -1px;
}

/* 排行榜空状态 */
.leaderboard-empty {
  padding: 48px 24px;
  text-align: center;
}

.leaderboard-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.leaderboard-empty p {
  font-size: 14px;
  color: var(--text-soft);
  margin-bottom: 4px;
}

.leaderboard-empty-hint {
  font-size: 12px !important;
  color: var(--text-light) !important;
  line-height: 1.6;
}

/* 排行榜底部 */
.leaderboard-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--bg-soft);
  font-size: 12px;
  color: var(--text-light);
  text-align: center;
}

.leaderboard-footer:hover {
  color: var(--primary);
}

/* 排行榜头像 */
.lb-avatar {
  font-size: 24px;
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

/* 当前用户高亮 */
.lb-item-me {
  background: linear-gradient(90deg, rgba(108, 92, 231, 0.1), transparent) !important;
  border-left: 3px solid var(--primary);
}

.lb-me-tag {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  vertical-align: middle;
  margin-left: 4px;
}

/* ---------- 广告区 ---------- */
.ad-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.ad-header {
  background: var(--bg-soft);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.ad-body {
  padding: 20px 16px;
}

.ad-placeholder {
  text-align: center;
  padding: 24px 8px;
}

.ad-placeholder .ad-icon {
  font-size: 36px;
  display: block;
  margin-bottom: 8px;
  opacity: 0.5;
}

.ad-placeholder p {
  font-size: 14px;
  color: var(--text-soft);
  font-weight: 600;
  margin-bottom: 4px;
}

.ad-placeholder .ad-hint {
  font-size: 11px !important;
  color: var(--text-light) !important;
  font-weight: 400 !important;
}

.ad-img {
  width: 100%;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  display: block;
}

.ad-primary .ad-img:not(.ad-qr-img) {
  max-height: 220px;
  object-fit: cover;
}

.ad-qr-img {
  max-width: 160px;
  margin: 0 auto 10px;
}

.ad-qr-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  text-align: center;
}

.ad-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 6px;
  line-height: 1.4;
}

.ad-desc {
  font-size: 12px;
  color: var(--text-soft);
  margin: 0 0 10px;
  line-height: 1.5;
}

.ad-features {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}

.ad-features li {
  font-size: 12px;
  color: var(--text-main);
  padding: 3px 0;
  line-height: 1.4;
}

.ad-slogan {
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  margin: 0 0 10px;
  line-height: 1.5;
}

.ad-cta {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  text-align: center;
  margin: 0;
  line-height: 1.4;
  white-space: nowrap;
  letter-spacing: -0.5px;
}

.ad-qr-text {
  font-size: 12px;
  color: var(--text-soft);
  text-align: center;
  margin: 0;
  line-height: 1.5;
}

/* ---------- 登录/注册界面 ---------- */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 20px;
  min-height: calc(100vh - 64px);
}

.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo-icon {
  font-size: 56px;
  display: block;
  margin-bottom: 8px;
}

.auth-logo h1 {
  font-size: 24px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.auth-logo p {
  font-size: 14px;
  color: var(--text-soft);
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border);
}

.auth-tab {
  flex: 1;
  text-align: center;
  padding: 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
}

.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.auth-form {
  animation: fadeInUp 0.3s ease;
}

.auth-field {
  margin-bottom: 16px;
}

.auth-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.auth-field input {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: var(--transition);
  font-family: inherit;
  background: var(--bg-main);
}

.auth-field input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.1);
}

.auth-submit {
  width: 100%;
  margin-top: 8px;
  justify-content: center;
  padding: 14px;
  font-size: 16px;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.avatar-option {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-main);
}

.avatar-option:hover {
  border-color: var(--primary-light);
  transform: scale(1.05);
}

.avatar-option.selected {
  border-color: var(--primary);
  background: var(--bg-soft);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

/* ---------- 导航栏用户信息 ---------- */
.nav-user {
  gap: 6px;
  padding: 4px 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-xl);
}

.nav-user-avatar {
  font-size: 20px;
}

.nav-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.nav-user-score {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

/* ---------- 完整排行榜 ---------- */
.full-leaderboard {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.full-leaderboard .leaderboard-list {
  max-height: none;
}

/* ---------- 响应式 ---------- */

/* ★ 小屏桌面（1366px 及以下）：移除负 margin，缩小侧栏，防止溢出 */
@media (max-width: 1366px) {
  .home-layout {
    gap: 16px;
  }
  .home-sidebar {
    width: 240px;
    margin-left: 0;    /* ★ 移除负 margin，防止内容溢出视口左边缘 */
  }
  .home-ad {
    width: 240px;
    margin-right: 0;   /* ★ 移除负 margin，防止内容溢出视口右边缘 */
  }
  .typing-display .char-cell { width: 34px; }
  .typing-display .pinyin-input-cell { width: 34px; }
}

/* ★ 中等屏幕（1200px 及以下）：隐藏广告区，缩窄排行榜 */
@media (max-width: 1200px) and (min-width: 769px) {
  .home-ad { display: none; }
  .home-sidebar {
    width: 220px;
    margin-left: 0;
  }
  .home-layout { gap: 14px; }
}

@media (max-width: 768px) {
  .navbar { padding: 0 16px; }
  .container { padding: 16px 12px; }
  .typing-area { padding: 20px; }
  .typing-display { font-size: 22px; }
  .typing-display .char-cell { width: 32px; margin: 0; }
  .typing-display .char-cell .cell-pinyin { font-size: 11px; height: 16px; }
  .typing-display .char-cell .cell-char { font-size: 22px; }
  .typing-display .pinyin-input-cell { width: 32px; margin: 0; }
  .typing-display .pinyin-input-cell .cell-char-top { font-size: 22px; }
  .typing-display .pinyin-input-cell .cell-typed-bottom { font-size: 11px; height: 16px; }
  .stats-bar { gap: 8px; }
  .stat-card { min-width: 90px; padding: 12px 8px; }
  .stat-card .stat-number { font-size: 20px; }
  .grade-grid { grid-template-columns: repeat(3, 1fr); }
  .subject-tabs { flex-direction: column; align-items: center; }
  .subject-tab { width: 100%; max-width: 300px; justify-content: center; }
  .result-stats { grid-template-columns: repeat(2, 1fr); }
  /* 移动端：三列变单列堆叠 */
  .home-layout { flex-direction: column; }
  .home-sidebar {
    width: 100%;
    position: static;
    margin-left: 0;
    max-height: none;
  }
  .home-ad {
    width: 100%;
    position: static;
    margin-right: 0;
    flex-direction: row;
    max-height: none;
  }
  .home-ad .ad-card { flex: 1; }
  .leaderboard-list { max-height: 400px; }
  /* 移动端导航栏 */
  .nav-user-name, .nav-user-score { display: none; }
  .nav-stat-item span:not(.stat-icon):not(.stat-value) { display: none; }
  /* 移动端登录界面 */
  .auth-card { padding: 24px 20px; }
  .avatar-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- 滚动条美化 ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-soft);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--primary-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* ============================================
   管理后台样式
   ============================================ */

.admin-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.admin-header h1 {
  font-size: 1.6rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
}

.admin-tab {
  padding: 8px 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-soft);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.admin-tab:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}

.admin-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.admin-content {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  min-height: 300px;
}

.admin-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-filters select {
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition);
}

.admin-filters select:focus {
  outline: none;
  border-color: var(--primary-light);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table thead th {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg-soft);
  color: var(--text-soft);
  font-weight: 700;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.admin-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
  vertical-align: middle;
}

.admin-table tbody tr:hover {
  background: var(--bg-soft);
}

.admin-table select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.85rem;
  cursor: pointer;
}

.admin-form {
  background: var(--bg-soft);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.admin-form h3 {
  font-size: 1.1rem;
  color: var(--primary);
  margin-bottom: 16px;
}

.admin-form-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.admin-form-row label {
  width: 60px;
  flex-shrink: 0;
  text-align: right;
  padding-top: 8px;
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 600;
}

.admin-form-row input,
.admin-form-row textarea,
.admin-form-row select {
  flex: 1;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.9rem;
  font-family: inherit;
  transition: var(--transition);
}

.admin-form-row input:focus,
.admin-form-row textarea:focus,
.admin-form-row select:focus {
  outline: none;
  border-color: var(--primary-light);
}

.admin-form-row textarea {
  resize: vertical;
  line-height: 1.6;
}

.admin-form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding-left: 72px;
}

.admin-btn-edit {
  padding: 4px 12px;
  border: none;
  border-radius: 4px;
  background: var(--info);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.admin-btn-edit:hover {
  opacity: 0.85;
}

.admin-btn-del {
  padding: 4px 12px;
  border: none;
  border-radius: 4px;
  background: var(--danger);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.admin-btn-del:hover {
  opacity: 0.85;
}

/* 管理表格操作列：按钮左右布局 */
.admin-ops {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

/* 管理后台移动端适配 */
@media (max-width: 768px) {
  .admin-container { padding: 12px; }
  .admin-content { padding: 16px; }
  .admin-header { flex-direction: column; align-items: flex-start; }
  .admin-table { font-size: 0.8rem; }
  .admin-table thead th,
  .admin-table tbody td { padding: 8px 6px; }
  .admin-form-row { flex-direction: column; gap: 4px; }
  .admin-form-row label { text-align: left; width: auto; padding-top: 0; }
  .admin-form-actions { padding-left: 0; }
}

/* ==================== 数学视频观看界面 ==================== */
.math-video-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  margin-top: 16px;
}

.math-video-main {
  min-width: 0;
}

.math-video-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  aspect-ratio: 16 / 9;
  max-height: 540px;
  margin: 0;
}

.math-video-iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  min-height: 0;
}

.math-video-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 360px;
  color: #999;
  background: #1a1a1a;
  padding: 40px 20px;
  text-align: center;
}
.math-video-empty .empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}
.math-video-empty .empty-text {
  font-size: 18px;
  color: #ccc;
  margin-bottom: 8px;
}
.math-video-empty .empty-hint {
  font-size: 13px;
  color: #888;
}

.math-video-info {
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px;
  margin-top: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.math-video-title {
  font-size: 22px;
  font-weight: 600;
  color: #2d3436;
  margin: 0 0 12px 0;
  line-height: 1.4;
}
.math-video-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.meta-item {
  font-size: 13px;
  color: #636e72;
  background: #f1f2f6;
  padding: 4px 12px;
  border-radius: 20px;
}

.math-video-desc {
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px;
  margin-top: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.math-video-desc h3 {
  font-size: 16px;
  font-weight: 600;
  color: #2d3436;
  margin: 0 0 12px 0;
}
.math-video-desc .desc-content {
  font-size: 15px;
  line-height: 1.8;
  color: #2d3436;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.math-video-aside {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  align-self: start;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}
.aside-title {
  font-size: 15px;
  font-weight: 600;
  color: #2d3436;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f2f6;
}
.aside-list {
  overflow-y: auto;
  flex: 1;
}
.aside-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}
.aside-item:hover {
  background: #f1f2f6;
}
.aside-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5f27cd, #341f97);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.aside-info {
  flex: 1;
  min-width: 0;
}
.aside-name {
  font-size: 13px;
  color: #2d3436;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aside-meta {
  font-size: 11px;
  color: #b2bec3;
  margin-top: 2px;
}
.aside-play {
  color: #5f27cd;
  font-size: 14px;
  flex-shrink: 0;
}
.aside-empty {
  text-align: center;
  color: #b2bec3;
  font-size: 13px;
  padding: 20px 0;
}

@media (max-width: 900px) {
  .math-video-layout {
    grid-template-columns: 1fr;
  }
  .math-video-aside {
    position: static;
    max-height: none;
  }
  .math-video-wrapper {
    max-height: 360px;
  }
}

/* ==================== 用户状态徽章 ==================== */
.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-active { background: #e6f7e6; color: #1a9c3c; }
.badge-disabled { background: #eee; color: #888; }
.badge-frozen { background: #e6f3ff; color: #1a73e8; }

/* ==================== 状态弹窗 ==================== */
.modal-mask {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
}
.modal-close {
  border: none;
  background: none;
  font-size: 20px;
  color: var(--text-light);
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: #e74c3c; }
.modal-body { padding: 16px 18px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: #fafafa;
}
.status-options { display: flex; gap: 10px; flex-wrap: wrap; }
.status-option {
  flex: 1;
  min-width: 110px;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.15s;
}
.status-option:hover { border-color: var(--primary); }
.status-option.selected { border-color: var(--primary); background: rgba(52,152,219,0.06); }
.status-option input { display: none; }
.status-option small { color: var(--text-light); font-size: 12px; }

/* ==================== 答题模式（编程学科） ==================== */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 12px 0 16px;
  padding: 10px 16px;
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.quiz-progress { font-weight: 700; }
.quiz-stats { color: var(--text-light); }

.quiz-card {
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.quiz-type-tag {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 12px;
  margin-bottom: 12px;
}
.quiz-question {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.6;
  margin-bottom: 20px;
  white-space: pre-wrap;
}

.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.quiz-option:hover { border-color: var(--primary); background: rgba(108,92,231,0.04); }
.quiz-opt-key {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: #f0f0f5;
  border-radius: 50%;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.quiz-opt-text { font-size: 15px; line-height: 1.5; }

/* 正确 / 错误 / 选中 状态 */
.quiz-option.correct { border-color: #27ae60; background: rgba(39,174,96,0.08); }
.quiz-option.correct .quiz-opt-key { background: #27ae60; color: #fff; }
.quiz-option.wrong { border-color: #e74c3c; background: rgba(231,76,60,0.08); }
.quiz-option.wrong .quiz-opt-key { background: #e74c3c; color: #fff; }
.quiz-option.quiz-selected { border-color: var(--primary); background: rgba(108,92,231,0.1); }
.quiz-option.quiz-selected .quiz-opt-key { background: var(--primary); color: #fff; }
.quiz-option.quiz-disabled { cursor: default; }
.quiz-option.quiz-disabled:hover { border-color: var(--border); background: none; }

.quiz-submit { margin-top: 16px; }

.quiz-feedback {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.feedback-correct { background: rgba(39,174,96,0.12); color: #1e8449; }
.feedback-wrong { background: rgba(231,76,60,0.12); color: #c0392b; }

.quiz-nav { margin-top: 18px; text-align: right; }

.quiz-fill { display: flex; gap: 10px; }
.quiz-fill-input {
  flex: 1;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
.quiz-fill-input:focus { border-color: var(--primary); }

.quiz-program-input {
  width: 100%;
  box-sizing: border-box;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
  resize: vertical;
  background: #fafafa;
}
.quiz-program-input:focus { border-color: var(--primary); }

.quiz-program-ref {
  margin-top: 16px;
  padding: 16px;
  background: #f8f9fa;
  border: 1px dashed var(--border);
  border-radius: 10px;
}
.quiz-program-ref-title { font-weight: 700; margin-bottom: 8px; }
.quiz-program-ref-code {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  background: #272c35;
  color: #e6e6e6;
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
}
.quiz-self-btns { display: flex; gap: 10px; margin-top: 10px; }

.quiz-done {
  text-align: center;
  padding: 60px 20px;
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
}
.quiz-done-icon { font-size: 56px; margin-bottom: 12px; }
.quiz-done h2 { margin: 0 0 8px; font-size: 22px; }
.quiz-done p { color: var(--text-light); margin: 4px 0; font-size: 15px; }
.quiz-done-score { font-size: 18px !important; font-weight: 700; color: var(--primary) !important; margin: 12px 0 20px !important; }
.quiz-done .btn { margin: 0 6px; }

/* ==================== 注册状态徽章 ==================== */
.badge-registered { background: #fff8e1; color: #b8860b; }

/* ==================== 访问设置（管理后台） ==================== */
.access-config {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}
.access-subject {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--bg-soft);
}
.access-subject-head { margin-bottom: 8px; }
.access-lang { display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.access-lang input { width: 16px; height: 16px; }
.access-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.access-row-label {
  flex-shrink: 0;
  width: 90px;
  padding-top: 6px;
  font-size: 13px;
  color: var(--text-soft);
  font-weight: 600;
}
.access-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.access-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-card);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
}
.access-chip:hover { border-color: var(--primary); }
.access-chip input { width: 14px; height: 14px; }

/* ==================== 用户筛选区 ==================== */
.admin-filters-users {
  flex-wrap: wrap;
  align-items: center;
}
.admin-filters-users input[type="text"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  min-width: 140px;
}
.admin-filters-users input[type="text"]:focus { border-color: var(--primary); }

/* ==================== 分页控件 ==================== */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 16px 0 4px;
  flex-wrap: wrap;
}
.pager-btn {
  min-width: 34px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.pager-btn:hover:not(:disabled):not(.active) { border-color: var(--primary); color: var(--primary); }
.pager-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.pager-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.pager-ellipsis { color: var(--text-light); font-size: 13px; padding: 0 2px; }
.pager-info { font-size: 13px; color: var(--text-soft); margin-left: 8px; }

/* ==================== 解锁引导弹窗（注册用户） ==================== */
.unlock-modal {
  padding: 28px 30px 24px;
  text-align: center;
  position: relative;
  border-radius: 16px;
}
.unlock-modal .modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 22px;
}
.unlock-icon { font-size: 44px; margin-bottom: 8px; }
.unlock-modal h3 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}
.unlock-sub {
  margin: 0 0 16px;
  font-size: 15px;
  color: var(--text-soft);
  line-height: 1.6;
}
.unlock-qr {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
.unlock-qr-img {
  width: 180px;
  height: 180px;
  border: 1px solid var(--border);
  border-radius: 12px;
  object-fit: cover;
}
.unlock-tip {
  margin: 0;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}
