/* ------------------------------------------------------------------ *
 * rhmoller.dev — a small, content-first stylesheet.
 * Light + dark via the CSS light-dark() function, driven by color-scheme.
 * Defaults to the browser preference; a toggle can override it.
 * ------------------------------------------------------------------ */

:root {
  color-scheme: light dark;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "Fira Code",
    Menlo, Consolas, monospace;

  /* Palette: light-dark(light, dark). Resolved by `color-scheme` below,
     which follows the system unless the toggle forces a value. */
  --bg: light-dark(oklch(0.99 0.005 95), oklch(0.19 0.015 265));
  --surface: light-dark(oklch(0.97 0.006 95), oklch(0.23 0.018 265));
  --text: light-dark(oklch(0.27 0.02 265), oklch(0.92 0.015 265));
  --muted: light-dark(oklch(0.52 0.02 265), oklch(0.68 0.02 265));
  --border: light-dark(oklch(0.9 0.01 265), oklch(0.32 0.02 265));
  --accent: light-dark(oklch(0.55 0.2 270), oklch(0.78 0.15 270));
  --accent-hover: light-dark(oklch(0.45 0.2 270), oklch(0.88 0.12 270));
  --code-bg: light-dark(oklch(0.96 0.006 265), oklch(0.24 0.02 265));
  --scrollbar-thumb: light-dark(oklch(0.82 0.01 265), oklch(0.42 0.02 265));
  --scrollbar-thumb-hover: light-dark(oklch(0.7 0.015 265), oklch(0.52 0.02 265));

  --measure: 60rem;
  --radius: 10px;
}

/* The toggle sets data-theme, which forces color-scheme and thus the
   resolution of every light-dark() above. */
:root[data-theme="light"] {
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.125rem);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Layout ---- */

.site-header,
main,
.site-footer {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

main {
  flex: 1;
  padding-block: 2rem 4rem;
}

/* ---- Header ---- */

.site-header {
  padding-block: 1.5rem;
}

.site-header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

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

.nav-links {
  display: flex;
  gap: 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.nav-links a:hover {
  color: var(--accent);
}

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

/* Hidden until the inline head script confirms JS is available, so
   no-JS visitors never see a dead button (they still get system theme). */
.theme-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  appearance: none;
}

:root.js .theme-toggle {
  display: inline-flex;
}

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

.theme-toggle svg {
  width: 1rem;
  height: 1rem;
}

/* ---- Typography ---- */

h1,
h2,
h3,
h4 {
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 650;
  margin: 2.25rem 0 0.75rem;
}

h1 {
  font-size: clamp(1.9rem, 1.5rem + 1.8vw, 2.6rem);
  margin-top: 0;
}

h2 {
  font-size: clamp(1.4rem, 1.2rem + 0.9vw, 1.7rem);
}

h3 {
  font-size: 1.25rem;
}

p,
ul,
ol {
  margin: 0 0 1.2rem;
}

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

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

img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

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

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ---- Home / intro ---- */

.intro {
  margin-bottom: 3rem;
}

.intro h1 {
  margin-bottom: 0.5rem;
}

.intro p {
  color: var(--muted);
  font-size: 1.1em;
}

/* ---- Post list ---- */

.post-list h1,
.post-list h2 {
  margin-bottom: 1.25rem;
}

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

.post-list li {
  padding: 1rem 0;
  border-top: 1px solid var(--border);
}

.post-list li:last-child {
  border-bottom: 1px solid var(--border);
}

.post-list li a {
  font-weight: 600;
  font-size: 1.1rem;
  text-decoration: none;
}

.post-list li a:hover {
  text-decoration: underline;
}

.post-list time {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.post-summary {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ---- Single post ---- */

.post-header {
  margin-bottom: 2rem;
}

.post-header h1 {
  margin-bottom: 0.4rem;
}

.post-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.prose img {
  display: block;
  margin: 1.5rem auto;
  border: 1px solid var(--border);
}

/* ---- Code ---- */

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

:not(pre) > code {
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 5px;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  line-height: 1.5;
  font-size: 0.875rem;
  margin: 1.5rem 0;
  /* Firefox + modern Chromium */
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

/* Safari + older Chromium */
pre::-webkit-scrollbar {
  height: 12px;
}

pre::-webkit-scrollbar-track {
  background: transparent;
}

pre::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  /* Inset the thumb so it doesn't touch the rounded code-block edges. */
  border: 3px solid var(--code-bg);
}

pre::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

pre code {
  font-size: inherit;
}

/* ---- Footer ---- */

.site-footer {
  padding-block: 2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
}

.site-footer p {
  margin: 0;
}

.footer-links {
  display: flex;
  gap: 1rem;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--accent);
}

/* ---- Accessibility ---- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--bg);
  padding: 0.5rem 1rem;
  border-radius: 0 0 var(--radius) 0;
  z-index: 10;
}

.skip-link:focus {
  left: 0;
}

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

/* ------------------------------------------------------------------ *
 * Syntax highlighting (PrismJS tokens), themed for light + dark.
 * ------------------------------------------------------------------ */

:root {
  --tok-comment: light-dark(oklch(0.55 0.02 265), oklch(0.62 0.02 265));
  --tok-keyword: light-dark(oklch(0.5 0.18 300), oklch(0.78 0.13 300));
  --tok-string: light-dark(oklch(0.5 0.13 150), oklch(0.8 0.13 150));
  --tok-number: light-dark(oklch(0.55 0.15 40), oklch(0.82 0.12 50));
  --tok-function: light-dark(oklch(0.5 0.16 250), oklch(0.78 0.12 250));
  --tok-punctuation: var(--muted);
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: var(--tok-comment);
  font-style: italic;
}

.token.punctuation {
  color: var(--tok-punctuation);
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol {
  color: var(--tok-number);
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin {
  color: var(--tok-string);
}

.token.operator,
.token.entity,
.token.url,
.token.variable {
  color: var(--text);
}

.token.atrule,
.token.attr-value,
.token.keyword {
  color: var(--tok-keyword);
}

.token.function,
.token.class-name {
  color: var(--tok-function);
}

.token.regex,
.token.important {
  color: var(--tok-number);
}
