:root {
  --bg: #f7f8f6;
  --surface: #ffffff;
  --text: #1a1f1c;
  --muted: #5a6560;
  --border: #d8e0db;
  --accent: #306998;
  --accent-dark: #1e4d73;
  --python-yellow: #ffd43b;
  --code-bg: #1e2430;
  --code-text: #e8eef5;
  --sidebar-w: 280px;
  --header-h: 56px;
  --link: #2a6f97;
  --success: #3776ab;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.site-header a {
  color: #fff;
  text-decoration: none;
}

.site-header .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent-dark) 50%, var(--python-yellow) 50%);
  display: inline-block;
}

.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.header-links {
  margin-left: auto;
  display: flex;
  gap: 1.25rem;
  font-size: 0.95rem;
}

/* Layout */
.layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  padding: 1rem 0 2rem;
}

.sidebar h3 {
  margin: 1.25rem 1rem 0.4rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar a {
  display: block;
  padding: 0.4rem 1.1rem;
  color: var(--text);
  font-size: 0.92rem;
  border-left: 3px solid transparent;
}

.sidebar a:hover {
  background: #eef3f0;
  text-decoration: none;
}

.sidebar a.active {
  background: #e3eef6;
  border-left-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 600;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 1.75rem 2rem 3rem;
  max-width: 860px;
}

.content h1 {
  margin: 0 0 0.75rem;
  font-size: 2rem;
  color: var(--accent-dark);
  line-height: 1.25;
}

.content h2 {
  margin: 2rem 0 0.75rem;
  font-size: 1.35rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
}

.content h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.1rem;
}

.content p {
  margin: 0.75rem 0;
}

.content ul,
.content ol {
  margin: 0.5rem 0 1rem;
  padding-left: 1.4rem;
}

.content li {
  margin: 0.35rem 0;
}

.lead {
  font-size: 1.1rem;
  color: var(--muted);
}

.note {
  background: #eef5fb;
  border-left: 4px solid var(--accent);
  padding: 0.85rem 1rem;
  margin: 1.25rem 0;
  border-radius: 0 6px 6px 0;
}

.example {
  margin: 1.25rem 0;
}

.example-label {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.7rem;
  border-radius: 4px 4px 0 0;
}

pre {
  margin: 0;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 1rem 1.15rem;
  border-radius: 0 6px 6px 6px;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

code {
  font-family: "SF Mono", "Fira Code", "Consolas", "Menlo", monospace;
  font-size: 0.9em;
}

p code,
li code,
td code,
th code {
  background: #e8eee9;
  color: #1e4d73;
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

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

pre code.hljs {
  color: #d4d4d4;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.5rem;
  font-size: 0.95rem;
  background: var(--surface);
}

th,
td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

th {
  background: #e8f0e9;
  font-weight: 600;
}

tr:nth-child(even) td {
  background: #fafbfa;
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.pager a {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  font-weight: 600;
  text-decoration: none;
}

.pager a:hover {
  background: var(--accent-dark);
  text-decoration: none;
}

.pager .spacer {
  flex: 1;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.topic-grid a {
  display: block;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-weight: 600;
}

.topic-grid a:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
  text-decoration: none;
}

.hero-cta {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.75rem 1.4rem;
  background: var(--accent);
  color: #fff !important;
  border-radius: 4px;
  font-weight: 700;
  text-decoration: none !important;
}

.hero-cta:hover {
  background: var(--accent-dark);
}

/* Collapsible exam solutions */
.solution-reveal {
  margin: 1rem 0 1.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.solution-reveal > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 0.85rem 1.1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.solution-reveal > summary::-webkit-details-marker {
  display: none;
}

.solution-reveal > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s ease;
}

.solution-reveal[open] > summary::before {
  transform: rotate(90deg);
}

.solution-reveal > summary:hover {
  background: var(--accent-dark);
}

.solution-reveal .when-open {
  display: none;
}

.solution-reveal[open] .when-closed {
  display: none;
}

.solution-reveal[open] .when-open {
  display: inline;
}

.solution-reveal .solution-body {
  padding: 1rem 1.1rem 1.15rem;
  border-top: 1px solid var(--border);
}

.solution-reveal .solution-body .example {
  margin-bottom: 0;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 900px) {
  .menu-toggle {
    display: inline-block;
  }

  .header-links {
    display: none;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-h);
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.12);
  }

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

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: var(--header-h) 0 0 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 80;
  }

  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  .content {
    padding: 1.25rem 1rem 2.5rem;
  }

  .pager {
    flex-direction: column;
  }
}
