/* ============================================================
   文言文精读助手 - 主样式表
   阅读类应用风格（Medium/Notion inspired）
   ============================================================ */

/* --- CSS 变量 --- */
:root {
  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-border: #e5e5e5;
  --color-text: #1a1a1a;
  --color-text-secondary: #555555;
  --color-text-muted: #999999;
  --color-accent: #2563eb;
  --color-accent-light: #93bbfd;
  --color-highlight: #eff6ff;
  --color-highlight-border: #bfdbfe;
  --color-danger: #dc2626;
  --color-success: #16a34a;
  --color-card-bg: #f9fafb;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun",
    "STSong", serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  --max-width: 720px;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --transition: 0.2s ease;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.75;
  min-height: 100vh;
}

/* --- 排版 --- */
h1,
h2,
h3,
h4 {
  font-family: var(--font-serif);
  line-height: 1.4;
  color: var(--color-text);
}

h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
}
h2 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}
h3 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

p {
  margin-bottom: 0.75rem;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover {
  color: #1d4ed8;
}

/* --- 布局 --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.container-wide {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* --- 导航栏 --- */
.navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.navbar-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar-brand {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-accent);
  text-decoration: none;
}

.navbar-nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.navbar-nav a {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}
.navbar-nav a:hover,
.navbar-nav a.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

.navbar-user {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.btn-logout {
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all var(--transition);
}
.btn-logout:hover {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* --- 按钮 --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-card-bg);
  border-color: var(--color-accent-light);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-danger:hover {
  background: #a93226;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- 表单 --- */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--color-text-secondary);
}

.form-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--color-surface);
  transition: border-color var(--transition);
  outline: none;
}
.form-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-input::placeholder {
  color: var(--color-text-muted);
}

textarea.form-input {
  resize: vertical;
  min-height: 120px;
}

.form-error {
  color: var(--color-danger);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.form-hint {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

/* --- 卡片 --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.card:hover {
  box-shadow: var(--shadow-md);
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-text);
}

.card-title a {
  color: inherit;
  text-decoration: none;
}
.card-title a:hover {
  color: var(--color-accent);
}

.card-meta {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* --- 认证页面 --- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}

.auth-title {
  font-family: var(--font-serif);
  text-align: center;
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}

.auth-footer {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.alert-error {
  background: #fdeaea;
  color: var(--color-danger);
  border: 1px solid #f5c6cb;
}
.alert-success {
  background: #eafaf1;
  color: var(--color-success);
  border: 1px solid #c3e6cb;
}
.alert-info {
  background: #eaf2f8;
  color: #2c3e50;
  border: 1px solid #aed6f1;
}

/* --- 文章阅读页 --- */
.article-header {
  padding: 2rem 0 1rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
}

.article-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.article-overview {
  background: var(--color-card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  line-height: 1.8;
  border-left: 3px solid var(--color-accent-light);
}

.article-overview p {
  margin-bottom: 0.5rem;
}

/* --- 段落区 --- */
.paragraph-block {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px dashed var(--color-border);
}

.paragraph-original {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  line-height: 2.2;
  color: var(--color-text);
  margin-bottom: 0.75rem;
}

.paragraph-translation {
  font-size: 0.95rem;
  color: var(--color-text-secondary);
  line-height: 1.8;
  padding-left: 1rem;
  border-left: 2px solid var(--color-border);
}

/* --- 词汇高亮 --- */
.vocab-highlight {
  color: var(--color-accent);
  border-bottom: 1px dashed var(--color-accent-light);
  cursor: pointer;
  position: relative;
  transition: all var(--transition);
  padding: 0 1px;
}
.vocab-highlight:hover,
.vocab-highlight:focus {
  background: var(--color-highlight);
  border-bottom-color: var(--color-accent);
  border-radius: 2px;
}

.vocab-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  min-width: 220px;
  max-width: 320px;
  box-shadow: var(--shadow-md);
  z-index: 50;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.6;
  text-align: left;
}

.vocab-highlight:hover .vocab-tooltip,
.vocab-highlight:focus .vocab-tooltip {
  display: block;
}

.vocab-tooltip-word {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-accent);
  margin-bottom: 0.25rem;
}

.vocab-tooltip-explanation {
  color: var(--color-text-secondary);
}

.vocab-tooltip-example {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--color-border);
  font-family: var(--font-serif);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.vocab-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-accent-light);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  margin-left: 3px;
  vertical-align: middle;
  transition: all var(--transition);
}
.vocab-add-btn:hover {
  background: var(--color-accent);
  transform: scale(1.15);
}

/* --- 加载与状态 --- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--color-text-muted);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.5rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
  margin: 1rem 0;
}

.progress-bar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* --- 闪卡复习 --- */
.flashcard {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: 12px;
  padding: 3rem 2rem;
  text-align: center;
  max-width: 560px;
  margin: 2rem auto;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  cursor: pointer;
  user-select: none;
}
.flashcard:hover {
  border-color: var(--color-accent-light);
}

.flashcard-word {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  color: var(--color-accent);
  margin-bottom: 1rem;
}

.flashcard-example {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--color-text-secondary);
  line-height: 2;
}

.flashcard-reveal {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
  text-align: left;
  width: 100%;
}

.flashcard-explanation {
  font-size: 1rem;
  color: var(--color-text);
  line-height: 1.8;
}

.flashcard-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.review-stats {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin: 1.5rem 0;
}

.review-stat {
  text-align: center;
  padding: 0.75rem 1.25rem;
  background: var(--color-card-bg);
  border-radius: var(--radius);
}

.review-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-accent);
}

.review-stat-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* --- 工具条 --- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* --- Toast 提示 --- */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast-success {
  border-left: 3px solid var(--color-success);
}
.toast-error {
  border-left: 3px solid var(--color-danger);
}
.toast-info {
  border-left: 3px solid var(--color-accent);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* --- 设置页 --- */
.settings-section {
  margin-bottom: 2rem;
}

.settings-section h3 {
  font-size: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1rem;
}

/* --- 响应式 --- */
@media (max-width: 640px) {
  html {
    font-size: 15px;
  }

  .auth-card {
    padding: 1.5rem;
  }

  .navbar-nav {
    gap: 0.75rem;
  }

  .navbar-nav a {
    font-size: 0.8rem;
  }

  .flashcard {
    padding: 2rem 1rem;
    min-height: 200px;
  }

  .flashcard-word {
    font-size: 2rem;
  }

  .article-title {
    font-size: 1.5rem;
  }
}

/* --- 打印样式 --- */
@media print {
  .navbar,
  .btn,
  .toolbar,
  .vocab-add-btn {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .article-title {
    font-size: 1.5rem;
  }
}
