/* ============================================================
   main.css —— 布局与组件
   ============================================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-1);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

body { min-height: 100vh; }

button { font-family: inherit; cursor: pointer; }

.serif { font-family: Georgia, "Times New Roman", "Songti SC", serif; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-glass);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar-inner {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 12px 16px 8px;
}

.brand { display: flex; flex-direction: column; gap: 1px; }

.brand-en {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Noto Sans SC", "Source Han Sans SC", sans-serif;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--text-1);
  line-height: 1.2;
}

.brand-cn {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-3);
  line-height: 1.2;
}

.meta-count {
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  padding-bottom: 2px;
}

/* ---------- 分类横滑条 ---------- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 16px 12px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  letter-spacing: 0.02em;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.chip:active { transform: scale(.97); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  font-weight: 500;
}
.chip .chip-emoji { font-size: 14px; line-height: 1; }

/* ---------- 主体 ---------- */
main { padding: 4px 14px calc(88px + env(safe-area-inset-bottom, 0px)); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 2px 12px;
}
.sh-title {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text-1);
}
.sh-count {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ---------- 卡片网格 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 12px;
}

.card {
  position: relative;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 12px 14px;
  box-shadow: var(--shadow);
  transition: transform .16s ease, box-shadow .2s ease, border-color .2s ease;
  animation: rise .34s cubic-bezier(.22, .68, .36, 1) both;
}
.card:active { transform: scale(.985); }
.card.playing {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-lift);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.emoji {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border-radius: 15px;
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 27px;
  line-height: 1;
}

/* 喇叭：视觉 19px，触摸区撑到 40px */
.speak {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .18s ease, color .18s ease;
}
.speak:active { background: var(--surface-2); color: var(--primary); }
.speak svg { width: 19px; height: 19px; }
.speak.speaking { color: var(--accent); }
.speak.speaking svg { animation: pulse .9s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: .9; }
  50% { transform: scale(1.14); opacity: 1; }
}

.word {
  margin: 11px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 21px;
  font-weight: 500;
  letter-spacing: 0.005em;
  color: var(--text-1);
  line-height: 1.22;
  word-break: break-word;
}
/* 长单词自动降字号，避免换行把卡片撑高 */
.word.md { font-size: 18px; letter-spacing: 0; }
.word.sm { font-size: 16px; letter-spacing: 0; }

.ipa {
  margin: 4px 0 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--text-3);
  letter-spacing: 0.01em;
}

.zh {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--text-2);
  letter-spacing: 0.03em;
}

/* ---------- 底部 TabBar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-glass);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  border: none;
  background: transparent;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 58px;
  padding: 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  transition: color .18s ease;
}
.tab:active { background: var(--surface-2); }
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--primary); }
.tab .tab-num { font-variant-numeric: tabular-nums; }
.tab .i-pause { display: none; }
.tab.is-playing .i-play { display: none; }
.tab.is-playing .i-pause { display: block; }
/* 可一键安装时给第 4 个按钮一点提示色 */
.tab.can-install { color: var(--primary); }

/* 已从桌面图标启动（全屏模式）→ 隐藏安装按钮，回到三栏 */
.tabbar.no-install { grid-template-columns: repeat(3, 1fr); }
.tabbar.no-install #tabInstall { display: none; }

/* ---------- 安装引导弹层 ---------- */
.install-lead {
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text-2);
  margin: 0 0 14px;
}
.install-steps {
  margin: 0;
  padding: 0 0 0 2px;
  list-style: none;
  counter-reset: step;
}
.install-steps li {
  counter-increment: step;
  position: relative;
  padding: 0 0 0 30px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-1);
}
.install-steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11.5px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.install-steps b { font-weight: 500; color: var(--primary); }
.install-tip {
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-3);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 14px;
}

/* ---------- 弹层 ---------- */
.mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.36);
  opacity: 0;
  visibility: hidden;
  transition: opacity .26s ease, visibility .26s ease;
}
.mask.show { opacity: 1; visibility: visible; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.12);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 78vh;
  overflow-y: auto;
  transform: translateY(101%);
  transition: transform .3s cubic-bezier(.32, .72, 0, 1);
}
.sheet.show { transform: translateY(0); }

/* 分类总览：域导航 + 分组滚动 */
.sheet.tall {
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}
.sheet.tall .sheet-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
/* 标题与手势条不参与压缩，否则会被挤掉 */
.sheet.tall .sheet-handle,
.sheet.tall .sheet-title { flex: 0 0 auto; }

