/* Typography styles for ICARUS blog */

/* Base typography */
body {
  font-family: var(--font-serif);
  font-size: 16.5px;
  line-height: 1.6;
  background-color: var(--bg);
  color: var(--fg);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  overflow-x: hidden; /* ensure only vertical scrolling on body */
}

/* General content typography styles */
.content {
  padding-top: 0.25rem;
}

.content .MathJax {
  font-size: 100% !important;
  /* Do not clip vertical glyphs (radicals, braces). Allow natural height. */
  overflow: visible;
}

.content .katex {
  font-size: 100% !important;
  /* Allow KaTeX to extend above/below baseline (needed for \sqrt, \underbrace). */
  overflow: visible;
  /* padding-bottom: 1.0rem; */
}

/* Center-align display equations */
.content .katex-display {
  text-align: center;
  margin: 1.5rem 0;
}

/* Center-align equations that are inside paragraphs (common case with rehype-katex) */
.content p:has(> .katex) {
  text-align: center;
  margin: 1.5rem 0;
}

/* Make katex elements in paragraphs display as block for proper centering */
.content p > .katex {
  display: block;
  text-align: center;
}

/* If extremely wide display equations overflow horizontally, allow scrolling on the
   inner KaTeX block while keeping vertical overflow visible. */
.content .katex-display > .katex {
  overflow-x: auto;
  overflow-y: visible;
}

.content :last-child {
  margin-bottom: 0;
}

.content a {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg4) 30%, transparent);
  transition:
    color 0.3s ease-in-out,
    text-decoration-color 0.3s ease-in-out;
}

.content a:hover {
  color: var(--fg2);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg2) 30%, transparent);
}

.content a.footnote-ref {
  text-decoration: none;
}

.content a.footnote-ref::before {
  content: "[";
}

.content a.footnote-ref::after {
  content: "]";
}

.content blockquote {
  background-color: var(--bg_s);
  border-left: none;
  font-style: normal;
  padding: 0 1rem;
  margin: 0.9rem 0 0.9rem 0.8rem;
}

.content blockquote blockquote {
  background-color: var(--bg1);
}

/* Epigraph style (Tufte-inspired) */
.content blockquote.epigraph {
  background: transparent;
  border: none;
  color: var(--fg2);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 0.9rem 0 0.9rem 0.8rem;
  max-width: 100%;
  padding: 0 1rem;
  position: relative;
}
.content blockquote.epigraph::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.2rem;
  bottom: 0.2rem;
  width: 3px;
  background-color: var(--fg5);
  opacity: 0.6;
}

.content pre {
  background-color: var(--bg_code) !important;
  border-radius: 0.5rem;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
  position: relative;
  overflow-x: auto;
  padding: 0.9rem 1.5rem 0.9rem 0.9rem; /* default top padding for blocks without language */
  -webkit-text-size-adjust: none; /* prevent iOS font boosting */
  text-size-adjust: none;
  font-variant-ligatures: none;
  /* letter-spacing: 0; keep tracking tight */
  font-weight: 400;
}

/* Increase top padding only when language label is present */
.content pre:has(code[data-lang]) {
  padding-top: 1.6rem;
}

/* Copy button styles */
.code-block-wrapper {
  position: relative;
}
button.copy-button,
.content pre .copy-button,
.highlight .copy-button,
pre.astro-code .copy-button,
pre.chroma .copy-button,
pre .copy-button {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  left: auto;
  background-color: rgba(245, 245, 245, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #666;
  border: 1px solid rgba(233, 233, 233, 0.8);
  border-radius: 0.2rem;
  padding: 0.25rem 0.35rem;
  cursor: pointer;
  opacity: 0;
  transition:
    opacity 0.2s ease-in-out,
    background-color 0.15s ease-in-out,
    color 0.15s ease-in-out;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  font-size: 0.65rem;
  font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
  line-height: 1;
}

.code-block-wrapper:hover .copy-button,
.content pre:hover .copy-button,
.highlight:hover .copy-button,
pre.astro-code:hover .copy-button,
pre.chroma:hover .copy-button,
pre:hover .copy-button {
  opacity: 1;
}

button.copy-button:hover,
.content pre .copy-button:hover,
.highlight .copy-button:hover,
pre.astro-code .copy-button:hover,
pre.chroma .copy-button:hover,
pre .copy-button:hover {
  opacity: 1 !important;
  background-color: rgba(245, 245, 245, 0.95);
  color: #333;
  border-color: rgba(208, 208, 208, 0.9);
}

button.copy-button svg,
.content pre .copy-button svg,
.highlight .copy-button svg,
pre.astro-code .copy-button svg,
pre.chroma .copy-button svg,
pre .copy-button svg {
  width: 0.75rem;
  height: 0.75rem;
  stroke: currentColor;
  fill: none;
  flex-shrink: 0;
}

button.copy-button .copy-text,
.content pre .copy-button .copy-text,
.highlight .copy-button .copy-text,
pre.astro-code .copy-button .copy-text,
pre.chroma .copy-button .copy-text,
pre .copy-button .copy-text {
  margin: 0;
}

.content pre code {
  padding: 0;
  color: var(--fg3); /* slightly darker to match prod */
  font-family: inherit; /* inherit monospace from pre */
  padding: 0 0.8rem 0 0.2rem;
  font-size: 13px;
  /* Preserve original lines; allow horizontal scroll on container */
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
  display: block;
  line-height: 1.4;
  -webkit-text-size-adjust: none; /* ensure nested spans don't inflate */
  text-size-adjust: none;
  letter-spacing: 0;
  font-weight: 400;
}

/* Improve text selection contrast inside code blocks */
.content pre::selection,
.content pre code::selection,
.content pre *::selection {
  background-color: #d0d0d0;
}
.content pre::-moz-selection,
.content pre code::-moz-selection,
.content pre *::-moz-selection {
  background-color: #d0d0d0;
}

.darkmode .content pre::selection,
.darkmode .content pre code::selection,
.darkmode .content pre *::selection {
  background-color: rgba(255, 255, 255, 0.5);
  color: var(--bg);
}
.darkmode .content pre::-moz-selection,
.darkmode .content pre code::-moz-selection,
.darkmode .content pre *::-moz-selection {
  background-color: rgba(255, 255, 255, 0.5);
  color: var(--bg);
}

/* Language label chip shown at top-left of code blocks */
.content pre code[data-lang]::before,
pre.chroma code[data-lang]::before,
pre.astro-code code[data-lang]::before,
pre code[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0.45rem;
  left: 0.75rem;
  z-index: 5;
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--fg4);
  padding: 0;
  text-transform: lowercase;
  pointer-events: none;
}

