/* Dark is the default; light applies when data-theme="light". */
:root {
  --bg: #1a1815;
  --surface: #221f1b;
  --text: #e0dbd1;
  --muted: #9b9486;
  --line: #2c2823;
  --accent: #b9a98b;
  color-scheme: dark;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
:root[data-theme="light"] {
  --bg: #f7f5f0;
  --surface: #eeebe3;
  --text: #3a3631;
  --muted: #756e63;
  --line: #e6e1d6;
  --accent: #7d6d55;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1.1875rem/1.65 var(--serif);
  transition: background-color 0.2s ease, color 0.2s ease;
}
main { max-width: 40rem; margin: 0 auto; padding: clamp(48px, 10vw, 112px) 16px 48px; }

a { color: var(--text); text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 16px; background: var(--text); color: var(--bg); padding: 6px 12px; }

h1 { font-size: 2.25rem; font-weight: 500; line-height: 1.15; letter-spacing: -0.01em; margin: 0 0 16px; }
h2 { font-size: 1.25rem; font-weight: 600; margin: 0 0 12px; }
.meta { font-family: var(--mono); font-size: 0.8125rem; color: var(--muted); }
.muted, .wip { color: var(--muted); margin: 0; }
.wip { font-style: italic; }

.intro { margin-bottom: 40px; }
.about { margin: 0; }
.intro > p { color: var(--muted); margin: 0; }
section { margin-bottom: 48px; }

.posts { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.posts li { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.posts a { text-decoration: none; }
.posts a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.posts time { white-space: nowrap; }

/* Articles */
.back { font-family: var(--mono); font-size: 0.8125rem; color: var(--muted); }
.post h1 { margin-top: 24px; margin-bottom: 8px; }
.post > .meta { margin: 0 0 32px; }
.cover { display: block; width: 100%; height: auto; border-radius: 4px; margin: 0 0 40px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }
.prose h2 { font-size: 1.5rem; font-weight: 500; margin: 2em 0 0.5em; }
.prose h3 { font-size: 1.25rem; font-weight: 600; margin: 1.6em 0 0.4em; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.1em; }
.prose li { margin-bottom: 0.35em; }
.prose img { max-width: 100%; height: auto; }
.prose blockquote { margin: 0 0 1.1em; padding-left: 18px; border-left: 2px solid var(--accent); color: var(--muted); }
.prose code { font-family: var(--mono); font-size: 0.85em; background: var(--surface); padding: 0.1em 0.35em; border-radius: 3px; }
.prose pre { font-family: var(--mono); font-size: 0.875rem; line-height: 1.6; background: var(--surface); padding: 16px 18px; border-radius: 4px; overflow-x: auto; margin: 0 0 1.4em; }
.prose pre code { background: none; padding: 0; font-size: inherit; }

/* Footer */
.site-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 72px; padding-top: 20px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 0.8125rem; }
.site-footer nav { display: flex; gap: 20px; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); }
.theme-toggle { font: inherit; color: var(--muted); background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; cursor: pointer; }
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }

/* Long words (Unreal identifiers, URLs) wrap instead of pushing the page sideways */
.prose { overflow-wrap: break-word; }
.prose code { overflow-wrap: anywhere; }
.prose pre code { overflow-wrap: normal; }
.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 0 0 1.4em; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose img { display: block; margin: 0 auto; }

/* Tablets and small laptops */
@media (max-width: 720px) {
  main { padding-top: 40px; }
  .post h1 { font-size: 1.875rem; }
}

