/* Art direction: technical personal blog -> calm, modern editorial
   Palette: warm-neutral surfaces with restrained teal accent
   Typography: Newsreader + Inter for readable long-form writing and clean UI
   Density: balanced with generous reading width */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Newsreader:opsz,wght@6..72,400;6..72,600;6..72,700&display=swap');

:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  --color-bg: #f6f4ef;
  --color-surface: #fbfaf7;
  --color-surface-2: #ffffff;
  --color-surface-offset: #ece8df;
  --color-border: rgba(40, 37, 29, 0.14);
  --color-divider: rgba(40, 37, 29, 0.1);
  --color-text: #25221c;
  --color-text-muted: #66635d;
  --color-text-faint: #8d8a84;
  --color-primary: #0c6a6f;
  --color-primary-hover: #094f53;
  --color-primary-soft: rgba(12, 106, 111, 0.1);
  --color-code-bg: #23262b;
  --color-code-text: #eef2f6;
  --color-inline-code-bg: rgba(12, 106, 111, 0.09);
  --color-selection: rgba(12, 106, 111, 0.18);

  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;

  --shadow-sm: 0 1px 2px rgba(31, 28, 22, 0.06);
  --shadow-md: 0 10px 30px rgba(31, 28, 22, 0.08);
  --shadow-lg: 0 20px 50px rgba(31, 28, 22, 0.12);

  --content-width: 72rem;
  --reading-width: 44rem;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-display: 'Newsreader', Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #161714;
    --color-surface: #1d1f1b;
    --color-surface-2: #222520;
    --color-surface-offset: #2a2d28;
    --color-border: rgba(230, 228, 221, 0.14);
    --color-divider: rgba(230, 228, 221, 0.08);
    --color-text: #ece8dd;
    --color-text-muted: #b7b3aa;
    --color-text-faint: #8f8a82;
    --color-primary: #66aeb5;
    --color-primary-hover: #8cc4c9;
    --color-primary-soft: rgba(102, 174, 181, 0.14);
    --color-code-bg: #0f1115;
    --color-code-text: #eef2f6;
    --color-inline-code-bg: rgba(102, 174, 181, 0.14);
    --color-selection: rgba(102, 174, 181, 0.22);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.28);
    --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.34);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.75;
  color: var(--color-text);
  background:
    radial-gradient(circle at top left, var(--color-primary-soft), transparent 28%),
    linear-gradient(180deg, var(--color-surface) 0%, var(--color-bg) 14rem);
}

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

a {
  color: var(--color-primary);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
  transition: color 180ms ease, background-color 180ms ease;
}

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

a:focus-visible,
button:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

img, svg, video { max-width: 100%; height: auto; }
hr {
  border: 0;
  border-top: 1px solid var(--color-divider);
  margin: var(--space-12) 0;
}

body > header,
body > nav,
body > main,
body > footer,
body > article,
body > section,
body > div,
body > p,
body > h1,
body > h2,
body > h3,
body > ul,
body > ol,
body > pre,
body > table,
body > blockquote {
  width: min(calc(100% - 2rem), var(--content-width));
  margin-inline: auto;
}

body > header,
body > nav,
body > main,
body > article,
body > section,
body > div:first-of-type {
  padding-inline: clamp(var(--space-4), 2vw, var(--space-8));
}

body > h1:first-of-type,
main > h1:first-of-type,
article > h1:first-of-type {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: 1.03;
  letter-spacing: -0.03em;
  margin-top: clamp(var(--space-12), 10vw, var(--space-20));
  margin-bottom: var(--space-3);
  max-width: 15ch;
}

body > h2:first-of-type,
body > h3:first-of-type {
  margin-top: 0;
}

body > h1 + h2,
body > h1 + h3,
article > h1 + h2,
article > h1 + h3,
main > h1 + h2,
main > h1 + h3 {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: var(--space-10);
}

p, li, blockquote, figcaption {
  max-width: var(--reading-width);
}

p, ul, ol, pre, table, blockquote {
  margin-top: 0;
  margin-bottom: var(--space-6);
}

ul, ol {
  padding-left: 1.4em;
}

li + li { margin-top: var(--space-2); }

h1, h2, h3, h4 {
  color: var(--color-text);
  line-height: 1.15;
  margin-top: var(--space-12);
  margin-bottom: var(--space-4);
}

h2, h3, h4 {
  font-family: var(--font-body);
  letter-spacing: -0.02em;
}

h2 { font-size: var(--text-xl); font-weight: 800; }
h3 { font-size: var(--text-lg); font-weight: 700; }
h4 { font-size: var(--text-base); font-weight: 700; }

blockquote {
  margin-inline: 0;
  padding: var(--space-5) var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--color-text-muted);
}

code, kbd, samp {
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
  font-size: 0.92em;
}

p code,
li code,
blockquote code,
td code {
  background: var(--color-inline-code-bg);
  color: var(--color-primary-hover);
  padding: 0.15em 0.4em;
  border-radius: 0.45rem;
}

pre {
  max-width: 100%;
  overflow-x: auto;
  padding: var(--space-5);
  background: var(--color-code-bg);
  color: var(--color-code-text);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255,255,255,0.05);
}

pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

table {
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  box-shadow: var(--shadow-sm);
}

th, td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

th {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  background: var(--color-surface);
}

tr:last-child td { border-bottom: 0; }

#TOC,
nav[role='doc-toc'] {
  width: min(calc(100% - 2rem), var(--content-width));
  margin: var(--space-8) auto var(--space-12);
  padding: var(--space-5) var(--space-6);
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}

#TOC ul,
#TOC ol,
nav[role='doc-toc'] ul,
nav[role='doc-toc'] ol {
  margin-bottom: 0;
}

#TOC li + li,
nav[role='doc-toc'] li + li {
  margin-top: var(--space-2);
}

body > ul:first-of-type,
body > ol:first-of-type {
  list-style: none;
  padding-left: 0;
  display: grid;
  gap: var(--space-3);
  margin-top: clamp(var(--space-12), 8vw, var(--space-16));
  margin-bottom: var(--space-16);
}

body > ul:first-of-type li,
body > ol:first-of-type li {
  margin: 0;
  padding: 0;
}

body > ul:first-of-type li a,
body > ol:first-of-type li a,
body > p > a:only-child {
  display: inline-block;
  padding: var(--space-4) var(--space-5);
  background: color-mix(in srgb, var(--color-surface-2) 92%, transparent);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--color-text);
}

body > ul:first-of-type li a:hover,
body > ol:first-of-type li a:hover,
body > p > a:only-child:hover {
  border-color: color-mix(in srgb, var(--color-primary) 35%, var(--color-border));
  color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

body > p:first-of-type {
  margin-top: clamp(var(--space-12), 8vw, var(--space-16));
}

body > p:first-of-type,
body > ul:first-of-type,
body > ol:first-of-type,
body > h1,
body > h2,
body > h3,
body > h4,
body > blockquote,
body > pre,
body > table,
body > hr {
  width: min(calc(100% - 2rem), var(--reading-width));
}

body > ul:first-of-type,
body > ol:first-of-type,
body > table,
body > pre {
  width: min(calc(100% - 2rem), var(--content-width));
}

@media (max-width: 720px) {
  body {
    line-height: 1.68;
    background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-bg) 12rem);
  }

  body > h1:first-of-type,
  main > h1:first-of-type,
  article > h1:first-of-type {
    max-width: none;
  }

  pre,
  table,
  #TOC,
  nav[role='doc-toc'] {
    border-radius: var(--radius-lg);
  }
}

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