/* xuanxin default theme variables */

:root {
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  --font-serif: "Merriweather", "Georgia", "Times New Roman", serif;

  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-muted: #64748b;
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-border: #e2e8f0;
  --color-code-bg: #f1f5f9;
  --color-blockquote-bg: #f8fafc;
  --color-shadow: rgba(15, 23, 42, 0.08);
  --color-shadow-hover: rgba(15, 23, 42, 0.14);

  --max-width: 720px;
  --radius: 10px;
  --radius-sm: 6px;
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: calc(var(--max-width) + 80px);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Header */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.site-brand:hover { color: var(--color-primary); }

.site-nav a {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.site-nav a:hover { color: var(--color-primary); }

/* Index */
.index-hero {
  padding: 3rem 0 2rem;
  text-align: center;
}

.index-hero h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0 0 0.5rem;
}

.index-desc {
  color: var(--color-text-muted);
  font-size: 1.05rem;
  max-width: 540px;
  margin: 0 auto 0.5rem;
}

.index-count {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.post-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding-bottom: 3rem;
}

.post-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  box-shadow: 0 1px 3px var(--color-shadow);
  transition: box-shadow 0.2s, transform 0.2s;
}

.post-card:hover {
  box-shadow: 0 8px 24px var(--color-shadow-hover);
  transform: translateY(-2px);
}

.post-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.post-card h2 a {
  color: var(--color-text);
  text-decoration: none;
}

.post-card h2 a:hover { color: var(--color-primary); }

.post-excerpt {
  color: var(--color-text-muted);
  margin: 0.5rem 0;
  font-size: 0.95rem;
}

.read-more {
  display: inline-block;
  margin-top: 0.75rem;
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.read-more:hover { color: var(--color-primary-hover); }

.empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 3rem;
}

.empty code {
  background: var(--color-code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.85em;
}

/* Post page */
.post {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 12px var(--color-shadow);
  padding: 2.5rem 2rem;
  margin: 2rem auto 3rem;
  max-width: var(--max-width);
}

.post-header { margin-bottom: 2rem; }

.post-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin: 0 0 1rem;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.post-meta time::before { content: "📅 "; }

.post-author::before { content: "✍️ "; }

.post-lead {
  font-size: 1.1rem;
  color: var(--color-text-muted);
  border-left: 4px solid var(--color-primary);
  padding: 0.75rem 1rem;
  margin: 1.25rem 0 0;
  background: var(--color-blockquote-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.post-featured {
  margin: 1.5rem 0 0;
}

.post-featured img {
  width: 100%;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px var(--color-shadow);
}

.post-tags, .post-card .post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.tag {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--color-code-bg);
  color: var(--color-text-muted);
  border-radius: 999px;
  border: 1px solid var(--color-border);
}

/* Prose — markdown body (memoir: one markdown line → one <p>, keep gaps tight) */
.prose {
  font-family: var(--font-serif);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--color-text);
  --prose-line-gap: 0.15rem;
}

.prose > :first-child { margin-top: 0; }

.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.prose h1 { font-size: 1.8rem; }
.prose h2 { font-size: 1.5rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.3rem; scroll-margin-top: 4rem; scroll-margin-bottom: 1rem; }
.prose h3 { font-size: 1.25rem; }

.prose p { margin: 0 0 var(--prose-line-gap); }

/* Lone ``\\`` in source → bubble ``\\hfill\\break`` in PDF (one extra line, not a full paragraph) */
.prose p:has(+ .xuanxin-blank) {
  margin-bottom: 0;
}

.prose .xuanxin-blank {
  display: block;
  height: 1lh;
  margin: 0;
  padding: 0;
}

/* LaTeX ``\\newpage`` / ``\\clearpage`` → CSS page break (bubble EPUB hook) */
.prose .xuanxin-pagebreak {
  display: none;
}

/* Paginated reader (one screen per \\newpage) */
body.xuanxin-paginated .post-paginated {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 10rem);
}

body.xuanxin-paginated .post-paginated:has(.fullpage-image) {
  min-height: 0;
}

.prose.prose-paginated {
  flex: 1;
  display: flex;
  flex-direction: column;
}

body.xuanxin-paginated .prose-paginated:has(.fullpage-image) {
  flex: 0 1 auto;
}

