/* ==========================================================================
   Szymon Kaliski & Steph Ango Inspired Theme (Dense & Compact Layout)
   Typography: SF Pro + Helvetica / Helvetica Neue Stack
   ========================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "SF Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Light Theme Palette */
  --bg: #ffffff;
  --bg-blur: rgba(255, 255, 255, 0.85);
  --bg-secondary: #f6f8fa;
  --bg-hover: #eaeef2;
  --text: #111111;
  --text-muted: #666666;
  --text-dim: #888888;
  --border: #e1e4e8;
  --link: #111111;
  --link-hover: #444444;
  --accent: #2b5c8f;
  --code-bg: #f5f5f5;
  --tooltip-shadow: rgba(0, 0, 0, 0.08);
  --fn-num-color: #d97706;

  /* Syntax Highlighting - One Light (Light Mode) */
  --code-text: #383a42;
  --code-border: #e5e5e6;
  --syntax-keyword: #a626a4;
  --syntax-type: #c18401;
  --syntax-name: #383a42;
  --syntax-var: #e45649;
  --syntax-builtin: #c18401;
  --syntax-fn: #4078f2;
  --syntax-special-fn: #0184bc;
  --syntax-string: #50a14f;
  --syntax-number: #986801;
  --syntax-operator: #0184bc;
  --syntax-comment: #a0a1a7;
  --syntax-ln: #a0a1a7;
  --syntax-hl: #f2f2f3;
}

.theme-dark {
  /* Dark Theme Palette */
  --bg: #121316;
  --bg-blur: rgba(18, 19, 22, 0.85);
  --bg-secondary: #1a1c23;
  --bg-hover: #252830;
  --text: #e6e8ec;
  --text-muted: #9aa0a6;
  --text-dim: #6c727c;
  --border: #2a2d37;
  --link: #e6e8ec;
  --link-hover: #ffffff;
  --accent: #64a2df;
  --code-bg: #1b1d24;
  --tooltip-shadow: rgba(0, 0, 0, 0.5);
  --fn-num-color: #e07a5f;

  /* Syntax Highlighting - One Dark Pro Darker (Dark Mode) */
  --code-text: #abb2bf;
  --code-border: #282c34;
  --syntax-keyword: #c678dd;
  --syntax-type: #e5c07b;
  --syntax-name: #abb2bf;
  --syntax-var: #e06c75;
  --syntax-builtin: #e5c07b;
  --syntax-fn: #61afef;
  --syntax-special-fn: #56b6c2;
  --syntax-string: #98c379;
  --syntax-number: #d19a66;
  --syntax-operator: #56b6c2;
  --syntax-comment: #7f848e;
  --syntax-ln: #4b5263;
  --syntax-hl: #2c313c;
}

/* System preference fallback if no explicit theme set */
@media (prefers-color-scheme: dark) {
  :root:not(.theme-light) {
    --bg: #121316;
    --bg-blur: rgba(18, 19, 22, 0.85);
    --bg-secondary: #1a1c23;
    --bg-hover: #252830;
    --text: #e6e8ec;
    --text-muted: #9aa0a6;
    --text-dim: #6c727c;
    --border: #2a2d37;
    --link: #e6e8ec;
    --link-hover: #ffffff;
    --accent: #64a2df;
    --code-bg: #1b1d24;
    --tooltip-shadow: rgba(0, 0, 0, 0.5);
    --fn-num-color: #e07a5f;

    /* Syntax Highlighting - One Dark Pro Darker (Dark Mode) */
    --code-text: #abb2bf;
    --code-border: #282c34;
    --syntax-keyword: #c678dd;
    --syntax-type: #e5c07b;
    --syntax-name: #abb2bf;
    --syntax-var: #e06c75;
    --syntax-builtin: #e5c07b;
    --syntax-fn: #61afef;
    --syntax-special-fn: #56b6c2;
    --syntax-string: #98c379;
    --syntax-number: #d19a66;
    --syntax-operator: #56b6c2;
    --syntax-comment: #7f848e;
    --syntax-ln: #4b5263;
    --syntax-hl: #2c313c;
  }
}

