:root {
  --max: 42rem;
  --figure-medium: 43rem;
  --figure-wide: 46rem;
  --wide: 56rem;
  --font-sans: "Inter", "Segoe UI", sans-serif;
  --font-display: "Source Serif 4", Georgia, serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

:root,
html[data-theme="light"] {
  color-scheme: light;

  --bg: #f6f7f1;
  --bg-accent: #e8eddf;
  --ink: #1f241d;
  --muted: #626b5d;
  --line: #cfd7c8;
  --accent: #355c2f;
  --accent-bright: #4f7b43;
  --accent-soft: rgba(53, 92, 47, 0.13);
  --code-bg: #eceee7;
  --code-number: #a45127;
  --code-keyword: #35632f;
  --code-type: #3f6073;
  --code-comment: #697264;
  --code-fn: #4b6544;
  --code-border: #cbd2c4;
  --selection: rgba(53, 92, 47, 0.22);
  /* Explicit light journal code surface (not dark terminal) */
  --pre-bg: #eceee7;
  --pre-ink: #1f241d;
  --pre-line: #cbd2c4;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #191b17;
  --bg-accent: #20231e;
  --ink: #e7e9e1;
  --muted: #a5ac9f;
  --line: #343a31;
  --accent: #8fbc7a;
  --accent-bright: #a8d090;
  --accent-soft: rgba(143, 188, 122, 0.16);
  --code-bg: #232720;
  --code-number: #d08a5a;
  --code-keyword: #8fbc7a;
  --code-type: #8aae8d;
  --code-comment: #8a9284;
  --code-fn: #a5c48e;
  --code-border: #3b4538;
  --selection: rgba(143, 188, 122, 0.28);
  --pre-bg: #293027;
  --pre-ink: #edf0e9;
  --pre-line: var(--code-border);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;

    --bg: #191b17;
    --bg-accent: #20231e;
    --ink: #e7e9e1;
    --muted: #a5ac9f;
    --line: #343a31;
    --accent: #8fbc7a;
    --accent-bright: #a8d090;
    --accent-soft: rgba(143, 188, 122, 0.16);
    --code-bg: #232720;
    --code-number: #d08a5a;
    --code-keyword: #8fbc7a;
    --code-type: #8aae8d;
    --code-comment: #8a9284;
    --code-fn: #a5c48e;
    --code-border: #3b4538;
    --selection: rgba(143, 188, 122, 0.28);
    --pre-bg: #293027;
    --pre-ink: #edf0e9;
    --pre-line: var(--code-border);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 100% -10%, var(--bg-accent), transparent 55%),
    var(--bg);
}

::selection {
  background: var(--selection);
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--accent-bright);
  text-decoration-thickness: 2px;
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

h1,
h2,
h3 {
  text-wrap: balance;
}

.page {
  width: min(100% - 2rem, var(--wide));
  margin: 0 auto;
  padding: 1.75rem 0 3rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2rem;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand:hover {
  color: var(--accent);
}

.header-end {
  display: flex;
  align-items: center;
  gap: 0.35rem 0.85rem;
}

.nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}

.nav a:hover,
.nav a[aria-current="page"] {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 2px;
}

.theme-toggle-icon {
  font-size: 1.05rem;
  line-height: 1;
}

.theme-toggle:hover {
  color: var(--ink);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.main {
  flex: 1;
  width: min(100%, var(--max));
  margin-inline: auto;
}

.site-footer {
  margin-top: 3.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.95rem;
}

.site-footer p {
  margin: 0;
}

.sep {
  margin: 0 0.35rem;
  color: var(--line);
}

.placeholder {
  color: var(--muted);
  font-style: italic;
}

/* Home */
.home-hero {
  position: relative;
  margin-bottom: 2.75rem;
  padding-bottom: 2.5rem;
}

.home-hero::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 4rem;
  height: 4px;
  background: var(--accent);
}

.home-hero h1 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.04em;
  max-width: none;
}

.home-hero .lede {
  margin: 0;
  font-size: 1.2rem;
  color: var(--muted);
  max-width: 32rem;
}

.home-hero h1,
.page-header h1,
.post-list a.title {
  font-variation-settings: "opsz" 48;
}

.section-label {
  margin: 0 0 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-list li + li {
  margin-top: 1.75rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--line);
}

.post-list a.title {
  display: inline-block;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.035em;
}

