/* ==========================================================================
   JZWXZ Blog · Minimalist Paper & Castle Town Dual-Theme Stylesheet
   ========================================================================== */

:root {
  /* Light Mode: Warm Archival Paper + Ralsei Emerald & Rose Accents */
  --bg: #faf9f6;
  --bg-sidebar: #f3f1ec;
  --surface: #ffffff;
  --surface-subtle: #f5f3ee;
  --surface-hover: #eeebe4;

  --ink: #1c1e21;
  --ink-secondary: #545b66;
  --ink-muted: #868d98;

  --border: #e6e2d8;
  --border-strong: #d5cfc2;

  --accent: #2d7d63;
  --accent-hover: #236550;
  --accent-soft: rgba(45, 125, 99, 0.1);
  --accent-rose: #c44f78;
  --accent-rose-soft: rgba(196, 79, 120, 0.1);
  --accent-gold: #b88420;
  --accent-gold-soft: rgba(184, 132, 32, 0.12);

  --code-bg: #f4f2ec;
  --code-border: #e4dfd4;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.04);
  --shadow-md: 0 10px 28px rgba(24, 24, 27, 0.06);

  --sidebar-width: 256px;
  --content-max: 780px;
  --radius-sm: 6px;
  --radius-md: 11px;
  --radius-lg: 15px;

  --font-sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Songti SC", "Noto Serif SC", "STSong", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-theme="dark"] {
  /* Dark Mode: Deltarune Castle Town Night + Translucent Frosted Surfaces */
  --bg: #0c0f1d;
  --bg-sidebar: rgba(14, 17, 30, 0.88);
  --surface: rgba(17, 22, 40, 0.78);
  --surface-subtle: rgba(23, 29, 52, 0.76);
  --surface-hover: rgba(34, 43, 74, 0.82);

  --ink: #eef2fa;
  --ink-secondary: #b4bfd6;
  --ink-muted: #8290ad;

  --border: rgba(105, 130, 196, 0.24);
  --border-strong: rgba(128, 158, 228, 0.38);

  --accent: #52d1a0;
  --accent-hover: #70e2b7;
  --accent-soft: rgba(82, 209, 160, 0.16);
  --accent-rose: #e87ca4;
  --accent-rose-soft: rgba(232, 124, 164, 0.16);
  --accent-gold: #ffd454;
  --accent-gold-soft: rgba(255, 212, 84, 0.16);

  --code-bg: rgba(12, 16, 30, 0.88);
  --code-border: rgba(105, 130, 196, 0.25);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 14px 36px rgba(0, 0, 0, 0.42);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.75;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.pixel-art {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Castle Town Full-Viewport Backdrop (Dark Mode Only)
   ========================================================================== */

.castle-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--sidebar-width);
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

[data-theme="dark"] .castle-backdrop {
  opacity: 1;
  visibility: visible;
}

.castle-backdrop-image {
  position: absolute;
  inset: 0;
  background-image: url("/assets/deltarune/castle-town-bg.webp");
  background-size: cover;
  background-position: center 64%;
  background-repeat: no-repeat;
  transform: scale(1.01);
}

/* Live Canvas Layer: Surging Dark Fountain + Twinkling Starlight */
.castle-backdrop-fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Official back-view Ralsei with 4-frame animated fluttering pink scarf (close foreground) */
.castle-backdrop-ralsei {
  --ralsei-fw: 162px;
  position: absolute;
  left: 50%;
  bottom: 29%;
  transform: translateX(-29%);
  width: var(--ralsei-fw);
  height: calc(var(--ralsei-fw) * 40 / 36);
  pointer-events: none;
}

.castle-ralsei-shadow {
  position: absolute;
  left: 6%;
  bottom: -6px;
  width: 44%;
  height: 18px;
  border-radius: 50%;
  background: rgba(4, 7, 18, 0.78);
  filter: blur(4px);
}

.castle-ralsei-sprite {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url("/assets/deltarune/ralsei-back-wind.png");
  background-repeat: no-repeat;
  background-size: calc(var(--ralsei-fw) * 4) 100%;
  background-position: 0 0;
  filter: brightness(0.95) drop-shadow(0 0 10px rgba(80, 140, 255, 0.22));
  animation: ralseiScarf 0.92s steps(4) infinite;
}

@keyframes ralseiScarf {
  from {
    background-position-x: 0;
  }
  to {
    background-position-x: calc(var(--ralsei-fw) * -4);
  }
}

/* Balanced atmospheric veil so content stays crisp and readable */
.castle-backdrop-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(9, 12, 24, 0.5) 0%,
    rgba(10, 14, 28, 0.28) 44%,
    rgba(10, 14, 28, 0.42) 76%,
    rgba(8, 11, 22, 0.64) 100%
  );
}

