/* ============================================================
   英语学习工作台 - 样式表
   移动端优先、响应式、蓝白配色、暗色模式
   ============================================================ */

/* ---- CSS 变量 ---- */
:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --primary-dark: #1d4ed8;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;

  --bg: #f0f7ff;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;

  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 16px;

  --header-h: 56px;
  --bottom-nav-h: 60px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

/* ---- 暗色模式 ---- */
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #1e293b;

  --primary-50: #1e293b;
  --primary-100: #1e3a5f;

  --success-bg: #064e3b;
  --warning-bg: #78350f;
  --danger-bg: #7f1d1d;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

/* ---- 重置 ---- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: var(--font); font-size: 16px; }

/* ---- 滚动条 ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   访问口令页
   ============================================================ */
.access-gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  z-index: 9999;
  padding: 24px;
}
.gate-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  max-width: 380px; width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.gate-logo { margin-bottom: 16px; }
.gate-card h1 { font-size: 24px; margin-bottom: 8px; color: var(--primary); }
.gate-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.gate-input-row { margin-bottom: 16px; }
.gate-input {
  width: 100%; padding: 14px 16px;
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 16px; text-align: center;
  transition: border-color 0.2s;
  background: var(--surface); color: var(--text);
}
.gate-input:focus { outline: none; border-color: var(--primary); }
.gate-btn {
  width: 100%; padding: 14px;
  background: var(--primary); color: #fff;
  border-radius: var(--radius); font-size: 16px; font-weight: 600;
  transition: background 0.2s;
}
.gate-btn:hover { background: var(--primary-dark); }
.gate-btn:active { transform: scale(0.98); }
.gate-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ============================================================
   主应用布局
   ============================================================ */
