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

/* ── Tokens ──────────────────────────────────── */

:root {
  --text:    #262626;
  --muted:   #6b6b6b;
  --border:  #e2e2e2;
  --bg:      #fafafa;
  --code-bg: #f0f0f0;
  --link:    #0066cc;
  --width:   960px;
  --sidebar: 220px;
  --gap:     56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text:    #dcdcdc;
    --muted:   #8c8c8c;
    --border:  #333;
    --bg:      #171717;
    --code-bg: #222;
    --link:    #60a5fa;
  }
}

[data-theme="dark"] {
  --text:    #dcdcdc;
  --muted:   #8c8c8c;
  --border:  #333;
  --bg:      #171717;
  --code-bg: #222;
  --link:    #60a5fa;
}

/* ── Base ────────────────────────────────────── */

html { font-size: 18px; }

body {
  font-family: system-ui, sans-serif;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  transition: color 0.15s, background-color 0.15s;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 0.75rem;
}

h1 { font-size: 1.5rem; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; letter-spacing: -0.01em; }
h3 { font-size: 1rem; }

p { margin: 0 0 1.2rem; }

a {
  color: inherit;
  text-decoration: none;
}

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

code {
  font-family: ui-monospace, monospace;
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

pre {
  background: var(--code-bg);
  padding: 1.25rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1.5rem 0;
}

pre code { background: none; padding: 0; }

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

/* ── Header ──────────────────────────────────── */

.site-header {
  border-bottom: 1px solid var(--border);
  padding: 24px 0;
}

.header-inner {
  max-width: var(--width);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.site-title:hover { opacity: 0.6; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-link {
  font-size: 0.875rem;
  color: var(--muted);
}

.nav-link:hover,
.nav-link.active { color: var(--text); }

/* ── Layout ──────────────────────────────────── */

.page-wrapper {
  max-width: var(--width);
  margin: 52px auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 1fr var(--sidebar);
  gap: var(--gap);
  align-items: start;
}

.main-content { min-width: 0; }

/* ── Sidebar ─────────────────────────────────── */

.sidebar {
  font-size: 0.92rem;
  position: sticky;
  top: 32px;
}

.sidebar-section + .sidebar-section {
  margin-top: 28px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 14px;
}

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

.sidebar-list li {
  margin-bottom: 12px;
  line-height: 1.6;
}

.sidebar-list a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--link);
}

.sidebar-list a:hover { opacity: 0.75; }

.sidebar-note {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 3px;
}

/* ── Content (prose) ─────────────────────────── */

.content { max-width: 640px; }

.content a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--link);
}

.content a:hover { opacity: 0.75; }

.content h2,
.content h3 { margin-top: 2rem; }

/* ── Posts ───────────────────────────────────── */

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

.post-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

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

.post-item {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}

.post-item:first-child { border-top: 1px solid var(--border); }

.post-date {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  min-width: 80px;
  flex-shrink: 0;
}

.post-link:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── About page ──────────────────────────────── */

.about-hero {
  display: flex;
  align-items: flex-start;
  gap: 2.5rem;
}

.about-hero-body {
  min-width: 0;
}

.about-page .post-header {
  margin-bottom: 1.25rem;
}

.about-photo {
  flex-shrink: 0;
  margin-bottom: 0;
}

.about-photo img {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  object-fit: cover;
}

.about-page .content {
  max-width: 620px;
  font-size: 1.1rem;
  line-height: 1.8;
}

.about-page .content p {
  margin-bottom: 1.5rem;
}

@media (max-width: 640px) {
  .about-hero {
    flex-direction: column;
    gap: 1.75rem;
  }
}

/* ── Home ────────────────────────────────────── */

.home-intro {
  max-width: 560px;
  margin-bottom: 3rem;
  line-height: 1.75;
}

/* ── Theme toggle ────────────────────────────── */

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--muted);
  display: flex;
  align-items: center;
}

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

.icon-sun  { display: none; }
.icon-moon { display: block; }

