/* =============================================================================
   Lingua Atlas v2 — 增强层
   1) 修复原样式未定义的 CSS 变量
   2) 深色模式（跟随系统 / 手动切换）
   3) 移动端底部标签栏（原生 App 手感）
   4) 新组件：完整词条、搜索、复习、每日目标、阅读、文化、句型、无障碍
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. 修复：原站引用了 --text / --text-muted / --text-soft / --bg-card 但从未定义，
      导致语音诊断面板与游戏页出现黑字/透明底。这里补齐为语义别名。
   -------------------------------------------------------------------------- */
:root {
  --text: var(--ink);
  --text-muted: var(--ink-soft);
  --text-soft: var(--ink-faint);
  --bg-card: var(--surface);
  --ok: var(--success);
  --err: var(--danger);
  --radius-xl: 28px;
  --tabbar-h: 62px;
}

/* -----------------------------------------------------------------------------
   2. 深色模式
   采用 data-theme 属性：light | dark | auto（auto 时跟随系统）
   -------------------------------------------------------------------------- */
:root[data-theme='dark'],
:root[data-theme='auto'] {
  /* 由下方 media query 在 auto 模式下生效；显式 dark 立即生效 */
}

:root[data-theme='dark'] {
  --bg: #14181C;
  --bg-2: #1B2126;
  --surface: #1E252B;
  --surface-2: #232B32;
  --ink: #EDE7DC;
  --ink-soft: #B4AEA4;
  --ink-faint: #7C766E;
  --line: #2E3841;
  --line-soft: #262F37;

  --primary: #7FB6CE;
  --primary-deep: #A5D2E6;
  --primary-soft: #23323B;

  --accent: #F0A742;
  --accent-deep: #FFC06B;
  --accent-soft: #3A2E1B;
  --accent-glow: rgba(240, 167, 66, 0.18);

  --success: #34D399;
  --danger: #F87171;
  --warning: #FBBF24;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 46px rgba(0, 0, 0, 0.55);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme='auto'] {
    --bg: #14181C;
    --bg-2: #1B2126;
    --surface: #1E252B;
    --surface-2: #232B32;
    --ink: #EDE7DC;
    --ink-soft: #B4AEA4;
    --ink-faint: #7C766E;
    --line: #2E3841;
    --line-soft: #262F37;
    --primary: #7FB6CE;
    --primary-deep: #A5D2E6;
    --primary-soft: #23323B;
    --accent: #F0A742;
    --accent-deep: #FFC06B;
    --accent-soft: #3A2E1B;
    --accent-glow: rgba(240, 167, 66, 0.18);
    --success: #34D399;
    --danger: #F87171;
    --warning: #FBBF24;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 46px rgba(0, 0, 0, 0.55);
  }
}

/* 深色模式下的硬编码色修正 */
:root[data-theme='dark'] body::before,
:root[data-theme='dark'] body { background-image: none; }

