/* ==========================================================================
   Corporate Valuation — Global Styles & Dark Mode System
   ========================================================================== */

/* --- CSS Custom Properties (Dark Theme Default) --- */
:root,
[data-theme="dark"] {
  --bg: #0f0f1a;
  --bg-secondary: #161625;
  --surface: #1c1c2e;
  --surface-hover: #252540;
  --text: #e4e4ed;
  --text-light: #a0a0b8;
  --text-muted: #6b6b80;
  --border: #2a2a45;
  --border-light: #35355a;
  --primary: #6c8cff;
  --primary-light: #8fa8ff;
  --primary-dark: #4a5fcc;
  --accent: #00c9a7;
  --accent-light: #33d4b9;
  --warning: #f0a040;
  --warning-bg: rgba(240, 160, 64, 0.12);
  --danger: #e0556a;
  --danger-bg: rgba(224, 85, 106, 0.12);
  --success: #4caf7d;
  --success-bg: rgba(76, 175, 125, 0.12);
  --info: #4da6d9;
  --info-bg: rgba(77, 166, 217, 0.12);
  --code-bg: #1a1a2e;
  --inline-code-bg: #252540;
  --gradient-start: #1a1a3e;
  --gradient-end: #2c1f52;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  --transition: 200ms ease;
}

[data-theme="light"] {
  --bg: #f8f9fc;
  --bg-secondary: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f0f2f8;
  --text: #1a1a2e;
  --text-light: #555570;
  --text-muted: #8888a0;
  --border: #d8dae5;
  --border-light: #e8eaf2;
  --primary: #4a5fcc;
  --primary-light: #6c8cff;
  --primary-dark: #3a4db0;
  --accent: #009977;
  --accent-light: #00b894;
  --warning: #d4880a;
  --warning-bg: rgba(212, 136, 10, 0.08);
  --danger: #c0392b;
  --danger-bg: rgba(192, 57, 43, 0.08);
  --success: #27ae60;
  --success-bg: rgba(39, 174, 96, 0.08);
  --info: #2980b9;
  --info-bg: rgba(41, 128, 185, 0.08);
  --code-bg: #f0f2f8;
  --inline-code-bg: #e8eaf2;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.72;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  margin-bottom: 0.75rem;
}

h1 { font-size: 2.25rem; }
h2 { font-size: 1.75rem; margin-top: 2.5rem; }
h3 { font-size: 1.35rem; margin-top: 2rem; }
h4 { font-size: 1.15rem; margin-top: 1.5rem; }

p { margin-bottom: 1.25rem; }

a {
  color: var(--primary-light);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--primary); text-decoration: underline; }

strong { font-weight: 600; color: var(--text); }

ul, ol { margin: 0 0 1.25rem 1.5rem; }
li { margin-bottom: 0.4rem; }

blockquote {
  border-left: 4px solid var(--primary);
  padding: 0.75rem 1.25rem;
  margin: 1.5rem 0;
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-light);
}

/* --- Code --- */
code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

:not(pre) > code {
  background: var(--inline-code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: var(--accent);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-x: auto;
  margin: 1.25rem 0;
}

pre code {
  color: var(--text);
  background: none;
  padding: 0;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.925rem;
}

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

th {
  background: var(--surface);
  font-weight: 600;
  color: var(--text);
}

tr:nth-child(even) td { background: var(--surface); }

/* --- Horizontal Rule --- */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* --- Images --- */
img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* --- Chapter Layout --- */
.chapter-container {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  flex: 1;
}

/* --- Chapter Header --- */
.chapter-header {
  padding: 2.5rem 2rem;
  border-radius: var(--radius-xl);
  margin-bottom: 2.5rem;
  text-align: left;
}

.chapter-header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  color: #fff;
}

.chapter-header .chapter-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  color: rgba(255,255,255,0.75);
  font-size: 0.9rem;
}

.chapter-header .chapter-meta span {
  background: rgba(255,255,255,0.12);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
}

/* --- Chapter Navigation --- */
.chapter-nav-top,
.chapter-nav-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.chapter-nav-bottom {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-light);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.nav-link:hover {
  color: var(--primary-light);
  border-color: var(--primary);
  text-decoration: none;
}

.nav-link.disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* --- Learning Objectives --- */
.learning-objectives {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  margin-bottom: 2.5rem;
}

.learning-objectives h2 {
  margin-top: 0;
  font-size: 1.25rem;
  color: var(--primary-light);
  margin-bottom: 1rem;
}

.learning-objectives ul {
  list-style: none;
  margin: 0;
}

.learning-objectives li {
  padding: 0.35rem 0 0.35rem 1.75rem;
  position: relative;
}

.learning-objectives li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

/* --- Sections --- */
.content-section {
  margin-bottom: 2.5rem;
}

/* --- Key Takeaways --- */
.key-takeaways {
  margin: 3rem 0;
}

.takeaways-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.takeaway-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  transition: border-color var(--transition);
}

.takeaway-card:hover { border-color: var(--primary); }

.takeaway-number {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
}

.takeaway-card p { margin: 0; font-size: 0.925rem; }

/* --- Site Header --- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.site-header .header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-header .site-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.site-header .site-title a {
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-header nav { display: flex; gap: 1.5rem; align-items: center; }

.site-header nav a {
  color: var(--text-light);
  font-size: 0.875rem;
}

.site-header nav a:hover { color: var(--primary-light); text-decoration: none; }

/* --- Theme Toggle --- */
.theme-toggle {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  color: var(--text-light);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
}

.theme-toggle:hover {
  border-color: var(--primary);
  color: var(--primary-light);
}

/* --- Site Footer --- */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.site-footer .footer-inner { max-width: 860px; margin: 0 auto; }

.site-footer nav {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.site-footer nav a { color: var(--text-light); font-size: 0.85rem; }

/* --- Math / Formula display --- */
.formula-block {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.25rem 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--accent);
  overflow-x: auto;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  html { font-size: 15px; }
  .chapter-container { padding: 1rem 1rem 3rem; }
  .chapter-header { padding: 1.75rem 1.25rem; }
  .chapter-header h1 { font-size: 1.75rem; }
  .takeaways-grid { grid-template-columns: 1fr; }
}
