/* ═══════════════════════════════════════════
   全宋词 · 掌上词库 — 水墨宋韵风格
   ═══════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
  --bg-primary: #f5f0e8;
  --bg-secondary: #ede6d9;
  --bg-card: #faf7f2;
  --bg-overlay: rgba(62, 44, 26, 0.6);
  --text-primary: #2c2416;
  --text-secondary: #6b5c48;
  --text-muted: #9a8b7a;
  --text-light: #c4b8a8;
  --accent: #8b4513;
  --accent-light: #a0522d;
  --accent-gold: #b8962e;
  --border: #d4c9b8;
  --border-light: #e2d9cc;
  --shadow: rgba(44, 36, 22, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 52px;
  --menu-w: 260px;
  --font-cn: "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", "STSong", serif;
  --font-heading: "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark theme (night mode) */
[data-theme="dark"] {
  --bg-primary: #1a1612;
  --bg-secondary: #231e18;
  --bg-card: #2a241e;
  --bg-overlay: rgba(0, 0, 0, 0.7);
  --text-primary: #dad0c2;
  --text-secondary: #b0a090;
  --text-muted: #7a6e5e;
  --text-light: #5a4e3e;
  --accent: #c49a6c;
  --accent-light: #d4aa7c;
  --border: #3a342c;
  --border-light: #2e2820;
  --shadow: rgba(0, 0, 0, 0.3);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-cn);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.8;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: none; color: inherit; }
input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--bg-card);
  color: var(--text-primary);
  outline: none;
  transition: border var(--transition), box-shadow var(--transition);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.15);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.7; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b5c48' fill='none' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
img { max-width: 100%; height: auto; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Header ── */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 12px;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
#app-title {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 2px;
  margin-left: 8px;
}
#header-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 6px;
  letter-spacing: 1px;
}
#header-right {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.icon-btn {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 18px;
  transition: background var(--transition);
  color: var(--text-secondary);
}
.icon-btn:hover, .icon-btn:active {
  background: var(--border-light);
}

/* ── Side Menu ── */
#side-menu {
  position: fixed;
  top: 0; left: 0;
  width: var(--menu-w);
  height: 100vh;
  height: 100dvh;
  background: var(--bg-card);
  border-right: 1px solid var(--border-light);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 20px var(--shadow);
}
#side-menu.open { transform: translateX(0); }
.menu-header {
  display: flex;
  align-items: center;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-light);
}
.menu-title {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 3px;
  flex: 1;
}
.menu-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.menu-item {
  display: block;
  padding: 12px 20px;
  color: var(--text-secondary);
  font-size: 15px;
  transition: all var(--transition);
  cursor: pointer;
  border-left: 3px solid transparent;
}
.menu-item:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.menu-item.active {
  color: var(--accent);
  background: rgba(139, 69, 19, 0.08);
  border-left-color: var(--accent);
  font-weight: 600;
}
.menu-divider {
  height: 1px;
  background: var(--border-light);
  margin: 8px 16px;
}
.menu-footer {
  padding: 12px 16px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
}

/* ── Menu Overlay ── */
#menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: var(--bg-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
#menu-overlay.show { opacity: 1; pointer-events: auto; }

/* ── Main Content ── */
#main-content {
  margin-top: var(--header-h);
  padding: 16px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  min-height: calc(100vh - var(--header-h));
  min-height: calc(100dvh - var(--header-h));
}

/* ── Page Header ── */
.page-header {
  text-align: center;
  padding: 20px 0 16px;
}
.page-header h2 {
  font-family: var(--font-heading);
  font-size: 20px;
  color: var(--accent);
  letter-spacing: 2px;
  font-weight: 700;
}
.page-header p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  transition: box-shadow var(--transition);
}
.card:hover {
  box-shadow: 0 2px 12px var(--shadow);
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.card-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  color: #f5f0e8;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-light); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 12px; }

/* ── Form Groups ── */
.form-group {
  margin-bottom: 12px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.form-group .hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.form-row {
  display: flex;
  gap: 8px;
}
.form-row > * { flex: 1; }

/* ── Search Bar ── */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.search-bar input { flex: 1; }
.search-bar .btn { flex-shrink: 0; }

/* ── Tags / Chips ── */
.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  background: rgba(139, 69, 19, 0.1);
  color: var(--accent);
  margin: 2px 3px;
}
.tag-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ── Poem Display ── */
.poem-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}
.poem-title {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.poem-poet {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.poem-content {
  text-align: center;
  line-height: 2.2;
  font-size: 16px;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}
.poem-content .line {
  display: block;
  padding: 2px 0;
}
.poem-content .line-short {
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}
.poem-notes {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Loading ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* ── Pagination ── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
}
.pagination .page-info {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
#modal-overlay.show { opacity: 1; pointer-events: auto; }
#modal-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px var(--shadow);
  overflow: hidden;
}
#modal-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
}
#modal-title {
  flex: 1;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
}
#modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
}
#modal-body .poem-content { text-align: left; }
#modal-body .poem-content .line { text-align: center; }

