:root, [data-theme="black"] {
  --bg: #060a14;
  --topbar-bg: rgba(8, 13, 26, 0.72);
  --panel: rgba(15, 23, 42, 0.55);
  --search-bg: rgba(6, 10, 20, 0.6);
  --rapid-bg: rgba(13, 20, 37, 0.8);
  --deck-card-bg: rgba(13, 20, 37, 0.92);
  --deck-head-bg: rgba(37, 99, 235, 0.12);
  --modal-veil: rgba(3, 6, 14, 0.8);
  --ink: #e7eefb;
  --ink-strong: #ffffff;
  --ink-dim: #aebacd;
  --muted: #8b98ad;
  --neon: #22d3ee;
  --neon2: #60a5fa;
  --violet: #a78bfa;
  --gold: #fbbf24;
  --ok: #34d399;
  --line: rgba(120, 170, 255, 0.14);
  --btn-bg: rgba(96, 165, 250, 0.08);
  --tbl-head-bg: rgba(37, 99, 235, 0.18);
  --tbl-stripe: rgba(96, 165, 250, 0.04);
  --note-bg: rgba(251, 191, 36, 0.07);
  --note-ink: #e8d9b0;
  --img-prompt-bg: rgba(37, 99, 235, 0.1);
  --head-grad: linear-gradient(90deg, rgba(37, 99, 235, 0.85), rgba(8, 145, 178, 0.85));
  --title-grad: linear-gradient(90deg, #7dd3fc, var(--neon) 45%, var(--violet));
  --accent-grad: linear-gradient(135deg, #0891b2, #2563eb);
  --ok-grad: linear-gradient(135deg, #059669, #10b981);
  --orb1: rgba(34, 211, 238, 0.16);
  --orb2: rgba(96, 165, 250, 0.14);
  --orb3: rgba(167, 139, 250, 0.13);
  --gridline: rgba(96, 165, 250, 0.05);
  --glow: 0 0 24px rgba(34, 211, 238, 0.25);
  --bg-glow1: radial-gradient(ellipse 80% 60% at 20% -10%, rgba(34, 60, 140, 0.35), transparent 60%);
  --bg-glow2: radial-gradient(ellipse 70% 50% at 90% 10%, rgba(90, 40, 160, 0.28), transparent 60%);
}

[data-theme="light"] {
  --bg: #edf2f9;
  --topbar-bg: rgba(255, 255, 255, 0.78);
  --panel: rgba(255, 255, 255, 0.78);
  --search-bg: #ffffff;
  --rapid-bg: rgba(255, 255, 255, 0.9);
  --deck-card-bg: rgba(255, 255, 255, 0.96);
  --deck-head-bg: rgba(37, 99, 235, 0.08);
  --modal-veil: rgba(226, 233, 244, 0.85);
  --ink: #17203a;
  --ink-strong: #0a1020;
  --ink-dim: #45536e;
  --muted: #66738a;
  --neon: #0e7490;
  --neon2: #2563eb;
  --violet: #7c3aed;
  --gold: #b45309;
  --ok: #059669;
  --line: rgba(37, 99, 235, 0.18);
  --btn-bg: rgba(37, 99, 235, 0.06);
  --tbl-head-bg: rgba(37, 99, 235, 0.1);
  --tbl-stripe: rgba(37, 99, 235, 0.03);
  --note-bg: rgba(217, 119, 6, 0.08);
  --note-ink: #7c5a12;
  --img-prompt-bg: rgba(37, 99, 235, 0.07);
  --head-grad: linear-gradient(90deg, #2563eb, #0891b2);
  --title-grad: linear-gradient(90deg, #1d4ed8, #0e7490 45%, #7c3aed);
  --accent-grad: linear-gradient(135deg, #0891b2, #2563eb);
  --ok-grad: linear-gradient(135deg, #059669, #10b981);
  --orb1: rgba(56, 189, 248, 0.22);
  --orb2: rgba(96, 165, 250, 0.2);
  --orb3: rgba(167, 139, 250, 0.18);
  --gridline: rgba(37, 99, 235, 0.06);
  --glow: 0 0 20px rgba(14, 116, 144, 0.18);
  --bg-glow1: radial-gradient(ellipse 80% 60% at 20% -10%, rgba(147, 197, 253, 0.4), transparent 60%);
  --bg-glow2: radial-gradient(ellipse 70% 50% at 90% 10%, rgba(196, 181, 253, 0.35), transparent 60%);
}

[data-theme="cream"] {
  --bg: #f0e8d5;
  --topbar-bg: rgba(247, 240, 224, 0.85);
  --panel: rgba(250, 245, 230, 0.85);
  --search-bg: #fbf6e9;
  --rapid-bg: rgba(250, 244, 228, 0.95);
  --deck-card-bg: rgba(250, 245, 230, 0.97);
  --deck-head-bg: rgba(180, 83, 9, 0.08);
  --modal-veil: rgba(60, 48, 30, 0.55);
  --ink: #3a3122;
  --ink-strong: #241d10;
  --ink-dim: #5d5040;
  --muted: #857763;
  --neon: #b45309;
  --neon2: #c2410c;
  --violet: #92600f;
  --gold: #8f6607;
  --ok: #4d7c0f;
  --line: rgba(120, 85, 30, 0.22);
  --btn-bg: rgba(180, 83, 9, 0.07);
  --tbl-head-bg: rgba(180, 83, 9, 0.12);
  --tbl-stripe: rgba(180, 83, 9, 0.04);
  --note-bg: rgba(143, 102, 7, 0.1);
  --note-ink: #6b4e08;
  --img-prompt-bg: rgba(194, 65, 12, 0.07);
  --head-grad: linear-gradient(90deg, #a16207, #c2410c);
  --title-grad: linear-gradient(90deg, #92400e, #c2410c 45%, #6d4b08);
  --accent-grad: linear-gradient(135deg, #b45309, #c2410c);
  --ok-grad: linear-gradient(135deg, #4d7c0f, #65a30d);
  --orb1: rgba(217, 119, 6, 0.16);
  --orb2: rgba(194, 65, 12, 0.12);
  --orb3: rgba(146, 96, 15, 0.14);
  --gridline: rgba(120, 85, 30, 0.07);
  --glow: 0 0 20px rgba(180, 83, 9, 0.2);
  --bg-glow1: radial-gradient(ellipse 80% 60% at 20% -10%, rgba(217, 119, 6, 0.16), transparent 60%);
  --bg-glow2: radial-gradient(ellipse 70% 50% at 90% 10%, rgba(194, 65, 12, 0.12), transparent 60%);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background .3s ease, color .3s ease;
}

.bg-fx { position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: var(--bg-glow1), var(--bg-glow2), var(--bg);
}
.orb { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.5; animation: drift 26s ease-in-out infinite alternate; }
.orb1 { width: 480px; height: 480px; background: var(--orb1); top: -120px; left: -80px; }
.orb2 { width: 560px; height: 560px; background: var(--orb2); top: 30%; right: -160px; animation-delay: -8s; }
.orb3 { width: 420px; height: 420px; background: var(--orb3); bottom: -120px; left: 30%; animation-delay: -16s; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(60px, 40px) scale(1.12); }
}
.grid-fx { position: absolute; inset: 0; opacity: 0.35;
  background-image:
    linear-gradient(var(--gridline) 1px, transparent 1px),
    linear-gradient(90deg, var(--gridline) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 30%, transparent 75%);
}

#topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  background: var(--topbar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.12);
}
#app-title {
  font-size: 21px; margin: 0; flex: 1; font-weight: 800; letter-spacing: 0.3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--title-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#home-btn {
  background: var(--btn-bg); color: var(--neon);
  border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 10px; font-size: 15px; cursor: pointer;
  transition: all .15s ease;
}
#home-btn:hover { box-shadow: var(--glow); border-color: var(--neon); }
#topbar-actions { display: flex; align-items: center; gap: 10px; position: relative; }
#progress-label { font-size: 14px; color: var(--neon); white-space: nowrap; font-weight: 600; }

#theme-switch { display: flex; gap: 3px; background: var(--btn-bg); border: 1px solid var(--line); border-radius: 22px; padding: 3px; }
#theme-switch button {
  width: 32px; height: 32px; border-radius: 50%; border: none; background: transparent;
  cursor: pointer; font-size: 15px; color: var(--ink-dim);
  display: flex; align-items: center; justify-content: center; transition: all .15s ease;
}
#theme-switch button:hover { color: var(--neon); }
#theme-switch button.active { background: var(--accent-grad); color: #fff; }

.btn {
  border: 1px solid var(--line); background: var(--btn-bg); color: var(--ink);
  padding: 8px 16px; border-radius: 10px; font-size: 15px; cursor: pointer;
  transition: all .15s ease;
}
.btn:hover { border-color: var(--neon); color: var(--neon); box-shadow: var(--glow); }
.btn.accent {
  background: var(--accent-grad);
  border-color: transparent; color: #fff; font-weight: 600;
}
.btn.accent:hover { filter: brightness(1.12); box-shadow: var(--glow); }
.btn.ok { background: var(--ok-grad); border-color: transparent; color: #fff; }
.btn.ok:hover { filter: brightness(1.12); }

#deck-menu {
  position: absolute; top: calc(100% + 10px); right: 0; min-width: 250px;
  background: var(--deck-card-bg); border: 1px solid var(--line); border-radius: 14px;
  padding: 6px; z-index: 90; backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.25);
}
#deck-menu button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--ink); padding: 10px 13px; border-radius: 9px; font-size: 15px; cursor: pointer;
  transition: background .12s ease;
}
#deck-menu button:hover { background: var(--btn-bg); color: var(--neon); }
#deck-menu .menu-title { font-size: 12px; font-weight: 700; letter-spacing: 1px; color: var(--muted); padding: 7px 13px 3px; text-transform: uppercase; }
#deck-menu .sep { border-top: 1px solid var(--line); margin: 5px 0; }

.view { max-width: 1280px; margin: 0 auto; padding: 24px 20px 70px; }
.hidden { display: none !important; }
.tagline { color: var(--ink-dim); max-width: 760px; font-size: 17px; }
.muted { color: var(--muted); font-size: 14px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; margin-top: 22px; }
.topic-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; cursor: pointer; transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease;
  display: flex; flex-direction: column; gap: 10px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  position: relative; overflow: hidden;
}
.topic-card::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(120, 170, 255, 0.08) 50%, transparent 70%);
  opacity: 0; transition: opacity .25s ease;
}
.topic-card:hover { transform: translateY(-4px); border-color: var(--neon); box-shadow: var(--glow); }
.topic-card:hover::before { opacity: 1; }
.topic-card h3 { margin: 0; font-size: 18px; color: var(--ink); font-weight: 700; }
.topic-card .num { font-size: 13px; color: var(--neon); font-weight: 800; letter-spacing: 1.5px; }
.topic-card .stats { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.topic-card .stats span {
  background: var(--btn-bg); border: 1px solid var(--line);
  border-radius: 20px; padding: 3px 11px;
}
.topic-card .stats b { color: var(--neon); }

#topic-toolbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: 12px 16px; margin-bottom: 18px; position: sticky; top: 62px; z-index: 40;
}
#search {
  flex: 1; min-width: 220px; font-size: 16px; padding: 10px 14px;
  background: var(--search-bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
}
#search::placeholder { color: var(--muted); }
#search:focus { outline: none; border-color: var(--neon); box-shadow: 0 0 0 3px var(--line); }
.switch { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink-dim); cursor: pointer; }
.switch input { accent-color: var(--neon); width: 17px; height: 17px; cursor: pointer; }

#topic-layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
#chapter-nav {
  position: sticky; top: 118px; display: flex; flex-direction: column; gap: 2px;
  max-height: 74vh; overflow: auto; padding-right: 6px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
#chapter-nav a {
  text-decoration: none; color: var(--ink-dim); font-size: 14px; padding: 7px 12px;
  border-radius: 8px; border-left: 3px solid transparent; transition: all .12s ease;
}
#chapter-nav a:hover { background: var(--btn-bg); color: var(--ink); }
#chapter-nav a.active {
  background: var(--btn-bg); border-left-color: var(--neon);
  color: var(--neon); font-weight: 700;
}