:root[data-theme='dark'] .topbar { background: rgba(20, 24, 28, 0.86); }
:root[data-theme='dark'] .mobile-tabbar { background: rgba(20, 24, 28, 0.94); }
:root[data-theme='dark'] .btn-secondary:hover { background: #2A3944; }
:root[data-theme='dark'] .btn-primary { color: #10202A; }
:root[data-theme='dark'] .btn-accent { color: #2A1B05; }
:root[data-theme='dark'] .nav-item.active { color: #10202A; }
:root[data-theme='dark'] .lang-select { color-scheme: dark; }
:root[data-theme='dark'] .fc-front,
:root[data-theme='dark'] .fc-back { background: var(--surface); }
:root[data-theme='dark'] input,
:root[data-theme='dark'] textarea,
:root[data-theme='dark'] select { color-scheme: dark; }

@media (prefers-color-scheme: dark) {
  :root[data-theme='auto'] body::before { background-image: none; }
  :root[data-theme='auto'] .topbar { background: rgba(20, 24, 28, 0.86); }
  :root[data-theme='auto'] .mobile-tabbar { background: rgba(20, 24, 28, 0.94); }
  :root[data-theme='auto'] .btn-secondary:hover { background: #2A3944; }
  :root[data-theme='auto'] .btn-primary { color: #10202A; }
  :root[data-theme='auto'] .btn-accent { color: #2A1B05; }
  :root[data-theme='auto'] .nav-item.active { color: #10202A; }
  :root[data-theme='auto'] input,
  :root[data-theme='auto'] textarea,
  :root[data-theme='auto'] select { color-scheme: dark; }
}

/* 主题切换按钮 */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px;
  font-size: 15px; line-height: 1;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  transition: all 0.2s ease;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--ink-faint); transform: translateY(-1px); }

/* -----------------------------------------------------------------------------
   3. 无障碍 / 通用增强
   -------------------------------------------------------------------------- */
.sr-only {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute; left: 12px; top: -60px;
  z-index: 200; padding: 10px 16px; border-radius: 10px;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 13px;
  transition: top 0.18s ease;
}
.skip-link:focus { top: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* 通用小徽标 / 标签 */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
  background: var(--surface-2); color: var(--ink-soft);
  border: 1px solid var(--line-soft);
  white-space: nowrap;
}
.chip-accent { background: var(--accent-soft); color: var(--accent-deep); border-color: transparent; }
.chip-primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.chip-ok { background: rgba(16, 185, 129, 0.14); color: #067A55; border-color: transparent; }
.chip-warn { background: rgba(245, 158, 11, 0.16); color: #92610A; border-color: transparent; }
:root[data-theme='dark'] .chip-ok { color: #6EE7B7; }
:root[data-theme='dark'] .chip-warn { color: #FCD34D; }

/* 工具栏（页面级操作条） */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 14px 0 18px;
}
.toolbar .spacer { flex: 1; }

/* 搜索输入 */
.search-box { position: relative; flex: 1; min-width: 190px; }
.search-box input {
  width: 100%; padding: 10px 14px 10px 36px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 13.5px;
}
.search-box input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.search-box::before {
  content: '🔍'; position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); font-size: 13px; opacity: 0.6; pointer-events: none;
}

/* 复制/收藏等图标按钮 */
.icon-action {
  width: 32px; height: 32px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-soft); font-size: 14px;
  transition: all 0.18s ease;
}
.icon-action:hover { background: var(--surface-2); color: var(--ink); }
.icon-action.on { color: var(--accent); background: var(--accent-soft); }

/* -----------------------------------------------------------------------------
   4. 完整词条卡（核心新增）
   -------------------------------------------------------------------------- */
.word-sheet,
.word-card-full {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow-sm);
}
.word-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.word-head-main { flex: 1; min-width: 180px; }
.word-form {
  font-family: var(--font-display);
  font-size: 34px; font-weight: 700; line-height: 1.15;
  color: var(--primary); letter-spacing: -0.01em;
  word-break: break-word;
}
.word-pron { color: var(--accent-deep); font-size: 14px; font-weight: 600; margin-top: 2px; letter-spacing: 0.02em; }
.word-pron .pron-label {
  font-size: 10.5px; color: var(--ink-faint); font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; margin-right: 6px;
}
.word-actions { display: flex; align-items: center; gap: 6px; }

.word-glosses { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.gloss { display: flex; gap: 10px; align-items: baseline; }
.gloss-pos {
  flex-shrink: 0; font-size: 11.5px; font-weight: 700; color: var(--accent-deep);
  background: var(--accent-soft); border-radius: 6px; padding: 1px 7px;
  font-style: italic; min-width: 44px; text-align: center;
}
.gloss-text { font-size: 15px; color: var(--ink); }

.wsec { margin-top: 18px; }
.wsec-title {
  font-size: 11.5px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.wsec-title::after { content: ''; flex: 1; height: 1px; background: var(--line-soft); }

.ex-list { display: flex; flex-direction: column; gap: 10px; }
.ex-item {
  padding: 11px 13px; border-radius: 12px;
  background: var(--surface-2); border-left: 3px solid var(--accent);
}
.ex-src { font-size: 15px; color: var(--ink); line-height: 1.55; }
.ex-src b { color: var(--accent-deep); font-weight: 700; }
.ex-tr { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.ex-tools { margin-top: 6px; display: flex; gap: 6px; }

.tag-row { display: flex; flex-wrap: wrap; gap: 7px; }
.kv-list { display: flex; flex-direction: column; gap: 7px; font-size: 13.5px; }
.kv { display: flex; gap: 8px; align-items: baseline; }
.kv-k { flex-shrink: 0; color: var(--ink-faint); font-weight: 700; font-size: 12px; min-width: 46px; }
.kv-v { color: var(--ink-soft); }

.note-box {
  padding: 11px 13px; border-radius: 12px; font-size: 13.5px; line-height: 1.6;
  background: var(--surface-2); color: var(--ink-soft); border: 1px dashed var(--line);
}
.note-box.tip { border-style: solid; border-color: rgba(217, 119, 6, 0.35); background: var(--accent-soft); color: var(--accent-deep); }
.note-box.warn { border-style: solid; border-color: rgba(220, 38, 38, 0.3); background: rgba(220, 38, 38, 0.07); color: #B91C1C; }
:root[data-theme='dark'] .note-box.warn { color: #FCA5A5; }
.note-box.mem { border-style: solid; border-color: rgba(99, 102, 241, 0.28); background: rgba(99, 102, 241, 0.08); color: #4338CA; }
:root[data-theme='dark'] .note-box.mem { color: #A5B4FC; }

/* 词条速览表格 */
.word-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.word-table th {
  text-align: left; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 800; padding: 0 10px 8px 0; border-bottom: 1px solid var(--line-soft);
}
.word-table td { padding: 9px 10px 9px 0; border-bottom: 1px solid var(--line-soft); color: var(--ink-soft); vertical-align: top; }
.word-table tr:last-child td { border-bottom: none; }
.word-table .wt-word { color: var(--primary); font-weight: 700; font-size: 14.5px; cursor: pointer; }
.word-table .wt-word:hover { color: var(--accent); }

/* 词条抽屉（浮层） */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(20, 16, 12, 0.42);
  backdrop-filter: blur(3px);
  animation: sheetFade 0.18s ease;
}
@keyframes sheetFade { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  position: fixed; z-index: 121;
  right: 0; top: 0; bottom: 0; width: min(560px, 100%);
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  padding: 20px 22px calc(30px + env(safe-area-inset-bottom, 0px));
  animation: sheetIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes sheetIn { from { transform: translateX(24px); opacity: 0 } to { transform: none; opacity: 1 } }
.sheet-close {
  position: sticky; top: 0; float: right;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink-soft); font-size: 16px; line-height: 1;
}
@media (max-width: 640px) {
  .sheet {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    max-height: 88vh; border-left: none; border-top: 1px solid var(--line);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: sheetUp 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  }
  @keyframes sheetUp { from { transform: translateY(40px); opacity: 0 } to { transform: none; opacity: 1 } }
}

/* -----------------------------------------------------------------------------
   5. 复习 / 每日目标 / 学习路径
   -------------------------------------------------------------------------- */
.goal-ring {
  --pct: 0;
  width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center; flex-shrink: 0;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--line-soft) 0);
  position: relative;
}
.goal-ring::after {
  content: ''; position: absolute; inset: 8px; border-radius: 50%; background: var(--surface);
}
.goal-ring-inner { position: relative; z-index: 1; text-align: center; line-height: 1.15; }
.goal-ring-num { font-family: var(--font-display); font-size: 21px; font-weight: 700; color: var(--primary); }
.goal-ring-lab { font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); font-weight: 700; }

.goal-card { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.goal-lines { flex: 1; min-width: 200px; }
.goal-line { font-size: 13.5px; color: var(--ink-soft); margin-bottom: 6px; }
.goal-line b { color: var(--ink); }
.streak-flame { font-size: 15px; }

.review-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 34px 24px; text-align: center;
  box-shadow: var(--shadow-sm);
}
.review-word { font-family: var(--font-display); font-size: 40px; font-weight: 700; color: var(--primary); line-height: 1.15; }
.review-pron { color: var(--accent-deep); font-size: 14px; margin-top: 4px; }
.review-answer { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }
.review-mean { font-size: 20px; font-weight: 700; color: var(--ink); }
.review-ex { font-size: 13.5px; color: var(--ink-soft); margin-top: 10px; }
.review-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
.srs-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
@media (max-width: 560px) { .srs-btns { grid-template-columns: repeat(2, 1fr); } }
.srs-btn { padding: 11px 6px; border-radius: 12px; font-size: 12.5px; font-weight: 700; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft); }
.srs-btn small { display: block; font-weight: 500; font-size: 10.5px; opacity: 0.75; margin-top: 2px; }
.srs-btn.s0:hover { border-color: var(--danger); color: var(--danger); }
.srs-btn.s1:hover { border-color: var(--warning); color: var(--warning); }
.srs-btn.s2:hover { border-color: #0EA5E9; color: #0EA5E9; }
.srs-btn.s3:hover { border-color: var(--success); color: var(--success); }

/* 阅读短文 */
.reading-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px; }
.reading-title { font-family: var(--font-display); font-size: 20px; font-weight: 700; color: var(--primary); margin-bottom: 12px; }
.reading-text { font-size: 16.5px; line-height: 1.95; color: var(--ink); }
.reading-text .sen { cursor: pointer; border-radius: 5px; transition: background 0.15s ease; }
.reading-text .sen:hover { background: var(--accent-soft); }
.reading-text .sen.playing { background: var(--accent-soft); box-shadow: inset 0 -2px 0 var(--accent); }
.reading-tr { margin-top: 14px; font-size: 13.5px; color: var(--ink-soft); line-height: 1.8; }
.reading-tr .sen-tr { display: block; }
.reading-tr .sen-tr.hide { display: none; }

/* 文化小贴士 */
.culture-card {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 16px 18px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-2));
  border: 1px solid var(--line-soft);
}
.culture-icon { font-size: 24px; flex-shrink: 0; line-height: 1.2; }
.culture-title { font-weight: 700; font-size: 14.5px; color: var(--primary); margin-bottom: 4px; }
.culture-body { font-size: 13.5px; color: var(--ink-soft); line-height: 1.7; }

/* 句型表 */
.phrase-list { display: flex; flex-direction: column; gap: 6px; }
.phrase-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px; background: var(--surface-2);
  font-size: 14px;
}
.phrase-row .ph-src { font-weight: 600; color: var(--ink); flex: 1; }
.phrase-row .ph-tr { color: var(--ink-faint); font-size: 12.5px; }

/* -----------------------------------------------------------------------------
   6. 移动端底部标签栏
   -------------------------------------------------------------------------- */
.mobile-tabbar { display: none; }

@media (max-width: 760px) {
  .nav-main { display: none; }
  .topbar { gap: 12px; padding: 10px 14px; }
  .app-inner { padding: 0 14px calc(96px + env(safe-area-inset-bottom, 0px)); }

  .mobile-tabbar {
    display: flex; align-items: stretch; justify-content: space-around;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(247, 242, 232, 0.94);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
  }
  .mtab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: 10px; font-weight: 600; color: var(--ink-faint);
    padding-top: 6px;
  }
  .mtab-icon { font-size: 18px; line-height: 1; }
  .mtab.active { color: var(--accent-deep); }
  .mtab.active .mtab-icon { transform: translateY(-1px); }
}

/* 顶栏在窄屏下精简 */
@media (max-width: 760px) {
  .xp-pill, .streak-pill { display: none; }
  .brand-tag { display: none; }
  .user-chip .username { display: none; }
}

/* -----------------------------------------------------------------------------
   7. 其它细节
   -------------------------------------------------------------------------- */
.section-title {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-size: 19px; font-weight: 700; color: var(--primary);
  margin: 26px 0 12px;
}
.section-title .st-count { font-family: var(--font-body); font-size: 12px; color: var(--ink-faint); font-weight: 600; }

.hint-row { font-size: 12px; color: var(--ink-faint); margin-top: 8px; }
.kbd {
  display: inline-block; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-family: var(--font-body); font-size: 11px; font-weight: 700; color: var(--ink-soft);
}

.encouragement {
  padding: 12px 14px; border-radius: 12px;
  background: var(--primary-soft); color: var(--primary);
  font-size: 13.5px; font-weight: 600;
}

.soon-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: var(--radius);
  border: 1px dashed var(--line); background: var(--surface-2);
  font-size: 13px; color: var(--ink-faint);
}

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }

.divider { height: 1px; background: var(--line-soft); margin: 20px 0; }

.speak-diff { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; justify-content: center; }
.speak-diff span { padding: 1px 7px; border-radius: 6px; font-size: 13px; }
.speak-diff .ok { background: rgba(16,185,129,.16); color: #067A55; }
.speak-diff .miss { background: rgba(220,38,38,.14); color: #B91C1C; text-decoration: line-through; }
:root[data-theme='dark'] .speak-diff .ok { color: #6EE7B7; }
:root[data-theme='dark'] .speak-diff .miss { color: #FCA5A5; }

/* 打印 */
@media print {
  .topbar, .mobile-tabbar, .toolbar, .sheet, .sheet-backdrop { display: none !important; }
  .app-inner { padding: 0; }
  body { background: #fff; }
}
