/* =============================================================================
   熊猫速记 — 全局样式
   借用 pd/public/index.html 视觉风格（森林绿主题），按 PRINCIPLE-001 严格控制
   首屏元素数量：Review 页 ≤3，Hub 页 ≤4。
   ============================================================================= */

/* ─── CSS 变量（亮色模式） ─── */
:root {
  --bg:            #f4f5ee;
  --surface:       #ffffff;
  --surface-soft:  #ecefe1;
  --surface-raised:#ffffff;
  --ink:           #1c2620;
  --ink-soft:      #55625a;
  --ink-faint:     #889086;
  --accent:        #2e6e4e;
  --accent-strong: #20563b;
  --accent-soft:   #e4efe6;
  --accent-2:      #c9773a;
  --accent-2-soft: #f6e7d8;
  --line:          #dbdfd0;
  --line-strong:   #c3c9b8;
  --danger:        #b5502f;
  --danger-soft:   #f7e4dc;
  --shadow:        0 1px 2px rgba(28,38,32,.07), 0 10px 28px rgba(28,38,32,.09);
  --shadow-lg:     0 4px 10px rgba(28,38,32,.10), 0 24px 60px rgba(28,38,32,.16);

  /* 手势与动画常量 */
  --card-border-radius: 20px;
  --hub-border-radius:  24px 24px 0 0;
  --transition-bounce:  cubic-bezier(.25,.8,.25,1);
  --transition-spring:  cubic-bezier(.34,1.56,.64,1);
}

/* 深色模式 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #12180f;
    --surface:       #1a2117;
    --surface-soft:  #212a1c;
    --surface-raised:#232d1e;
    --ink:           #e9ece2;
    --ink-soft:      #aab3a2;
    --ink-faint:     #7c877a;
    --accent:        #74c397;
    --accent-strong: #8fd3ac;
    --accent-soft:   #1e3327;
    --accent-2:      #e6a05e;
    --accent-2-soft: #33261a;
    --line:          #2b3427;
    --line-strong:   #3a4535;
    --danger:        #e0947a;
    --danger-soft:   #3a2620;
    --shadow:        0 1px 2px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.40);
    --shadow-lg:     0 4px 14px rgba(0,0,0,.40), 0 30px 70px rgba(0,0,0,.50);
  }
}
[data-theme="dark"] {
  --bg:            #12180f;
  --surface:       #1a2117;
  --surface-soft:  #212a1c;
  --surface-raised:#232d1e;
  --ink:           #e9ece2;
  --ink-soft:      #aab3a2;
  --ink-faint:     #7c877a;
  --accent:        #74c397;
  --accent-strong: #8fd3ac;
  --accent-soft:   #1e3327;
  --accent-2:      #e6a05e;
  --accent-2-soft: #33261a;
  --line:          #2b3427;
  --line-strong:   #3a4535;
  --danger:        #e0947a;
  --danger-soft:   #3a2620;
  --shadow:        0 1px 2px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.40);
  --shadow-lg:     0 4px 14px rgba(0,0,0,.40), 0 30px 70px rgba(0,0,0,.50);
}

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden; /* 禁止页面级滚动，GST-003 */
  overscroll-behavior: none; /* 禁止 iOS/Android 橡皮筋，GST-003 */
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }

/* ─── App Shell ─── */
.app-shell {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  touch-action: none; /* 手势完全由 JS 控制 */
}

/* ─── 通用：Toast 提示 ─── */
#toasts {
  position: fixed;
  bottom: max(env(safe-area-inset-bottom, 0px) + 80px, 80px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 100px;
  font-size: .82rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px) scale(.95);
  transition: opacity .22s, transform .22s var(--transition-bounce);
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ─── 通用：全局 Loading 遮罩 ─── */
#global-loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8000;
  transition: opacity .3s;
}
#global-loader.hidden { opacity: 0; pointer-events: none; }
.loader-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── 通用：顶栏（Hub 页 & Auth 页使用） ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(env(safe-area-inset-top, 0px) + 12px, 12px) 20px 12px;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-logo-mark {
  font-size: 1.5rem;
  line-height: 1;
}
.topbar-logo-name {
  font-size: .88rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: .02em;
}
.topbar-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 1.2rem;
  transition: background .15s;
}
.topbar-icon-btn:hover { background: var(--surface-soft); }
.topbar-icon-btn:active { background: var(--line); }

/* ─── Hub 页 ─── */
.hub-page {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.hub-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 24px;
  gap: 0;
  overflow: hidden;
}

