/* ===== DESIGN TOKENS ===== */
:root {
  --bg: #FAFAF8;
  --text: #1A1A1A;
  --text-secondary: rgba(26,26,26,0.7);
  --text-tertiary: rgba(26,26,26,0.5);
  --accent: #5B6CFF;
  --accent-bg: rgba(91,108,255,0.06);
  --accent-border: rgba(91,108,255,0.25);
  --divider: #E8E8E5;
  --card-bg: #FFFFFF;
  --code-bg: #1E1E2E;
  --code-text: #E8E8E6;
  --hover-bg: rgba(0,0,0,0.03);
  --sidebar-bg: #FFFFFF;
  --topbar-bg: rgba(250,250,248,0.92);
  --green: #16a34a;
  --green-bg: rgba(22,163,74,0.1);
  --amber: #d97706;
  --amber-bg: rgba(217,119,6,0.1);
  --red: #dc2626;
  --red-bg: rgba(220,38,38,0.1);
}

[data-theme="dark"] {
  --bg: #121212;
  --text: #E8E8E6;
  --text-secondary: rgba(232,232,230,0.7);
  --text-tertiary: rgba(232,232,230,0.5);
  --accent: #5B6CFF;
  --accent-bg: rgba(91,108,255,0.1);
  --accent-border: rgba(91,108,255,0.3);
  --divider: #2A2A2A;
  --card-bg: #1A1A1A;
  --code-bg: #0D0D0D;
  --code-text: #D4D4D4;
  --hover-bg: rgba(255,255,255,0.04);
  --sidebar-bg: #161616;
  --topbar-bg: rgba(18,18,18,0.92);
  --green: #4ade80;
  --green-bg: rgba(74,222,128,0.12);
  --amber: #fbbf24;
  --amber-bg: rgba(251,191,36,0.12);
  --red: #f87171;
  --red-bg: rgba(248,113,113,0.12);
}

/* ===== RESET & BASE ===== */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 200ms ease, color 200ms ease;
}

/* ===== LAYOUT ===== */
.app {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--divider);
  position: fixed;
  left: 0; top: 0; bottom: 0;
  overflow-y: auto;
  padding: 24px 16px;
  z-index: 20;
  transition: transform 0.22s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.brand-text {
  font-weight: 700;
  font-size: 15px;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  letter-spacing: 0.2px;
}

/* --- Navigation --- */
.nav {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 150ms ease, color 150ms ease;
}

.nav a .nav-icon {
  font-size: 16px;
  opacity: 0.6;
  width: 22px;
  text-align: center;
  transition: opacity 150ms ease;
}

.nav a:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.nav a:hover .nav-icon {
  opacity: 0.85;
}

.nav a.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.nav a.active .nav-icon {
  opacity: 1;
}

.section-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 400;
}

.nav a.active .section-count {
  color: var(--accent);
  opacity: 0.7;
}

/* Sidebar stats */
.sidebar-stats {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--divider);
}

.sidebar-stats-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.stats-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.ring {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) 0deg, var(--divider) 0deg);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  position: relative;
}

.ring::after {
  content: '';
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--sidebar-bg);
  position: absolute;
}

.ring span {
  position: relative;
  z-index: 1;
}

.stat-block .stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

.stat-block .stat-value {
  font-weight: 700;
  font-size: 18px;
}

.sidebar-tip {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.5;
}

/* --- Topbar --- */
.topbar {
  position: fixed;
  left: 260px; right: 0; top: 0;
  height: 60px;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  z-index: 15;
}

.hamburger {
  display: none;
  background: none;
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: background 150ms;
}

.hamburger:hover {
  background: var(--hover-bg);
}

