:root {
  --bg: #f7f0dd;
  --bg-2: #f2e6cf;
  --ink: #1d150c;
  --muted: #6b5a43;
  --accent: #c2692e;
  --accent-2: #2d5a3c;
  --accent-link: #b05a8a;
  --accent-hover: #7a1a5c;
  --line: rgba(45, 34, 22, 0.2);
  --overscroll: #efe3c6;
  --max-width: 860px;
}

* {
  box-sizing: border-box;
}

/* The macOS rubber-band exposes the canvas past the ends of the page. Paint it
   from <html> as a flat tone: the body gradient would tile there and read as a
   mirrored copy of itself. */
html {
  background-color: var(--overscroll);
}

@media (max-width: 767px) {
  html,
  body {
    overflow-x: hidden;
  }

  .page,
  .content {
    min-width: 0;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Roboto Mono", "Courier New", monospace;
  font-weight: 400;
  line-height: 1.7;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #fdf6e7 0%, rgba(253, 246, 231, 0) 65%),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 50%, #f9f2e2 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.page {
  max-width: var(--max-width);
  margin-left: clamp(20px, 10vw, 25vw);
  margin-right: clamp(20px, 8vw, 20vw);
  padding: 64px 0 96px;
  animation: fade-in 0.6s ease-out;
}

@media (min-width: 1200px) {
  .page {
    margin-left: 25vw;
    margin-right: auto;
  }
}

.site-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-bottom: 32px;
}

.site-title {
  font-size: clamp(1rem, 1.8vw, 1.6rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
}

.site-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.back-link {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: none;
}

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

.content {
  animation: rise-in 0.5s ease-out;
}

.content > h1 {
  margin-top: 0;
}

h1,
h2,
h3 {
  line-height: 1.2;
  font-weight: 400;
  letter-spacing: 0.02em;
}

h1 {
  font-size: clamp(1.4rem, 3.3vw, 2rem);
}

h2 {
  font-size: clamp(1.1rem, 2.4vw, 1.55rem);
}

h3 {
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  font-size: clamp(0.9rem, 1.7vw, 1.1rem);
}

p,
li {
  font-size: 0.85rem;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  margin: 1rem 0;
}

.content table {
  width: max-content;
  max-width: none;
  margin-inline: auto;
  border-collapse: collapse;
  /*border-top: 3px double currentColor; */
  /*border-bottom: 3px double currentColor; */
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  font-size: 0.85rem;
  white-space: nowrap;
}

.content th,
.content td {
  padding: 0.25rem 0.5rem;
}

.content th {
  border-bottom: 3px double currentColor;
  font-weight: 700;
}

.content tbody tr:first-child {
  border-top: 0;
}

.content tbody tr + tr {
  border-top: 1px solid currentColor;
}

.content tbody tr:has(td.total-row) {
  border-top: 2px double currentColor;
}

.content th:first-child,
.content td:first-child {
  text-align: left;
}

.content th:not(:first-child) {
  text-align: center;
}

.content td:not(:first-child) {
  text-align: right;
}

.content .figure-caption,
.content .table-caption {
  font-size: 0.75rem;
}

.compact-break {
  height: 0.5em;
}

a,
a:visited {
  color: var(--accent-link);
  text-decoration-line: underline;
  text-decoration-color: var(--accent-link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
  text-decoration-skip-ink: none;
  border-bottom: none;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

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

pre {
  background: #1e1a16;
  color: #f4e7d5;
  padding: 16px 18px;
  border-radius: 12px;
  border: none;
  box-shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.18);
  overflow-x: auto;
  position: relative;
}

code {
  font-family: "Roboto Mono", "Courier New", monospace;
  font-size: 0.95em;
}

.hljs {
  background: transparent !important;
  color: #f4e7d5;
}

pre code.hljs {
  padding: 0 !important;
  background: transparent !important;
}

/* Match paragraph text even before Highlight.js finishes (or if it fails). */
pre code {
  font-size: 0.85rem;
}

.copy-button {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 2px 4px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #f0e2cd;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.code-block-wrapper {
  position: relative;
  margin: 1em 0;
}

.code-block-wrapper > pre {
  margin: 0;
}

blockquote {
  margin: 24px 0;
  padding: 8px 20px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.4);
}

.algorithm-block {
  margin: 24px 0;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.algorithm-title {
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.algorithm-steps {
  margin: 0;
  padding-left: 1.5rem;
}

.algorithm-steps li {
  margin: 6px 0;
  padding-left: calc(var(--indent) * 1.5rem);
}

.algo-key {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

img,
video,
iframe {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(40, 30, 20, 0.15);
}

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 32px 0;
}

/* Keep MathJax comfortably legible relative to the surrounding monospace text. */
mjx-container {
  font-size: 120% !important;
}

/* Keep wide display equations inside the article and let each one scroll. */
mjx-container[jax="CHTML"][display="true"] {
  display: block !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}

/* Preserve MathJax's centered layout unless the equation actually overflows. */
mjx-container[jax="CHTML"][display="true"].math-overflow {
  text-align: left !important;
}

.pub-list,
.post-list {
  margin-top: 48px;
}

.pub-list h2,
.post-list h2 {
  margin-top: 0;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.pub-list h2 a,
.pub-list h2 a:visited {
  font-size: 0.85rem;
}

.pub-list h2 a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

.pub-list ul {
  list-style: none;
  padding: 0;
  margin: 20px 0 0;
  display: grid;
  gap: 20px;
}

.pub {
  display: grid;
  gap: 2px;
  animation: lift-in 0.5s ease-out both;
}

.pub-title {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
  font-size: 0.85rem;
  line-height: 1.4;
}

.pub-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.pub:nth-child(2) {
  animation-delay: 0.04s;
}

.pub:nth-child(3) {
  animation-delay: 0.08s;
}

.pub:nth-child(4) {
  animation-delay: 0.12s;
}

.pub:nth-child(n + 5) {
  animation-delay: 0.16s;
}

.post-list ul {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: grid;
  gap: 12px;
}

.post-list li {
  display: flex !important;
  flex-direction: row !important;
  align-items: baseline;
  gap: 12px;
  animation: lift-in 0.5s ease-out both;
}

.post-list li > .post-date,
.post-list li > a {
  display: inline-block;
  vertical-align: baseline;
}

.post-list li:nth-child(2) {
  animation-delay: 0.04s;
}

.post-list li:nth-child(3) {
  animation-delay: 0.08s;
}

.post-list li:nth-child(4) {
  animation-delay: 0.12s;
}

.post-list li:nth-child(5) {
  animation-delay: 0.16s;
}

.post-date {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
  flex: 0 0 auto;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes lift-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
