/* =============================================================================
   Claude How-To — Documentation Reader & Interaction Stylesheet
   Enhanced for long-form reading, ergonomic line lengths, code copy, and micro-interactions
   ============================================================================= */

html {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code,
pre,
kbd,
samp {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* =============================================================================
   Anthropic-inspired Theme Palettes:
   1. Ivory (Default Light): Warm paper #FAF9F5, charcoal #141413, terracotta #CC5A3F
   2. Charcoal (Anthropic Dark): Warm obsidian #141413, ivory text #FAF9F5, terracotta #D97757
   3. Midnight (Cold Slate Dark): Deep midnight #090D16, cold slate text #F8FAFC, indigo #818CF8
   ============================================================================= */

:root,
html[data-theme="ivory"],
html:not(.dark):not([data-theme="dark"]):not([data-theme="midnight"]) {
  --site-bg: #faf9f5;
  --site-surface: #ffffff;
  --site-surface-alt: #f4f0e8;
  --site-surface-translucent: rgba(250, 249, 245, 0.94);
  --site-header: rgba(250, 249, 245, 0.92);
  --site-border: rgba(20, 20, 19, 0.08);
  --site-border-strong: rgba(20, 20, 19, 0.16);
  --site-text: #141413;
  --site-text-muted: #5e5d59;
  --site-text-faint: #878680;
  --site-accent: #cc5a3f;
  --site-accent-hover: #b84b32;
  --site-accent-bg: rgba(204, 90, 63, 0.08);
  --site-code-bg: #ede9df;
  --site-code-text: #141413;
  --site-code-border: rgba(20, 20, 19, 0.08);
  --site-pre-bg: #181817;
  --site-pre-header: #121211;
  --site-pre-border: #2a2a28;
  --site-shadow-sm: 0 1px 3px rgba(20, 20, 19, 0.04);
  --site-shadow-md: 0 4px 14px rgba(20, 20, 19, 0.06);
}

html.dark,
html[data-theme="dark"] {
  --site-bg: #141413;
  --site-surface: #1c1c1a;
  --site-surface-alt: #232321;
  --site-surface-translucent: rgba(20, 20, 19, 0.94);
  --site-header: rgba(20, 20, 19, 0.92);
  --site-border: rgba(255, 255, 255, 0.08);
  --site-border-strong: rgba(255, 255, 255, 0.16);
  --site-text: #faf9f5;
  --site-text-muted: #9e9d99;
  --site-text-faint: #6e6d69;
  --site-accent: #d97757;
  --site-accent-hover: #e28567;
  --site-accent-bg: rgba(217, 119, 87, 0.14);
  --site-code-bg: #222220;
  --site-code-text: #faf9f5;
  --site-code-border: rgba(255, 255, 255, 0.1);
  --site-pre-bg: #191918;
  --site-pre-header: #131312;
  --site-pre-border: #282826;
  --site-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --site-shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
}

html[data-theme="midnight"] {
  --site-bg: #090d16;
  --site-surface: #0f172a;
  --site-surface-alt: #1e293b;
  --site-surface-translucent: rgba(9, 13, 22, 0.94);
  --site-header: rgba(9, 13, 22, 0.92);
  --site-border: rgba(255, 255, 255, 0.08);
  --site-border-strong: rgba(255, 255, 255, 0.16);
  --site-text: #f8fafc;
  --site-text-muted: #94a3b8;
  --site-text-faint: #64748b;
  --site-accent: #818cf8;
  --site-accent-hover: #a5b4fc;
  --site-accent-bg: rgba(129, 140, 248, 0.14);
  --site-code-bg: #1e293b;
  --site-code-text: #e2e8f0;
  --site-code-border: rgba(255, 255, 255, 0.1);
  --site-pre-bg: #0d1117;
  --site-pre-header: #0b0f19;
  --site-pre-border: #1e293b;
  --site-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --site-shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
}

body {
  background-color: var(--site-bg) !important;
  color: var(--site-text) !important;
  transition: background-color 0.18s ease, color 0.18s ease;
}

/* ---------- Top Reading Progress Bar ---------- */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, #cc5a3f 0%, #d97757 50%, #f97316 100%);
  z-index: 100;
  transition: width 0.08s ease-out;
  pointer-events: none;
}

/* ---------- Typography & Reading Ergonomics ---------- */
.prose {
  color: var(--site-text);
  font-size: 1.025rem;
  line-height: 1.8;
  min-width: 0;
  max-width: 100%;
}

/* Limit line length of reading paragraphs for optimal eye tracking (65-75ch) */
.prose > p,
.prose > ul,
.prose > ol,
.prose > blockquote {
  max-width: 75ch;
}

.prose p {
  margin-top: 1.25em;
  margin-bottom: 1.25em;
  font-size: 1.025rem;
  letter-spacing: -0.005em;
  color: var(--site-text);
}

.prose a {
  color: var(--site-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color 0.15s ease;
}

.prose a:hover {
  color: var(--site-accent-hover);
}

/* Larger Text / Reading Mode */
.reading-text-lg .prose p,
.reading-text-lg .prose li {
  font-size: 1.15rem;
  line-height: 1.88;
}

/* Headings with editorial serif warmth inspired by Anthropic engineering */
.prose :where(h1, h2, h3, h4, h5, h6) {
  scroll-margin-top: 5.5rem;
  color: var(--site-text);
  letter-spacing: -0.02em;
}

.prose h1 {
  font-family: 'Fraunces', Georgia, 'Times New Roman', serif;
  font-size: 2.35rem;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 1.35rem;
  letter-spacing: -0.03em;
  color: var(--site-text);
}

.prose h2 {
  font-family: 'Fraunces', Georgia, 'Times New Roman', serif;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.35;
  margin-top: 2.85rem;
  margin-bottom: 1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--site-border);
  position: relative;
  color: var(--site-text);
}

.prose h3 {
  font-size: 1.28rem;
  font-weight: 650;
  line-height: 1.4;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--site-text);
}

