/* ===== 全局样式 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #4a90d9;
  --primary-dark: #357abd;
  --word-blue: #2563eb;
  --secondary: #ff9f43;
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --success: #48bb78;
  --danger: #f56565;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ===== 顶部导航 ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  box-shadow: var(--shadow);
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
}

.app-header .subtitle {
  text-align: center;
  font-size: 0.78rem;
  opacity: 0.85;
  margin-top: 2px;
}

/* ===== 分类菜单（可展开/折叠） ===== */
.menu-panel {
  margin: 12px 16px 0;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--card-bg);
  overflow: hidden;
}

.menu-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 15px;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.menu-label {
  font-size: 0.85rem;
  color: var(--text-light);
}

.menu-current {
  font-weight: 600;
  color: var(--primary);
}

.menu-arrow {
  margin-left: auto;
  color: var(--text-light);
  font-size: 0.8rem;
  transition: transform 0.25s ease;
}

.menu-panel.open .menu-arrow {
  transform: rotate(180deg);
}

.menu-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.28s ease;
}

.menu-panel.open .menu-list {
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--border);
}

.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

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

.menu-item:active {
  background: var(--bg);
}

.menu-item.active {
  background: rgba(74, 144, 217, 0.1);
  color: var(--primary);
  font-weight: 600;
}

.menu-count {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-light);
}

/* ===== 语速选择 ===== */
.rate-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 2px;
}

.rate-label {
  font-size: 0.85rem;
  color: var(--text-light);
  flex-shrink: 0;
}

.rate-chip {
  flex-shrink: 0;
  padding: 5px 14px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.rate-chip.active {
  background: var(--secondary);
  color: white;
  border-color: var(--secondary);
}

.rate-chip:active {
  transform: scale(0.94);
}

/* ===== 主内容区 ===== */
main {
  padding: 12px 16px calc(24px + var(--safe-bottom));
  max-width: 600px;
  margin: 0 auto;
}

/* ===== 学习卡片 ===== */
.study-card {
  position: relative;
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 16px 20px 14px;
  text-align: center;
  transition: box-shadow 0.2s ease;
  user-select: none;
}

.study-card.playing {
  box-shadow: 0 0 0 3px var(--primary), var(--shadow-lg);
}

.study-card .card-fav {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 1.4rem;
  opacity: 0.3;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 2;
}

.study-card.favorite .card-fav {
  opacity: 1;
  color: var(--secondary);
}

.study-card .card-fav:active {
  transform: scale(1.3);
}

.study-img-wrap {
  position: relative;
  width: 100%;
  height: 160px;
  margin-bottom: 10px;
}

.study-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.study-img-wrap.no-img .study-img {
  display: none;
}

.study-img-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cbd5e1;
  font-weight: 700;
  font-size: 2rem;
  padding: 12px;
}

.study-en {
  font-size: 2.1rem;
  font-weight: 800;
  color: var(--word-blue);
  letter-spacing: 0.5px;
  line-height: 1.2;
  word-break: break-word;
}

.study-zh {
  font-size: 1rem;
  color: var(--text-light);
  margin-top: 4px;
}

.study-divider {
  border-top: 2px dashed var(--border);
  margin: 12px 8px;
}

.study-sentence {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--word-blue);
  line-height: 1.35;
  word-break: break-word;
}

.study-sz {
  font-size: 0.92rem;
  color: var(--text-light);
  margin-top: 4px;
}

.study-progress {
  margin-top: 10px;
  font-size: 0.75rem;
  color: #b0b8c4;
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* ===== 学习控制按钮 ===== */
.study-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
}

.nav-btn {
  flex: 1;
  max-width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 1.1rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn span {
  font-size: 0.72rem;
  color: var(--text-light);
}

.nav-btn:active {
  transform: scale(0.94);
  background: var(--bg);
}

.round-btn {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.round-btn:active {
  transform: scale(0.9);
}

.round-btn.play {
  background: var(--primary);
  box-shadow: 0 4px 16px rgba(74, 144, 217, 0.4);
}

.round-btn.mic {
  background: #10b981;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.round-btn.mic.listening {
  animation: mic-pulse 1.1s ease-in-out infinite;
  background: var(--danger);
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 101, 101, 0.5); }
  50% { transform: scale(1.08); box-shadow: 0 0 0 12px rgba(245, 101, 101, 0); }
}

/* ===== 跟读结果面板 ===== */
.follow-panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-top: 16px;
  text-align: center;
}

.follow-status {
  font-size: 0.95rem;
  color: var(--text-light);
}

.follow-score {
  font-size: 2.2rem;
  font-weight: 800;
  margin: 6px 0;
}

.follow-score.good { color: var(--success); }
.follow-score.ok { color: var(--secondary); }
.follow-score.bad { color: var(--danger); }

.follow-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 6px 0;
}

.word-chip {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
}

.word-chip.hit {
  background: #e6f9f0;
  color: #0f9d63;
}

.word-chip.miss {
  background: #fdecec;
  color: var(--danger);
  text-decoration: line-through;
}

.follow-heard {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 4px;
  word-break: break-word;
}

.follow-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

/* ===== 功能控制栏 ===== */
.control-bar {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  align-items: center;
}

.control-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 6px;
  border-radius: 12px;
  border: none;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.control-btn.primary {
  background: var(--primary);
  color: white;
}

.control-btn.primary:active {
  background: var(--primary-dark);
}

.control-btn.secondary {
  background: var(--card-bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.control-btn.secondary:active {
  background: var(--bg);
}

.control-btn.secondary.active {
  background: var(--secondary);
  color: white;
  border-color: var(--secondary);
}

/* ===== 提示弹窗 ===== */
.toast {
  position: fixed;
  top: calc(50% - 30px);
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.9rem;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  max-width: 82vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ===== 离线提示 ===== */
.offline-banner {
  display: none;
  background: #ff6b6b;
  color: white;
  text-align: center;
  padding: 6px;
  font-size: 0.8rem;
}

.offline-banner.show {
  display: block;
}

/* ===== 自定义滚动条 ===== */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ===== 小屏幕适配 ===== */
@media (max-width: 360px) {
  .study-en { font-size: 1.8rem; }
  .study-sentence { font-size: 1.05rem; }
  .study-img-wrap { height: 130px; }
  .round-btn { width: 54px; height: 54px; }
}