.app-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--primary);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: var(--shadow);
}
.app-header h1 { color: #fff; font-size: 18px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff;
  transition: background 0.2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

.app-content {
  padding-top: var(--header-h);
  padding-bottom: calc(var(--bottom-nav-h) + 16px);
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

/* ---- 底部导航 ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  flex: 1; height: 100%;
  color: var(--text-muted);
  font-size: 10px;
  padding-top: 8px;
  transition: color 0.2s;
}
.nav-item.active { color: var(--primary); }
.nav-item:active { color: var(--primary-light); }

/* ============================================================
   通用组件
   ============================================================ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 8px; color: var(--text); }

.section-title {
  font-size: 18px; font-weight: 700;
  margin: 20px 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-title:first-child { margin-top: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.97); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-secondary.active { border-color: var(--primary); background: var(--primary-50); color: var(--primary); font-weight: 600; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

.input-field, .textarea-field, .select-field {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
}
.input-field:focus, .textarea-field:focus, .select-field:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-100);
}
.textarea-field { resize: vertical; min-height: 80px; }

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

/* ---- 标签 ---- */
.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.tag-consolidate { background: var(--success-bg); color: var(--success); }
.tag-improve { background: var(--warning-bg); color: var(--warning); }
.tag-advanced { background: var(--danger-bg); color: var(--danger); }
.tag-default { background: var(--primary-100); color: var(--primary); }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff;
  padding: 10px 20px; border-radius: var(--radius);
  font-size: 14px; z-index: 9000;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  animation: toast-in 0.3s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- Loading ---- */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 9500;
  gap: 16px;
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: #fff; font-size: 14px; }

/* ---- 模态 ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 9000;
  animation: fade-in 0.2s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-width: 600px; width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  animation: slide-up 0.3s ease;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ---- 空状态 ---- */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ---- 列表项 ---- */
.list-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.list-item:hover { background: var(--surface-alt); }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 15px; }
.list-item-sub { font-size: 13px; color: var(--text-secondary); }

/* ============================================================
   生词相关
   ============================================================ */
.word-search-bar {
  display: flex; gap: 8px; margin-bottom: 16px; position: sticky; top: 56px; z-index: 50;
  background: var(--bg); padding: 8px 0;
}
.word-search-bar .input-field { flex: 1; }

.word-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s;
}
.word-card:active { transform: scale(0.99); }
.word-card-header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.word-card-word { font-size: 17px; font-weight: 700; color: var(--text); }
.word-card-phonetic { font-size: 13px; color: var(--text-secondary); font-family: var(--font-mono); }
.word-card-pos { font-size: 12px; color: var(--primary); font-style: italic; }
.word-card-def { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }
.word-card-date { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.word-card-actions { display: flex; gap: 8px; margin-top: 8px; }

.audio-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary-100);
  color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.audio-btn:hover { background: var(--primary); color: #fff; }

/* ---- 词典面板 ---- */
.dict-panel { }
.dict-panel-word {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.dict-panel-word-text { font-size: 24px; font-weight: 700; }
.dict-panel-phonetic { font-size: 15px; color: var(--text-secondary); font-family: var(--font-mono); }
.dict-panel-pos {
  font-size: 13px; color: var(--primary);
  background: var(--primary-100); padding: 2px 10px; border-radius: 20px;
  font-style: italic;
}
.dict-panel-section { margin-bottom: 14px; }
.dict-panel-section h4 { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.dict-panel-section p { font-size: 14px; }
.dict-panel-example { font-size: 13px; color: var(--text-secondary); font-style: italic; background: var(--surface-alt); padding: 8px 12px; border-radius: var(--radius-sm); border-left: 3px solid var(--primary-light); }

/* ============================================================
   日历
   ============================================================ */
.calendar-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.calendar-header h2 { font-size: 18px; font-weight: 700; }
.calendar-nav-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--text);
  transition: background 0.2s;
}
.calendar-nav-btn:hover { background: var(--surface-alt); }
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
}
.calendar-weekday {
  text-align: center; font-size: 12px; font-weight: 600; color: var(--text-muted);
  padding: 8px 0;
}
.calendar-day {
  aspect-ratio: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm); font-size: 14px;
  cursor: pointer; transition: background 0.15s;
  position: relative;
}
.calendar-day:hover { background: var(--surface-alt); }
.calendar-day.today { font-weight: 700; color: var(--primary); }
.calendar-day.has-data::after {
  content: ''; position: absolute; bottom: 4px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
}
.calendar-day.other-month { color: var(--text-muted); opacity: 0.4; }
.calendar-day.selected { background: var(--primary); color: #fff; }
.calendar-day.selected.has-data::after { background: #fff; }

.calendar-day-detail { margin-top: 16px; }

/* ============================================================
   阅读题
   ============================================================ */
.reading-passage {
  font-size: 15px; line-height: 1.8;
  white-space: pre-wrap; word-break: break-word;
  padding: 16px; background: var(--surface-alt); border-radius: var(--radius);
  margin-bottom: 16px;
}
.reading-passage .word-clickable {
  cursor: pointer; border-radius: 3px;
  transition: background 0.15s;
}
.reading-passage .word-clickable:hover { background: var(--primary-100); }
.reading-passage.no-click .word-clickable { cursor: default; }
.reading-passage.no-click .word-clickable:hover { background: transparent; }

.question-item {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.question-item .q-num { font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.question-item .q-text { font-size: 14px; margin-bottom: 12px; }
.question-option {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; margin-bottom: 6px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.15s;
  font-size: 14px;
}
.question-option:hover { border-color: var(--primary-light); }
.question-option.selected { border-color: var(--primary); background: var(--primary-50); }
.question-option.correct { border-color: var(--success); background: var(--success-bg); }
.question-option.wrong { border-color: var(--danger); background: var(--danger-bg); }
.question-option .opt-label { font-weight: 700; min-width: 24px; }

.reading-score {
  text-align: center; padding: 24px;
  background: var(--primary-50); border-radius: var(--radius);
  margin-bottom: 16px;
}
.reading-score .score-num { font-size: 36px; font-weight: 800; color: var(--primary); }
.reading-score .score-total { font-size: 18px; color: var(--text-secondary); }
.reading-score .score-label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.analysis-box { margin-bottom: 12px; }
.analysis-box h4 { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.analysis-box p { font-size: 14px; color: var(--text-secondary); }
.translation-box { background: var(--surface-alt); padding: 16px; border-radius: var(--radius); margin-bottom: 12px; }
.translation-box h4 { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.translation-box p { font-size: 14px; line-height: 1.8; white-space: pre-wrap; }
.vocab-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 0; border-bottom: 1px solid var(--border-light);
}
.vocab-item:last-child { border-bottom: none; }
.vocab-word { font-weight: 600; font-size: 14px; }
.vocab-phonetic { font-size: 12px; color: var(--text-secondary); font-family: var(--font-mono); }
.vocab-def { font-size: 13px; color: var(--text-secondary); }

/* ---- 生成页 ---- */
.generate-difficulty { display: flex; gap: 8px; margin-bottom: 16px; }
.difficulty-option {
  flex: 1; text-align: center; padding: 12px 8px;
  border: 2px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: all 0.2s;
}
.difficulty-option:hover { border-color: var(--primary-light); }
.difficulty-option.active { border-color: var(--primary); background: var(--primary-50); }
.difficulty-option .d-title { font-weight: 700; font-size: 14px; }
.difficulty-option .d-desc { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

.word-select-list {
  max-height: 300px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; margin-bottom: 16px;
}
.word-select-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-sm);
  cursor: pointer;
}
.word-select-item:hover { background: var(--surface-alt); }
.word-select-item input { width: 18px; height: 18px; accent-color: var(--primary); }
.word-select-item .w-word { font-weight: 600; }
.word-select-item .w-def { font-size: 12px; color: var(--text-secondary); }

/* ---- 仪表盘 ---- */
.dash-section { margin-bottom: 24px; }
.dash-word-list { display: flex; flex-direction: column; gap: 6px; }
.dash-word-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--surface); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.dash-word-item .w { font-weight: 600; font-size: 15px; }
.dash-word-item .p { font-size: 12px; color: var(--text-secondary); }
.dash-word-item .d { font-size: 13px; color: var(--text-secondary); flex: 1; }

.reading-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 8px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  transition: transform 0.15s;
}
.reading-card:active { transform: scale(0.99); }
.reading-card-icon {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.reading-card-main { flex: 1; min-width: 0; }
.reading-card-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reading-card-sub { font-size: 12px; color: var(--text-secondary); }

.mini-calendar { }
.mini-calendar .calendar-day { font-size: 13px; }

/* ---- 设置页 ---- */
.settings-group { margin-bottom: 24px; }
.settings-group h3 { font-size: 14px; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.settings-item {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: var(--shadow-sm);
}
.settings-item-label { flex: 1; }
.settings-item-label .s-title { font-size: 14px; font-weight: 600; }
.settings-item-label .s-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.settings-item input[type="password"], .settings-item input[type="text"] {
  width: 200px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.settings-item .switch { position: relative; width: 44px; height: 24px; }
.settings-item .switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border); border-radius: 24px; transition: 0.3s;
}
.slider::before {
  content: ''; position: absolute;
  height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.3s;
}
input:checked + .slider { background: var(--primary); }
input:checked + .slider::before { transform: translateX(20px); }

/* ============================================================
   响应式 - 桌面端
   ============================================================ */
@media (min-width: 768px) {
  .app-content { max-width: 800px; padding-left: 24px; padding-right: 24px; }
  .bottom-nav {
    max-width: 800px; left: 50%; transform: translateX(-50%);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: var(--shadow-lg);
  }
  .modal-overlay { align-items: center; }
  .modal-content {
    border-radius: var(--radius-lg);
    max-height: 90vh;
  }
  .nav-item { font-size: 12px; }
  .nav-item span { font-size: 11px; }
}

@media (min-width: 1024px) {
  .app-content { max-width: 900px; }
  .bottom-nav { max-width: 900px; }
  .card { padding: 20px; }
}

/* ---- 动画 ---- */
.fade-in { animation: fade-in-anim 0.3s ease; }
@keyframes fade-in-anim { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
