/* ===================================================================
   ME 200: Thermodynamics I - Open Textbook Web Stylesheet
   Modern, accessible design with distinct callouts & dark mode support
   =================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'Fira Code', 'Cascadia Code', Consolas, Monaco, monospace;
  --header-height: 70px;

  /* Light Theme */
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-code: #f1f5f9;
  --bg-code-output: #f8fafc;
  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-heading: #0f172a;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;

  /* Distinct Callout Palettes */
  /* Example (Warm Amber) */
  --callout-example-bg: #fffbeb;
  --callout-example-border: #f59e0b;
  --callout-example-subtle: #fef3c7;
  --callout-example-title: #b45309;

  /* Practice Problem (Deep Indigo / Purple) */
  --callout-practice-bg: #eef2ff;
  --callout-practice-border: #6366f1;
  --callout-practice-subtle: #e0e7ff;
  --callout-practice-title: #4338ca;

  /* Definition (Academic Navy) */
  --callout-def-bg: #eff6ff;
  --callout-def-border: #3b82f6;
  --callout-def-subtle: #dbeafe;
  --callout-def-title: #1e40af;

  /* Key Idea (Emerald) */
  --callout-key-bg: #ecfdf5;
  --callout-key-border: #10b981;
  --callout-key-subtle: #d1fae5;
  --callout-key-title: #047857;

  /* Caution / Warning (Crimson) */
  --callout-caution-bg: #fef2f2;
  --callout-caution-border: #ef4444;
  --callout-caution-subtle: #fee2e2;
  --callout-caution-title: #b91c1c;

  /* Solution / Analysis (Slate) */
  --callout-sol-bg: #f8fafc;
  --callout-sol-border: #64748b;
  --callout-sol-subtle: #e2e8f0;
  --callout-sol-title: #334155;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.06);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.06);

  --sidebar-width: 320px;
}

[data-theme="dark"] {
  --bg-page: #090d16;
  --bg-surface: #0f172a;
  --bg-sidebar: #0b1120;
  --bg-card: #131d35;
  --bg-code: #162036;
  --bg-code-output: #0d1527;
  --border-color: #1e293b;
  --border-subtle: #334155;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --text-heading: #f8fafc;
  --primary: #38bdf8;
  --primary-hover: #7dd3fc;
  --primary-light: #082f49;

  /* Dark Theme Callouts */
  --callout-example-bg: #221a08;
  --callout-example-border: #d97706;
  --callout-example-subtle: #451a03;
  --callout-example-title: #fbbf24;

  --callout-practice-bg: #151638;
  --callout-practice-border: #818cf8;
  --callout-practice-subtle: #312e81;
  --callout-practice-title: #a5b4fc;

  --callout-def-bg: #0c1a3a;
  --callout-def-border: #60a5fa;
  --callout-def-subtle: #1e3a8a;
  --callout-def-title: #93c5fd;

  --callout-key-bg: #062319;
  --callout-key-border: #34d399;
  --callout-key-subtle: #064e3b;
  --callout-key-title: #6ee7b7;

  --callout-caution-bg: #290d0d;
  --callout-caution-border: #f87171;
  --callout-caution-subtle: #7f1d1d;
  --callout-caution-title: #fca5a5;

  --callout-sol-bg: #111827;
  --callout-sol-border: #94a3b8;
  --callout-sol-subtle: #374151;
  --callout-sol-title: #cbd5e1;
}

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

html {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  scroll-behavior: smooth;
  line-height: 1.7;
}

body {
  display: block;
  min-height: 100vh;
}

.book-layout {
  display: flex;
  min-height: calc(100vh - var(--header-height));
}

/* Reading Progress Bar */
#progress-bar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, #0284c7, #6366f1, #f59e0b);
  width: 0%;
  z-index: 9999;
  transition: width 0.1s;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.book-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  margin-bottom: 0.5rem;
}

.book-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-heading);
  line-height: 1.3;
}

.book-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Download Action Badges */
.download-links {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.dl-btn {
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  background: var(--bg-surface);
  transition: all 0.15s ease;
}

.dl-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Sidebar Search */
.sidebar-search {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.search-input {
  width: 100%;
  padding: 0.5rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--primary);
}

/* Navigation List */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
  margin-bottom: 0.15rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.86rem;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--bg-page);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
}

.chapter-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 2.2rem;
  font-variant-numeric: tabular-nums;
}

.nav-item.active .chapter-num {
  color: var(--primary);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Main Content Area */
.main-content {
  flex: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 2.5rem 3rem 5rem;
  overflow-y: auto;
}

@media (max-width: 1024px) {
  .main-content {
    padding: 2rem 1.5rem;
  }
}

/* Top bar for mobile chapter sidebar toggle */
.top-nav {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: var(--header-height);
  z-index: 90;
}

@media (max-width: 860px) {
  .top-nav {
    display: flex;
  }
  .sidebar {
    position: fixed;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 25px rgba(0,0,0,0.3);
  }
}

.mobile-menu-btn {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  color: var(--text-main);
  cursor: pointer;
  font-size: 1rem;
}

/* Typography */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text-heading);
  font-weight: 700;
  line-height: 1.3;
}

h1 {
  font-size: 2.1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border-color);
}

