:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #5b6b7b;
  --border: #e3e8ef;
  --sidebar-bg: #0f2038;
  --sidebar-text: #cdd7e4;
  --sidebar-active: #ffffff;
  --accent: #2563eb;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --maxw: 900px;

  /* Per-unit accent colors (mirroring the book's color coding) */
  --u1: #e0533d; /* Trigonometry  */
  --u2: #1f9d8f; /* Scalar Product */
  --u3: #3b82f6; /* Counting */
  --u4: #8b5cf6; /* Sequences */
  --u5: #d97706; /* Functions */
  --u6: #0ea5e9; /* Differential Calculus */
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
}

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1.5rem 1rem 3rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: block;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.3;
  margin-bottom: 0.25rem;
}
.sidebar .brand small {
  display: block;
  font-weight: 400;
  font-size: 0.78rem;
  color: #8ea3bd;
  margin-top: 0.25rem;
}

.sidebar nav { margin-top: 1.5rem; }
.sidebar .nav-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7d92ad;
  margin: 1.25rem 0.5rem 0.5rem;
}
.sidebar a.nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  font-size: 0.92rem;
  transition: background 0.15s, color 0.15s;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar a.nav-link.active { background: rgba(255,255,255,0.12); color: var(--sidebar-active); font-weight: 600; }
.sidebar a.nav-link .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 2.5rem clamp(1rem, 4vw, 3.5rem) 5rem;
}
.content-inner { max-width: var(--maxw); margin: 0 auto; }

/* ---------- Topbar (mobile) ---------- */
.topbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  background: var(--sidebar-bg);
  color: #fff;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .menu-btn {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  font-size: 1.25rem;
  width: 40px; height: 40px;
  border-radius: 8px;
  cursor: pointer;
}
.topbar .topbar-title { font-weight: 600; }

/* ---------- Headings & text ---------- */
h1 { font-size: clamp(1.7rem, 3vw, 2.3rem); line-height: 1.2; margin: 0 0 0.5rem; }
h2 {
  font-size: 1.45rem;
  margin: 2.5rem 0 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
h3 { font-size: 1.15rem; margin: 1.75rem 0 0.5rem; }
p { margin: 0.75rem 0; }
a { color: var(--accent); }
ul, ol { margin: 0.5rem 0 1rem; padding-left: 1.4rem; }
li { margin: 0.3rem 0; }
code {
  background: #eef1f6;
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
  font-size: 0.9em;
}

.lead { font-size: 1.1rem; color: var(--muted); }

.unit-tag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

/* ---------- Callout boxes ---------- */
.box {
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
  box-shadow: var(--shadow);
}
.box .box-title {
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.box.definition { border-left-color: #2563eb; }
.box.definition .box-title { color: #2563eb; }
.box.formula { border-left-color: #7c3aed; background: #faf8ff; }
.box.formula .box-title { color: #7c3aed; }
.box.example { border-left-color: #059669; background: #f3fbf7; }
.box.example .box-title { color: #059669; }
.box.tip { border-left-color: #d97706; background: #fffaf1; }
.box.tip .box-title { color: #b45309; }
.box.recall { border-left-color: #64748b; background: #f8fafc; }
.box.recall .box-title { color: #475569; }

/* ---------- Practice / solutions ---------- */
.practice { margin: 1.25rem 0; }
.practice ol { padding-left: 1.4rem; }
details.solution {
  margin: 0.6rem 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  padding: 0 0.9rem;
}
details.solution > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  padding: 0.6rem 0;
  list-style: none;
}
details.solution > summary::-webkit-details-marker { display: none; }
details.solution > summary::before { content: "\25B6"; font-size: 0.7rem; margin-right: 0.5rem; }
details.solution[open] > summary::before { content: "\25BC"; }
details.solution .sol-body { padding: 0 0 0.9rem; border-top: 1px solid var(--border); margin-top: -1px; }

/* ---------- Cards (home) ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.1rem;
  margin: 1.5rem 0;
}
.unit-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
  border-top: 4px solid var(--accent);
}
.unit-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(16,24,40,0.12); }
.unit-card .card-num {
  font-size: 0.8rem; font-weight: 700; color: var(--muted);
}
.unit-card h3 { margin: 0.3rem 0 0.4rem; }
.unit-card p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.vol-badge {
  display: inline-block;
  font-size: 0.72rem;
  background: #eef1f6;
  color: var(--muted);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  margin-top: 0.75rem;
}

/* ---------- Tables ---------- */
table.data {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 0.95rem;
}
table.data th, table.data td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  text-align: center;
}
table.data th { background: #f1f5f9; font-weight: 700; }

/* ---------- Pager ---------- */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.pager a {
  text-decoration: none;
  color: var(--accent);
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  max-width: 48%;
}
.pager a.next { margin-left: auto; text-align: right; }
.pager a small { display: block; color: var(--muted); font-weight: 400; font-size: 0.78rem; }

.footer-note {
  margin-top: 3rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

/* ---------- Overlay for mobile nav ---------- */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 25;
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; }
  .content { padding-top: 1.5rem; }
}
