:root {
  --background: #ffffff;
  --foreground: #0f172a;
  --muted-foreground: #475569;
  --border: #e2e8f0;
  --card: #f8fafc;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-foreground: #ffffff;
  --secondary: #f1f5f9;
  --secondary-foreground: #0f172a;
  --success: #16a34a;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --chart-1: #2563eb;
  --chart-2: #0d9488;
  --chart-3: #7c3aed;
  --chart-4: #d97706;
  --chart-5: #dc2626;
  --chart-6: #64748b;
  --chart-7: #16a34a;
}
[data-theme="dark"] {
  --background: #090e1a;
  --foreground: #f1f5f9;
  --muted-foreground: #94a3b8;
  --border: #1e293b;
  --card: #111827;
  --surface: #0f172a;
  --primary: #3b82f6;
  --primary-foreground: #ffffff;
  --secondary: #1e293b;
  --secondary-foreground: #f1f5f9;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--background);
  color: var(--foreground);
  line-height: 1.68;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
#read-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  z-index: 100;
  transition: width 0.1s linear;
}
/* Top Workspace Bar */
#workspace-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.ws-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--background);
  color: var(--foreground);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.ws-btn:hover:not(:disabled) { background: var(--secondary); }
.ws-btn:disabled { opacity: 0.4; cursor: default; }
.ws-brand {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--foreground);
  margin-right: 4px;
  flex-shrink: 0;
}
#tab-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}
#tab-strip::-webkit-scrollbar { display: none; }
.ws-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  max-width: 190px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ws-tab:hover { background: var(--secondary); color: var(--foreground); }
.ws-tab.active {
  background: var(--card);
  color: var(--foreground);
  border-color: var(--border);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.ws-tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-tab-close {
  border: none;
  background: none;
  color: var(--muted-foreground);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  border-radius: 4px;
}
.ws-tab-close:hover { background: var(--border); color: var(--foreground); }
.ws-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.unlock-pill {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 7px;
  background: var(--primary);
  color: var(--primary-foreground);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.unlock-pill.pro-active { background: var(--success); }

/* App Shell */
.app-shell {
  display: flex;
  flex: 1;
  min-height: 0;
}
aside {
  width: 292px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--card);
  padding: 14px;
  overflow-y: auto;
  height: calc(100vh - 46px);
  position: sticky;
  top: 46px;
  transition: width 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
}
body.sidebar-collapsed aside {
  width: 0;
  padding: 0;
  border-right: none;
  overflow: hidden;
  opacity: 0;
}
main {
  flex: 1;
  min-width: 0;
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 42px 56px;
}
.brand-tag {
  font-size: 11px;
  color: var(--muted-foreground);
  margin-bottom: 12px;
  line-height: 1.4;
}
.filter-row { display: flex; gap: 6px; margin-bottom: 12px; }
#nav-filter {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--foreground);
  font-size: 12.5px;
}
.free-toggle {
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--foreground);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.free-toggle.active {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}
.nav-group { margin-bottom: 8px; }
.nav-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-foreground);
  cursor: pointer;
  text-align: left;
}
.nav-title:hover { color: var(--foreground); }
.nav-group.collapsed ul { display: none; }
aside ul { list-style: none; padding: 0; margin: 2px 0 6px; }
aside li {
  display: flex;
  align-items: center;
  gap: 2px;
}
aside li a {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 7px;
  color: var(--foreground);
  text-decoration: none;
  font-size: 12.5px;
}
aside li a span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
aside li a:hover, aside li a.active { background: var(--secondary); font-weight: 600; }
.tab-open-btn {
  opacity: 0.55;
  border: none;
  background: none;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 5px;
  cursor: pointer;
  flex-shrink: 0;
}
aside li:hover .tab-open-btn { opacity: 1; }
.tab-open-btn:hover { background: var(--secondary); color: var(--foreground); }
.tier-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}
.tier-free { background: rgba(22, 163, 74, 0.14); color: #15803d; }
[data-theme="dark"] .tier-free { color: #4ade80; }
.tier-pro { background: rgba(37, 99, 235, 0.12); color: var(--primary); }
body.pro-unlocked .tier-pro { display: none; }

/* Content Typography & Elements */
h1 { font-size: 28px; letter-spacing: -0.025em; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 20px; letter-spacing: -0.015em; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
h3 { font-size: 16px; margin: 22px 0 8px; }
a { color: var(--primary); text-underline-offset: 2px; }
.src-ref { color: var(--muted-foreground); }
.table-wrap { overflow-x: auto; margin: 14px 0; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { border-bottom: 1px solid var(--border); padding: 8px 12px; text-align: left; }
th { background: var(--card); font-weight: 600; }
tr:last-child td { border-bottom: none; }
details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 10px 0;
  background: var(--card);
  box-shadow: var(--shadow-sm);
}
summary { cursor: pointer; font-weight: 600; }
.callout {
  border-left: 4px solid var(--primary);
  background: var(--card);
  padding: 12px 16px;
  margin: 14px 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.callout-tip { border-color: #16a34a; }
.callout-important { border-color: #d97706; }
pre {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
}
hr { border: none; border-top: 1px solid var(--border); margin: 26px 0; }

/* Sticky Study Toolbar (Drill Decks & Solution Banks only) */
.study-toolbar {
  position: sticky;
  top: 54px;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 14px 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 13px;
}
.study-toolbar button {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--foreground);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.study-toolbar button:hover { background: var(--secondary); }
.study-meter {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
}
.meter-bar {
  width: 96px;
  height: 7px;
  border-radius: 999px;
  background: var(--secondary);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: var(--success);
  transition: width 0.2s ease;
}
.card-master-btn {
  margin-left: 10px;
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--background);
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  vertical-align: middle;
}
.card-master-btn.solved {
  background: rgba(22, 163, 74, 0.14);
  border-color: var(--success);
  color: var(--success);
}

/* Aligned Prev/Next Pager */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.pager a {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  background: var(--card);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pager a:hover { background: var(--secondary); }
.pager-next { text-align: right; grid-column: 2; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  aside {
    width: 100%;
    height: auto;
    max-height: 60vh;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  body.sidebar-collapsed aside { height: 0; border-bottom: none; }
  main { padding: 20px 18px 40px; }
  .pager { grid-template-columns: 1fr; }
  .pager-next { grid-column: 1; text-align: left; }
}