.chapter { scroll-margin-top: 120px; margin-bottom: 10px; }
.chapter-head {
  background: var(--head-grad);
  color: #fff; border-radius: 14px 14px 0 0; padding: 12px 18px;
  font-size: 16.5px; font-weight: 700; display: flex; justify-content: space-between; align-items: center;
  border: 1px solid var(--line); border-bottom: none;
}
.chapter-head .count { font-size: 13px; font-weight: 500; opacity: 0.85; }
.chapter-cards {
  background: var(--panel); border: 1px solid var(--line); border-top: none;
  border-radius: 0 0 14px 14px; padding: 8px 16px 14px; margin-bottom: 26px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}

.item { border-bottom: 1px solid var(--line); padding: 14px 6px; }
.item:last-child { border-bottom: none; }
.qa-q { font-weight: 650; font-size: 17px; color: var(--ink-strong); }
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 800; padding: 2px 9px;
  border-radius: 20px; margin-right: 8px; vertical-align: 2px; letter-spacing: 0.5px;
}
.badge.high {
  background: rgba(217, 119, 6, 0.12); color: var(--gold);
  border: 1px solid var(--gold);
}
.badge.type {
  background: var(--btn-bg); color: var(--neon);
  border: 1px solid var(--line);
}
.qa-a { margin-top: 10px; color: var(--ink-dim); }
.qa-a:empty { display: none; }
.hidden-a { display: none; margin-top: 10px; }
.reveal-btn { margin-top: 10px; font-size: 13.5px; }
.known-btn { margin-top: 10px; margin-left: 8px; font-size: 13.5px; }
.known-btn.done { background: rgba(5, 150, 105, 0.15); border-color: var(--ok); color: var(--ok); }

