/* app.css - 标日中级词汇复习 PWA 样式表 */

:root {
  /* 基础系统色彩 (默认浅色) */
  --bg-primary: #f5f7fa;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-input: #eef2f6;
  --text-primary: #182036;
  --text-secondary: #5a6a85;
  --text-muted: #8c9ba5;
  --border-color: #d8e2ea;
  
  /* 交互色彩 */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-text: #ffffff;
  
  --color-success: #10b981;
  --color-success-bg: #ecfdf5;
  --color-success-border: #6ee7b7;
  
  --color-danger: #ef4444;
  --color-danger-bg: #fef2f2;
  --color-danger-border: #fca5a5;
  
  --color-warning: #f59e0b;
  --color-warning-bg: #fffbeb;
  
  --color-gold: #b45309;
  --color-gold-bg: #fef3c7;
  
  /* 圆角与阴影 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  /* 字体栈：严格日语字体在前 */
  --font-family-cjk: "Hiragino Sans", "Noto Sans CJK JP", "Yu Gothic", "Meiryo", sans-serif;
  --font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, var(--font-family-cjk);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0f1422;
    --bg-surface: #182036;
    --bg-surface-elevated: #212c47;
    --bg-input: #121929;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #2b395a;
    
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-primary-text: #ffffff;
    
    --color-success: #10b981;
    --color-success-bg: rgba(16, 185, 129, 0.15);
    --color-success-border: #059669;
    
    --color-danger: #f87171;
    --color-danger-bg: rgba(239, 68, 68, 0.18);
    --color-danger-border: #dc2626;
    
    --color-warning: #fbbf24;
    --color-warning-bg: rgba(245, 158, 11, 0.18);
    
    --color-gold: #fbbf24;
    --color-gold-bg: rgba(251, 191, 36, 0.15);
  }
}

/* 基础重置 */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family-base);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  overflow-x: hidden;
}

/* 语言专有样式 */
[lang="ja"] {
  font-family: var(--font-family-cjk);
  letter-spacing: 0.02em;
}

[lang="zh-CN"] {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* 辅助显示类（严格遵守 CSP 无内联样式） */
.hidden { display: none !important; }
.visible { display: block !important; }
.flex { display: flex !important; }
.sr-only { display: none !important; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 10px; }
.mt-lg { margin-top: 12px; }
.mb-sm { margin-bottom: 8px; }
.gap-sm { gap: 8px; }
.input-compact { min-height: 38px; padding: 4px 8px; font-size: 0.85rem; }

/* 页面主容器 - 默认 390px 竖屏居中适配，支持平板桌面居中放大 */
#app-container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  min-height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-surface);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

@media (min-width: 768px) {
  #app-container {
    max-width: 580px;
    margin: 20px auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    height: calc(100vh - 40px);
    max-height: calc(100vh - 40px);
  }
}

/* 顶部导航头 */
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 按钮通用（最小点击区域 44px） */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease-in-out;
  user-select: none;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary:active {
  background-color: var(--color-primary-hover);
}