.prose h4 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--site-text);
}

/* Anchor link copy on heading hover */
.heading-anchor {
  opacity: 0;
  margin-left: 0.5rem;
  color: var(--site-text-faint);
  text-decoration: none !important;
  font-weight: 400;
  transition: opacity 0.15s ease, color 0.15s ease;
}

:hover > .heading-anchor {
  opacity: 1;
}

.heading-anchor:hover {
  color: var(--site-accent);
}

/* ---------- Inline Code & Code Blocks ---------- */
/* Soft pill style for inline code */
.prose :where(p, li, h1, h2, h3, h4) code {
  font-size: 0.875em;
  font-weight: 500;
  padding: 0.15rem 0.45rem;
  border-radius: 0.375rem;
  background-color: var(--site-code-bg);
  color: var(--site-code-text);
  border: 1px solid var(--site-code-border);
  white-space: break-spaces;
  word-break: break-word;
}

/* Fenced code block wrapper */
.code-block-wrapper {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 1.5rem 0;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--site-pre-border);
  box-shadow: var(--site-shadow-md);
  box-sizing: border-box;
}

.code-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.875rem;
  background-color: var(--site-pre-header);
  border-bottom: 1px solid var(--site-pre-border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--site-text-faint);
  user-select: none;
}

.code-lang-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #d1cfc7;
}

.code-lang-tag::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--site-accent);
}

.copy-code-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.6rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #a8a69e;
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: all 0.15s ease;
}

.copy-code-btn:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.25);
}

.copy-code-btn.copied {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.4);
  background-color: rgba(52, 211, 153, 0.12);
}

/* Code block pre styles */
.prose pre {
  margin: 0 !important;
  border-radius: 0 !important;
  background-color: var(--site-pre-bg) !important;
  color: #ede9df !important;
  padding: 1.125rem 1.25rem;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  line-height: 1.6;
  font-size: 0.875rem;
  box-sizing: border-box;
}

.prose pre code {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  color: inherit !important;
  font-size: inherit !important;
}

/* Custom scrollbar for code blocks */
.prose pre::-webkit-scrollbar {
  height: 6px;
}

.prose pre::-webkit-scrollbar-track {
  background: var(--site-pre-bg);
}

.prose pre::-webkit-scrollbar-thumb {
  background: #3a3a36;
  border-radius: 3px;
}

.prose pre::-webkit-scrollbar-thumb:hover {
  background: #52524d;
}

/* ---------- Callouts & Blockquotes ---------- */
.prose blockquote {
  position: relative;
  font-style: normal;
  margin: 1.5rem 0;
  padding: 1rem 1.25rem 1rem 1.25rem;
  border-left: 3.5px solid var(--site-accent);
  background: var(--site-accent-bg);
  border-radius: 0 0.5rem 0.5rem 0;
  color: var(--site-text);
}

.prose blockquote p {
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

/* ---------- Tables & Responsive Card Wrapper ---------- */
.table-wrapper {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.75rem 0;
  border-radius: 0.75rem;
  border: 1px solid var(--site-border);
  background-color: var(--site-surface);
  box-shadow: var(--site-shadow-sm);
  box-sizing: border-box;
}

.table-wrapper table,
.prose table {
  width: 100%;
  min-width: 640px;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0 !important;
  font-size: 0.875rem;
  border: none !important;
}

/* Fallback if a table is not inside .table-wrapper */
.prose > table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border-radius: 0.75rem;
  border: 1px solid var(--site-border);
  margin: 1.75rem 0 !important;
  background-color: var(--site-surface);
  box-shadow: var(--site-shadow-sm);
}

.prose thead {
  background-color: var(--site-surface-alt);
  border-bottom: 1px solid var(--site-border);
}

