/* ============ TOKENS ============ */
:root {
  --bg: #FFFFFF;
  --ink: #1A1A1A;
  --ink-soft: #6B6B6B;
  --line: #E5E5E5;
  --accent: #2F5FE0;
  --green: #1A9E5C;
  --amber: #9A7B1F;

  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, monospace;

  --max-w: 960px;
  --pad: clamp(20px, 6vw, 32px);
}

[data-theme="dark"] {
  --bg: #15171A;
  --ink: #E8E8E8;
  --ink-soft: #9A9A9A;
  --line: #2E3034;
  --accent: #6E93FF;
  --green: #3FCB85;
  --amber: #D9B24C;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  transition: background 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-weight: 700;
  margin: 0;
  color: var(--ink);
}

p { margin: 0; }
a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease;
}
a:hover { border-bottom-color: var(--accent); }

.mono { font-family: var(--font-mono); }

.skip-link { position: absolute; left: -999px; top: 0; }
.skip-link:focus {
  left: 8px; top: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 4px;
  z-index: 200;
}

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

/* ============ HEADER (sticky) ============ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
.site-header.is-scrolled { border-bottom-color: var(--line); }

.header-row {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 14px var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 24px;
}

.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  border-bottom: none;
}
.logo:hover { border-bottom-color: transparent; opacity: 0.7; }

.main-nav { display: flex; gap: 16px; flex: 1; font-size: 0.92rem; }
.main-nav a { color: var(--ink-soft); border-bottom: none; }
.main-nav a:hover, .main-nav a.is-current { color: var(--accent); }

.header-controls { display: flex; align-items: center; gap: 14px; font-size: 0.8rem; }

.toggle-group { display: flex; gap: 10px; }
.toggle-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  padding: 2px 0;
  border-bottom: 1px solid transparent;
}
.toggle-btn:hover { color: var(--accent); }
.toggle-btn.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

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

/* ============ HERO ============ */
.hero {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 48px var(--pad) 8px;
}
.hero h1 { font-size: clamp(1.7rem, 5vw, 2.1rem); }

.hero-top {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--bg-secondary, #f0f0f0);
}

