:root {
  --bg: #F6F1E8;
  --surface: #EFE7D8;
  --text: #2D2926;
  --muted: #7A7268;
  --accent: #6B7A4B;
  --border: #D6C9B8;
  --serif: "Source Serif 4", Georgia, serif;
  --heading: "IBM Plex Serif", Georgia, serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #101311;
  --surface: #171B17;
  --text: #ECE8E1;
  --muted: #A39C90;
  --accent: #7A9B68;
  --border: #2C332D;
}

* { box-sizing: border-box; }
html { min-height: 100dvh; background: var(--bg); scroll-behavior: smooth; transition: background .2s ease, color .2s ease; }
body { min-height: 100dvh; margin: 0; color: var(--text); background: var(--bg); font: 400 18px/1.68 var(--serif); text-rendering: optimizeLegibility; overflow-wrap: break-word; }
a { color: inherit; text-decoration-color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
button { font: inherit; }

.site-shell { display: flex; flex-direction: column; min-height: 100dvh; width: min(100% - 3rem, 760px); margin: 0 auto; }
.site-header { display: flex; align-items: center; gap: 12px; margin-bottom: 48px; padding-top: 60px; font-family: var(--heading); font-size: 14px; font-weight: 700; line-height: 1.3; }
nav { display: flex; flex: 1; gap: 4px; margin-right: auto; }
nav a, .theme-toggle, .eyebrow, .mono, .stack, .library-kind, .entry-meta, .tag-list, footer { font-family: var(--mono); font-size: .69rem; letter-spacing: .035em; text-transform: lowercase; }
nav a { min-width: 70px; padding: 6px 14px; border: 1px dotted var(--border); color: var(--muted); font-family: var(--heading); font-size: inherit; letter-spacing: normal; text-align: center; white-space: nowrap; text-decoration: none; text-transform: uppercase; }
nav a:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; padding: 7px 10px; border: 1px dotted var(--border); color: var(--muted); background: transparent; cursor: pointer; line-height: 0; text-transform: none; }
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-icon { transform: rotate(-40deg); transition: transform .4s ease; }
.theme-icon-core { r: 8; transition: r .4s ease; }
.theme-icon-mask circle { cx: 17; cy: 7; transition: cx .4s ease, cy .4s ease; }
.theme-icon-rays { transform-box: view-box; transform-origin: center; transform: scale(0); opacity: 0; transition: transform .4s ease, opacity .25s ease; }
:root[data-theme="dark"] .theme-icon { transform: rotate(0deg); }
:root[data-theme="dark"] .theme-icon-core { r: 5; }
:root[data-theme="dark"] .theme-icon-mask circle { cx: 30; cy: 4; }
:root[data-theme="dark"] .theme-icon-rays { transform: scale(1); opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .theme-icon, .theme-icon-core, .theme-icon-mask circle, .theme-icon-rays { transition: none; }
}

main { flex: 1; }
.hero { padding: .3rem 0 4.5rem; }
.eyebrow { margin: 0 0 1.2rem; color: var(--muted); }
.eyebrow span { color: var(--accent); padding: 0 .25rem; }
h1, h2, h3 { margin: 0; font-family: var(--heading); font-weight: 600; line-height: 1.18; letter-spacing: -.025em; }
h1 { font-size: clamp(2.85rem, 9vw, 5.2rem); }
h2 { font-size: 1.48rem; }
.hero h1 { margin-bottom: .75rem; }
.jp { margin: 0 0 1.9rem; color: var(--accent); font-size: 1.35rem; }
.hero-copy { max-width: 37rem; margin: 0; font-size: clamp(1.2rem, 3vw, 1.45rem); line-height: 1.55; }
blockquote { max-width: 28rem; margin: 3rem 0 0; padding: 1.1rem 0 1.1rem 1.3rem; border-left: 2px solid var(--accent); color: var(--muted); font-style: italic; }

.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; align-items: stretch; }
.notebook-section, .latest, .project-card, .library-list article { border: 1px solid var(--border); background: var(--surface); }
.notebook-section { display: flex; flex-direction: column; padding: 1.7rem; }
/* pin each card's footer line to the bottom so both cards share the same
   heading / body / footer rhythm; padding preserves the gap when stacked */