/* ── Home Page ── */
.home-hero {
  text-align: center;
  padding: 24px 0 8px;
}
.home-hero h1 {
  font-family: var(--font-heading);
  font-size: 28px;
  color: var(--accent);
  letter-spacing: 4px;
}
.home-hero .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 2px;
}
.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
  text-align: center;
}
.stat-card .num {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-heading);
}
.stat-card .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.home-poem-of-day {
  margin-top: 8px;
}
.home-poem-of-day .section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.quick-action-btn {
  padding: 16px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  text-align: center;
  transition: all var(--transition);
  font-size: 13px;
  color: var(--text-secondary);
}
.quick-action-btn:active {
  background: rgba(139, 69, 19, 0.05);
  transform: scale(0.97);
}
.quick-action-btn .qa-icon { font-size: 24px; display: block; margin-bottom: 4px; }

/* ── Search Filters ── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.filter-bar .tag {
  cursor: pointer;
  transition: all var(--transition);
}
.filter-bar .tag.active {
  background: var(--accent);
  color: #f5f0e8;
}

/* ── Result Items ── */
.result-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background var(--transition);
}
.result-item:last-child { border-bottom: none; }
.result-item:hover { background: var(--bg-secondary); margin: 0 -18px; padding: 12px 18px; border-radius: var(--radius-sm); }
.result-item .ri-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}
.result-item .ri-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.result-item .ri-preview {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Chat / Report Output ── */
.chat-output {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  line-height: 2;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 60vh;
  overflow-y: auto;
}
.chat-output h2, .chat-output h3, .chat-output h4 {
  font-family: var(--font-heading);
  color: var(--accent);
  margin: 16px 0 8px;
}
.chat-output h2 { font-size: 18px; }
.chat-output h3 { font-size: 16px; }
.chat-output p { margin: 8px 0; }
.chat-output ul, .chat-output ol { padding-left: 20px; margin: 8px 0; }
.chat-output blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 8px 0;
}

/* ── Poets Grid ── */
.poets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.poet-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.poet-card:active { transform: scale(0.97); }
.poet-card .pc-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}
.poet-card .pc-dynasty {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.poet-card .pc-count {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 2px;
}

/* ── Poet Detail ── */
.poet-detail-header {
  text-align: center;
  padding: 16px 0;
}
.poet-detail-header h2 {
  font-family: var(--font-heading);
  font-size: 24px;
  color: var(--accent);
  letter-spacing: 2px;
}
.poet-detail-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 8px 0;
}
.poet-detail-meta span { margin: 0 8px; }
.poet-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin: 16px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-light);
}

/* ── Cipai Grid ── */
.cipai-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 6px;
}
.cipai-item {
  padding: 10px 8px;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.cipai-item:active { transform: scale(0.95); }
.cipai-item .ci-name { font-weight: 600; color: var(--text-primary); }
.cipai-item .ci-count { font-size: 11px; color: var(--text-muted); }

/* ── Back button ── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 8px;
}
.back-btn:hover { color: var(--text-secondary); }

/* ── Ink wash decorative elements ── */
.ink-divider {
  text-align: center;
  color: var(--border);
  font-size: 20px;
  letter-spacing: 8px;
  padding: 8px 0;
  user-select: none;
}
.ink-dot {
  display: inline-block;
  width: 4px; height: 4px;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0.3;
  margin: 0 4px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  z-index: 999;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ── */
@media (max-width: 480px) {
  #main-content { padding: 12px; }
  .home-stats { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat-card .num { font-size: 20px; }
  .quick-actions { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .poets-grid { grid-template-columns: repeat(2, 1fr); }
  .poem-content { font-size: 15px; }
  .home-hero h1 { font-size: 24px; }
  .form-row { flex-direction: column; }
}

@media (min-width: 768px) {
  #main-content { padding: 24px; }
  .poets-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── Print ── */
@media print {
  #app-header, #side-menu, .btn, .back-btn, .pagination, .quick-actions {
    display: none !important;
  }
  #main-content { margin-top: 0; }
  .card { break-inside: avoid; }
}