/* Scalable disk contours behind the header and introduction on every screen. */
.disk-bleed {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: clamp(420px, 90vw, 720px);
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

@media (min-width: 1200px) {
  .disk-bleed { height: min(46vw, 760px); }
}

.disk-bleed svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Global Reset & Base Setup */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 5.5rem;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  /* Compact font size like Szymon's site */
  line-height: 1.48;
  /* Dense line spacing */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Container & Layout */
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-wrapper,
.header-inner {
  max-width: 50rem;
  margin: 0 auto;
  padding: 0 1rem;
  width: 100%;
}

.site-wrapper {
  padding-bottom: 3rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

@media (min-width: 1024px) {
  .site-wrapper,
  .header-inner {
    margin-left: max(6rem, 18vw);
    margin-right: auto;
    max-width: 48rem;
  }
}

@media (min-width: 900px) and (max-width: 1023px) {
  .site-wrapper,
  .header-inner {
    margin-left: max(3.5rem, 11vw);
    margin-right: auto;
    max-width: 42rem;
  }
}

main {
  flex: 1;
}

.post-content {
  position: relative;
}

/* Typography & Headings (All-Lowercase Minimal Style for Nav & UI Headers) */
h1,
h2,
h3,
h4,
h5,
h6,
.site-title,
.site-title a,
nav.main-nav a,
.fig-bar-title {
  text-transform: lowercase;
  letter-spacing: -0.01em;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 1.25;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

h1 {
  font-size: 1.35rem;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  font-size: 1rem;
}

h4 {
  font-size: 0.95rem;
}

p {
  margin-top: 0;
  margin-bottom: 0.85rem;
  color: var(--text);
}

.intro-section > p:first-of-type {
  font-size: 1.15rem;
  line-height: 1.6;
  margin-bottom: 1.25rem;
}

.tabular-num,
time,
.date-col {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* Links & Underline Hover Effect */
a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--border);
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
  position: relative;
  z-index: 2;
  display: inline;
}

a:hover {
  color: var(--link-hover);
  text-decoration-color: var(--text);
}

a.plain {
  text-decoration: none;
}

a.plain:hover {
  text-decoration: underline;
}

/* External Link Indicator Arrow ↗ */
a.external-link::after {
  content: " ↗";
  font-size: 0.85em;
  color: var(--text-dim);
  display: inline-block;
  text-decoration: none;
  font-weight: normal;
  transition: transform 0.15s ease, color 0.15s ease;
}

a.external-link:hover::after {
  color: var(--text);
  transform: translate(1px, -1px);
}

/* Tag / Topic Badges */
.badge {
  display: inline-block;
  font-size: 0.78rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background-color: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin-right: 0.3rem;
  text-decoration: none;
  font-weight: 500;
}

.badge:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* Images, Figures & Media (Minimal Card Aesthetic) */
img {
  max-width: 100%;
  max-height: 480px;
  object-fit: contain;
  height: auto;
  display: block;
  margin: 1.25rem auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.post-content img {
  cursor: zoom-in;
}

.post-content img:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--tooltip-shadow);
  border-color: var(--accent);
}

figure {
  margin: 1.5rem 0;
  text-align: center;
}

figure img {
  margin: 0 auto 0.45rem auto;
}

figcaption {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.35rem;
}

video {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin: 1.25rem 0;
}

/* Navigation Header (Szymon Kaliski Layout - Compact) */
header.site-header {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-blur);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  backdrop-filter: blur(12px) saturate(180%);
  padding-top: calc(1.75rem + env(safe-area-inset-top, 0px));
  padding-bottom: 0.85rem;
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

/* Keep the thin contours sharp at the top; restore the reading surface on scroll. */
header.site-header.has-disk:not(.is-scrolled) {
  background-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.header-inner {
  position: relative;
  z-index: 1;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}

.site-title {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.site-title a,
.site-title-link {
  display: inline-flex;
  align-items: baseline;
  text-decoration: none;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  border-radius: 4px;
}

.site-title a:hover,
.site-title-link:hover {
  color: var(--link-hover);
}

.chinese-name-wrapper {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  outline: none;
  box-shadow: none !important;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  vertical-align: baseline;
}

.chinese-name-wrapper:focus-visible {
  outline: 1.5px solid var(--accent);
  outline-offset: 2px;
}

.chinese-ruby {
  display: inline-flex;
  align-items: baseline;
  gap: 1.5px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  line-height: 1;
  transition: color 0.2s ease;
}

.chinese-name-wrapper:hover .chinese-ruby,
.chinese-name-wrapper.is-pinyin-active .chinese-ruby {
  color: var(--text-muted);
}

.chinese-char-pair {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.chinese-hanzi {
  display: inline-block;
  line-height: 1;
}

.chinese-rt {
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%) translateY(2px);
  font-family: var(--font-sans);
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--accent);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

/* Active State: Triggered on click / touch for 5 seconds */
.chinese-name-wrapper.is-pinyin-active .chinese-rt {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

nav.main-nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

nav.main-nav::-webkit-scrollbar {
  display: none;
}

nav.main-nav a {
  font-size: 0.92rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

nav.main-nav a:hover,
nav.main-nav a.active {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Sticky Page Title Bar (Reveals smoothly when scrolled past main h1) */
.sticky-page-title-bar {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  padding-top: 0;
  overflow: hidden;
  transform: translateY(-4px);
  transition: max-height 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              margin-top 0.25s cubic-bezier(0.16, 1, 0.3, 1),
              padding-top 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.sticky-page-title-bar.is-visible {
  max-height: 2.2rem;
  opacity: 1;
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--border);
  transform: translateY(0);
  pointer-events: auto;
}

.sticky-page-title-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  cursor: pointer;
  max-width: 100%;
  user-select: none;
  color: var(--text);
  line-height: 1.25;
}

.sticky-page-title-text {
  font-size: 0.94rem;
  font-weight: 700;
  font-style: italic;
  letter-spacing: -0.015em;
  text-transform: lowercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  transition: color 0.15s ease;
  min-width: 0;
}

.sticky-page-title-inner:hover .sticky-page-title-text {
  color: var(--link-hover);
}

.sticky-page-title-date {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: normal;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: auto;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Steph Ango Signature Pill Shaped Theme Toggle */
.theme-toggle-pill {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 9999px;
  background-color: var(--bg);
  border: 1px solid var(--border);
  padding: 2px;
  cursor: pointer;
  outline: none;
  display: inline-flex;
  align-items: center;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.theme-toggle-pill:hover {
  border-color: var(--text-muted);
}

.theme-toggle-knob {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transform: translateX(0);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), color 0.25s ease;
}

.theme-toggle-knob .icon-sun {
  display: block;
}

.theme-toggle-knob .icon-moon {
  display: none;
}

/* Dark theme state */
.theme-dark .theme-toggle-knob,
:root:not(.theme-light) .theme-toggle-knob {
  transform: translateX(18px);
}

.theme-dark .theme-toggle-knob .icon-sun,
:root:not(.theme-light) .theme-toggle-knob .icon-sun {
  display: none;
}

.theme-dark .theme-toggle-knob .icon-moon,
:root:not(.theme-light) .theme-toggle-knob .icon-moon {
  display: block;
}

/* Explicit Light theme override */
.theme-light .theme-toggle-knob {
  transform: translateX(0) !important;
}

.theme-light .theme-toggle-knob .icon-sun {
  display: block !important;
}

.theme-light .theme-toggle-knob .icon-moon {
  display: none !important;
}

/* Search Trigger Button */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: inherit;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background-color: var(--bg-secondary);
  color: var(--text);
  border-color: var(--text-muted);
}

kbd {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  color: var(--text-muted);
  line-height: 1;
  display: inline-block;
}

@media (max-width: 640px) {
  .search-trigger kbd {
    display: none;
    /* Clean icon-only search button on mobile */
  }
}

/* Dense List Item Styles (Szymon Kaliski Style) */
.item-list {
  list-style: none;
  padding: 0;
  margin: 0.85rem 0;
}

.item-list li {
  margin-bottom: 0.85rem;
  /* Tight item spacing matching Szymon Kaliski's site */
  display: flex;
  align-items: baseline;
  gap: 1rem;
  line-height: 1.45;
}

.item-list .item-date {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  width: 90px;
}

.item-list .item-content {
  flex: 1;
}

.item-title-wrapper {
  display: block;
  margin-bottom: 0.1rem;
}

.item-list .item-title {
  font-weight: 600;
  display: inline;
}

.item-list .item-desc {
  display: block;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.12rem;
  margin-left: 0;
  line-height: 1.42;
}

/* Instant Search Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.search-modal-content {
  background: var(--bg);
  border: 1px solid var(--border);
  width: 90%;
  max-width: 600px;
  border-radius: 12px;
  box-shadow: 0 20px 40px var(--tooltip-shadow);
  overflow: hidden;
}

.search-input-header {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.search-input-header input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text);
}

.search-results-list {
  max-height: 360px;
  overflow-y: auto;
  padding: 0.4rem 0;
  margin: 0;
  list-style: none;
}

.search-results-list li a {
  display: block;
  padding: 0.65rem 1.1rem;
  text-decoration: none;
  color: var(--text);
  transition: background 0.1s ease;
}

.search-results-list li a:hover,
.search-results-list li a.selected {
  background: var(--bg-secondary);
}

.search-results-list .res-title {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.15rem;
}

.search-results-list .res-snippet {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.search-results-list mark {
  background-color: rgba(255, 200, 0, 0.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

/* Horizontal Rule Divider (Compact) */
hr {
  border: none;
  height: 1px;
  background-color: var(--border);
  margin: 1.5rem 0;
}

/* Code Blocks */
pre,
code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

code {
  background-color: var(--code-bg);
  color: var(--code-text);
  padding: 0.12rem 0.3rem;
  border-radius: 4px;
  white-space: nowrap;
}

pre {
  background-color: var(--code-bg);
  color: var(--code-text);
  padding: 0.85rem 1rem;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--code-border);
}

pre code {
  background: transparent;
  padding: 0;
  white-space: pre;
  color: inherit;
}

/* Chroma Syntax Highlighting - One Light (Light Mode) / One Dark Pro Darker (Dark Mode) */
.chroma {
  color: var(--code-text);
  background-color: var(--code-bg);
}

.chroma .line {
  display: flex;
}

.chroma .lntd {
  vertical-align: top;
  padding: 0;
  margin: 0;
  border: 0;
}

.chroma .lntable {
  border-spacing: 0;
  padding: 0;
  margin: 0;
  border: 0;
}

.chroma .hl {
  background-color: var(--syntax-hl);
}

.chroma .lnt,
.chroma .ln {
  white-space: pre;
  user-select: none;
  margin-right: 0.8em;
  padding: 0 0.4em;
  color: var(--syntax-ln);
}

.chroma .k,
.chroma .kd,
.chroma .kn,
.chroma .kp,
.chroma .kr {
  color: var(--syntax-keyword);
  font-weight: 500;
}

/* Keywords (Mauve) */
.chroma .kc,
.chroma .kt {
  color: var(--syntax-type);
}

/* Keyword Constants & Types (Yellow) */
.chroma .n,
.chroma .na,
.chroma .no,
.chroma .nd,
.chroma .ni,
.chroma .ne,
.chroma .nl,
.chroma .nn,
.chroma .nx,
.chroma .py,
.chroma .nt {
  color: var(--syntax-name);
}

/* Names */
.chroma .nv,
.chroma .vc,
.chroma .vg,
.chroma .vi,
.chroma .vm {
  color: var(--syntax-var);
}

/* Variables (Red) */
.chroma .nc,
.chroma .nb,
.chroma .bp {
  color: var(--syntax-builtin);
}

/* Classes & Builtins (Yellow/Lavender) */
.chroma .nf {
  color: var(--syntax-fn);
  font-weight: 500;
}

/* Functions (Blue) */
.chroma .fm {
  color: var(--syntax-special-fn);
  font-weight: 500;
}

/* Special Functions (Teal) */
.chroma .s,
.chroma .sa,
.chroma .sb,
.chroma .sc,
.chroma .dl,
.chroma .sd,
.chroma .s2,
.chroma .se,
.chroma .sh,
.chroma .si,
.chroma .sx,
.chroma .sr,
.chroma .s1,
.chroma .ss {
  color: var(--syntax-string);
}

/* Strings (Green) */
.chroma .m,
.chroma .mb,
.chroma .mf,
.chroma .mh,
.chroma .mi,
.chroma .il,
.chroma .mo {
  color: var(--syntax-number);
}

/* Numbers (Peach) */
.chroma .o,
.chroma .ow {
  color: var(--syntax-operator);
}

/* Operators (Sky) */
.chroma .c,
.chroma .ch,
.chroma .cm,
.chroma .c1,
.chroma .cs,
.chroma .cp,
.chroma .cpf {
  color: var(--syntax-comment);
  font-style: italic;
}

/* Comments (Overlay) */
.chroma .gd {
  color: var(--syntax-var);
  background-color: rgba(243, 139, 168, 0.15);
}

/* Generic Deleted */
.chroma .gi {
  color: var(--syntax-string);
  background-color: rgba(166, 227, 161, 0.15);
  font-weight: bold;
}

/* Generic Inserted */

/* Blockquotes */
blockquote {
  margin: 1.25rem 0;
  padding-left: 0.85rem;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  font-style: italic;
}

/* Footer */
footer.site-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.85rem;
}

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

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

/* ==========================================================================
   Footnote Details Tag & Side Margin Rendering
   ========================================================================== */

details.footnote-details {
  display: inline;
  position: static;
}

details.footnote-details>summary.footnote-summary {
  display: inline;
  cursor: pointer;
  list-style: none;
  outline: none;
  user-select: none;
  position: relative;
  z-index: 5;
}

details.footnote-details>summary.footnote-summary::-webkit-details-marker,
details.footnote-details>summary.footnote-summary::marker {
  display: none !important;
  content: "" !important;
}

.footnote-ref-num {
  color: var(--fn-num-color);
  font-weight: 600;
  font-size: 0.78em;
  line-height: 0;
  vertical-align: super;
  padding: 0 1px;
  transition: opacity 0.15s ease;
}

details.footnote-details>summary.footnote-summary:hover .footnote-ref-num {
  opacity: 0.75;
}

.footnote-body {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.footnote-num {
  color: var(--fn-num-color);
  font-weight: 600;
  font-size: 0.85em;
  vertical-align: super;
  margin-right: 0.2rem;
}

/* Desktop layout: Footnote displayed permanently in the right margin beside corresponding line */
@media (min-width: 900px) {
  details.footnote-details>summary.footnote-summary {
    cursor: default;
    pointer-events: none;
  }

  details.footnote-details>.footnote-body,
  .footnote-body {
    display: block !important;
    position: absolute;
    left: calc(100% + 2rem);
    width: 280px;
    margin-top: -0.15em;
    padding: 0;
    pointer-events: auto;
  }
}

/* Mobile & Tablet layout: Footnote expands directly below/beside the line when clicked */
@media (max-width: 899px) {
  details.footnote-details {
    position: relative;
  }

  details.footnote-details>summary.footnote-summary {
    cursor: pointer;
    pointer-events: auto;
  }

  .footnote-body {
    display: block;
    margin: 0.4rem 0 0.65rem 0;
    padding: 0.5rem 0.75rem;
    background-color: var(--bg-secondary);
    border-left: 3px solid var(--fn-num-color);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.85rem;
  }
}

/* ==========================================================================
   Figure & Video Containers (.fig-bar)
   ========================================================================== */

.fig-bar {
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--bg-secondary);
  padding: 0.75rem;
  overflow: hidden;
}

.fig-bar-content {
  text-align: center;
}

.fig-bar-media {
  display: inline-block;
  max-width: 100%;
  text-align: left;
}

.fig-bar-content img,
.post-content img {
  cursor: zoom-in;
}

.fig-bar-content img,
.fig-bar-content video {
  display: block;
  max-width: 100%;
  max-height: 480px;
  object-fit: contain;
  margin: 0 auto;
  border-radius: 4px;
}

.fig-bar-content figcaption {
  font-size: 0.825rem;
  font-style: italic;
  color: var(--text-muted);
  margin-top: 0.5rem;
  text-align: left;
}

/* ==========================================================================
   Image Lightbox / Zoom Modal
   ========================================================================== */

.image-zoom-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  padding: 1.5rem;
}

.image-zoom-overlay.active {
  opacity: 1;
  visibility: visible;
}

.image-zoom-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 92vw;
  max-height: 92vh;
}

.image-zoom-img {
  max-width: 92vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  cursor: zoom-out;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  will-change: transform;
}

.image-zoom-caption {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  font-style: italic;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
  max-width: 800px;
}

.image-zoom-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  z-index: 10000;
}