/* ==========================================================================
   App Shell: Fixed Sidebar + Scrollable Main Column
   ========================================================================== */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 18px 20px;
  z-index: 50;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.25s ease;
}

[data-theme="dark"] .sidebar {
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.sidebar-brand {
  padding: 0 10px 22px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  color: var(--ink);
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex-shrink: 0;
}

.brand-sub {
  margin: 6px 0 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
  letter-spacing: 0.03em;
}

/* Sidebar Index Navigation */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.nav-item.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

.nav-index {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
  width: 18px;
  flex-shrink: 0;
}

.nav-item.is-active .nav-index {
  color: var(--accent);
}

.nav-en {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

/* Sidebar Quiet Ralsei Mascot */
.ralsei-mascot {
  margin-top: 16px;
  padding: 6px 10px 2px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  pointer-events: none;
  user-select: none;
}

.ralsei-sprite {
  width: auto;
  height: 54px;
  opacity: 0.94;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.14));
}

.ralsei-sprite--dark {
  display: none;
}

[data-theme="dark"] .ralsei-sprite--light {
  display: none;
}

[data-theme="dark"] .ralsei-sprite--dark {
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
}

/* Sidebar Footer Tools */
.sidebar-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.76rem;
  color: var(--ink-secondary);
  transition: border-color 0.16s ease, color 0.16s ease, background-color 0.16s ease;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.theme-toggle svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.social-links {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.icon-link {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  transition: background-color 0.16s ease, color 0.16s ease;
}

.icon-link:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.icon-link svg {
  width: 16px;
  height: 16px;
}

/* Mobile Top Bar & Overlay */
.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  height: 54px;
  padding: 0 16px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
}

.mobile-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.82rem;
  color: var(--ink);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.45);
  backdrop-filter: blur(2px);
  z-index: 35;
}

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