.now > :last-child { margin-top: auto; padding-top: 1rem; }
.notebook-section h2, .latest h2 { font-size: 1.2rem; }
.notebook-section h2 a { color: inherit; text-decoration: none; }
.notebook-section h2 a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.notebook-section p { margin: 1rem 0 0; }
.muted { color: var(--muted); }
.log-list, .latest-list { margin: 1.1rem 0 0; padding: 0; list-style: none; }
.log-list li { display: grid; grid-template-columns: 7.2rem minmax(0, 1fr); gap: .75rem; padding: .55rem 0; border-top: 1px solid var(--border); font-size: .91rem; line-height: 1.45; }
.log-list time, .latest time { color: var(--muted); font: .64rem var(--mono); font-variant-numeric: tabular-nums; letter-spacing: .02em; white-space: nowrap; }
.log-viewport { max-height: 15.5rem; overflow-x: hidden; overflow-y: auto; margin-top: 1rem; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.log-viewport .log-list { margin-top: 0; }
.log-viewport::-webkit-scrollbar { width: 6px; }
.log-viewport::-webkit-scrollbar-thumb { background: var(--border); }
.log-more { margin: 0; padding-top: .9rem; margin-top: auto; font: .7rem var(--mono); }
.log-more a { color: var(--muted); text-decoration: none; }
.log-more a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.log-archive { margin-bottom: 4rem; }
.log-list--archive li { padding: .7rem 0; }
.latest { margin-top: 1.2rem; padding: 1.7rem; background: transparent; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.section-heading a { color: var(--muted); font: .7rem var(--mono); }
.latest-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1rem; padding: .8rem 0; border-top: 1px solid var(--border); }
.latest-list a { min-width: 0; text-decoration: none; }

.page-intro { padding: 0 0 3rem; }
.page-intro:has(+ .prose) { padding-bottom: 0; }
.page-intro:has(+ .plain-list) { padding-bottom: 1.4rem; }
.page-intro h1 { margin-bottom: 1.2rem; }
.page-intro h1:last-child { margin-bottom: 1.7rem; }
.page-intro > p:last-child { max-width: 32rem; margin: 0; color: var(--muted); font-size: 1.18rem; }
.page-intro:has(+ .prose) > p:last-child { margin-bottom: 1.35rem; }
.entry-list { margin-bottom: 4rem; }
.entry-card { padding: 1.8rem 0; border-top: 1px solid var(--border); }
.entry-card:last-child { border-bottom: 1px solid var(--border); }
.entry-meta { display: flex; gap: .7rem; color: var(--muted); }
.entry-card h2 { margin: .65rem 0 .5rem; font-size: 1.7rem; }
.entry-card h2 a { text-decoration: none; }
.entry-card p { max-width: 37rem; margin: 0; color: var(--muted); }
.tag-list { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: 1rem; color: var(--accent); }
.tag-list a { color: var(--accent); text-decoration: none; }

.project-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem; margin-bottom: 4rem; }
.project-card { display: flex; min-height: 235px; flex-direction: column; padding: 1.7rem; }
.project-card h2 { font-size: 1.5rem; }
.project-card > p:nth-child(2) { margin: .8rem 0 1.2rem; color: var(--muted); }
.stack { margin: auto 0 1.3rem; color: var(--accent); }
.project-links { margin: 0; font: .7rem var(--mono); }