/* Hub：状态行（H-A 引导 / H-B 成果 / H-C 返回条） */
.hub-status {
  margin-top: 8px;
  margin-bottom: 20px;
}
.hub-welcome {
  font-size: 1rem;
  color: var(--ink-soft);
  line-height: 1.5;
}
.hub-stat-line {
  font-size: .9rem;
  color: var(--ink-soft);
}
.hub-stat-line strong {
  color: var(--accent);
  font-weight: 700;
}
.hub-return-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--accent-soft);
  border-radius: 14px;
  cursor: pointer;
  transition: background .15s;
  border: 1px solid var(--accent-soft);
}
.hub-return-bar:hover { background: #d4e8da; }
.hub-return-bar:active { background: #c5dfcc; }
.hub-return-bar-text {
  font-size: .88rem;
  font-weight: 600;
  color: var(--accent-strong);
}
.hub-return-bar-arrow {
  font-size: 1rem;
  color: var(--accent);
}

/* Hub：搜索框 */
.hub-search-wrap {
  position: relative;
  margin-bottom: 20px;
}
.hub-search-input {
  width: 100%;
  padding: 13px 16px 13px 44px;
  border: 1.5px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font-size: .95rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.hub-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.hub-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
  font-size: 1rem;
  pointer-events: none;
}
.hub-search-input::placeholder { color: var(--ink-faint); }

/* Hub：词库入口 */
.hub-library-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
  border: 1px solid var(--line);
  text-align: left;
}
.hub-library-btn:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.hub-library-btn:active { transform: translateY(0); box-shadow: var(--shadow); }
.hub-library-btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.hub-library-btn-text { flex: 1; }
.hub-library-btn-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--ink);
}
.hub-library-btn-sub {
  font-size: .76rem;
  color: var(--ink-soft);
  margin-top: 2px;
}
.hub-library-btn-arrow {
  color: var(--ink-faint);
  font-size: .85rem;
}

/* Hub：开始按钮（H-A / H-B state，首屏不显示，只在 index.html 用） */
.hub-start-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px;
  margin-top: 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 16px;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(46,110,78,.35);
  transition: background .15s, transform .15s, box-shadow .15s;
}
.hub-start-btn:hover { background: var(--accent-strong); box-shadow: 0 6px 20px rgba(46,110,78,.4); }
.hub-start-btn:active { transform: scale(.98); }
.hub-start-btn:disabled {
  background: var(--line-strong);
  color: var(--ink-faint);
  box-shadow: none;
  cursor: not-allowed;
}

/* ─── Review 页（卡片复习） ─── */
.review-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  touch-action: none;
}

/* Review：顶部进度条 */
.review-progress {
  position: absolute;
  top: max(env(safe-area-inset-top, 0px) + 8px, 8px);
  left: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
}
.progress-bar-track {
  flex: 1;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .3s var(--transition-bounce);
}
.progress-text {
  font-size: .78rem;
  font-weight: 600;
  color: var(--ink-faint);
  flex-shrink: 0;
}

/* Review：卡片区域 */
.card-area {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 24px max(env(safe-area-inset-bottom, 0px) + 80px, 80px);
  /* GST-001: 底部 24pt 禁区留白由 padding-bottom 保证 */
}
.card {
  position: relative;
  width: 100%;
  max-width: 420px;
  min-height: 260px;
  background: var(--surface);
  border-radius: var(--card-border-radius);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  overflow: hidden;
  /* 手势跟手变换由 JS 控制，此处不设 transition */
  will-change: transform;
}

/* 卡片：评分方向色条（手势跟手时浮现） */
.card::before, .card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--card-border-radius);
  opacity: 0;
  transition: opacity .1s;
  pointer-events: none;
  z-index: 0;
}
.card.hint-left::before { background: linear-gradient(135deg, var(--danger-soft) 0%, transparent 60%); opacity: 1; }
.card.hint-right::after { background: linear-gradient(-135deg, var(--accent-soft) 0%, transparent 60%); opacity: 1; }

/* 卡片：正面单词（L0） */
.card-word-wrap {
  position: relative;
  z-index: 1;
  text-align: center;
  width: 100%;
}
.card-word {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
  letter-spacing: -.01em;
  word-break: break-word;
  /* 母语注释空位 A: 下方空一行 */
  margin-bottom: 0;
}
.card-word-zh {
  /* 空位 A：母语注释（L2 时填入） */
  font-size: .9rem;
  color: var(--accent);
  font-weight: 500;
  margin-top: 8px;
  min-height: 22px; /* 保留空位，避免抖动 */
  opacity: 0;
  transition: opacity .2s;
}
.card-word-zh.visible { opacity: 1; }