.main-wrap {
  position: relative;
  z-index: 1;
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main-content {
  width: 100%;
  max-width: calc(var(--content-max) + 96px);
  margin: 0 auto;
  padding: 52px 48px 72px;
  flex: 1;
}

.page-header {
  margin-bottom: 34px;
}

.page-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.page-title {
  margin: 0 0 10px;
  font-family: var(--font-serif);
  font-size: clamp(1.85rem, 3.2vw, 2.35rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.page-subtitle {
  margin: 0;
  font-size: 0.98rem;
  color: var(--ink-secondary);
  max-width: 62ch;
}

.page-footer {
  width: 100%;
  max-width: calc(var(--content-max) + 96px);
  margin: 0 auto;
  padding: 18px 48px 34px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-family: var(--font-mono);
}

/* ==========================================================================
   Home Welcome Layout (Open & Airy so Castle Town Backdrop Shines in Dark Mode)
   ========================================================================== */

.home-layout {
  min-height: calc(100vh - 148px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
}

.welcome-hero {
  margin-bottom: 0;
}

.welcome-hero .page-title {
  font-size: clamp(1.9rem, 3.2vw, 2.45rem);
}

.welcome-lead {
  margin: 10px 0 0;
  color: var(--ink-secondary);
  font-size: 0.96rem;
  line-height: 1.75;
  max-width: 56ch;
}

[data-theme="dark"] .welcome-hero .page-title,
[data-theme="dark"] .welcome-lead,
[data-theme="dark"] .page-header .page-title,
[data-theme="dark"] .page-header .page-subtitle {
  text-shadow: 0 2px 14px rgba(6, 8, 18, 0.78);
}

[data-theme="dark"] .index-card {
  background: rgba(15, 20, 38, 0.68);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

[data-theme="dark"] .note-hero-card,
[data-theme="dark"] .chapter-item,
[data-theme="dark"] .project-banner,
[data-theme="dark"] .contact-card,
[data-theme="dark"] .blog-tip,
[data-theme="dark"] .blog-empty,
[data-theme="dark"] .pdf-viewer-shell {
  backdrop-filter: blur(11px);
  -webkit-backdrop-filter: blur(11px);
}

[data-theme="dark"] .blog-list {
  background: rgba(15, 19, 35, 0.76);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px 16px;
  backdrop-filter: blur(11px);
  -webkit-backdrop-filter: blur(11px);
}

[data-theme="dark"] .blog-list .blog-row:last-child {
  border-bottom: 0;
}

[data-theme="dark"] .prose {
  padding: 28px 32px;
  border-radius: var(--radius-lg);
  background: rgba(14, 18, 34, 0.82);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Home Index Directory Cards */
.section-label {
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.index-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.index-card {
  display: flex;
  flex-direction: column;
  padding: 16px 17px 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

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

.index-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent);
}

.index-card h2 {
  margin: 0 0 5px;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--ink);
}

.index-card p {
  margin: 0 0 10px;
  font-size: 0.83rem;
  line-height: 1.55;
  color: var(--ink-secondary);
  flex: 1;
}

.index-card-foot {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.index-card:hover .index-card-foot {
  color: var(--accent);
}

/* ==========================================================================
   Buttons, Badges & Meta Chips
   ========================================================================== */

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

[data-theme="dark"] .btn--primary {
  color: #0b1410;
  font-weight: 600;
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}

[data-theme="dark"] .btn--primary:hover {
  color: #0b1410;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--ink-secondary);
}

.chip--accent {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.chip--gold {
  background: var(--accent-gold-soft);
  border-color: transparent;
  color: var(--accent-gold);
}

/* ==========================================================================
   Blog List & Article View
   ========================================================================== */

.blog-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}

.blog-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 18px;
  padding: 20px 10px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease;
}

.blog-row:hover {
  background: var(--surface);
}

.blog-date {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}

.blog-row-title {
  margin: 0 0 6px;
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--ink);
  transition: color 0.15s ease;
}

.blog-row:hover .blog-row-title {
  color: var(--accent);
}

.blog-row-summary {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--ink-secondary);
  line-height: 1.65;
}

.blog-empty {
  padding: 40px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  text-align: center;
  color: var(--ink-secondary);
  background: var(--surface);
}

.blog-tip {
  margin-top: 28px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--ink-secondary);
}

.blog-tip code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 22px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-muted);
  transition: color 0.15s ease;
}

.back-link:hover {
  color: var(--accent);
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-muted);
}

/* ==========================================================================
   Study Notes (Abstract Algebra)
   ========================================================================== */

.note-hero-card {
  padding: 26px 26px 24px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.note-hero-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.note-hero-card h2 {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--ink);
}

.note-ref {
  margin: 0 0 14px;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.note-summary {
  margin: 0 0 16px;
  color: var(--ink-secondary);
  font-size: 0.94rem;
}

.note-highlights {
  margin: 0 0 20px;
  padding-left: 18px;
  color: var(--ink-secondary);
  font-size: 0.9rem;
}

.note-highlights li {
  margin-bottom: 5px;
}

/* Chapter Outline Accordion */
.outline-block {
  margin-bottom: 26px;
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chapter-item {
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.chapter-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease;
}

.chapter-summary::-webkit-details-marker {
  display: none;
}

.chapter-summary:hover {
  background: var(--surface-subtle);
}

.chapter-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.chapter-num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 600;
}

.chapter-title {
  font-weight: 600;
  font-size: 0.96rem;
  color: var(--ink);
}

.chapter-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chapter-pages {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.chapter-sections {
  margin: 0;
  padding: 4px 18px 16px 36px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 20px;
  font-size: 0.87rem;
  color: var(--ink-secondary);
}

/* Embedded PDF Reader */
.pdf-viewer-shell {
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.pdf-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-secondary);
}

.pdf-frame {
  display: block;
  width: 100%;
  height: min(76vh, 820px);
  border: 0;
  background: #2b2e38;
}

.pdf-fallback-note {
  padding: 10px 16px;
  font-size: 0.8rem;
  color: var(--ink-muted);
  border-top: 1px solid var(--border);
  background: var(--surface-subtle);
}

.pdf-fallback-note a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ==========================================================================
   Projects Page (auto_vaulting)
   ========================================================================== */

.project-banner {
  padding: 26px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.project-banner-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.project-banner h2 {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 1.45rem;
  color: var(--ink);
}

.project-banner p {
  margin: 0;
  color: var(--ink-secondary);
  font-size: 0.94rem;
}

.workflow-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.workflow-step {
  padding: 12px 13px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.workflow-step-num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 700;
  display: block;
  margin-bottom: 4px;
}

.workflow-step strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 3px;
  color: var(--ink);
}

.workflow-step span {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--ink-secondary);
  display: block;
}

