/* ============================================================================
   Claude Code Wiki - Premium Technical Journal Theme
   ============================================================================ */

/* Font Imports */
@import url("https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@400;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap");

/* ============================================================================
   Design Tokens - Light Theme
   ============================================================================ */

:root {
  /* Typography */
  --font-display: "Crimson Pro", Georgia, serif;
  --font-body:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-code: "JetBrains Mono", "Courier New", monospace;

  /* Type Scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;
  --text-4xl: 2.5rem;
  --text-5xl: 3rem;

  /* Colors - Light Theme (Cream & Charcoal) */
  --bg-primary: #fdfbf7;
  --bg-secondary: #f5f1ea;
  --bg-elevated: #ffffff;
  --bg-overlay: rgba(0, 0, 0, 0.05);

  --text-primary: #1a1512;
  --text-secondary: #5c564f;
  --text-tertiary: #8b8378;

  --accent-primary: #d97706;
  --accent-secondary: #b45309;
  --accent-subtle: #fef3c7;
  --accent-hover: #f59e0b;

  --border-light: #e8e3da;
  --border-medium: #d1c7b7;
  --border-dark: #8b8378;

  /* Code Blocks */
  --code-bg: #2d2a27;
  --code-text: #f5f1ea;
  --code-accent: #fbbf24;
  --code-comment: #8b8378;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.1);
  --shadow-elevated:
    0 1px 3px rgba(0, 0, 0, 0.05), 0 10px 25px rgba(0, 0, 0, 0.03);

  /* Layout */
  --container-max-width: 95vw;
  --body-min-width: 20rem;
  --content-max-width: 85ch;
  --sidebar-width: 280px;
  --toc-width: 350px;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

  /* Animation */
  --transition-fast: 0.15s;
  --transition-base: 0.2s;
  --transition-slow: 0.3s;
  --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #1a1512;
  --bg-secondary: #242019;
  --bg-elevated: #2d2721;
  --bg-overlay: rgba(255, 255, 255, 0.05);

  --text-primary: #fdfbf7;
  --text-secondary: #c9bfb4;
  --text-tertiary: #8b8378;

  --accent-primary: #fbbf24;
  --accent-secondary: #fde68a;
  --accent-subtle: #451a03;
  --accent-hover: #fcd34d;

  --border-light: #3d362e;
  --border-medium: #5c564f;
  --border-dark: #8b8378;

  --code-bg: #1a1512;
  --code-text: #f5f1ea;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* ============================================================================
   Base Styles & Layout
   ============================================================================ */

html {
  scroll-behavior: smooth;
  scroll-padding-top: 2rem;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  font-size: var(--text-base);
  position: relative;
}

/* Subtle background texture for depth */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    radial-gradient(
      circle at 20% 50%,
      rgba(217, 119, 6, 0.03) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(217, 119, 6, 0.02) 0%,
      transparent 50%
    );
  pointer-events: none;
  z-index: -1;
}

/* Responsive container */
.container {
  max-width: var(--container-max-width) !important;
}

.book-page {
  max-width: none;
  flex: 1 1 auto;
  animation: fadeInUp 0.5s ease-out;
}

/* ============================================================================
   Typography
   ============================================================================ */

/* Headings - Editorial Display Font */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-top: 2rem;
  line-height: 1.2;
}

h1 {
  font-size: var(--text-4xl);
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 1.5rem;
  margin-top: 0;
  animation: fadeInUp 0.5s ease-out 0.1s both;
}

h2 {
  font-size: var(--text-3xl);
  margin-top: 3rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-light);
  position: relative;
  animation: fadeInUp 0.5s ease-out 0.15s both;
}

h2::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 60px;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-primary), transparent);
}