.xuanxin-paginated-reader {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.xuanxin-paginated .xuanxin-paginated-reader:has(.fullpage-image) {
  flex: 0 1 auto;
}

.xuanxin-page {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0 1.5rem;
}

body.xuanxin-paginated .xuanxin-page:has(> .fullpage-image) {
  flex: 0 0 auto;
  overflow: visible;
  padding-top: 0;
  padding-bottom: 0.75rem;
}

.xuanxin-page[hidden] {
  display: none !important;
}

.page-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 0.75rem 0;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.page-nav-bottom {
  margin-top: auto;
}

.page-nav-btn {
  font: inherit;
  font-size: 0.92rem;
  color: var(--color-primary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.page-nav-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.page-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.page-nav-prev { justify-self: start; }
.page-nav-next { justify-self: end; }

.page-nav-indicator {
  justify-self: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

body.xuanxin-paginated .prose .fullpage-image {
  width: 100%;
  height: auto;
  min-height: 0;
  margin: 0;
  page-break-before: auto;
  break-before: auto;
}

body.xuanxin-paginated .prose .fullpage-image.is-rotated-side img {
  max-width: 100% !important;
  max-height: none !important;
  width: auto !important;
  height: auto !important;
}

@media print {
  .prose .xuanxin-pagebreak {
    display: block;
    page-break-before: always;
    break-before: page;
    margin: 0;
    padding: 0;
    height: 0;
    border: 0;
    overflow: hidden;
  }

  .xuanxin-page[hidden] {
    display: block !important;
  }

  .page-nav,
  .chapter-nav,
  .xuanxin-section-nav,
  .xuanxin-fullpage-controls,
  .xuanxin-fullpage-lightbox {
    display: none !important;
  }
}

/* Extra breathing room before/after section headings */
.prose h2 + p,
.prose h3 + p {
  margin-top: 0.5rem;
}

.prose a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

.prose ul, .prose ol {
  margin: 0 0 1.2rem;
  padding-left: 1.5rem;
}

.prose li { margin-bottom: 0.4rem; }

.prose blockquote {
  border-left: 4px solid var(--color-primary);
  background: var(--color-blockquote-bg);
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-muted);
  font-style: italic;
}

/* Bubble-style NOTES/IMPORS/WARNS sections */
.prose aside.xuanxin-notesection,
.prose aside.xuanxin-importantsection,
.prose aside.xuanxin-warnsection {
  display: block;
  margin: 1rem 0;
  padding: 0.65rem 0.85rem 0.65rem 2.1rem;
  border-radius: var(--radius-sm);
  border: 0.8px solid;
  font-size: 0.92rem;
  line-height: 1.55;
  position: relative;
}

.prose aside.xuanxin-notesection::before,
.prose aside.xuanxin-importantsection::before,
.prose aside.xuanxin-warnsection::before {
  position: absolute;
  left: 0.55rem;
  top: 0.65rem;
  font-size: 1rem;
  line-height: 1;
}

.prose aside.xuanxin-notesection {
  background: color-mix(in srgb, #facc15 12%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-primary) 55%, #94a3b8);
  color: var(--color-text);
  font-style: normal;
}

.prose aside.xuanxin-notesection::before { content: "📝"; }

.prose aside.xuanxin-importantsection {
  background: color-mix(in srgb, var(--color-primary) 10%, var(--color-surface));
  border-color: color-mix(in srgb, var(--color-primary) 70%, #64748b);
  color: var(--color-text);
  font-style: normal;
}

.prose aside.xuanxin-importantsection::before { content: "ℹ️"; }

.prose aside.xuanxin-warnsection {
  background: color-mix(in srgb, #f97316 12%, var(--color-surface));
  border-color: color-mix(in srgb, #f97316 55%, #94a3b8);
  color: var(--color-text);
  font-style: normal;
}

.prose aside.xuanxin-warnsection::before { content: "⚠️"; }

.prose aside.xuanxin-notesection > :first-child,
.prose aside.xuanxin-importantsection > :first-child,
.prose aside.xuanxin-warnsection > :first-child {
  margin-top: 0;
}

.prose aside.xuanxin-notesection > :last-child,
.prose aside.xuanxin-importantsection > :last-child,
.prose aside.xuanxin-warnsection > :last-child {
  margin-bottom: 0;
}

.prose aside.xuanxin-notesection p,
.prose aside.xuanxin-importantsection p,
.prose aside.xuanxin-warnsection p {
  margin: 0 0 var(--prose-line-gap);
}

/* GALLERYS/GALLERYE image carousel */
.prose .xuanxin-gallery {
  margin: 0.75rem 0;
  border: 1px solid color-mix(in srgb, var(--color-border, #cbd5e1) 80%, transparent);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface);
}

.prose .xuanxin-gallery-viewport {
  height: 168px;
  overflow: hidden;
  background: color-mix(in srgb, var(--color-bg) 92%, #000 8%);
}

.prose .xuanxin-gallery:not(.xuanxin-gallery-has-captions) .xuanxin-gallery-viewport {
  height: 188px;
}

.prose .xuanxin-gallery-single .xuanxin-gallery-viewport {
  height: 188px;
}

.prose .xuanxin-gallery-single:not(.xuanxin-gallery-has-captions) .xuanxin-gallery-viewport {
  height: 200px;
}

.prose .xuanxin-gallery-track {
  display: flex;
  height: 100%;
  transition: transform 0.25s ease;
}

.prose .xuanxin-gallery-slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0.15rem;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

.prose .xuanxin-gallery-slide img {
  max-height: 100%;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0;
}

.prose .xuanxin-gallery-caption {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 0.3rem 0.55rem;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.3;
  text-align: left;
  color: var(--color-text-muted);
  background: color-mix(in srgb, var(--color-bg) 96%, transparent);
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--color-border, #cbd5e1) 80%, transparent);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prose .xuanxin-gallery-caption[hidden] {
  display: none;
}

.prose .xuanxin-gallery-caption:hover {
  color: var(--color-text);
}

.prose .xuanxin-gallery-caption[aria-expanded="true"] {
  white-space: normal;
  color: var(--color-text);
  max-height: 4.5rem;
  overflow-y: auto;
}

.prose .xuanxin-gallery-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.45rem;
  border-top: 1px solid color-mix(in srgb, var(--color-border, #cbd5e1) 80%, transparent);
}

.prose .xuanxin-gallery-btn {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--color-border, #cbd5e1) 80%, transparent);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.55rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.2;
  cursor: pointer;
}

.prose .xuanxin-gallery-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.prose .xuanxin-gallery-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.prose .xuanxin-gallery-indicator {
  text-align: center;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.prose .xuanxin-gallery-lock {
  margin: 0.75rem 0;
  border: 1px solid color-mix(in srgb, var(--color-border, #cbd5e1) 80%, transparent);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  overflow: hidden;
}

.prose .xuanxin-gallery-lock.is-unlocked .xuanxin-gallery-unlock {
  display: none;
}

.prose .xuanxin-gallery-unlock {
  margin: 0;
  padding: 0.85rem 0.75rem;
  display: grid;
  gap: 0.45rem;
}

.prose .xuanxin-gallery-unlock-label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.prose .xuanxin-gallery-unlock-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
}

.prose .xuanxin-gallery-unlock-input {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid color-mix(in srgb, var(--color-border, #cbd5e1) 80%, transparent);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
}

.prose .xuanxin-gallery-unlock-btn {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--color-border, #cbd5e1) 80%, transparent);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  font: inherit;
  cursor: pointer;
}

.prose .xuanxin-gallery-unlock-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.prose .xuanxin-gallery-unlock-error {
  margin: 0;
  font-size: 0.82rem;
  color: #dc2626;
}

.prose .xuanxin-gallery-lock .xuanxin-gallery {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.prose .xuanxin-gallery-lock .xuanxin-gallery[hidden] {
  display: none;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--color-code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
}

.prose pre {
  background: #1e293b;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.85rem;
  line-height: 1.6;
}

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

.prose .highlight { border-radius: var(--radius); overflow: hidden; }

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  font-family: var(--font-sans);
}

.prose th, .prose td {
  border: 1px solid var(--color-border);
  padding: 0.6rem 0.9rem;
  text-align: left;
}

.prose th {
  background: var(--color-code-bg);
  font-weight: 600;
}

.prose tr:nth-child(even) { background: var(--color-blockquote-bg); }

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 1.25rem 0;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.prose .tp-image-section img,
.prose .fullpage-image img,
.post-featured img {
  -webkit-user-drag: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Chapter opening artwork from **tp_image** — flat, bottom-right in opening block */
.prose .tp-image-section {
  margin: 1.1em 0;
}

/* Quote above, image below (no overlap — quote bg would hide the art) */
.prose .tp-image-section:has(blockquote) {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.prose .tp-image-section:has(blockquote) blockquote {
  align-self: stretch;
  margin-bottom: 0;
}

.prose .tp-image-section img.tp-image {
  margin: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.prose .tp-image-section img.tp-image:hover {
  box-shadow: none;
}

/* Opening block is only the image (no blockquote above) */
.prose .tp-image-section:has(> img.tp-image:only-child) {
  display: flex;
  justify-content: flex-end;
}

/* Bubble-style placement modes (see docs/markdown_syntax_extensions.md) */
.prose img.background {
  margin: 0;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
}

.prose img.background:hover {
  box-shadow: none;
}

.prose .image-background-section {
  position: relative;
  isolation: isolate;
  margin: 1.5rem 0;
}

.prose .image-background-section.image-background-bottom-right {
  margin: 0;
}

.prose .image-background-section > img.background {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}

.prose .image-background-section > img.background.bottom-right {
  left: auto;
  top: auto;
  width: auto;
  height: auto;
  max-width: 100%;
}

.prose .image-background-section > :not(img.background) {
  position: relative;
  z-index: 1;
}

/* Stacked full-bleed backgrounds: N images → N equal vertical bands. */
.prose .image-background-stack {
  display: flex;
  flex-direction: column;
  height: min(72vh, calc(100dvh - 16rem));
  min-height: min(72vh, calc(100dvh - 16rem));
  max-height: min(72vh, calc(100dvh - 16rem));
  margin: 1.5rem 0;
  overflow: hidden;
  flex-shrink: 0;
}

.prose .image-background-stack > .image-background-section.image-background-stack-item {
  flex: 1 0 0;
  min-height: 0;
  max-height: none;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  isolation: isolate;
}

.prose .image-background-stack > .image-background-section.image-background-stack-item > img.background {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  object-fit: cover;
  margin: 0;
}

body.xuanxin-paginated .xuanxin-page .image-background-stack {
  height: min(68vh, calc(100dvh - 18rem));
  min-height: min(68vh, calc(100dvh - 18rem));
  max-height: min(68vh, calc(100dvh - 18rem));
}

.prose figure.image-block {
  margin: 1.5rem 0;
  text-align: center;
}

.prose figure.image-block img {
  margin: 0 auto 0.5rem;
}

.prose figure.image-block figcaption {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-style: italic;
}

.prose .fullpage-image {
  page-break-before: always;
  break-before: page;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2rem 0;
  overflow: visible;
  position: relative;
}

@media print {
  .prose .fullpage-image {
    min-height: 100vh;
  }
}

.prose .fullpage-image img {
  margin: 0;
  transition: transform 0.35s ease;
  transform-origin: center center;
}

.prose .fullpage-image.is-rotated-side img {
  max-width: min(75vh, 100%) !important;
  max-height: 100vw !important;
  width: auto !important;
  height: auto !important;
}

.xuanxin-fullpage-controls[hidden] {
  display: none !important;
}

.prose .fullpage-image .xuanxin-fullpage-controls {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  left: auto;
  z-index: 5;
  display: flex;
  gap: 0.4rem;
}

.xuanxin-fullpage-controls {
  display: flex;
  gap: 0.4rem;
}

.xuanxin-fullpage-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  color: var(--color-primary);
  background: color-mix(in srgb, var(--color-surface) 96%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  box-shadow: 0 4px 16px var(--color-shadow);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.xuanxin-fullpage-icon {
  display: block;
}

.xuanxin-fullpage-btn:hover,
.xuanxin-fullpage-btn:focus-visible {
  color: #fff;
  background: var(--color-primary);
  border-color: var(--color-primary);
  outline: none;
}

.xuanxin-fullpage-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.xuanxin-fullpage-lightbox[hidden] {
  display: none !important;
}

.xuanxin-fullpage-lightbox-backdrop {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  background: color-mix(in srgb, #0f172a 88%, transparent);
  cursor: pointer;
}

.xuanxin-fullpage-lightbox-stage {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 96vw;
  max-height: 96vh;
  pointer-events: none;
}

.xuanxin-fullpage-lightbox-img {
  max-width: min(96vw, 96vh);
  max-height: min(96vw, 96vh);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.45);
  transition: transform 0.35s ease;
  pointer-events: auto;
}

.xuanxin-fullpage-lightbox-img.is-rotated-side {
  max-width: min(96vh, 96vw);
  max-height: min(96vw, 96vh);
}

.xuanxin-fullpage-lightbox-close {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 4px 16px var(--color-shadow);
}

.xuanxin-fullpage-lightbox-close:hover,
.xuanxin-fullpage-lightbox-close:focus-visible {
  color: #fff;
  background: var(--color-primary);
  border-color: var(--color-primary);
  outline: none;
}

body.xuanxin-lightbox-open {
  overflow: hidden;
}

.prose img:hover {
  box-shadow: 0 8px 24px var(--color-shadow-hover);
}

/* Image utility classes (from MockSphere) */
.prose .img-small { width: 200px !important; max-width: 200px !important; }
.prose .img-medium { width: 400px !important; max-width: 400px !important; }
.prose .img-large { width: 600px !important; max-width: 600px !important; }
.prose .img-full { width: 100% !important; }
.prose .img-left { float: left; margin: 0 1.25rem 1rem 0; }
.prose .img-right { float: right; margin: 0 0 1rem 1.25rem; }
.prose .img-center { display: block; margin: 1.25rem auto; }
.prose .img-rounded { border-radius: 15px; }
.prose .img-circle { border-radius: 50%; }
.prose .img-border { border: 2px solid var(--color-border); }
.prose .img-border-primary { border: 2px solid var(--color-primary); }

.prose hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2rem 0;
}

.prose .toc {
  background: var(--color-blockquote-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin: 1.5rem 0;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}

.prose .toc ul { margin: 0; padding-left: 1.2rem; }

/* Video embeds */
.video-embed, .youtube-embed-container {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  max-width: 100%;
  margin: 1.5rem 0;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px var(--color-shadow);
}

.video-embed iframe, .youtube-embed-container iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: 0;
  border-radius: var(--radius);
}

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

.site-footer a { color: var(--color-primary); }

/* Chapter section quick nav (subtitle → H2 jump buttons) */
.xuanxin-section-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.75rem 0 1.35rem;
}

.xuanxin-section-nav--floating {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  left: auto;
  z-index: 250;
  margin: 0;
  padding: 0.45rem 0.55rem;
  max-width: min(22rem, calc(100vw - 2rem));
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
  background: color-mix(in srgb, var(--color-surface) 96%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px var(--color-shadow);
}

.xuanxin-section-nav--floating .xuanxin-section-nav-btn {
  padding: 0.32rem 0.75rem;
  font-size: 0.82rem;
}

body.xuanxin-has-section-nav {
  padding-bottom: 0;
}

body.xuanxin-has-section-nav .site-footer {
  margin-bottom: 0;
}

.xuanxin-section-nav-btn {
  display: inline-block;
  padding: 0.38rem 0.95rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 500;
  font-style: normal;
  line-height: 1.3;
  text-decoration: none;
  color: var(--color-primary);
  background: var(--color-surface);
  border: 1px solid color-mix(in srgb, var(--color-primary) 35%, var(--color-border));
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.xuanxin-section-nav-btn:hover,
.xuanxin-section-nav-btn:focus-visible {
  color: #fff;
  background: var(--color-primary);
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--color-primary) 35%, transparent);
  outline: none;
}

.prose h2.xuanxin-section-target {
  animation: xuanxin-section-flash 1.6s ease;
}

@keyframes xuanxin-section-flash {
  0%, 100% { background: transparent; }
  18% { background: color-mix(in srgb, var(--color-primary) 14%, transparent); }
  45% { background: color-mix(in srgb, var(--color-primary) 8%, transparent); }
}

/* Book table of contents */
.book-toc { margin: 2rem 0 3rem; }
.book-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}
.book-toc-item a {
  display: block;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.book-toc-item a:hover {
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px var(--color-shadow);
}

/* Chapter prev/next navigation */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin: 1.5rem 0;
  font-size: 0.92rem;
}
.chapter-nav-top { margin-top: 0.5rem; }
.chapter-nav-bottom { margin-bottom: 2rem; }
.chapter-nav-prev,
.chapter-nav-next {
  color: var(--color-primary);
  text-decoration: none;
  line-height: 1.35;
}
.chapter-nav-prev:hover,
.chapter-nav-next:hover { text-decoration: underline; }
.chapter-nav-prev { justify-self: start; text-align: left; }
.chapter-nav-next { justify-self: end; text-align: right; }
.chapter-nav-index {
  justify-self: center;
  color: var(--color-text-muted);
  text-decoration: none;
  white-space: nowrap;
}
.chapter-nav-index:hover { color: var(--color-primary); }
.chapter-nav-spacer { display: block; }

@media (max-width: 640px) {
  html { font-size: 16px; }
  .post { padding: 1.5rem 1.25rem; margin: 1rem auto 2rem; }
  .post-title { font-size: 1.7rem; }
  .index-hero h1 { font-size: 1.8rem; }
  .chapter-nav {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .chapter-nav-prev,
  .chapter-nav-next { justify-self: center; text-align: center; }
  .chapter-nav-index { order: -1; margin-bottom: 0.25rem; }
  .page-nav {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .page-nav-prev,
  .page-nav-next { justify-self: center; }
  .page-nav-indicator { order: -1; margin-bottom: 0.25rem; }
}
