: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);
}

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(1.2rem, 2vw, 1.8rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
}

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

.back-link {
  font-size: 0.9rem;
  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.8rem, 4vw, 2.6rem);
}

h2 {
  font-size: clamp(1.4rem, 3vw, 2rem);
}

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

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

a,
a:visited {
  color: var(--accent-link);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-link);
  transition: color 0.2s ease, border-color 0.2s ease;
}

a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

pre {
  background: #1e1a16;
  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;
}

.copy-button {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid #1e1a16;
  background: #1e1a16;
  color: #f0e2cd;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.copy-button:hover {
  color: var(--accent-hover);
  border-color: #1e1a16;
}

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;
}

/* Allow wide display math to scroll horizontally on small screens. */
mjx-container[display="true"] {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
}

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

.pub-list h2,
.post-list h2 {
  margin-top: 0;
  font-size: 1.1rem;
  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.95rem;
  line-height: 1.4;
}

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

.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;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  animation: lift-in 0.5s ease-out both;
}

.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.85rem;
  white-space: nowrap;
}

@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 (max-width: 700px) {
  .post-list li {
    flex-direction: column;
    align-items: flex-start;
  }
}

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