:root {
  color-scheme: light;
  --paper: #f8f7f2;
  --paper-raised: #efede6;
  --ink: #1c1b19;
  --muted: #625f5a;
  --accent: #9a364a;
  --line: #d9d6cc;
  --code: #242428;
  --code-ink: #f1ede5;
  --max: 1180px;
  --reading: 680px;
  font-size-adjust: from-font;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #19191c;
  --paper-raised: #2b2a2d;
  --ink: #f4f1ea;
  --muted: #b5b2aa;
  --accent: #db8091;
  --line: #484549;
  --code: #101013;
  --code-ink: #f4f1ea;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Noto Sans SC", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
}
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
a, button, input, textarea { -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
h1, h2, h3, h4 {
  font-family: "Noto Serif SC", "Playfair Display", serif;
  font-weight: 500;
  line-height: 1.25;
  text-wrap: balance;
}
p { text-wrap: pretty; }
.shell { width: min(calc(100% - 48px), var(--max)); margin-inline: auto; }
.shell-narrow { width: min(calc(100% - 48px), var(--reading)); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.eyebrow {
  margin: 0 0 16px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.muted { color: var(--muted); }
.text-link, .article-content a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 4px; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(14px);
}
.nav-inner { min-height: 80px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: flex; flex-direction: column; flex-shrink: 0; }
.brand-name, .footer-brand { font-family: "Noto Serif SC", serif; font-size: 30px; font-weight: 600; letter-spacing: -.05em; line-height: 1; }
.brand-note { margin-top: 7px; color: var(--muted); font-size: 10px; letter-spacing: .06em; }
.desktop-nav { display: flex; align-items: center; gap: 36px; font-size: 13px; }
.desktop-nav a:hover, .footer-links a:hover { color: var(--accent); }
.nav-actions { display: flex; align-items: center; gap: 8px; }
.icon-button, .text-button {
  min-width: 34px;
  min-height: 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}
.icon-button:hover, .text-button:hover { color: var(--accent); }
.mobile-toggle { display: none; font-size: 22px; }
.mobile-nav { padding-block: 16px 24px; border-top: 1px solid var(--line); }
.mobile-nav a { display: block; padding: 10px 0; font-family: "Noto Serif SC", serif; font-size: 22px; }

.hero-backdrop {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.hero-backdrop::before {
  content: "";
  position: absolute;
  z-index: -2;
  inset: -12%;
  background:
    radial-gradient(ellipse at 18% 28%, #9a364a26 0, transparent 48%),
    radial-gradient(ellipse at 78% 18%, #a389bd38 0, transparent 52%),
    radial-gradient(ellipse at 68% 82%, #dbc28d40 0, transparent 50%);
  animation: ambient-drift 24s ease-in-out infinite alternate;
}
.hero-backdrop::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] .hero-backdrop::before {
  background:
    radial-gradient(ellipse at 18% 28%, #9a364a38 0, transparent 48%),
    radial-gradient(ellipse at 78% 18%, #8c72ad38 0, transparent 52%),
    radial-gradient(ellipse at 68% 82%, #bda16b26 0, transparent 50%);
}
@keyframes ambient-drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to { transform: translate3d(2%, 1%, 0) scale(1.04); }
}
.hero {
  min-height: calc(100dvh - 80px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding-block: 64px;
}
.hero-avatar {
  width: 112px;
  height: 112px;
  margin-bottom: 32px;
  border: 4px solid var(--paper);
  border-radius: 50%;
  outline: 1px solid var(--line);
  aspect-ratio: 1;
  object-fit: cover;
}
.hero .eyebrow { margin-bottom: 12px; }
.hero h1 {
  max-width: 1000px;
  margin: 0;
  font-size: clamp(42px, 6.2vw, 80px);
  letter-spacing: -.035em;
  line-height: 1.14;
}
.hero-intro { max-width: 580px; margin: 24px 0 0; color: var(--muted); font-size: 17px; }
.hero-link {
  display: inline-flex;
  align-items: center;
  gap: 20px;
  margin-top: 32px;
  padding: 10px 20px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 14px;
}
.hero-link:hover { background: var(--accent); color: var(--paper); }
#recent-notes { scroll-margin-top: 80px; }
.content-section { padding-block: 64px; border-bottom: 1px solid var(--line); }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.section-head h2 { margin: 0; font-size: clamp(30px, 4vw, 42px); }
.section-head p { margin: 8px 0 0; color: var(--muted); }
.section-link { color: var(--accent); font-size: 13px; white-space: nowrap; }
.entry-list { display: flex; flex-direction: column; }
.entry { display: grid; grid-template-columns: 130px minmax(0, 1fr) auto; gap: 24px; padding-block: 26px; border-top: 1px solid var(--line); }
.entry:last-child { border-bottom: 1px solid var(--line); }
.entry-date { color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px; }
.entry h3 { margin: 0; font-size: clamp(23px, 2.6vw, 30px); }
.entry p { margin: 8px 0 0; color: var(--muted); }
.entry-arrow { color: var(--muted); }
.entry:hover h3, .entry:hover .entry-arrow { color: var(--accent); }
.entry-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.empty-state { padding: 32px 0; color: var(--muted); }
.moment-image { width: 180px; aspect-ratio: 4 / 3; object-fit: cover; }
.project-links { display: flex; flex-wrap: wrap; gap: 12px 28px; }
.project-links a { color: var(--accent); border-bottom: 1px solid var(--line); }

.page-header { padding-block: 72px 40px; border-bottom: 1px solid var(--line); }
.page-header h1 { max-width: 820px; margin: 0; font-size: clamp(40px, 5vw, 66px); letter-spacing: -.03em; }
.page-header p { max-width: 600px; margin: 18px 0 0; color: var(--muted); }
.article { padding-block: 64px 88px; }
.article-header { margin-bottom: 44px; padding-bottom: 32px; border-bottom: 1px solid var(--line); }
.article-header h1 { margin: 0 0 18px; font-size: clamp(38px, 5vw, 58px); letter-spacing: -.025em; }
.article-header time { color: var(--muted); font-size: 13px; }
.article-toc { margin-bottom: 36px; padding: 18px 20px; border-block: 1px solid var(--line); background: var(--paper-raised); }
.article-toc summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.article-toc a { display: block; padding-top: 8px; font-size: 14px; }
.article-content { overflow-wrap: anywhere; }
.article-content p, .article-content li { font-size: 17px; line-height: 1.95; }
.article-content h1 { margin: 48px 0 20px; font-size: 36px; }
.article-content h2 { margin: 44px 0 18px; font-size: 30px; scroll-margin-top: 110px; }
.article-content h3 { margin: 34px 0 14px; font-size: 24px; scroll-margin-top: 110px; }
.article-content blockquote { margin: 32px 0; padding: 12px 20px; border-left: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 4%, transparent); color: var(--muted); }
.article-content blockquote p:last-child { margin-bottom: 0; }
.article-content pre { max-width: 100%; overflow-x: auto; margin: 28px 0; padding: 22px; background: var(--code); color: var(--code-ink); }
.article-content code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .9em; }
.article-content :not(pre) > code { padding: 2px 5px; background: var(--paper-raised); color: var(--accent); }
.article-content table { width: 100%; border-collapse: collapse; margin: 28px 0; font-size: 15px; }
.article-content th, .article-content td { padding: 12px 16px; border-bottom: 1px solid var(--line); text-align: left; }
.article-content th { background: var(--paper-raised); }
.table-wrap { max-width: 100%; overflow-x: auto; }
.katex-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding-block: 10px; }
.katex { max-width: 100%; }
.moment-images { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-top: 32px; }
.moment-images img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }

.site-footer { padding-block: 52px 28px; }
.footer-grid { display: grid; grid-template-columns: 1fr auto auto; align-items: start; gap: 48px; }
.footer-grid p { max-width: 330px; color: var(--muted); }
.footer-links { display: flex; flex-wrap: wrap; gap: 16px 24px; font-size: 13px; }
.footer-bottom { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.footer-signature { display: inline-flex; align-items: center; gap: 8px; }
.starry-link { display: inline-flex; width: 32px; height: 32px; align-items: center; justify-content: center; color: var(--muted); transition: color .2s; }
.starry-link:hover, .starry-link:focus-visible { color: var(--accent); }

.search-dialog { width: min(calc(100% - 32px), 620px); max-height: 70dvh; padding: 0; border: 1px solid var(--line); background: var(--paper); color: var(--ink); box-shadow: 0 24px 80px #0002; }
.search-dialog::backdrop { background: #0007; }
.search-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
#search-input { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 16px; background: transparent; color: var(--ink); }
.search-results { max-height: 45dvh; overflow-y: auto; }
.search-result { display: block; padding: 16px; border-bottom: 1px solid var(--line); }
.search-result:hover, .search-result.is-active { background: var(--paper-raised); }
.search-result small { display: block; color: var(--accent); }
.search-result span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.search-empty { padding: 24px 16px; color: var(--muted); }

.starry-page { padding-block: 72px; }
.starry-page h1 { max-width: 760px; margin: 0; font-size: clamp(42px, 6vw, 72px); }
.starry-page > p:not(.eyebrow) { color: var(--muted); }
.star-map { position: relative; min-height: 420px; margin-top: 32px; border-block: 1px solid var(--line); background-image: radial-gradient(circle at 20% 30%, var(--line) 1px, transparent 1px), radial-gradient(circle at 80% 65%, var(--line) 1px, transparent 1px); background-size: 80px 90px, 130px 120px; }
.star-point { position: absolute; left: var(--star-x); top: var(--star-y); display: flex; align-items: center; gap: 12px; color: var(--accent); font-size: 24px; }
.star-point span { color: var(--muted); font-size: 14px; }
.starry-links { display: flex; gap: 24px; margin-top: 24px; color: var(--accent); font-size: 14px; }

.tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 32px; padding-block: 40px; }
.tool-card { padding: 28px 0; border-top: 1px solid var(--line); }
.tool-card h2 { margin: 0 0 10px; font-size: 28px; }
.tool-card p { color: var(--muted); }
.tool-card a { color: var(--accent); font-size: 14px; }
.tool-form { display: grid; gap: 16px; padding-block: 32px; }
.tool-form label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.tool-form input, .tool-form textarea, .tool-form select { width: 100%; border: 1px solid var(--line); padding: 12px; background: var(--paper); color: var(--ink); }
.tool-form textarea { min-height: 220px; resize: vertical; }
.tool-button { width: fit-content; border: 1px solid var(--accent); padding: 10px 18px; background: var(--accent); color: var(--paper); cursor: pointer; }
.tool-output { min-height: 80px; padding: 20px; border-block: 1px solid var(--line); white-space: pre-wrap; }

@media (max-width: 800px) {
  .desktop-nav { display: none; }
  .mobile-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .brand-note { display: none; }
  .entry { grid-template-columns: 1fr auto; gap: 12px; }
  .entry-date { grid-column: 1 / -1; }
  .entry-arrow { grid-column: 2; grid-row: 2; }
  .footer-grid { grid-template-columns: 1fr; gap: 24px; }
  .tool-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .shell, .shell-narrow { width: min(calc(100% - 36px), var(--max)); }
  .nav-inner { min-height: 68px; }
  .nav-actions { gap: 2px; }
  .hero h1 { font-size: clamp(40px, 12vw, 58px); }
  .content-section { padding-block: 48px; }
  .section-head { align-items: start; flex-direction: column; }
  .moment-image { width: 100%; aspect-ratio: 16 / 10; }
  .footer-bottom { align-items: start; flex-direction: column; }
}

.code-wrap { position: relative; }
.code-copy { position: absolute; top: 10px; right: 10px; border: 1px solid #ffffff30; padding: 4px 8px; background: var(--code); color: var(--code-ink); font-size: 11px; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
