:root {
  --paper: #f6f7f9;
  --white: #ffffff;
  --ink: #17202e;
  --muted: #5b687d;
  --line: #dfe5ee;
  --rail: #131c2b;
  --rail-card: #1b273b;
  --rail-line: #2a3952;
  --rail-ink: #e8eef7;
  --rail-muted: #93a4be;
  --accent: #0f4c81;
  --wearer: #10b981;
  --other: #ef4444;
  --quiz: #0284c7;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 100vh;
}

/* ---- Left Sidebar Rail ---- */
.rail {
  background: var(--rail);
  color: var(--rail-ink);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 16px 14px;
  border-right: 1px solid var(--rail-line);
  overflow: hidden;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--wearer);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.7);
}

.rail-sub {
  margin: 4px 0 12px;
  font-size: 11.5px;
  color: var(--rail-muted);
  letter-spacing: 0.03em;
}

.rail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.rail-link {
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--rail-card);
  border: 1px solid var(--rail-line);
  color: #cbd5e1;
  font-size: 11.5px;
  font-weight: 600;
}

.rail-link:hover {
  border-color: #38bdf8;
  color: #ffffff;
}

.search-box {
  width: 100%;
  padding: 9px 11px;
  border-radius: 7px;
  border: 1px solid var(--rail-line);
  background: var(--rail-card);
  color: #ffffff;
  margin-bottom: 12px;
}

.search-box::placeholder { color: #7c8ea8; }

.filter-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--rail-muted);
  margin: 6px 0 6px;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.chip {
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid var(--rail-line);
  background: transparent;
  color: #b7c5da;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip:hover { border-color: #64748b; color: #ffffff; }
.chip.active {
  background: var(--wearer);
  border-color: var(--wearer);
  color: #092018;
}

.chip .cnt { opacity: 0.72; font-family: var(--font-mono); font-size: 10.5px; }

.subset-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0 6px;
  font-size: 11px;
  color: var(--rail-muted);
}

.subset-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 4px;
}

.subset-item {
  width: 100%;
  text-align: left;
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: #cbd5e1;
  font-size: 12.2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.subset-item:hover { background: var(--rail-card); color: #ffffff; }
.subset-item.active {
  background: #1e3454;
  border-color: #38bdf8;
  color: #ffffff;
  font-weight: 600;
}

.subset-item .s-lvl {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.09);
  color: #93c5fd;
  flex-shrink: 0;
}

/* ---- Main Stage ---- */
.main {
  padding: 20px 26px 48px;
  min-width: 0;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.topbar-title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.topbar-title p {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.mode-switch {
  display: inline-flex;
  background: #e9eef5;
  padding: 3px;
  border-radius: 9px;
  gap: 3px;
}

.mode-btn {
  padding: 6px 13px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}

.mode-btn.active {
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.mode-btn.active.quiz-on {
  background: var(--quiz);
  color: #ffffff;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--white);
  border: 1px solid var(--line);
  font-size: 12.8px;
  color: var(--muted);
}

.stats-bar strong { color: var(--ink); }

.dl-cmd {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: #f1f5f9;
  padding: 4px 9px;
  border-radius: 6px;
  color: #0f3d68;
}

.copy-mini {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
}

/* ---- Cards Grid ---- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.ep-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
}

.ep-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  border-bottom: 1px solid #edf1f6;
  background: #fbfcfe;
}

.ep-title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--ink);
}

.ep-badges {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}

.b-lvl { background: #e0f2fe; color: #0369a1; }
.b-lens { background: #fef3c7; color: #b45309; }
.b-dom { background: #dcfce7; color: #15803d; }

.ep-imgs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: #0e121a;
}

.ep-img-box {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #0e121a;
  overflow: hidden;
  cursor: zoom-in;
}

.ep-img-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.ep-img-tag {
  position: absolute;
  top: 7px;
  left: 7px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(12, 16, 24, 0.78);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ep-img-tag.exo { color: #38bdf8; }
.ep-img-tag.ego { color: #fbbf24; }

.ep-foot {
  padding: 10px 13px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ep-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.8px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.quiz-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.quiz-prompt {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  margin-right: 4px;
}

.cand-btn {
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.cand-btn:hover { border-color: var(--quiz); background: #e0f2fe; }
.cand-btn.correct { background: #10b981; border-color: #10b981; color: #ffffff; }
.cand-btn.wrong { background: #fee2e2; border-color: #ef4444; color: #b91c1c; }

.reveal-btn {
  margin-left: auto;
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
}

.quiz-feedback {
  font-size: 12px;
  font-weight: 700;
}
.quiz-feedback.ok { color: #059669; }
.quiz-feedback.bad { color: #dc2626; }

/* ---- Lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(9, 13, 20, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 94vw;
  max-height: 90vh;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

@media (max-width: 1120px) {
  .cards-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .subset-list { max-height: 220px; }
}