h3 {
  font-family: var(--font-body);
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

h4 {
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

h5,
h6 {
  font-size: var(--text-lg);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

/* Body text */
p {
  margin-bottom: 1rem;
  color: var(--text-primary);
}

/* Links */
a {
  color: var(--accent-primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all var(--transition-base) var(--ease-out);
}

a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-primary);
}

/* Lists */
ul,
ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

li::marker {
  color: var(--accent-primary);
}

/* Strong and emphasis */
strong {
  font-weight: 600;
  color: var(--text-primary);
}

em {
  font-style: italic;
  color: var(--text-secondary);
}

/* ============================================================================
   Code Blocks - Elevated & Refined
   ============================================================================ */

code {
  font-family: var(--font-code);
  font-size: 0.9em;
}

/* Inline code */
code:not(pre code) {
  background: var(--accent-subtle);
  color: var(--accent-secondary);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.875em;
  border: 1px solid var(--border-light);
  font-weight: 500;
}

/* Code blocks */
pre {
  background: var(--code-bg) !important;
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  box-shadow: var(--shadow-elevated);
  position: relative;
  line-height: 1.6;
}

/* Accent bar on top of code blocks */
pre::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--accent-primary),
    var(--accent-secondary)
  );
  border-radius: 8px 8px 0 0;
}

pre code {
  color: var(--code-text);
  font-size: 0.875rem;
  background: transparent !important;
  border: none;
  padding: 0;
}

/* Syntax highlighting adjustments for monokai */
.highlight .c,
.highlight .c1,
.highlight .cm {
  color: var(--code-comment);
  font-style: italic;
}

/* ============================================================================
   Tables & Decision Matrices
   ============================================================================ */

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 2rem 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
}

thead {
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--accent-primary);
}

th {
  padding: 1rem;
  text-align: left;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

tbody tr {
  transition: background var(--transition-base) var(--ease-out);
}

tbody tr:hover {
  background: var(--accent-subtle);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Striped tables for readability */
tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}

tbody tr:nth-child(even):hover {
  background: var(--accent-subtle);
}

/* ============================================================================
   Blockquotes & Callouts
   ============================================================================ */

blockquote,
.book-hint {
  background: var(--bg-elevated);
  border-left: 4px solid var(--accent-primary);
  padding: 1.5rem;
  margin: 2rem 0;
  border-radius: 0 8px 8px 0;
  box-shadow: var(--shadow-md);
  position: relative;
}

blockquote::before,
.book-hint::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(
    180deg,
    var(--accent-primary),
    var(--accent-secondary)
  );
  border-radius: 4px 0 0 4px;
}

blockquote p:first-child,
.book-hint p:first-child {
  margin-top: 0;
}

blockquote p:last-child,
.book-hint p:last-child {
  margin-bottom: 0;
}

blockquote cite {
  display: block;
  margin-top: 1rem;
  font-style: italic;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* ============================================================================
   Navigation - Left Sidebar
   ============================================================================ */

.book-menu {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  box-shadow: inset -1px 0 0 var(--bg-overlay);
  flex: 0 0 var(--sidebar-width);
}

.book-menu nav {
  padding: 1rem 0;
}

.book-brand {
  padding: 1.5rem 1rem;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 1rem;
}

.book-menu nav > ul > li {
  margin: 0.25rem 0;
}

.book-menu nav > ul > li > a {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin: 0 0.5rem;
  display: block;
  color: var(--text-primary);
  transition: all var(--transition-base) var(--ease-out);
}

.book-menu nav > ul > li > a:hover {
  background: var(--accent-subtle);
  color: var(--accent-secondary);
  transform: translateX(4px);
  border-bottom: none;
}

.book-menu nav > ul > li > a.active {
  background: var(--accent-primary);
  color: white;
  font-weight: 600;
}

/* Nested menu items */
.book-menu nav ul ul {
  margin-left: 1rem;
  border-left: 2px solid var(--border-light);
  padding-left: 0.5rem;
}

.book-menu nav ul ul a {
  font-size: 0.8125rem;
  padding: 0.5rem 0.75rem;
}

/* ============================================================================
   Table of Contents - Right Sidebar
   ============================================================================ */

aside.book-toc {
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-light);
  padding: 1.5rem;
  flex: 0 0 var(--toc-width);
  max-width: var(--toc-width);
  display: none;
}