.img-card img {
  max-width: 100%; max-height: 340px; border-radius: 10px; cursor: zoom-in;
  border: 1px solid var(--line); display: block; margin-top: 8px;
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.25);
}
.img-prompt {
  background: var(--img-prompt-bg); border-left: 3px solid var(--neon2); border-radius: 8px;
  padding: 10px 14px; margin-top: 10px; font-size: 15.5px; color: var(--ink);
}
.note-strip {
  background: var(--note-bg); border-left: 3px solid var(--gold); border-radius: 8px;
  padding: 10px 14px; margin-top: 8px; font-size: 15px; color: var(--note-ink);
}
.rapid-wrap { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-top: 10px; }
.rapid-item {
  background: var(--rapid-bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; font-size: 15px; transition: border-color .15s ease;
}
.rapid-item:hover { border-color: var(--neon); }
.rapid-item .rq { font-weight: 600; color: var(--ink); }
.rapid-item .ra { display: none; margin-top: 6px; color: var(--neon); font-weight: 600; }
.rapid-item.open .ra { display: block; }
.src { font-size: 12px; color: var(--muted); margin-top: 8px; }
.tbl { border-collapse: collapse; width: 100%; margin-top: 10px; font-size: 14.5px; }
.tbl th {
  background: var(--tbl-head-bg); color: var(--neon); font-weight: 700;
  text-align: left; padding: 8px 12px; border: 1px solid var(--line);
}
.tbl td { padding: 8px 12px; border: 1px solid var(--line); color: var(--ink-dim); }
.tbl tr:nth-child(even) td { background: var(--tbl-stripe); }
.tbl td b, .tbl th b { color: var(--ink-strong); }
.sub-head {
  margin: 18px 0 4px; font-size: 15.5px; font-weight: 700; color: var(--violet);
  letter-spacing: 0.3px; padding: 8px 12px; border-left: 3px solid var(--violet);
  background: var(--btn-bg); border-radius: 6px;
}
.md { white-space: pre-wrap; word-break: break-word; }
.md b, .md strong { color: var(--ink-strong); }
code { background: var(--btn-bg); border-radius: 5px; padding: 1px 6px; font-size: 14px; }

#match-count { font-size: 13.5px; color: var(--neon); }
.empty { color: var(--muted); text-align: center; padding: 50px 10px; }

.modal {
  position: fixed; inset: 0; background: var(--modal-veil); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#deck-modal .deck-card {
  background: var(--deck-card-bg); border: 1px solid var(--line);
  border-radius: 18px; max-width: 920px; width: 100%;
  max-height: 92vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
#deck-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: var(--deck-head-bg);
}
#deck-head .btn { color: var(--ink-dim); }
#deck-progress { font-size: 15.5px; color: var(--neon); font-weight: 700; }
#deck-body { flex: 1; overflow: auto; padding: 24px 26px; }
#deck-body .img-card img { max-height: 42vh; }
#deck-foot {
  display: flex; gap: 10px; padding: 14px 20px;
  border-top: 1px solid var(--line); justify-content: space-between; flex-wrap: wrap;
}
#deck-foot .btn { min-width: 110px; }
#lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 10px; }
#lightbox { cursor: zoom-out; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.item, .topic-card { animation: fadeUp 0.3s ease both; }

@media (max-width: 900px) {
  #topic-layout { grid-template-columns: 1fr; }
  #chapter-nav {
    position: static; flex-direction: row; overflow-x: auto; max-height: none; padding-bottom: 8px;
  }
  #chapter-nav a { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  #chapter-nav a.active { border-left: none; border-bottom-color: var(--neon); }
  #topic-toolbar { top: 58px; }
  #app-title { font-size: 17px; }
}