.btn-secondary {
  background-color: var(--bg-input);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-outline {
  background-color: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.btn-text {
  background-color: transparent;
  color: var(--text-secondary);
  padding: 8px;
  min-height: 44px;
}

.btn-sm {
  min-height: 38px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-lg {
  min-height: 52px;
  font-size: 1.05rem;
  padding: 14px 20px;
}

.btn-block {
  width: 100%;
}

.btn-again {
  background-color: var(--color-danger);
  color: #ffffff;
}

.btn-hard {
  background-color: var(--color-warning);
  color: #182036;
}

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

/* 主内容视图容器与内部滚动区分层 */
.view-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.content-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.bottom-actions-bar {
  flex-shrink: 0;
  padding: 10px 16px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 底部常驻导航条 */
.bottom-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 6px 12px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  position: relative;
  z-index: 20;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 50px;
  padding: 2px 4px;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
}

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

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-bottom: 2px;
}

.nav-icon svg, .svg-icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.header-logo-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  color: var(--color-primary);
}

/* 离线通知条 */
.offline-banner {
  background-color: var(--color-danger);
  color: #ffffff;
  padding: 8px 16px;
  font-size: 0.85rem;
  text-align: center;
  font-weight: 600;
  display: none;
}

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

/* 新版本就绪通知条 */
.update-banner {
  background-color: var(--color-primary);
  color: var(--color-primary-text);
  padding: 8px 16px;
  font-size: 0.88rem;
  text-align: center;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Toast 提示框 - 固定在底部导航栏上方，不得遮挡主按钮；pointer-events 设为 none */
.toast-container {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none !important;
  width: max-content;
  max-width: 90%;
}

.toast {
  background-color: rgba(24, 32, 54, 0.95);
  color: #ffffff;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: none !important;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.2s ease-out;
}

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

.toast-action {
  color: #60a5fa;
  font-weight: 700;
  cursor: pointer;
  border: none;
  background: transparent;
  font-size: 0.9rem;
}

/* 徽章 Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-level-3 { background-color: var(--color-gold-bg); color: var(--color-gold); }
.badge-level-2 { background-color: rgba(37, 99, 235, 0.12); color: var(--color-primary); }
.badge-level-1 { background-color: rgba(140, 155, 165, 0.18); color: var(--text-secondary); }
.badge-facet { background-color: var(--bg-input); color: var(--text-secondary); }
.badge-mastered { background-color: var(--color-success-bg); color: var(--color-success); }

/* 卡片容器 */
.card-box {
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
}

/* 首页 KPI 矩阵 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.kpi-card {
  background-color: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
}

.kpi-num {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--color-primary);
}

.kpi-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* 抽屉 Drawer / 弹窗 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.drawer {
  background-color: var(--bg-surface);
  width: 100%;
  max-width: 580px;
  max-height: 85vh;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.drawer-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.drawer-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

/* 复习页专用排版 */
.review-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.review-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.review-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* 读音字号分级与长词自适应缩放（防止换行成四五行大字） */
.reading-xl {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.2;
  word-break: break-all;
}

.reading-lg {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.25;
  word-break: break-all;
}

.reading-md {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  word-break: break-all;
}

.reading-sm {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.35;
  word-break: break-all;
  letter-spacing: -0.01em;
}

.word-card-reading {
  font-weight: 800;
  color: var(--text-primary);
  margin-top: 4px;
}

.word-card-kanji {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-top: 2px;
}

.word-card-meaning-line {
  font-size: 0.92rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

/* 新词 intro 学习卡大字号排版 */
.intro-headword {
  color: var(--text-primary);
  margin-bottom: 4px;
}

.intro-reading {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 8px;
}

.intro-pitch-pos {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.intro-meaning {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  padding: 10px 14px;
  background-color: var(--bg-input);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.intro-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-top: 12px;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.intro-item-line {
  font-size: 0.95rem;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border-color);
}

/* 题目选项大按钮 */
.question-prompt {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.6;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.option-btn {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 12px 16px;
  font-size: 1.05rem;
  text-align: left;
  border-radius: var(--radius-md);
  background-color: var(--bg-input);
  border: 2px solid transparent;
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.option-btn.opt-correct {
  background-color: var(--color-success-bg);
  border-color: var(--color-success);
  color: var(--color-success);
}

.option-btn.opt-wrong {
  background-color: var(--color-danger-bg);
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* 解析区域 */
.explanation-box {
  background-color: var(--bg-input);
  border-left: 4px solid var(--color-primary);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  margin-bottom: 14px;
  font-size: 0.95rem;
}

/* 屏幕下半部分固定操作区 */
.bottom-actions {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bottom-action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* 表单输入控件 */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-primary);
  font-size: 1rem;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* 课号网格选择 (4列) */
.lessons-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.lesson-chip {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.lesson-chip.selected {
  background-color: var(--color-primary);
  color: var(--color-primary-text);
  border-color: var(--color-primary);
}

/* 开关 Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-color);
}

.toggle-label {
  font-size: 0.95rem;
  font-weight: 600;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border-color);
  transition: 0.2s;
  border-radius: var(--radius-full);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--color-primary);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

/* 进度条 Progress Bar (使用标准 progress 标签配合类) */
progress {
  width: 100%;
  height: 10px;
  border-radius: var(--radius-full);
  overflow: hidden;
  border: none;
}

progress::-webkit-progress-bar {
  background-color: var(--bg-input);
}

progress::-webkit-progress-value {
  background-color: var(--color-primary);
}

progress::-moz-progress-bar {
  background-color: var(--color-primary);
}

/* 错误与空状态提示框 */
.alert-box {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  font-size: 0.95rem;
}

.alert-danger {
  background-color: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid var(--color-danger-border);
}

.alert-success {
  background-color: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid var(--color-success-border);
}

/* 折叠展开面板 */
.collapse-box {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 10px;
  overflow: hidden;
}

.collapse-header {
  padding: 10px 14px;
  background-color: var(--bg-input);
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
}

.collapse-content {
  padding: 12px 14px;
  background-color: var(--bg-surface);
}
