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

:root {
  --bg: #f5f5f0;
  --fg: #1a1a1a;
  --muted: #888;
  --accent: #3a3a3a;
  --border: #ddddd8;
  --max-width: 680px;
}

/* Dark palette — shared by the OS-preference and manual-toggle rules below */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1a15;
    --fg: #ededea;
    --muted: #8f8f86;
    --accent: #c7c7c0;
    --border: #33332c;
  }
}

:root[data-theme="dark"] {
  --bg: #1a1a15;
  --fg: #ededea;
  --muted: #8f8f86;
  --accent: #c7c7c0;
  --border: #33332c;
}

/* Secret "phosphor terminal" theme — unlocked with 5 fast clicks on the toggle */
:root[data-theme="terminal"] {
  --bg: #0a0f0a;
  --fg: #4dff88;
  --muted: #2f9c5e;
  --accent: #8affb5;
  --border: #14381f;
}

:root[data-theme="terminal"] body {
  text-shadow: 0 0 2px rgba(77, 255, 136, 0.35);
}

html {
  font-size: 15px;
}

body {
  background-color: var(--bg);
  color: var(--fg);
  font-family: 'Fira Code', monospace;
  font-weight: 400;
  line-height: 1.7;
  padding: 4rem 1.5rem;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
}

/* Typography */
h1 {
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

h2 {
  font-size: 0.85rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-top: 3rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

p {
  margin-bottom: 1rem;
  color: var(--accent);
}

a {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition: text-decoration-color 0.15s;
}

a:hover {
  text-decoration-color: var(--fg);
}

ul {
  list-style: none;
  padding: 0;
}

li {
  padding: 0.15rem 0;
  color: var(--accent);
}

/* Header / intro block */
.intro {
  margin-bottom: 0.5rem;
}

/* Dark-mode toggle button (top-right, all pages) */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  width: 2rem;
  height: 2rem;
  line-height: 1;
  font-size: 1rem;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
}

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

/* Topic / tech tags (used on projects and CV) */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.tag {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--muted);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  opacity: 0.7;
  transition: color 0.15s, border-color 0.15s, opacity 0.15s;
}

.tag:hover {
  opacity: 1;
  color: var(--fg);
  border-color: var(--fg);
}

.intro .subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

/* About "spec sheet" — aligned key/value rows */
.spec {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.75rem;
  font-size: 0.9rem;
  margin: 0.25rem 0 0;
}

.spec dt {
  color: var(--muted);
}

.spec dd {
  margin: 0;
  color: var(--accent);
}

/* "now" section timestamp */
.now-updated {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

/* Terminal-style block (e.g. the 404 page) */
.term {
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--accent);
  background: none;
  margin: 1.5rem 0;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Nav links */
.nav {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
  font-size: 0.875rem;
}

/* Project entries */
.project {
  margin-bottom: 1.5rem;
}

.project .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Show more / show less toggle */
.toggle-more {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.toggle-more:hover {
  color: var(--fg);
}

/* Contact line shown only in the printed/saved PDF (nav is hidden there) */
.print-contact {
  display: none;
}

/* Print / "download PDF" — clean output when printing (e.g. the CV page) */
@page {
  margin: 1.5cm;
}

@media print {
  /* Force the light palette even if the site is being viewed in dark mode */
  :root,
  :root[data-theme="dark"] {
    --bg: #fff;
    --fg: #000;
    --muted: #444;
    --accent: #000;
    --border: #bbb;
  }

  html {
    font-size: 12px;
  }

  body {
    padding: 0;
    line-height: 1.5;
    background: #fff;
    color: #000;
  }

  .container {
    max-width: none;
  }

  /* Hide interactive chrome; expand the full publication list */
  .nav,
  .toggle-more,
  .theme-toggle {
    display: none !important;
  }

  #papers-more {
    display: block !important;
  }

  .print-contact {
    display: block;
    font-size: 0.9rem;
    color: #000;
    margin: 0.3rem 0 0.6rem;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  /* Keep section headings with their content and avoid splitting entries */
  h2 {
    break-after: avoid;
  }

  .cv-entry,
  .project,
  .skills-grid > div {
    break-inside: avoid;
  }
}