/* Show TOC only when there are 2+ actual heading links */
aside.book-toc:has(nav > ul > li:nth-child(2)) {
  display: block;
}

aside.book-toc nav > ul {
  border-left: 2px solid var(--border-medium);
  padding-left: 0;
  margin: 0;
  list-style: none;
}

aside.book-toc a {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: 0.4rem 0 0.4rem 1rem;
  display: block;
  transition: all var(--transition-base) var(--ease-out);
  border-bottom: none;
}

aside.book-toc a:hover {
  color: var(--accent-primary);
  transform: translateX(4px);
}

aside.book-toc li.active > a {
  color: var(--accent-primary);
  font-weight: 600;
}

/* ============================================================================
   Content Area
   ============================================================================ */

.book-page article {
  background: var(--bg-elevated);
  padding: 3rem;
  border-radius: 12px;
  box-shadow: var(--shadow-elevated);
  margin: 2rem;
  min-height: calc(100vh - 8rem);
}

/* First paragraph lead style */
.book-page article > p:first-of-type {
  font-size: var(--text-lg);
  line-height: 1.8;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

/* ============================================================================
   Search
   ============================================================================ */

.book-search {
  padding: 1rem;
  border-bottom: 1px solid var(--border-light);
}

.book-search input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  transition: all var(--transition-base) var(--ease-out);
}

.book-search input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* ============================================================================
   Horizontal Rules
   ============================================================================ */

hr {
  border: none;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-primary), transparent);
  margin: 3rem 0;
}

/* ============================================================================
   Pagination & Navigation
   ============================================================================ */

.book-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-light);
}

.book-pagination a {
  padding: 0.75rem 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  color: var(--text-primary);
  font-weight: 500;
  transition: all var(--transition-base) var(--ease-out);
}

.book-pagination a:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ============================================================================
   Breadcrumbs
   ============================================================================ */

.book-breadcrumbs {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-bottom: 1rem;
}

.book-breadcrumbs a {
  color: var(--text-secondary);
}

.book-breadcrumbs a:hover {
  color: var(--accent-primary);
}

/* ============================================================================
   Images
   ============================================================================ */

img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  margin: 2rem 0;
}

/* ============================================================================
   Animations
   ============================================================================ */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}

/* ============================================================================
   Responsive Design
   ============================================================================ */

@media screen and (max-width: 1200px) {
  :root {
    --container-max-width: 100vw;
    --sidebar-width: 250px;
    --toc-width: 280px;
  }

  .book-page article {
    padding: 2rem;
    margin: 1rem;
  }
}

@media screen and (max-width: 992px) {
  :root {
    --text-4xl: 2rem;
    --text-3xl: 1.75rem;
    --text-2xl: 1.5rem;
  }

  aside.book-toc {
    display: none !important;
  }

  .book-page article {
    padding: 1.5rem;
    margin: 0.5rem;
  }
}

@media screen and (max-width: 768px) {
  .book-menu {
    display: none;
  }

  .book-page article {
    padding: 1rem;
    border-radius: 0;
    margin: 0;
  }

  h1 {
    font-size: var(--text-3xl);
  }

  h2 {
    font-size: var(--text-2xl);
  }

  pre {
    padding: 1rem;
    border-radius: 6px;
  }

  table {
    font-size: var(--text-sm);
  }

  th,
  td {
    padding: 0.75rem 0.5rem;
  }
}

/* ============================================================================
   Print Styles
   ============================================================================ */

@media print {
  body::before,
  .book-menu,
  aside.book-toc,
  .book-search,
  .book-pagination {
    display: none !important;
  }

  .book-page article {
    box-shadow: none;
    padding: 0;
    margin: 0;
  }

  a {
    border-bottom: 1px solid currentColor;
  }

  pre {
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }
}
