/* Algorithms — Interactive Textbook Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,wght@0,300;0,400;0,600;0,700;1,400;1,600&family=Source+Sans+3:wght@400;600;700&family=Source+Code+Pro:wght@400;500&display=swap');

:root {
  --bg: #fafaf8;
  --bg-sidebar: #1a1a2e;
  --bg-sidebar-hover: #16213e;
  --text: #2c2c2c;
  --text-light: #555;
  --text-sidebar: #c8c8d4;
  --text-sidebar-active: #ffffff;
  --accent: #0f3460;
  --accent-light: #1a5276;
  --accent-bright: #e94560;
  --border: #ddd;
  --bg-box: #f4f6f9;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --max-content: 780px;
  --sidebar-width: 300px;
}

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

html { font-size: 17px; scroll-behavior: smooth; }

body {
  font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.75;
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  padding: 2rem 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s ease;
}

#sidebar .book-title {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-sidebar-active);
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 1rem;
  line-height: 1.3;
}

#sidebar .book-title span {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-sidebar);
  margin-top: 0.3rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#sidebar nav ul {
  list-style: none;
}

#sidebar nav a {
  display: block;
  padding: 0.4rem 1.5rem;
  color: var(--text-sidebar);
  text-decoration: none;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.88rem;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

#sidebar nav a:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-sidebar-active);
  border-left-color: var(--accent-bright);
}

#sidebar nav a.active {
  background: var(--bg-sidebar-hover);
  color: var(--text-sidebar-active);
  border-left-color: var(--accent-bright);
  font-weight: 600;
}

#sidebar nav .part-label {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-bright);
  padding: 1rem 1.5rem 0.3rem;
}

/* ===== MAIN CONTENT ===== */
#content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 3rem 3rem 5rem;
  max-width: calc(var(--max-content) + 6rem + var(--sidebar-width));
}

#content > * { max-width: var(--max-content); }

/* ===== TYPOGRAPHY ===== */
h1 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.5rem;
  line-height: 1.2;
}

.chapter-title {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text-light);
  margin-bottom: 2rem;
}

.part-header {
  background: var(--bg-sidebar);
  color: var(--text-sidebar-active);
  padding: 2.5rem;
  margin: 3rem 0 1.5rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.part-header h2 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  border-bottom: none;
  padding-bottom: 0;
  color: var(--text-sidebar-active);
}

.part-header p {
  margin: 0;
  font-size: 1rem;
  opacity: 0.85;
}

h2 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid var(--border);
}

h3 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent-light);
  margin: 1.8rem 0 0.8rem;
}

h4 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 1.5rem 0 0.5rem;
}

p { margin-bottom: 1rem; }

ul {
  margin: 1rem 0 1.5rem 2rem;
}

li {
  margin-bottom: 0.4rem;
}

pre {
  background: var(--bg-box);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2rem;
  margin: 1.5rem 0;
  overflow-x: auto;
}

code {
  font-family: 'Source Code Pro', Courier, monospace;
  font-size: 0.9rem;
  color: #333;
}

/* ===== PAGE CARDS ===== */
.page-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2.5rem;
  margin: 2rem 0;
  box-shadow: var(--shadow);
  page-break-after: always;
}

.page-number {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-bright);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

.page-content {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.8;
}

/* ===== HAMBURGER (mobile) ===== */
#menu-toggle {
  display: none;
  position: fixed;
  top: 1rem; left: 1rem;
  z-index: 200;
  background: var(--bg-sidebar);
  color: #fff;
  border: none;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  font-size: 1.3rem;
  cursor: pointer;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #content { margin-left: 0; padding: 4rem 1.5rem 3rem; }
  #menu-toggle { display: block; }
}

/* ===== PRINT ===== */
@media print {
  body { background: white; color: black; }
  #sidebar, #menu-toggle { display: none; }
  #content { margin-left: 0; max-width: 100%; padding: 0; }
  .page-card {
    border: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }
}