.search-box {
  flex: 1;
  max-width: 480px;
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 0 12px;
  gap: 8px;
  transition: border-color 200ms;
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.search-box svg {
  width: 16px; height: 16px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.search-box input {
  background: transparent;
  border: 0;
  color: var(--text);
  outline: none;
  width: 100%;
  font-size: 14px;
  font-family: inherit;
  padding: 8px 0;
}

.search-box input::placeholder {
  color: var(--text-tertiary);
}

.search-clear {
  background: none;
  border: 0;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  border-radius: 4px;
  transition: color 150ms;
  display: none;
}

.search-clear.visible {
  display: block;
}

.search-clear:hover {
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.theme-toggle {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  transition: background 150ms;
  display: flex;
  align-items: center;
}

.theme-toggle:hover {
  background: var(--hover-bg);
}

.topbar-stat {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* --- Content --- */
.content {
  margin-left: 260px;
  padding: 84px 48px 64px;
  flex: 1;
  min-height: 100vh;
}

.content-inner {
  max-width: 760px;
  margin: 0 auto;
}

/* ===== TYPOGRAPHY ===== */
.page-title {
  font-size: 30px;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

h2.section-heading {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 4px;
}

.section-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ===== DASHBOARD ===== */
.dashboard-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.dashboard-stat {
  text-align: right;
}

.dashboard-stat .stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 500;
}

.dashboard-stat .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.dashboard-card {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 16px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 150ms, box-shadow 150ms;
  display: block;
}

.dashboard-card:hover {
  border-color: var(--accent-border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.dashboard-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.dashboard-card-icon {
  font-size: 20px;
  width: 28px;
  text-align: center;
}

.dashboard-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.dashboard-card .card-count {
  font-size: 13px;
  color: var(--text-secondary);
}

.progress-bar {
  height: 6px;
  background: var(--divider);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
  width: 0%;
  transition: width 300ms ease;
}

/* ===== TOPIC CARDS ===== */
.cards-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topic-card {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 150ms;
}

.topic-card:hover {
  border-color: var(--accent-border);
}

.topic-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 150ms;
}

.topic-header:hover {
  background: var(--hover-bg);
}

.topic-title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.topic-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  background: var(--hover-bg);
  padding: 3px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.topic-revised {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.topic-revised label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.topic-revised input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.topic-chevron {
  color: var(--text-tertiary);
  font-size: 12px;
  transition: transform 200ms ease;
  flex-shrink: 0;
  margin-left: 4px;
}

.topic-card.open .topic-chevron {
  transform: rotate(180deg);
}

.topic-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 300ms ease, opacity 200ms ease;
  opacity: 0;
  padding: 0 16px;
}

.topic-card.open .topic-body {
  max-height: 8000px;
  opacity: 1;
  padding: 0 16px 16px;
}

/* ===== QUICK RECALL CALLOUT ===== */
.quick-recall {
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  border-radius: 0 6px 6px 0;
  padding: 10px 14px;
  margin: 8px 0 12px;
}

.quick-recall-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.8;
  margin-bottom: 2px;
}

.quick-recall-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
}

/* ===== BODY CONTENT ===== */
.body-content {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.body-content b,
.body-content strong {
  color: var(--text);
  font-weight: 600;
}

.body-content ul,
.body-content ol {
  padding-left: 20px;
  margin: 8px 0;
}

.body-content li {
  margin: 4px 0;
}

.body-content code {
  font-family: var(--font-code, 'JetBrains Mono', monospace);
  font-size: 13px;
  background: var(--hover-bg);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--divider);
}

/* Signal/when-to-use line */
.topic-signal {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.topic-signal strong {
  color: var(--text-secondary);
}

/* Core idea */
.topic-core {
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 12px;
}

.topic-core strong {
  color: var(--text);
}

/* ===== CODE BLOCKS ===== */
.code-wrap {
  position: relative;
  margin: 10px 0;
}

.code-lang {
  position: absolute;
  top: 8px; left: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  font-family: 'JetBrains Mono', monospace;
  pointer-events: none;
  z-index: 1;
}

.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  transition: background 150ms, color 150ms;
  z-index: 1;
}

.copy-btn:hover {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
}

.copy-btn.copied {
  color: var(--green);
}

pre {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 8px;
  padding: 32px 16px 16px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0;
  border: 1px solid var(--divider);
}

pre code {
  background: none;
  padding: 0;
  border: none;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
}

/* ===== TABLES ===== */
.topic-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 10px 0;
}

.topic-card th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 8px 12px;
  border-bottom: 2px solid var(--divider);
  background: transparent;
}

.topic-card td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--divider);
  color: var(--text-secondary);
  vertical-align: top;
}

.topic-card tr:last-child td {
  border-bottom: none;
}

.topic-card tr:nth-child(even) td {
  background: var(--hover-bg);
}

.topic-card td code,
.topic-card td .mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