/* Extra top padding when language label is present */
.content pre:has(code[data-lang]),
pre.chroma:has(code[data-lang]),
pre.astro-code:has(code[data-lang]),
pre:has(code[data-lang]) {
  padding-top: 1.6rem;
}

.content code {
  padding: 0;
  color: var(--red);
  font-family: SFMono-Regular, 'SF Mono', ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  padding: 0 0.2rem 0 0.2rem;
  font-size: 0.9em;
  text-wrap: wrap;
  display: inline;
}

.content mark {
  background-color: var(--bg_s);
  color: var(--fg1);
  border-radius: 0.2rem;
  padding: 0 0.2rem;
}

.content kbd {
  background-color: var(--bg_s);
  color: var(--fg1);
  border-radius: 0.2rem;
}

.content table {
  display: block;
  overflow-x: auto;
  margin: auto;
  background-color: var(--bg);
  border-collapse: collapse;
  border: none;
}

.content table td,
.content table th {
  border: var(--fg4) 1px solid;
  padding: 0.6rem 0.6rem;
}
.content table td {
  vertical-align: top;
  font-size: 1.0rem;
}

.content table th {
  background-color: var(--bg_s);
  font-weight: bold;
}

.content ul {
  list-style: square;
  margin-left: 1.25rem;
  margin-top: 0.75rem;
  margin-bottom: 0.9rem;
}

.content ul > li {
  margin-bottom: 0.2rem;
}

.content ol {
  list-style: decimal;
  margin-left: 1.5rem;
  margin-top: 0.75rem;
  margin-bottom: 0.9rem;
}

.content ol > li {
  margin-bottom: 0.2rem;
}

/* Nested ordered lists use lowercase letters */
.content ol ol {
  list-style-type: lower-alpha;
}

.content dt {
  font-weight: bold;
}

.content dd {
  margin-left: 1rem;
}

.content blockquote,
.content div,
.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6,
.content p,
.content pre,
.content table,
.content dl,
.content video {
  margin-top: 0rem;
  margin-bottom: 1.1rem;
}

/* Only for blog title */
.content h1 {
  font-size: 1.9rem;
  margin: 0 0 0.5em;
  margin-top: 1.1em;
  font-weight: 700;
  line-height: 1.4;
}

/* Legal and other non-blog pages: match blog-post h1 styling */
#main.content article.content h1 {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 30px;
  line-height: 1.4;
}

/* Center-align the main page title on legal pages */
#main.content article.content h1:first-child {
  text-align: center;
  max-width: 480px;
  margin: 1.5rem auto 0;
}

/* Tighten spacing between legal page title and the Last updated line */
#main.content article.content h1 + h3 {
  margin-top: 0.3rem;   /* close the gap to the title */
  margin-bottom: 0.9rem;/* add breathing room below */
  text-align: center;   /* ensure centered regardless of inline styles */
}

/* Used for blog body content */
.content h2 {
  font-size: 1.35rem;
  margin: 1.3em 0 0.5em;
  margin-top: 1.1em;
  font-weight: 600;
  line-height: 1.4;
}

.content h3 {
  font-size: 1.2rem;
  margin: 1.1em 0 0.4em 0;
  font-weight: bold;
  font-style: italic;
  line-height: 1.4;
}

/* Use h4 and below sparingly */
.content h4 {
  font-size: 0.97rem;
  margin: 1.2em 0 0.55em 0;
  font-weight: bold;
  font-style: italic;
}

.content h5 {
  font-size: 0.76rem;
  margin: 1.2em 0 0.55em 0;
  font-weight: normal;
  font-style: italic;
}

.content h6 {
  font-size: 0.6rem;
  margin: 1.2em 0 0.55em 0;
  font-weight: normal;
  font-style: italic;
}

/* Ensure spacing after figures before the next heading (avoid margin collapse) */
.content figure + h1,
.content figure + h2,
.content figure + h3,
.content figure + h4,
.content figure + h5,
.content figure + h6 {
  margin-top: 1.5rem;
}

.content img {
  max-width: 100%;
}

.content strong.chinese {
  font-weight: normal;
  text-emphasis-style: dot;
  text-emphasis-position: under;
  -webkit-text-emphasis-style: dot;
  -webkit-text-emphasis-position: under;
}

/* Back to top link hover */
#back-to-top:hover {
  text-decoration: underline !important;
}