/* 卡片：层展开区域（L1 / L2） */
.card-detail {
  width: 100%;
  position: relative;
  z-index: 1;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height .28s var(--transition-bounce), opacity .22s;
}
.card-detail.visible {
  max-height: 240px;
  opacity: 1;
}
.card-phonetic {
  text-align: center;
  font-family: "JetBrains Mono", "Courier New", monospace;
  font-size: .9rem;
  color: var(--ink-soft);
  margin-top: 18px;
  margin-bottom: 2px;
}
.card-cefr-badge {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  margin-left: 8px;
  vertical-align: middle;
}
.card-definition {
  /* 空位 B：CEFR 分级注释（L1 时填入，下方有空着 B 供母语翻译） */
  text-align: center;
  font-size: .88rem;
  color: var(--ink-soft);
  line-height: 1.6;
  margin-top: 12px;
  padding: 0 4px;
}
.card-definition-zh {
  /* 空位 B：注释的母语翻译（L2 时追加） */
  text-align: center;
  font-size: .85rem;
  color: var(--ink-faint);
  margin-top: 6px;
  min-height: 20px;
  opacity: 0;
  transition: opacity .2s;
}
.card-definition-zh.visible { opacity: 1; }

/* 卡片：评分图标浮现 */
.card-grade-badge {
  position: absolute;
  top: 16px;
  font-size: 1.6rem;
  font-weight: 800;
  opacity: 0;
  transform: scale(.6) rotate(-15deg);
  transition: opacity .15s, transform .2s var(--transition-spring);
  z-index: 5;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.card-grade-badge.left  { right: 20px; color: var(--danger); }
.card-grade-badge.right { left: 20px; color: var(--accent); }
.card-grade-badge.show {
  opacity: 1;
  transform: scale(1) rotate(-8deg);
}

/* Review：底部手势提示把手 */
.gesture-hint {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom, 0px) + 16px, 16px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 100px;
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  z-index: 10;
  white-space: nowrap;
}
.gesture-hint:hover { background: var(--surface-soft); }
.gesture-hint-arrow { font-size: .8rem; color: var(--ink-faint); }
.gesture-hint-text {
  font-size: .74rem;
  font-weight: 500;
  color: var(--ink-soft);
}

/* ─── Hub Overlay（在 review.html 内部的 H-C 叠层） ─── */
.hub-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background: var(--bg);
  border-radius: var(--hub-border-radius);
  box-shadow: 0 -8px 40px rgba(28,38,32,.15);
  transform: translateY(100%); /* 默认在视口下方 */
  will-change: transform;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* transition 由 JS 控制，手势跟手时不加 transition */
}
.hub-overlay.animating {
  transition: transform .26s var(--transition-bounce);
}
.hub-overlay-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0 4px;
  flex-shrink: 0;
}
.hub-overlay-handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
}
.hub-overlay-body {
  flex: 1;
  padding: 4px 24px 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ─── Auth 页 ─── */
.auth-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.auth-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 28px 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.auth-mark   { font-size: 2.6rem; margin-bottom: 6px; }
.auth-title  { font-size: 1.3rem; font-weight: 700; margin: 0 0 4px; }
.auth-sub    { font-size: .84rem; color: var(--ink-soft); margin: 0 0 24px; }
.auth-tabs {
  display: flex;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  padding: 9px;
  font-size: .86rem;
  font-weight: 600;
  color: var(--ink-soft);
  border-radius: 10px;
  margin: 3px;
  transition: background .15s, color .15s;
}
.auth-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.auth-field { text-align: left; margin-bottom: 14px; }
.auth-field label {
  display: block;
  font-size: .76rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.auth-field input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  font-size: .95rem;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.auth-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-submit {
  width: 100%;
  padding: 14px;
  border-radius: 13px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 6px;
  box-shadow: 0 4px 14px rgba(46,110,78,.3);
  transition: background .15s, transform .1s, box-shadow .15s;
}
.auth-submit:hover { background: var(--accent-strong); }
.auth-submit:active { transform: scale(.98); }
.auth-submit:disabled {
  background: var(--line-strong);
  color: var(--ink-faint);
  box-shadow: none;
  cursor: not-allowed;
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  font-size: .76rem;
  color: var(--ink-faint);
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}
.auth-oauth-btn {
  width: 100%;
  padding: 12px;
  border-radius: 11px;
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s, border-color .15s;
}
.auth-oauth-btn:hover {
  background: var(--surface-soft);
  border-color: var(--line-strong);
}
.auth-error {
  font-size: .82rem;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 12px;
  text-align: left;
  display: none;
}
.auth-error.visible { display: block; }

/* ─── 减少动效适配（GSRT-003 / GST-011） ─── */
@media (prefers-reduced-motion: reduce) {
  .card,
  .hub-overlay,
  .card-detail,
  .card-word-zh,
  .card-definition-zh,
  .progress-bar-fill {
    transition-duration: 0ms !important;
  }
  .hub-overlay.animating {
    transition: opacity .12s !important;
  }
}