.topic-card td b,
.topic-card td strong {
  color: var(--text);
  font-weight: 600;
}

/* Standalone table container (complexity tables, etc) */
.table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
  overflow-x: auto;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-wrap th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 8px 10px;
  border-bottom: 2px solid var(--divider);
}

.table-wrap td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--divider);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-secondary);
}

.table-wrap tr:last-child td {
  border-bottom: none;
}

.table-wrap td:first-child {
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
}

/* ===== COMPLEXITY BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
}

.badge.green {
  background: var(--green-bg);
  color: var(--green);
}

.badge.amber {
  background: var(--amber-bg);
  color: var(--amber);
}

.badge.red {
  background: var(--red-bg);
  color: var(--red);
}

/* Complexity meta row */
.topic-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.topic-meta strong {
  color: var(--text);
}

/* Problems list */
.topic-problems {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.topic-problems strong {
  color: var(--text);
}

/* Gotchas */
.topic-gotchas {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

.topic-gotchas strong {
  color: var(--text-secondary);
}

/* ===== STICKY SUBNAV ===== */
.sticky-subnav {
  position: sticky;
  top: 60px;
  background: var(--bg);
  padding: 12px 0;
  margin-bottom: 16px;
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  z-index: 10;
  border-bottom: 1px solid var(--divider);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.sticky-subnav::-webkit-scrollbar {
  height: 3px;
}

.sticky-subnav::-webkit-scrollbar-thumb {
  background: var(--divider);
  border-radius: 3px;
}

.topic-card {
  scroll-margin-top: 120px;
}

.sticky-subnav a {
  flex-shrink: 0;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-decoration: none;
  background: var(--card-bg);
  border: 1px solid var(--divider);
  transition: background 150ms, color 150ms;
}

.sticky-subnav a:hover {
  color: var(--text);
  background: var(--hover-bg);
}

/* ===== SECTION PROGRESS BAR (top of section pages) ===== */
.section-progress {
  margin-bottom: 24px;
}

.section-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-tertiary);
}

.section-progress-info .count {
  font-weight: 600;
  color: var(--text-secondary);
}

/* ===== FOCUS & ACCESSIBILITY ===== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Remove default focus outline when not using keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-110%);
    top: 60px;
    z-index: 30;
    width: 260px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 25;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .topbar {
    left: 0;
    padding: 0 16px;
  }

  .hamburger {
    display: flex;
    align-items: center;
  }

  .content {
    margin-left: 0;
    padding: 76px 16px 48px;
  }

  .content-inner {
    max-width: 100%;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .search-box {
    flex: 1;
    max-width: none;
  }

  .topbar-stat {
    display: none;
  }

  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .dashboard-stat {
    text-align: left;
  }

  .sticky-subnav {
    top: 60px;
  }
}

/* ===== PRINT ===== */
@media print {
  .sidebar, .topbar, .copy-btn, .theme-toggle, .hamburger, .search-box,
  .sidebar-overlay, .topbar-right, .topic-revised, .topic-chevron { display: none !important; }
  .content { margin: 0; padding: 0; }
  .content-inner { max-width: 100%; }
  .topic-body { max-height: none !important; opacity: 1 !important; padding: 0 16px 16px !important; }
  .topic-card { break-inside: avoid; border: 1px solid #ccc; }
  pre { white-space: pre-wrap; }
  body { background: white; color: black; }
}

/* ===== PRISM OVERRIDES ===== */
code[class*="language-"],
pre[class*="language-"] {
  background: var(--code-bg) !important;
  color: var(--code-text) !important;
  font-family: 'JetBrains Mono', monospace !important;
  font-size: 13.5px !important;
  line-height: 1.55 !important;
  text-shadow: none !important;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #6a737d !important;
}

.token.keyword {
  color: #c792ea !important;
}

.token.function {
  color: #82aaff !important;
}

.token.string {
  color: #c3e88d !important;
}

.token.number {
  color: #f78c6c !important;
}

.token.operator {
  color: #89ddff !important;
}

.token.builtin {
  color: #ffcb6b !important;
}

.token.boolean {
  color: #f78c6c !important;
}

.token.punctuation {
  color: #89ddff !important;
}

.token.class-name {
  color: #ffcb6b !important;
}

.token.decorator {
  color: #82aaff !important;
}

/* ===== MISC UTILITY ===== */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
