/* timwhiting.dev — adaptive light/dark theme */

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,600;0,700;1,400&display=swap');

/* ── Dark theme (default) ───────────────────────────────── */
:root {
  color-scheme: dark;

  /* Layout / chrome */
  --accent: #01a2b7;
  --accent-dark: #007f90;
  --bg: #171e1e;
  --bg-nav: rgba(23, 30, 30, 0.92);
  --bg-card: #252526;
  --bg-code: #1e1e1e;
  /* VS Code editor background */
  --border: #2d2d30;
  --text: #e2e8e8;
  --text-muted: #8fa8a8;

  /* Syntax highlighting — dark (VS Code Dark+ / Dark Modern) */
  --syn-keyword: #569cd6;
  /* blue        — fun, effect, ctl, with, val */
  --syn-type: #4ec9b0;
  /* teal        — type names */
  --syn-string: #ce9178;
  /* orange      — string literals */
  --syn-comment: #6a9955;
  /* green       — comments */
  --syn-number: #b5cea8;
  /* pale green  — numeric literals */
  --syn-constructor: #c586c0;
  /* purple      — constructors */
  --syn-module: #9cdcfe;
  /* light blue  — module qualifiers */

  /* Theme-toggle icon */
  --toggle-icon: "☀";

  /* Constants */
  --nav-h: 56px;
  --content-max: 800px;
  --radius: 6px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Roboto Mono', 'Fira Code', Consolas, monospace;
}

/* ── Light theme ────────────────────────────────────────── */
[data-theme="light"] {
  color-scheme: light;

  --bg: #f8f9fa;
  --bg-nav: rgba(248, 249, 250, 0.92);
  --bg-card: #ffffff;
  --bg-code: #f0f2f4;
  --border: #dde1e5;
  --text: #1a2020;
  --text-muted: #5a7070;

  /* Syntax highlighting — light (GitHub-style) */
  --syn-keyword: #0070c1;
  --syn-type: #267f99;
  --syn-string: #a31515;
  --syn-comment: #6e7681;
  --syn-number: #098658;
  --syn-constructor: #7b3814;
  --syn-module: #811f3f;

  --toggle-icon: "☾";
}

/* Respect system preference if no manual override stored */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;

    --bg: #f8f9fa;
    --bg-nav: rgba(248, 249, 250, 0.92);
    --bg-card: #ffffff;
    --bg-code: #f0f2f4;
    --border: #dde1e5;
    --text: #1a2020;
    --text-muted: #5a7070;

    --syn-keyword: #0070c1;
    --syn-type: #267f99;
    --syn-string: #a31515;
    --syn-comment: #6e7681;
    --syn-number: #098658;
    --syn-constructor: #7b3814;
    --syn-module: #811f3f;

    --toggle-icon: "☾";
  }
}

/* ── Reset ─────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Nav ────────────────────────────────────────────────── */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--bg-nav);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
}

.nav-brand a {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: opacity 0.15s;
}

.nav-brand a:hover {
  opacity: 0.8;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
}

.nav-link {
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--bg-card);
}

.nav-link.active-page {
  color: var(--accent);
  background: rgba(1, 162, 183, 0.12);
}

/* Mobile nav toggle */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
}

@media (max-width: 640px) {
  .nav-toggle {
    display: flex;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: var(--nav-h);
    right: 0;
    left: 0;
    flex-direction: column;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    gap: 0.25rem;
  }

  .nav-links.open {
    display: flex;
  }

  .nav-link {
    font-size: 1rem;
    padding: 0.5rem 0.75rem;
  }
}

/* ── Main content ───────────────────────────────────────── */
.site-content {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}

/* ── Typography ─────────────────────────────────────────── */
h1,
h2,
h3,
h4 {
  color: var(--text);
  line-height: 1.3;
  font-weight: 700;
  margin-top: 2.25rem;
  margin-bottom: 0.75rem;
}

h1 {
  font-size: 2.2rem;
  margin-top: 0;
}

h2 {
  font-size: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3em;
}

h3 {
  font-size: 1.2rem;
}