.prose th {
  padding: 0.75rem 1rem;
  font-weight: 650;
  text-align: left;
  color: var(--site-text);
  letter-spacing: 0.03em;
  font-size: 0.8125rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.prose td {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--site-border);
  color: var(--site-text);
  line-height: 1.6;
  vertical-align: top;
}

.prose tbody tr:hover {
  background-color: var(--site-surface-alt);
}

/* Custom scrollbar for table wrapper */
.table-wrapper::-webkit-scrollbar {
  height: 6px;
}

.table-wrapper::-webkit-scrollbar-track {
  background: var(--site-surface-alt);
  border-radius: 0 0 0.75rem 0.75rem;
}

.table-wrapper::-webkit-scrollbar-thumb {
  background: var(--site-border-strong);
  border-radius: 3px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--site-text-faint);
}

/* ---------- Mermaid Diagrams ---------- */
.mermaid {
  background: var(--site-surface) !important;
  border: 1px solid var(--site-border);
  border-radius: 0.75rem;
  padding: 1.5rem 1rem;
  margin: 1.75rem 0;
  text-align: center;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  box-sizing: border-box;
  box-shadow: var(--site-shadow-sm);
}

.mermaid svg {
  max-width: 100%;
  height: auto;
  display: inline-block;
}

/* ---------- Interactive In-Page TOC (Scrollspy) ---------- */
.toc-link {
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
  padding-left: 0.625rem;
  color: var(--site-text-muted);
}

.toc-link:hover {
  color: var(--site-accent) !important;
}

.toc-link.active {
  color: var(--site-accent) !important;
  font-weight: 600;
  border-left-color: var(--site-accent);
  background-color: var(--site-accent-bg);
  border-radius: 0 0.375rem 0.375rem 0;
}

/* ---------- Back To Top Button ---------- */
#back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background-color: var(--site-surface);
  color: var(--site-text-muted);
  border: 1px solid var(--site-border);
  box-shadow: var(--site-shadow-md);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
}

#back-to-top:hover {
  color: var(--site-accent);
  border-color: var(--site-accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(204, 90, 63, 0.25);
}

#back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ---------- Sidebar Section Collapse / Active Pill ---------- */
.sidebar-section-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-section-header .chevron {
  transition: transform 0.2s ease;
}

.sidebar-section.collapsed .chevron {
  transform: rotate(-90deg);
}

.sidebar-section.collapsed ul {
  display: none;
}

/* Custom scrollbars */
.custom-scrollbar::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: var(--site-border-strong);
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: var(--site-text-faint);
}

/* Search input clear button */
.search-clear-btn {
  position: absolute;
  right: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--site-text-faint);
  cursor: pointer;
}

.search-clear-btn:hover {
  color: var(--site-text);
}

/* Keyboard hint badge */
.kbd-shortcut {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0.35rem;
  font-size: 0.7rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--site-text-muted);
  background-color: var(--site-surface-alt);
  border: 1px solid var(--site-border);
  border-radius: 0.25rem;
}

/* Hide focus rings on mouse, keep for keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

/* Pygments syntax highlighting overrides */
.codehilite {
  background: transparent;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.codehilite .hll { background-color: #ffffcc }
.codehilite .c, .codehilite .c1, .codehilite .cm { color: #8b949e; font-style: italic }
.codehilite .k, .codehilite .kc, .codehilite .kd, .codehilite .kn, .codehilite .kp,
.codehilite .kr, .codehilite .kt { color: #ff7b72; font-weight: 600 }
.codehilite .s, .codehilite .s1, .codehilite .s2 { color: #a5d6ff }
.codehilite .nb { color: #79c0ff }
.codehilite .nf { color: #d2a8ff }
.codehilite .o, .codehilite .p { color: #79c0ff }
.codehilite .m, .codehilite .mi, .codehilite .mf { color: #79c0ff }
.codehilite .nv, .codehilite .vc, .codehilite .vg, .codehilite .vi { color: #ffa657 }
.codehilite .err { color: inherit }

:root:not(.dark) .codehilite .k,
:root:not(.dark) .codehilite .kc,
:root:not(.dark) .codehilite .kd,
:root:not(.dark) .codehilite .kn,
:root:not(.dark) .codehilite .kp,
:root:not(.dark) .codehilite .kr,
:root:not(.dark) .codehilite .kt { color: #cf222e; }
:root:not(.dark) .codehilite .s,
:root:not(.dark) .codehilite .s1,
:root:not(.dark) .codehilite .s2 { color: #0a3069; }
:root:not(.dark) .codehilite .nb { color: #0550ae; }
:root:not(.dark) .codehilite .nf { color: #6f42c1; }
:root:not(.dark) .codehilite .m,
:root:not(.dark) .codehilite .mi,
:root:not(.dark) .codehilite .mf { color: #0550ae; }