h2 {
  font-size: 1.5rem;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

h3 {
  font-size: 1.2rem;
  margin-top: 1.8rem;
  margin-bottom: 0.75rem;
}

p {
  margin-bottom: 1.2rem;
}

ul, ol {
  margin-bottom: 1.2rem;
  padding-left: 1.8rem;
}

li {
  margin-bottom: 0.4rem;
}

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

a:hover {
  text-decoration: underline;
}

/* Images and Figures */
img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 1.5rem auto 0.5rem;
  box-shadow: var(--shadow-sm);
}

img[src*="course_structure_flowchart"] {
  width: 100%;
  max-width: 920px;
  margin: 2.5rem auto 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  background: #ffffff;
  padding: 0.75rem;
  border-radius: 8px;
}

em:has(+ img), p > em {
  display: block;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ===================================================================
   DISTINCT CALLOUT BOXES (Inspired by Open Textbook Library)
   =================================================================== */

.callout {
  margin: 1.8rem 0;
  padding: 1.1rem 1.4rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  border-left-width: 5px;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout::before {
  display: block;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

/* Example (Warm Amber) */
.callout-example {
  background: var(--callout-example-bg);
  border-color: var(--callout-example-subtle);
  border-left-color: var(--callout-example-border);
}
.callout-example::before {
  content: "💡 EXAMPLE";
  color: var(--callout-example-title);
}

/* Practice Problem (Deep Indigo / Purple) */
.callout-practice {
  background: var(--callout-practice-bg);
  border-color: var(--callout-practice-subtle);
  border-left-color: var(--callout-practice-border);
}
.callout-practice::before {
  content: "✏️ PRACTICE PROBLEM";
  color: var(--callout-practice-title);
}

/* Definition (Academic Navy) */
.callout-definition {
  background: var(--callout-def-bg);
  border-color: var(--callout-def-subtle);
  border-left-color: var(--callout-def-border);
}
.callout-definition::before {
  content: "📖 DEFINITION";
  color: var(--callout-def-title);
}

/* Key Idea (Emerald) */
.callout-keyidea {
  background: var(--callout-key-bg);
  border-color: var(--callout-key-subtle);
  border-left-color: var(--callout-key-border);
}
.callout-keyidea::before {
  content: "🔑 KEY IDEA";
  color: var(--callout-key-title);
}

/* Caution / Warning (Crimson) */
.callout-caution {
  background: var(--callout-caution-bg);
  border-color: var(--callout-caution-subtle);
  border-left-color: var(--callout-caution-border);
}
.callout-caution::before {
  content: "⚠️ CAUTION";
  color: var(--callout-caution-title);
}

/* Solution (Slate) */
.callout-solution {
  background: var(--callout-sol-bg);
  border-color: var(--callout-sol-subtle);
  border-left-color: var(--callout-sol-border);
}
.callout-solution::before {
  content: "📝 SOLUTION / ANALYSIS";
  color: var(--callout-sol-title);
}

/* Note (Generic) */
.callout-note {
  background: var(--bg-card);
  border-left-color: var(--primary);
}
.callout-note::before {
  content: "📌 NOTE";
  color: var(--primary);
}

/* Code Blocks & Copy Button */
div.sourceCode {
  position: relative;
  margin: 1.2rem 0;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1.2rem 0;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  position: relative;
}

div.sourceCode pre {
  margin: 0;
  padding-top: 2.25rem;
}

.code-copy-btn {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.code-copy-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

.code-copy-btn.copied {
  color: #047857;
  border-color: #10b981;
  background: #d1fae5;
}

/* Chapter Notebook Action Bar */
.chapter-notebook-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 0.75rem 1.15rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.chapter-notebook-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.chapter-notebook-info code {
  font-size: 0.8rem;
  color: var(--primary);
}

.ipynb-dl-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem 0.9rem;
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff !important;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none !important;
  transition: background 0.15s ease, transform 0.15s ease;
}

.ipynb-dl-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-code);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

pre code {
  background: none;
  padding: 0;
}

pre.text {
  background: var(--bg-code-output);
  border-left: 3px solid var(--border-subtle);
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* Citations & Bibliography */
.citation {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  font-weight: 500;
}

.references {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.csl-entry {
  margin-bottom: 0.75rem;
  padding-left: 1.5rem;
  text-indent: -1.5rem;
  font-size: 0.9rem;
}

/* Prev / Next Footer Navigation Cards */
.chapter-nav-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

@media (max-width: 600px) {
  .chapter-nav-footer {
    grid-template-columns: 1fr;
  }
}

.nav-card {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
  text-decoration: none;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.nav-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

.nav-card-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-card-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-top: 0.25rem;
}

.nav-card.next {
  text-align: right;
  grid-column: 2;
}

@media (max-width: 600px) {
  .nav-card.next {
    grid-column: 1;
  }
}

/* Landing Page TOC */
.toc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.toc-card {
  padding: 1rem 1.2rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
  text-decoration: none;
  transition: all 0.2s;
}

.toc-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.toc-card-num {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--primary);
}

.toc-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-top: 0.25rem;
}

/* Expandable Self-Study Solution Blocks (Site-Wide Standard) */
details {
  margin: 0.85rem 0 1.35rem 0;
  padding: 0.75rem 1.1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
}

details summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 0.95rem;
  user-select: none;
}

details[open] summary {
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

details ol,
details ul {
  margin: 0.5rem 0 0.25rem 1.35rem;
}

details p {
  margin: 0.45rem 0;
}