[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun  { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

/* ── Footer ──────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 72px;
}

.footer-inner {
  max-width: var(--width);
  margin: 0 auto;
  padding: 0 24px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Contact form ────────────────────────────── */

.contact-form {
  max-width: 480px;
  margin-top: 2rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--link);
}

.form-group textarea {
  resize: vertical;
  min-height: 140px;
}

.form-submit {
  padding: 0.55rem 1.5rem;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.form-submit:hover { opacity: 0.75; }

/* ── Portfolio ───────────────────────────────── */

.portfolio-intro {
  max-width: 640px;
  color: var(--muted);
  font-size: 1.05rem;
  margin-bottom: 0;
}

.portfolio-cards {
  display: flex;
  flex-direction: column;
  gap: 28px;
  margin-top: 2.5rem;
}

.portfolio-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.portfolio-card:hover {
  transform: translateY(-3px);
  border-color: var(--muted);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.portfolio-card-media {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--code-bg);
}

.portfolio-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.portfolio-card:hover .portfolio-card-media img {
  transform: scale(1.03);
}

.portfolio-card-placeholder {
  display: block;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    45deg,
    var(--code-bg),
    var(--code-bg) 12px,
    var(--border) 12px,
    var(--border) 24px
  );
  opacity: 0.5;
}

.portfolio-card-body {
  padding: 20px 24px 24px;
}

.portfolio-card-date {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.portfolio-card-title {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.portfolio-card-summary {
  color: var(--muted);
  margin-bottom: 0.75rem;
  max-width: 60ch;
}

.portfolio-card-more {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--link);
}

/* ── Portfolio detail page ───────────────────── */

.portfolio-back {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.portfolio-back:hover { color: var(--text); }

.portfolio-detail-media {
  margin: 0 0 2rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.portfolio-detail-media img {
  width: 100%;
  height: auto;
  display: block;
}

.portfolio-detail-link {
  margin-top: 2rem;
  font-weight: 600;
}

.portfolio-detail-link a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Responsive ──────────────────────────────── */

@media (max-width: 760px) {
  .page-wrapper {
    grid-template-columns: 1fr;
    margin: 36px auto;
  }

  .sidebar {
    position: static;
    border-top: 1px solid var(--border);
    padding-top: 32px;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
}

/* ── Shared small parts ──────────────────────── */

.status {
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  white-space: nowrap;
  margin-left: auto;
}

.post-meta .status { margin-left: 0; }

.meta-link,
.label-more {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.label-more {
  float: right;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  font-size: 0.8rem;
}

.topic-chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0.75rem 0 0;
  padding: 0;
}

.topic-chips a {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.7rem;
}

.topic-chips a:hover {
  color: var(--text);
  border-color: var(--muted);
}

.backlinks,
.topic-section,
.home-block { margin-top: 3rem; }

.home-block:first-of-type { margin-top: 0; }

.home-block .portfolio-cards { margin-top: 0; }

/* ── Interests & topics ──────────────────────── */

.interest-group,
.topic-kind { margin-top: 2.5rem; }

.interest { margin-top: 2rem; }

.interest h2 a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.interest-link,
.interest-more {
  font-size: 0.85rem;
  margin: -0.4rem 0 0.6rem;
}

.interest-link a,
.interest-more a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Experience timeline ─────────────────────── */

.timeline-section { margin-top: 2.5rem; }

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

.timeline-entry {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 1.25rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.timeline-entry:first-child { border-top: 1px solid var(--border); }

.timeline-dates {
  font-size: 0.8rem;
  color: var(--muted);
  padding-top: 0.2rem;
}

.timeline-body h2,
.timeline-body h3 {
  font-size: 1rem;
  margin-bottom: 0.2rem;
}

.timeline-org,
.timeline-summary,
.timeline-more {
  margin: 0;
  font-size: 0.9rem;
}

.timeline-org { color: var(--muted); }
.timeline-summary { margin-top: 0.5rem; }
.timeline-more { margin-top: 0.4rem; }

.timeline-org a,
.timeline-summary a,
.timeline-more a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 640px) {
  .timeline-entry {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
}

/* ── Library ─────────────────────────────────── */

.library-section { margin-top: 2.5rem; }

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

.library-list li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.library-list a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.library-title { font-weight: 600; }

.library-author {
  color: var(--muted);
  font-size: 0.9rem;
}

.library-list .status { margin-left: 0.4rem; }

.library-note {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

/* ── Dark-mode card hover ────────────────────── */

[data-theme="dark"] .portfolio-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .portfolio-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
}

/* ── Footer links, spam trap, phone sidebar ──── */

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

.footer-nav a:hover { color: var(--text); }

.form-trap { display: none; }

@media (max-width: 760px) {
  /* Blocks marked home-only are dropped from the stacked sidebar on other pages. */
  body:not(.is-home) .sidebar-home-only { display: none; }

  body:not(.is-home) .sidebar-home-only + .sidebar-section:not(.sidebar-home-only) {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }
}

/* ── CV extras on the Experience page ────────── */

.cv-headline {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0;
}

.cv-pdf {
  margin: 0.6rem 0 0;
  font-size: 0.9rem;
}

.cv-pdf a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cv-jump { margin-bottom: 0.5rem; }

.timeline-section > h2.label { margin-bottom: 14px; }

.cv-group { margin-top: 0.75rem; }

.cv-group-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0 0 0.25rem;
}

/* Hyphen bullets for responsibilities, accomplishments and awards.
   Wrapped lines line up with the text, not the hyphen. */
.cv-list {
  list-style: none;
  margin: 0;
  padding-left: 1rem;
  font-size: 0.9rem;
}

.cv-list li {
  position: relative;
  margin-bottom: 0.2rem;
}

.cv-list li::before {
  content: "-";
  position: absolute;
  left: -1rem;
  color: var(--muted);
}

.cv-list a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cv-role-skills { margin-top: 0; }

.cv-role-skills span { font-size: 0.78rem; }

.cv-tags span {
  display: block;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.75rem;
}

.cv-print-only { display: none; }

.cv-section-note {
  color: var(--muted);
  font-size: 0.9rem;
  margin: -0.5rem 0 0.75rem;
}

.cv-more > summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--link);
  margin-bottom: 0.75rem;
}

.cv-more > summary:hover { opacity: 0.75; }

.cv-more[open] > summary { margin-bottom: 0.75rem; }

/* ── Print (any page; tuned for the CV) ──────── */

@media print {
  :root {
    --text:   #000 !important;
    --muted:  #444 !important;
    --border: #ccc !important;
    --bg:     #fff !important;
    --link:   #000 !important;
  }

  html { font-size: 11pt; }
  body { line-height: 1.45; }

  .site-header,
  .site-footer,
  .sidebar,
  .cv-jump,
  .cv-pdf,
  .cv-section-collapsed,
  .timeline-more,
  .portfolio-back { display: none !important; }

  .page-wrapper {
    display: block;
    margin: 0;
    padding: 0;
    max-width: none;
  }

  .cv-print-only {
    display: block;
    color: var(--muted);
    margin: 0;
  }

  /* A zero page margin leaves the browser no room to print its own date,
     page title, web address and page numbers. The white space around the
     text comes from the page padding instead, which repeats on every page.
     If a browser still adds them, untick "Headers and footers" when printing. */
  @page {
    margin: 0;
    padding: 14mm 15mm;
  }

  .post-header { margin-bottom: 1rem; }
  .cv-contact a { color: var(--text); }
  .timeline-section { margin-top: 1.25rem; }
  .timeline-section > h2 { break-after: avoid; }

  /* Long roles may run onto the next page, so pages fill up instead of
     leaving gaps. A role's title, organisation and summary stay with its
     first details, and no single bullet or list heading is split. */
  .timeline-entry {
    padding: 0.5rem 0;
    break-inside: auto;
    grid-template-columns: 128px 1fr;
    gap: 1rem;
  }
  .timeline-body h3,
  .timeline-org,
  .timeline-summary,
  .cv-group-label { break-after: avoid; }
  .cv-list li { break-inside: avoid; }
  p, li { orphans: 2; widows: 2; }
  .cv-group { margin-top: 0.4rem; }

  /* Skills print as a compact dotted line instead of rounded tags. */
  .cv-tags { display: block; margin-top: 0.15rem; }
  .cv-tags li { display: inline; }
  .cv-tags span {
    display: inline;
    border: 0;
    padding: 0;
    font-size: 0.85rem;
  }
  .cv-tags li + li::before { content: " · "; color: var(--muted); }

  a { text-decoration: none !important; }
}