.cat-nav {
  flex: 0 0 auto;            /* 关键：不参与 flex 压缩，否则按钮被下方滚动区遮住 */
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 0 14px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cat-nav::-webkit-scrollbar { display: none; }

.cat-tab {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  min-height: 34px;
  padding: 0 11px;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  -webkit-tap-highlight-color: transparent;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.cat-tab:active { transform: scale(.97); }
.cat-tab-emoji { font-size: 13.5px; line-height: 1; }
.cat-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.cat-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 0 calc(18px + env(safe-area-inset-bottom, 0px));
}
.cat-group { margin-bottom: 20px; }
.cat-group-title {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cat-group-count {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  margin: 0 auto 14px;
}

.sheet-title {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin-bottom: 14px;
}

/* 分类宫格 */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
}
.cat-item {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 16px;
  padding: 12px 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-2);
  transition: border-color .18s ease, background .18s ease;
}
.cat-item:active { transform: scale(.97); }
.cat-item.active { border-color: var(--primary); background: var(--primary-soft); }
.cat-emoji { font-size: 26px; line-height: 1.1; }
.cat-name { font-size: 12.5px; color: var(--text-1); letter-spacing: 0.03em; }
.cat-count { font-size: 10.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* 主题列表 */
.theme-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  text-align: left;
  transition: border-color .18s ease, background .18s ease;
}
.theme-item:active { transform: scale(.99); }
.theme-item.active { border-color: var(--primary); background: var(--primary-soft); }
.theme-info { flex: 1; min-width: 0; }
.theme-name { font-size: 14px; color: var(--text-1); letter-spacing: 0.03em; }
.theme-desc { font-size: 11.5px; color: var(--text-3); margin-top: 2px; letter-spacing: 0.02em; }
.theme-dots { display: flex; gap: 5px; flex: 0 0 auto; }
.theme-dot { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,.06); }
.theme-check { flex: 0 0 auto; color: var(--primary); display: none; }
.theme-item.active .theme-check { display: block; }

/* ---------- 单词详情大卡 ---------- */
body.no-scroll { overflow: hidden; }

.dsheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 46px rgba(0, 0, 0, 0.16);
  padding: 6px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(103%);
  transition: transform .32s cubic-bezier(.32, .72, 0, 1);
}
.dsheet.show { transform: translateY(0); }

.dsheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  margin: 0 auto 10px;
  flex: 0 0 auto;
}

.ds-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}

.ds-nav-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform .14s ease, opacity .18s ease;
}
.ds-nav-btn svg { width: 20px; height: 20px; }
.ds-nav-btn:active { transform: scale(.9); }
.ds-nav-btn:disabled { opacity: .3; }

.ds-pos {
  flex: 1;
  text-align: center;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.ds-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
  padding: 14px 0 4px;
}

.ds-emoji {
  width: 92px;
  height: 92px;
  margin: 0 auto 12px;
  border-radius: 26px;
  background: var(--primary-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 50px;
  line-height: 1;
}

.ds-word {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 36px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.005em;
  color: var(--text-1);
  word-break: break-word;
}

.ds-ipa {
  margin-top: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 17px;
  color: var(--text-2);
  letter-spacing: 0.02em;
}

.ds-zh {
  margin-top: 10px;
  font-size: 25px;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 0.04em;
}

.ds-split {
  height: 1px;
  background: var(--border);
  margin: 20px 0 16px;
}

.ds-label {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text-3);
  text-transform: uppercase;
  margin-bottom: 7px;
}

.ds-sen-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
}

.ds-sen-en {
  flex: 1;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  line-height: 1.55;
  font-weight: 500;
  color: var(--text-1);
}

.ds-sen-zh {
  text-align: left;
  margin-top: 9px;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text-2);
}

.ds-mini {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform .14s ease;
}
.ds-mini svg { width: 21px; height: 21px; }
.ds-mini:active { transform: scale(.9); }
.ds-mini.speaking { color: var(--accent); }
.ds-mini.speaking svg { animation: pulse .9s ease-in-out infinite; }

.ds-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding-top: 16px;
}

.ds-btn {
  flex: 1;
  height: 50px;
  border: none;
  border-radius: 16px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .14s ease, opacity .18s ease;
}
.ds-btn svg { width: 20px; height: 20px; }
.ds-btn:active { transform: scale(.975); }
.ds-btn[disabled] { opacity: .55; }

.ds-btn.ghost {
  background: var(--surface-2);
  color: var(--text-1);
  border: 1px solid var(--border);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  z-index: 80;
  background: var(--text-1);
  color: var(--surface);
  font-size: 12.5px;
  letter-spacing: 0.03em;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .24s ease, transform .24s ease, visibility .24s ease;
  max-width: 82vw;
  text-align: center;
}
.toast.show { opacity: .94; visibility: visible; transform: translate(-50%, 0); }

/* ---------- 平板 / 桌面 ---------- */
@media (min-width: 700px) {
  main { max-width: 900px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }
  .grid { gap: 14px; }
  .card { padding: 15px; }
  .emoji { width: 52px; height: 52px; font-size: 29px; }
  .word { font-size: 21px; }
  .dsheet {
    left: 50%;
    right: auto;
    width: 540px;
    transform: translate(-50%, 103%);
    border-radius: 24px 24px 0 0;
  }
  .dsheet.show { transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
