:root {
  --bg: #15151f;
  --bg-elev: #1f1f2e;
  --bg-card: #232334;
  --bg-input: #2a2a3d;
  --text: #e8e8f0;
  --text-dim: #9a9ab0;
  --text-faint: #6a6a82;
  --accent: #6c8cff;
  --accent-soft: rgba(108,140,255,.15);
  --rating-s: #ff6b6b;
  --rating-a: #ffa94d;
  --rating-b: #6c8cff;
  --rating-c: #6a6a82;
  --tuiyan: #4ec9b0;
  --ref-bg: rgba(108,140,255,.10);
  --border: rgba(255,255,255,.08);
  --shadow: 0 8px 30px rgba(0,0,0,.4);
  --radius: 16px;
  --tap: 44px;
}
body.light {
  --bg: #f4f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #eef0f6;
  --text: #1a1a28;
  --text-dim: #5a5a72;
  --text-faint: #9a9ab0;
  --accent-soft: rgba(108,140,255,.12);
  --border: rgba(0,0,0,.08);
  --shadow: 0 8px 30px rgba(0,0,0,.12);
  --ref-bg: rgba(108,140,255,.08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 8px;
  border-bottom: 1px solid var(--border);
}
.header-top { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.brand h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .5px; }
.brand-ver { font-size: 11px; color: var(--text-faint); border: 1px solid var(--border); padding: 1px 5px; border-radius: 6px; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.pill-btn {
  min-height: var(--tap); padding: 0 16px; border-radius: 22px;
  border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent);
  font-size: 14px; font-weight: 600;
}
.pill-btn.danger { border-color: var(--rating-s); color: var(--rating-s); background: rgba(255,107,107,.1); }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  font-size: 18px;
}
.search-bar {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  background: var(--bg-input); border-radius: 12px; padding: 0 12px; min-height: var(--tap);
}
.search-icon { opacity: .5; font-size: 14px; }
.search-bar input { flex: 1; border: none; background: transparent; color: var(--text); font-size: 15px; outline: none; }
.filter-chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 36px; padding: 0 14px; border-radius: 18px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-dim);
  font-size: 13px; white-space: nowrap;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Stats */
.stats-bar {
  display: flex; gap: 14px; padding: 10px 16px; font-size: 13px; color: var(--text-dim);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.stats-bar b { color: var(--text); font-weight: 700; }

/* List */
.article-list { padding: 12px; display: grid; gap: 12px; }
@media (min-width: 760px) { .article-list { grid-template-columns: 1fr 1fr; max-width: 1000px; margin: 0 auto; } }
.card {
  background: var(--bg-card); border-radius: var(--radius); padding: 16px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .15s; cursor: pointer; position: relative; overflow: hidden;
}
.card:active { transform: scale(.98); }
.card.unread::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.cat-tag { font-size: 12px; padding: 2px 9px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.rating-badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 8px; }
.rating-S { background: rgba(255,107,107,.18); color: var(--rating-s); }
.rating-A { background: rgba(255,169,77,.18); color: var(--rating-a); }
.rating-B { background: rgba(108,140,255,.18); color: var(--rating-b); }
.rating-C { background: rgba(106,106,130,.18); color: var(--rating-c); }
.card h3 { font-size: 16px; margin: 0 0 8px; line-height: 1.5; font-weight: 650; }
.card-preview { font-size: 13px; color: var(--text-dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 12px; color: var(--text-faint); }
.card-flags { display: flex; gap: 10px; }
.flag { font-size: 14px; }
.flag.on { opacity: 1; } .flag.off { opacity: .25; }

/* Modal sheet */
.modal-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; }
.modal-overlay[hidden] { display: none; }
.modal-sheet {
  background: var(--bg-elev); width: 100%; max-height: 92vh; border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column; animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: var(--text-faint); margin: 10px auto 4px; }
.sheet-header { display: flex; align-items: center; gap: 8px; padding: 4px 18px; }
.sheet-cat { font-size: 12px; padding: 2px 9px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sheet-rating { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 8px; }
.sheet-close { margin-left: auto; width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--bg-input); color: var(--text); font-size: 16px; }
.sheet-title { font-size: 20px; margin: 8px 18px; line-height: 1.45; font-weight: 700; }
.sheet-meta { font-size: 12px; color: var(--text-faint); padding: 0 18px; }
.sheet-actions { display: flex; gap: 8px; padding: 12px 18px; flex-wrap: wrap; }
.mini-btn { min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-dim); font-size: 13px; }
.mini-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.sheet-body { padding: 0 18px 12px; overflow-y: auto; flex: 1; }
.module { margin-bottom: 18px; border-left: 3px solid var(--border); padding-left: 12px; }
.module-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; color: var(--accent); }
.module-content { font-size: 15px; color: var(--text); white-space: pre-wrap; }
.tuiyan-label { background: rgba(78,201,176,.18); color: var(--tuiyan); padding: 1px 7px; border-radius: 6px; font-size: 13px; font-weight: 600; }
.ref-analysis { background: var(--ref-bg); border-radius: 10px; padding: 10px 12px; margin-top: 8px; font-size: 14px; border: 1px solid var(--accent-soft); }
.ref-analysis strong { color: var(--accent); }
.sheet-notes { padding: 10px 18px calc(calc(16px + env(safe-area-inset-bottom))); border-top: 1px solid var(--border); }
.notes-toggle { width: 100%; text-align: left; background: transparent; border: 1px dashed var(--border); color: var(--text-dim); border-radius: 10px; padding: 9px 12px; font-size: 13px; font-family: inherit; cursor: pointer; }
.notes-toggle.has-notes { color: var(--accent); border-style: solid; }
.notes-area { width: 100%; min-height: 60px; margin-top: 8px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; color: var(--text); padding: 10px; font-size: 14px; resize: vertical; font-family: inherit; }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--bg-elev); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; min-height: 56px; border: none; background: transparent; color: var(--text-faint);
  font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.nav-btn span { font-size: 18px; }
.nav-btn.active { color: var(--accent); }

/* Drawers */
.drawer-overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: flex; justify-content: flex-end; }
.drawer-overlay[hidden] { display: none; }
.drawer { background: var(--bg-elev); width: min(420px, 90vw); height: 100%; display: flex; flex-direction: column; animation: slideIn .2s ease; }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 18px; border-bottom: 1px solid var(--border); }
.drawer-header h3 { margin: 0; font-size: 17px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px; }
.drawer-footer { padding: 14px 18px; border-top: 1px solid var(--border); }
.setting-row { margin-bottom: 20px; }
.setting-row label { font-size: 14px; font-weight: 600; display: block; margin-bottom: 8px; }
.setting-row input { width: 100%; min-height: var(--tap); border-radius: 10px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text); padding: 0 12px; font-size: 14px; }
.setting-row small { display: block; margin-top: 6px; font-size: 12px; color: var(--text-faint); }
.weekly-day { margin-bottom: 16px; }
.weekly-day h4 { margin: 0 0 6px; font-size: 14px; color: var(--accent); }
.weekly-day ul { margin: 0; padding-left: 18px; font-size: 14px; color: var(--text-dim); }

/* Toast */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--bg-card); color: var(--text); padding: 12px 20px; border-radius: 22px;
  box-shadow: var(--shadow); font-size: 14px; border: 1px solid var(--border);
  animation: fadeIn .2s ease;
}
.toast[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-faint); }
.empty-emoji { font-size: 48px; margin-bottom: 12px; }