.library-list { margin-bottom: 4rem; border-top: 1px solid var(--border); }
.library-list article { padding: 1.6rem 0; border-width: 0 0 1px; background: transparent; }
.library-kind { margin: 0 0 .4rem; color: var(--accent); }
.library-list h2 { font-size: 1.42rem; }
.byline { margin: .25rem 0 .75rem; color: var(--muted); font-style: italic; }
.library-list article > p:last-child { max-width: 34rem; margin: 0; }
.prose { max-width: 41rem; margin-bottom: 2.25rem; }
.prose p { margin: 0 0 1.65rem; }
.prose h2 { margin: 2.35rem 0 .55rem; font-size: 1.45rem; }
.prose > :last-child { margin-bottom: 0; }
.contact-note { color: var(--muted); }
.about-photo { margin: 0 0 1.65rem; }
.about-photo img { display: block; width: 100%; max-width: 100%; height: auto; }
.plain-list { margin: 0 0 2rem; padding: 0; list-style: none; border-top: 1px solid var(--border); }
.plain-list li { padding: .85rem 0; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: .92rem; letter-spacing: .02em; }
.plain-list a { text-decoration: none; }
.timeline { margin: 0 0 4rem; padding: 0; list-style: none; }
.timeline li { display: grid; grid-template-columns: 5.6rem minmax(0, 1fr); column-gap: 1.5rem; align-items: start; position: relative; }
.timeline time { grid-column: 1; padding-top: .2rem; color: var(--muted); font: .72rem var(--mono); letter-spacing: .04em; }
.timeline time.is-repeat { visibility: hidden; }
.timeline span { grid-column: 2; min-width: 0; padding: .05rem 0 1.45rem; }
.timeline li::before { content: ""; position: absolute; top: 0; bottom: 0; left: 6.25rem; width: 1px; background: var(--border); }
.timeline li::after { content: ""; position: absolute; top: .5rem; left: 6rem; width: 7px; height: 7px; border: 1px solid var(--accent); background: var(--bg); border-radius: 50%; }

.post { max-width: 42rem; padding: 5.3rem 0 4rem; }
.post h1 { margin: 1rem 0; font-size: clamp(2.6rem, 7vw, 4.2rem); }
.post-body { margin-top: 3.5rem; }
.post-body p { margin: 0 0 1.55rem; }
.post-back { margin-top: 4rem; font: .72rem var(--mono); }

.system-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0; margin-top: 58px; padding: 10px 0 32px; border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; letter-spacing: .02em; text-transform: uppercase; }
.system-bar > span, .system-bar > a { display: inline-flex; align-items: center; }
.system-bar > span:not(:last-child)::after, .system-bar > a:not(:last-child)::after { content: "|"; margin: 0 .55rem; color: var(--border); }
.system-bar a { color: var(--muted); text-decoration: none; }
.system-bar a:hover { color: var(--accent); }

::selection { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
:focus-visible { outline: 1px dotted var(--accent); outline-offset: 2px; }

@media (max-width: 768px) {
  .site-shell { width: min(100% - 2rem, 760px); }
  .site-header { gap: 8px; padding-top: 40px; flex-wrap: wrap; }
  nav { gap: 4px; margin-right: 0; flex-wrap: wrap; }
  nav a { min-width: auto; }
  .home-grid, .project-grid { grid-template-columns: 1fr; gap: 1rem; }
  .page-intro { padding-top: 0; }
  .page-intro:has(+ .plain-list) { padding-bottom: 1.1rem; }
  .page-intro:has(+ .prose) > p:last-child { margin-bottom: 1.1rem; }
  .page-intro h1:last-child { margin-bottom: 1.35rem; }
  .prose { margin-bottom: 1.5rem; }
  .prose p { margin-bottom: 1.35rem; }
  .prose h2 { margin-top: 1.85rem; }
  .prose > :last-child { margin-bottom: 0; }
  .about-photo { margin-bottom: 1.35rem; }
  .plain-list { margin-bottom: 1.25rem; }
  .post { padding-top: 4rem; }
  .latest-list li { align-items: baseline; }
  .log-viewport { max-height: 13.5rem; }
  .log-list li { grid-template-columns: minmax(0, 1fr); gap: .15rem .75rem; }
  .timeline li { grid-template-columns: 5.2rem minmax(0, 1fr); column-gap: 1.2rem; }
  .timeline li::before { left: 5.7rem; }
  .timeline li::after { left: 5.45rem; }
  .system-bar { margin-top: 40px; padding-bottom: 24px; }
}

pre { overflow-x: auto; max-width: 100%; }
img { max-width: 100%; height: auto; }