/* Phones */
@media (max-width: 480px) {
  body { font-size: 1.0625rem; line-height: 1.6; }
  main { padding: 32px 16px 32px; }
  h1 { font-size: 1.75rem; }
  .post h1 { font-size: 1.625rem; margin-top: 16px; }
  .prose h2 { font-size: 1.3125rem; }
  .prose h3 { font-size: 1.125rem; }
  .intro { margin-bottom: 32px; }
  section { margin-bottom: 36px; }
  .posts li { flex-direction: column; gap: 2px; }
  .prose pre { font-size: 0.8125rem; padding: 14px; margin-left: -16px; margin-right: -16px; border-radius: 0; }
  .prose .highlight { margin-left: -16px; margin-right: -16px; }
  .prose .highlight pre { margin-left: 0; margin-right: 0; }
  .cover { margin-bottom: 28px; }
  .site-footer { margin-top: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  body { transition: none; }
}

/* Embedded video: full column width, 16:9, with or without the .video wrapper */
.video { margin: 0 0 1.4em; }
.prose iframe { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border: 0; border-radius: 4px; background: var(--surface); }
.video iframe { margin: 0; }
.prose > iframe { margin: 0 0 1.4em; }

/* Code highlighting: warm, IDE-style colors for both themes */
:root {
  --hl-comment: #928374; --hl-keyword: #fb4934; --hl-type: #fabd2f; --hl-string: #b8bb26;
  --hl-number: #d3869b; --hl-function: #8ec07c; --hl-class: #83a598; --hl-preproc: #fe8019;
}
:root[data-theme="light"] {
  --hl-comment: #8a7f72; --hl-keyword: #9d0006; --hl-type: #b57614; --hl-string: #79740e;
  --hl-number: #8f3f71; --hl-function: #427b58; --hl-class: #076678; --hl-preproc: #af3a03;
}
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs, .highlight .ch, .highlight .cd { color: var(--hl-comment); font-style: italic; }
.highlight .cp, .highlight .cpf { color: var(--hl-preproc); }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kr, .highlight .kp, .highlight .kc, .highlight .ow { color: var(--hl-keyword); }
.highlight .kt, .highlight .nc, .highlight .nn { color: var(--hl-type); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sc, .highlight .sd, .highlight .se, .highlight .sh, .highlight .si, .highlight .sx, .highlight .sr { color: var(--hl-string); }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh, .highlight .mo, .highlight .mb, .highlight .il { color: var(--hl-number); }
.highlight .nf, .highlight .fm, .highlight .nb, .highlight .bp { color: var(--hl-function); }
.highlight .na, .highlight .nt, .highlight .nd, .highlight .nl { color: var(--hl-class); }
.highlight .o { color: var(--hl-preproc); }
.highlight .err { color: inherit; background: none; }
.prose .highlight { margin: 0 0 1.4em; }
.prose .highlight pre { margin: 0; }
.highlight .hl-fn { color: var(--hl-function); }
.highlight .hl-type { color: var(--hl-type); }
.highlight .hl-macro { color: var(--hl-preproc); }

/* Keep text clear of notches and rounded corners on phones in landscape */
@supports (padding: max(0px)) {
  main { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
}

/* GitHub source embeds (assets/js/gh-embed.js) */
.gh-embed { margin: 0 0 1.4em; }
.gh-embed + .gh-embed { margin-top: -0.4em; }
.src { margin: 0; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: var(--surface); }
.src-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 12px; border-bottom: 1px solid var(--line); background: var(--bg); font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }
.src-path { display: flex; min-width: 0; white-space: nowrap; }
.src-dir { min-width: 0; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; }
.src-name { flex-shrink: 0; color: var(--text); }
.src-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.src-copy { font: inherit; color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer; }
.src-copy:hover, .src-link:hover { color: var(--text); }
.src-link { color: var(--muted); text-decoration: none; }
.src-body { overflow: auto; }
.src-code { margin: 0; padding: 12px 0; background: none; border-radius: 0; font-family: var(--mono); font-size: 0.8125rem; line-height: 1.6; overflow: visible; }
.src-code code { display: grid; grid-template-columns: auto 1fr; width: max-content; min-width: 100%; background: none; padding: 0; font-size: inherit; }
.src-code .ln { position: sticky; left: 0; padding: 0 12px 0 14px; text-align: right; color: var(--muted); opacity: 0.6; background: var(--surface); user-select: none; }
.src-code .lc { padding-right: 16px; white-space: pre; }
.src-status { margin: 0; padding: 14px 16px; border: 1px dashed var(--line); border-radius: 4px; color: var(--muted); font-family: var(--mono); font-size: 0.8125rem; }

/* highlight.js tokens, mapped to the site's code colours */
.src .hljs-comment, .src .hljs-quote { color: var(--hl-comment); font-style: italic; }
.src .hljs-keyword, .src .hljs-selector-tag, .src .hljs-literal { color: var(--hl-keyword); }
.src .hljs-type, .src .hljs-title.class_, .src .hljs-class .hljs-title { color: var(--hl-type); }
.src .hljs-string, .src .hljs-regexp, .src .hljs-char.escape_ { color: var(--hl-string); }
.src .hljs-number { color: var(--hl-number); }
.src .hljs-title.function_, .src .hljs-built_in, .src .hljs-function .hljs-title { color: var(--hl-function); }
.src .hljs-meta, .src .hljs-meta .hljs-keyword, .src .hljs-operator { color: var(--hl-preproc); }
.src .hljs-meta .hljs-string { color: var(--hl-string); }
.src .hljs-attr, .src .hljs-attribute, .src .hljs-variable, .src .hljs-template-variable { color: var(--hl-class); }
.src .hl-fn { color: var(--hl-function); }
.src .hl-type { color: var(--hl-type); }
.src .hl-macro { color: var(--hl-preproc); }

@media (max-width: 480px) {
  .gh-embed { margin-left: -16px; margin-right: -16px; }
  .src { border-radius: 0; border-left: 0; border-right: 0; }
  .src-dir { display: none; }
}

/* Excalidraw diagrams (assets/diagrams/*.svg): transparent background, Excalidraw's own dark-mode filter */
.diagram { margin: 1.6em 0; }
.diagram a { display: block; text-decoration: none; cursor: zoom-in; }
.diagram img { display: block; width: 100%; height: auto; margin: 0; }
:root:not([data-theme="light"]) .diagram img { filter: invert(93%) hue-rotate(180deg); }
@media (min-width: 900px) {
  /* let wide diagrams breathe beyond the text column on large screens */
  .diagram { margin-left: -8vw; margin-right: -8vw; }
}
@media (max-width: 480px) {
  .diagram { margin-left: -8px; margin-right: -8px; }
}