.post-list a.title:hover {
  color: var(--accent-bright);
}

.post-list .meta {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.post-list .excerpt {
  margin: 0.45rem 0 0;
  color: var(--muted);
}

.empty-note {
  margin: 0;
  padding: 1rem 1.1rem;
  background: var(--accent-soft);
  color: var(--muted);
  border-left: 3px solid var(--accent);
}

/* Pages & posts */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header::after {
  content: "";
  display: block;
  width: 3rem;
  height: 3px;
  margin-top: 1rem;
  background: var(--accent);
}

.page-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.85rem, 4.5vw, 2.85rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.page-header .lede {
  margin: 0.65rem 0 0;
  font-size: 1.15rem;
  color: var(--muted);
}

.page-header .meta {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.project-links {
  margin: 1rem 0 0;
  font-weight: 500;
}

.prose {
  overflow-wrap: break-word;
}

.prose > * + * {
  margin-top: 1.25em;
}

.prose > p + p {
  margin-top: 1em;
}

.prose h2,
.prose h3 {
  font-family: var(--font-sans);
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.3;
  margin-top: 1.75em;
  margin-bottom: 0.5em;
}

.prose h2 {
  font-size: 1.45rem;
}

.prose h3 {
  font-size: 1.2rem;
}

.prose p,
.prose ul,
.prose ol {
  margin: 0;
}

.prose ul,
.prose ol {
  padding-left: 1.25rem;
}

.prose li + li {
  margin-top: 0.35rem;
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.5rem 0;
}

.prose figure {
  width: 100%;
  margin-top: 2rem;
  margin-bottom: 1.75rem;
  margin-left: 0;
  transform: none;
}

.prose figure img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0;
}

.prose figcaption {
  margin-top: 0.65rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.figure-source {
  margin-left: 0.35em;
  font-size: 0.9em;
  color: var(--muted);
}

.prose figure.medium,
.prose figure.wide {
  max-width: none;
  margin-left: 50%;
  transform: translateX(-50%);
}

.prose figure.medium {
  width: min(var(--figure-medium), calc(100vw - 4rem));
}

.prose figure.wide {
  width: min(var(--figure-wide), calc(100vw - 4rem));
}

.prose figure.medium img,
.prose figure.wide img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.prose figure + h2,
.prose figure + h3 {
  margin-top: 2rem;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  padding: 0.1em 0.35em;
  background: var(--code-bg);
  border-radius: 2px;
}

.prose pre,
.prose pre.highlight,
.prose .highlight pre {
  overflow-x: auto;
  padding: 1rem 1.1rem;
  background: var(--pre-bg);
  color: var(--pre-ink);
  border: 1px solid var(--pre-line);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.5;
  tab-size: 2;
}

.prose .highlighter-rouge,
.prose .highlight {
  background: transparent;
}

.prose pre code {
  padding: 0;
  background: none;
  color: inherit;
  border-radius: 0;
}

/* Restrained Rouge highlighting */
.highlight .c,
.highlight .c1,
.highlight .cm {
  color: var(--code-comment);
  font-style: italic;
}

.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kp,
.highlight .kr {
  color: var(--code-keyword);
  font-weight: 600;
}

.highlight .kt {
  color: var(--code-type);
  font-weight: 600;
}

.highlight .mi,
.highlight .mf,
.highlight .mh,
.highlight .il {
  color: var(--code-number);
}

.highlight .nf {
  color: var(--code-fn);
}

.prose blockquote {
  margin: 1.25rem 0;
  padding: 0 0 0 1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.todo {
  margin: 1.25rem 0;
  padding: 0.85rem 1rem;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-size: 0.95rem;
}

.todo strong {
  color: var(--ink);
  font-weight: 600;
}

.back {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

@media (max-width: 560px) {
  .page {
    width: min(100% - 1.5rem, var(--wide));
    padding-top: 1.25rem;
  }

  .site-header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.75rem 1rem;
    margin-bottom: 2rem;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
  }

  .header-end {
    display: contents;
  }

  .theme-toggle {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .nav {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .prose figure.medium,
  .prose figure.wide {
    width: calc(100vw - 1.5rem);
    margin-left: 50%;
    transform: translateX(-50%);
    overflow-x: auto;
  }

  .prose figure.medium img,
  .prose figure.wide img {
    width: 100%;
    max-width: none;
  }
}