.bio { margin-top: 14px; color: var(--ink-soft); font-size: 1.02rem; max-width: 56ch; }
.now { margin-top: 10px; font-size: 0.95rem; color: var(--ink); }
.inline-links { margin-top: 16px; font-size: 0.95rem; }
.hero .inline-links { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.btn-cv {
  margin-left: 10px;
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  border-bottom: none;
}
.btn-cv:hover { border-bottom: none; opacity: 0.88; }

/* ============ SECTIONS ============ */
.section {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 44px var(--pad) 0;
  scroll-margin-top: 72px;
}
.section h2 { font-size: 1.3rem; }
.section-sub { color: var(--ink-soft); margin-top: 6px; font-size: 0.95rem; max-width: 56ch; }

/* ============ LISTS ============ */
.list { margin-top: 22px; display: flex; flex-direction: column; }

.item {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.list .item:last-child { border-bottom: none; padding-bottom: 0; }

.item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.item-head h3 { font-size: 1.02rem; }
.verify { margin-left: 6px; font-size: 0.78rem; font-weight: 500; color: var(--ink-soft); white-space: nowrap; }
a:hover .verify { color: var(--accent); }
.item-date { font-size: 0.82rem; color: var(--ink-soft); white-space: nowrap; }

.item-meta { font-size: 0.88rem; color: var(--ink-soft); margin-top: 3px; }
.item-desc { font-size: 0.95rem; color: var(--ink-soft); margin-top: 8px; }
.item-desc + .item-desc { margin-top: 6px; }
.item-desc strong { color: var(--ink); }
.item-links { margin-top: 8px; font-size: 0.88rem; }

.dot { font-size: 0.75em; }
.status-live, .status-live .dot { color: var(--green); }
.status-wip, .status-wip .dot { color: var(--amber); }

/* ============ POSITIONS TABLE ============ */
.table-wrap { margin-top: 22px; overflow-x: auto; }

.positions {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.positions th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 0 12px 10px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.positions td {
  padding: 14px 12px 14px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.positions tr:last-child td { border-bottom: none; }

.positions .sym { font-size: 0.85rem; color: var(--ink-soft); white-space: nowrap; }
.positions td a { color: var(--ink); border-bottom: 1px solid transparent; font-weight: 600; }
.positions td a:hover { color: var(--accent); border-bottom-color: var(--accent); }

.positions .group-row th {
  padding: 28px 0 8px;
  border-bottom: 1px solid var(--line);
}

.row-tagline {
  display: block;
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-top: 3px;
}

.row-body:has(.row-shot) {
  display: grid;
  grid-template-columns: 1fr 180px;
  grid-template-rows: auto 1fr;
  column-gap: 18px;
  align-items: start;
}
.row-shot { grid-column: 2; grid-row: 1 / span 2; }
.positions td a.row-shot,
.positions td a.row-shot:hover { border-bottom: none; }
.row-shot img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  transition: opacity 0.15s ease;
}
.row-shot:hover img { opacity: 0.85; }

.positions .status a,
.positions .status span {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  white-space: nowrap;
}
.positions .status a { color: inherit; border-bottom: none; }
.positions .status a.src-link { display: block; margin-top: 4px; color: var(--ink-soft); }
.positions .status .wake-note {
  display: block;
  margin-top: 6px;
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--ink-soft);
  white-space: normal;
}
.positions .status a:hover { opacity: 0.75; border-bottom: none; }

.positions-note {
  margin-top: 14px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.positions-note .dot { margin-right: 4px; }

/* ============ SKILLS ============ */
.skills {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 12px 20px;
  margin: 22px 0 0;
  font-size: 0.95rem;
}
.skills dt { font-weight: 600; }
.skills dd { margin: 0; color: var(--ink-soft); }

/* ============ PROJECT WRITE-UPS (notes/) ============ */
.note { max-width: 720px; margin: 0 auto; padding: 40px var(--pad) 0; }
.note-kicker { font-size: 0.82rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.note h1 { font-size: clamp(1.6rem, 4.5vw, 2.05rem); line-height: 1.25; margin-top: 8px; }
.note-meta { margin-top: 10px; font-size: 0.92rem; color: var(--ink-soft); }
.note h2 { font-size: 1.2rem; margin-top: 36px; }
.note p, .note li { margin-top: 12px; }
.note ul { padding-left: 1.2em; margin: 0; }
.note li { margin-top: 8px; }
.note pre {
  margin: 16px 0 0;
  padding: 14px 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.5;
}
.note code { font-family: var(--font-mono); }
.table-scroll { overflow-x: auto; margin-top: 16px; }
.note table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.note th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); font-weight: 600; }
.note th, .note td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.note-back { margin: 40px 0 56px; }

/* ============ FOOTER ============ */
.site-footer {
  max-width: var(--max-w);
  margin: 56px auto 0;
  padding: 20px var(--pad) 40px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.82rem;
}

/* ============ SCROLL REVEAL (subtle) ============ */
.js [data-reveal] {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
[data-reveal].is-visible { opacity: 1; transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  [data-reveal] { opacity: 1; transform: none; transition: none; }
  html { scroll-behavior: auto; }
  body { transition: none; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 860px) {
  .header-row { padding: 10px var(--pad) 8px; row-gap: 6px; }
  .main-nav {
    order: 3;
    flex-basis: 100%;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .main-nav::-webkit-scrollbar { display: none; }
  .section { scroll-margin-top: 92px; }
}

@media (max-width: 540px) {
  .main-nav { gap: 14px; font-size: 0.88rem; }
  .btn-cv { margin: 6px 0 0; }

  /* projects table becomes one card per project */
  .positions thead { display: none; }
  .positions, .positions tbody, .positions tr, .positions td { display: block; width: 100%; }
  .positions tr { padding: 16px 0; border-bottom: 1px solid var(--line); }
  .positions td, .positions tr:last-child td { padding: 0; border-bottom: none; }
  .positions td.sym { display: none; }
  .positions td.status { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px; margin-top: 10px; }
  .positions .status a.src-link { display: inline; margin-top: 0; }
  .positions .status .wake-note { flex-basis: 100%; margin-top: 2px; }
  .positions .group-row { padding: 0; border-bottom: none; }
  .positions .group-row th { display: block; padding: 28px 0 8px; border-bottom: 1px solid var(--line); }
  .positions th:nth-child(3),
  .positions td:nth-child(3) { display: none; }
  .row-body:has(.row-shot) { grid-template-columns: 1fr; }
  .skills { grid-template-columns: 1fr; gap: 2px; }
  .skills dd { margin-bottom: 10px; }
  .row-shot { grid-column: 1; grid-row: auto; width: 220px; max-width: 100%; margin-top: 10px; }
}
/* ============ PRINT / CV PDF ============ */
.print-only { display: none; }

@media print {
  @page { size: A4; margin: 14mm; }
  :root, [data-theme="dark"] {
    --bg: #FFFFFF; --ink: #1A1A1A; --ink-soft: #444444; --line: #DDDDDD;
    --accent: #2F5FE0; --green: #1A9E5C; --amber: #9A7B1F;
  }
  body { font-size: 10pt; line-height: 1.45; }
  a { color: var(--ink); }

  .site-header, .hero, .skip-link, #contact, .site-footer, .section-sub, .verify,
  .row-shot, .positions-note, .positions th:nth-child(4), .positions td:nth-child(4) {
    display: none !important;
  }
  .print-only { display: block; }
  [data-reveal] { opacity: 1 !important; transform: none !important; }

  .cv-name { font-size: 20pt; font-weight: 700; }
  .cv-role, .cv-contact { color: var(--ink-soft); }
  .cv-contact a { color: var(--ink-soft); }

  .section { max-width: none; padding: 12pt 0 0; }
  .section h2 { font-size: 12.5pt; padding-bottom: 3pt; border-bottom: 1px solid var(--line); }
  .list { margin-top: 4pt; }
  .section h2 { break-after: avoid; }
  .item { padding: 4pt 0; border-bottom: none; break-inside: avoid; }
  .item-head { flex-wrap: nowrap; }
  .item-head h3, .item h3 { font-size: 10.5pt; }
  .item-meta { font-size: 9.5pt; margin-top: 1pt; }
  .item-date { font-size: 9pt; }
  .item-desc { margin-top: 2pt; font-size: 9.5pt; }
  .item-desc + .item-desc { margin-top: 1pt; }

  .skills { margin-top: 6pt; grid-template-columns: 150px 1fr; gap: 3pt 14pt; font-size: 9.5pt; }

  .table-wrap { margin-top: 4pt; overflow: visible; }
  .positions { font-size: 9.5pt; }
  .positions td { padding: 4pt 10pt 4pt 0; }
  .positions tr { break-inside: avoid; }
  .positions .group-row th { padding: 8pt 0 3pt; }
  #certifications .list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24pt; }
  .row-body:has(.row-shot) { display: block; }
  .row-tagline { font-size: 9pt; }
}

/* 1-page CV: tools/build_cv.py adds .cv-compact to <html> before printing */
@page compact { size: A4; margin: 8mm 11mm; }
@media print {
  .cv-compact body { page: compact; font-size: 8.6pt; line-height: 1.24; }
  .cv-compact .cv-name { font-size: 15pt; }
  .cv-compact .cv-role, .cv-compact .cv-contact { font-size: 8.6pt; }
  .cv-compact .section { padding-top: 4pt; }
  .cv-compact .section h2 { font-size: 10pt; padding-bottom: 1.5pt; }
  .cv-compact .list { margin-top: 1pt; }
  .cv-compact .item { padding: 1.5pt 0; }
  .cv-compact .item-head h3, .cv-compact .item h3 { font-size: 9pt; }
  .cv-compact .item-meta, .cv-compact .item-desc { font-size: 8.4pt; margin-top: 0; }
  .cv-compact .item-date { font-size: 8pt; }

  .cv-compact .skills { margin-top: 3pt; grid-template-columns: 120px 1fr; gap: 1pt 10pt; font-size: 8.4pt; }

  /* projects: one line each, no header or type column */
  .cv-compact .positions thead, .cv-compact .positions td:nth-child(3) { display: none; }
  .cv-compact .positions { font-size: 8.4pt; }
  .cv-compact .positions td { padding: 0.5pt 8pt 0.5pt 0; border-bottom: none; }
  .cv-compact .row-tagline { display: inline; font-size: 8.4pt; }
  .cv-compact .row-tagline::before { content: " — "; }
  .cv-compact .positions .group-row th { padding: 3pt 0 1pt; border-bottom: none; }

  /* certifications and competitions side by side in two columns */
  .cv-compact #certifications .list, .cv-compact #competitions .list {
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 18pt;
  }
  .cv-compact #certifications .list { grid-template-columns: 1fr 1fr 1fr; column-gap: 14pt; }
  .cv-compact .positions .sym { font-size: 7.6pt; }
}