.image-zoom-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   Chinese Name Stroke Order Animation (Theme-adaptive & Mobile-optimized)
   ========================================================================== */

:root {
  --stroke-bg: #ffffff;
  --stroke-grid-line: rgba(0, 0, 0, 0.07);
  --stroke-radical: #d9383a;
  --stroke-stem: #111111;
}

.theme-dark {
  --stroke-bg: #121316;
  --stroke-grid-line: rgba(255, 255, 255, 0.08);
  --stroke-radical: #ff4d4f;
  --stroke-stem: #e6e8ec;
}

@media (prefers-color-scheme: dark) {
  :root:not(.theme-light) {
    --stroke-bg: #121316;
    --stroke-grid-line: rgba(255, 255, 255, 0.08);
    --stroke-radical: #ff4d4f;
    --stroke-stem: #e6e8ec;
  }
}

@keyframes draw-stroke {
  0% {
    opacity: 0;
  }
  1% {
    opacity: 1;
  }
  100% {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

@-webkit-keyframes draw-stroke {
  0% {
    opacity: 0;
  }
  1% {
    opacity: 1;
  }
  100% {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

.chinese-stroke-anim {
  margin: 2rem 0 1.5rem;
  padding: 1.15rem;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stroke-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
}

.stroke-card {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.stroke-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.stroke-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 0.8rem;
}

.stroke-char {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.stroke-pinyin {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.stroke-meta {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.stroke-svg-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: var(--stroke-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stroke-char-svg {
  width: 100%;
  height: 100%;
  display: block;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.stroke-grid-bg {
  fill: var(--stroke-bg);
}

.stroke-grid-line {
  stroke: var(--stroke-grid-line);
  stroke-width: 1.5;
  stroke-dasharray: 6,6;
}

.stroke-path {
  opacity: 0;
  will-change: stroke-dashoffset, opacity;
}

.stroke-path.stroke-radical {
  stroke: var(--stroke-radical);
}

.stroke-path.stroke-stem {
  stroke: var(--stroke-stem);
}

.chinese-stroke-anim.is-animating .stroke-path {
  -webkit-animation-name: draw-stroke;
  animation-name: draw-stroke;
  -webkit-animation-duration: 800ms;
  animation-duration: 800ms;
  -webkit-animation-timing-function: linear;
  animation-timing-function: linear;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-play-state: running;
  animation-play-state: running;
}

.chinese-stroke-anim.is-animating .stroke-s1 {
  -webkit-animation-delay: 0ms;
  animation-delay: 0ms;
}
.chinese-stroke-anim.is-animating .stroke-s2 {
  -webkit-animation-delay: 1000ms;
  animation-delay: 1000ms;
}
.chinese-stroke-anim.is-animating .stroke-s3 {
  -webkit-animation-delay: 2000ms;
  animation-delay: 2000ms;
}
.chinese-stroke-anim.is-animating .stroke-s4 {
  -webkit-animation-delay: 3000ms;
  animation-delay: 3000ms;
}
.chinese-stroke-anim.is-animating .stroke-s5 {
  -webkit-animation-delay: 4000ms;
  animation-delay: 4000ms;
}
.chinese-stroke-anim.is-animating .stroke-s6 {
  -webkit-animation-delay: 5000ms;
  animation-delay: 5000ms;
}
.chinese-stroke-anim.is-animating .stroke-s7 {
  -webkit-animation-delay: 6000ms;
  animation-delay: 6000ms;
}

.chinese-stroke-anim.is-completed .stroke-path {
  stroke-dashoffset: 0 !important;
  opacity: 1 !important;
  animation: none !important;
  -webkit-animation: none !important;
}

.stroke-anim-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stroke-anim-caption {
  flex: 1;
  font-size: 0.82rem;
}

.radical-legend {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
}

.radical-legend-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--stroke-radical);
}

.stroke-credit-link {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.15s ease;
}

.stroke-credit-link:hover {
  color: var(--link-hover);
}

.stroke-anim-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.stroke-btn {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.32rem 0.65rem;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.stroke-btn:hover,
.stroke-btn:active {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.stroke-loop-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.loop-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text-dim);
  transition: background-color 0.15s ease;
}

.stroke-loop-btn.active .loop-dot {
  background-color: #ffffff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
}

@media (max-width: 580px) {
  .chinese-stroke-anim {
    padding: 0.75rem;
    margin: 1.5rem 0 1rem;
  }
  .stroke-cards-grid {
    gap: 0.45rem;
  }
  .stroke-card-header {
    padding: 0.3rem 0.4rem;
  }
  .stroke-char {
    font-size: 0.95rem;
  }
  .stroke-pinyin {
    font-size: 0.75rem;
  }
  .stroke-meta {
    display: none;
  }
  .stroke-anim-footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-top: 0.65rem;
    margin-top: 0.65rem;
  }
  .stroke-anim-caption {
    font-size: 0.75rem;
    line-height: 1.3;
  }
  .stroke-btn {
    padding: 0.28rem 0.5rem;
    font-size: 0.72rem;
  }
  .stroke-btn svg {
    width: 12px;
    height: 12px;
  }
}