/* ==========================================================================
   About Contact Cards
   ========================================================================== */

.contact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 28px;
}

.contact-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.contact-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.contact-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.contact-value {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
}

/* ==========================================================================
   Prose (Markdown, KaTeX, Code Highlight)
   ========================================================================== */

.prose {
  font-size: 0.98rem;
  line-height: 1.85;
  color: var(--ink);
}

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

.prose h2 {
  margin: 2em 0 0.75em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-serif);
  font-size: 1.32rem;
  font-weight: 700;
  color: var(--ink);
}

.prose h3 {
  margin: 1.6em 0 0.6em;
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--ink);
}

.prose p {
  margin: 0 0 1.15em;
  color: var(--ink);
}

.prose ul,
.prose ol {
  margin: 0 0 1.25em;
  padding-left: 1.45em;
}

.prose li {
  margin-bottom: 0.45em;
}

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

.prose blockquote {
  margin: 1.4em 0;
  padding: 10px 16px;
  border-left: 3px solid var(--accent);
  background: var(--surface-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--ink-secondary);
}

.prose blockquote > p:last-child {
  margin-bottom: 0;
}

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

.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
}

.prose pre {
  margin: 1.35em 0;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  overflow-x: auto;
  line-height: 1.6;
}

.prose pre code {
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.85rem;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 0.9rem;
}

.prose th,
.prose td {
  padding: 10px 12px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.prose th {
  background: var(--surface-subtle);
  font-weight: 600;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
}

/* Highlight.js minimal dual-theme tokens */
.hljs-keyword,
.hljs-selector-tag,
.hljs-title.function_ {
  color: #2d7d63;
  font-weight: 600;
}
.hljs-string,
.hljs-attr {
  color: #b45309;
}
.hljs-number,
.hljs-literal {
  color: #9f1239;
}
.hljs-comment {
  color: #868d98;
  font-style: italic;
}
.hljs-built_in,
.hljs-type {
  color: #1d4ed8;
}

[data-theme="dark"] .hljs-keyword,
[data-theme="dark"] .hljs-selector-tag,
[data-theme="dark"] .hljs-title.function_ {
  color: #52d1a0;
}
[data-theme="dark"] .hljs-string,
[data-theme="dark"] .hljs-attr {
  color: #f6c177;
}
[data-theme="dark"] .hljs-number,
[data-theme="dark"] .hljs-literal {
  color: #eb6f92;
}
[data-theme="dark"] .hljs-comment {
  color: #6f7a91;
}
[data-theme="dark"] .hljs-built_in,
[data-theme="dark"] .hljs-type {
  color: #9ccfd8;
}

/* ==========================================================================
   Responsive Design (Tablet & Mobile)
   ========================================================================== */

@media (max-width: 960px) {
  .index-grid {
    grid-template-columns: 1fr;
  }

  .workflow-steps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chapter-sections {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .mobile-header {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop.is-open {
    display: block;
  }

  .main-wrap {
    margin-left: 0;
  }

  .main-content {
    padding: 28px 20px 56px;
  }

  .page-footer {
    padding: 16px 20px 28px;
    flex-direction: column;
    align-items: flex-start;
  }

  .blog-row {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 16px 6px;
  }

  .contact-grid {
    grid-template-columns: 1fr;
  }

  .castle-backdrop {
    left: 0;
  }

  .castle-backdrop-ralsei {
    --ralsei-fw: 126px;
    bottom: 24%;
  }

  .home-layout {
    min-height: auto;
    gap: 32px;
  }

  [data-theme="dark"] .prose {
    padding: 20px 18px;
  }

  .pdf-frame {
    height: 62vh;
  }
}

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