p {
  margin-bottom: 1.1rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul,
ol {
  padding-left: 1.5rem;
  margin-bottom: 1.1rem;
}

li {
  margin-bottom: 0.4rem;
}

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

strong {
  font-weight: 600;
}

em {
  color: var(--text-muted);
}

/* ── Code ───────────────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.15em 0.4em;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* ── Madoko output compatibility ────────────────────────── */
/* Madoko wraps content in .body > .madoko; ensure it renders cleanly */
.madoko,
.body {
  all: unset;
  display: block;
}

/* Madoko heading numbers: hide if not wanted */
.heading-no-number::before {
  content: "" !important;
  margin-right: 0 !important;
}

/* ── Madoko Koka syntax: override inline style="color:#XXXXXX" attributes ── */
/* Madoko emits inline colors based on style.mdk; we override them with !important */
/* to map semantic tokens to our theme CSS variables.                        */

/* Dark theme (default :root) */
:root .koka [style*="color:#000001"] {
  color: var(--syn-keyword) !important;
}

/* keywords */
:root .koka [style*="color:#000002"] {
  color: var(--syn-type) !important;
}

/* types / operators */
:root .koka [style*="color:#000003"] {
  color: var(--syn-string) !important;
}

/* strings */
:root .koka [style*="color:#000004"] {
  color: var(--syn-comment) !important;
}

/* comments */
:root .koka [style*="color:#000005"] {
  color: var(--syn-constructor) !important;
}

/* constructors */
:root .koka [style*="color:#000006"] {
  color: var(--syn-number) !important;
}

/* numbers */
:root .koka [style*="color:#000007"] {
  color: var(--syn-module) !important;
}

/* modules */

/* Light theme */
[data-theme="light"] .koka [style*="color:#000001"] {
  color: var(--syn-keyword) !important;
}

[data-theme="light"] .koka [style*="color:#000002"] {
  color: var(--syn-type) !important;
}

[data-theme="light"] .koka [style*="color:#000003"] {
  color: var(--syn-string) !important;
}

[data-theme="light"] .koka [style*="color:#000004"] {
  color: var(--syn-comment) !important;
}

[data-theme="light"] .koka [style*="color:#000005"] {
  color: var(--syn-constructor) !important;
}

[data-theme="light"] .koka [style*="color:#000006"] {
  color: var(--syn-number) !important;
}

[data-theme="light"] .koka [style*="color:#000007"] {
  color: var(--syn-module) !important;
}

/* System light preference */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .koka [style*="color:#000001"] {
    color: var(--syn-keyword) !important;
  }

  :root:not([data-theme]) .koka [style*="color:#000002"] {
    color: var(--syn-type) !important;
  }

  :root:not([data-theme]) .koka [style*="color:#000003"] {
    color: var(--syn-string) !important;
  }

  :root:not([data-theme]) .koka [style*="color:#000004"] {
    color: var(--syn-comment) !important;
  }

  :root:not([data-theme]) .koka [style*="color:#000005"] {
    color: var(--syn-constructor) !important;
  }

  :root:not([data-theme]) .koka [style*="color:#000006"] {
    color: var(--syn-number) !important;
  }

  :root:not([data-theme]) .koka [style*="color:#000007"] {
    color: var(--syn-module) !important;
  }
}

/* Theme-toggle button in nav */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-left: 0.5rem;
}

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

.theme-toggle::after {
  content: var(--toggle-icon);
}

/* ── Home page hero ─────────────────────────────────────── */
.home-hero {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 3rem;
  align-items: center;
  padding: 2rem 0 3rem;
}

.home-hero .profile-photo {
  width: 100%;
  max-width: 220px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  display: block;
  margin: 0 auto;
}

.home-hero .hero-name {
  font-size: 2.5rem;
  margin-top: 0;
}

.home-hero .hero-roles {
  color: var(--text-muted);
  font-size: 1.05rem;
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 1.5rem;
}

.home-hero .hero-roles li::before {
  content: "· ";
  color: var(--accent);
}

@media (max-width: 640px) {
  .home-hero {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .home-hero .profile-photo {
    max-width: 160px;
  }
}

/* ── Blog post ──────────────────────────────────────────── */
.post-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.blog-list {
  list-style: none;
  padding: 0;
}

.blog-list li {
  margin-bottom: 1rem;
}

.blog-list a {
  font-size: 1.1rem;
  font-weight: 600;
}

/* ── Papers & Projects ──────────────────────────────────── */
.paper-section,
.project-section {
  margin-bottom: 2rem;
}

.paper-section h2,
.project-section h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border: none;
  padding: 0;
  margin-bottom: 0.75rem;
}

/* ── Footer ─────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  border-top: 1px solid var(--border);
}