/* =====================================================
   TOKENS
===================================================== */

:root {
  --ink: #15191d;
  --ink-soft: #1c2126;
  --paper: #ede8dc;
  --paper-dim: #c9c3b4;
  --rule: #3a4048;        /* borders only — too dark for text */
  --muted: #8a929b;       /* small secondary text, 5.6:1 on --ink (WCAG AA) */
  --rule-soft: #262b31;
  --green: #6f9c81;
  --brass: #c79a4b;

  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --measure: 62ch;
}

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

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

/* Accessibility helpers */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 10;
  padding: 0.5rem 0.9rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.skip-link:focus {
  top: 1rem;
}

main:focus {
  outline: none;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
}

/* =====================================================
   FRAME / LAYOUT
===================================================== */

.frame {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.rail {
  border-right: 1px solid var(--rule-soft);
  padding: 2.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 3rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-mark {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: var(--paper);
  text-decoration: none;
  border: 1px solid var(--rule);
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.rail-nav a {
  text-decoration: none;
  color: var(--paper-dim);
  position: relative;
  width: fit-content;
  transition: color 0.2s ease;
}

.rail-nav a:hover,
.rail-nav a:focus-visible {
  color: var(--green);
}

.rail-nav a span {
  position: relative;
}

.rail-nav a span::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -3px;
  width: 100%;
  height: 1px;
  background: var(--green);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s ease;
}

.rail-nav a:hover span::after,
.rail-nav a:focus-visible span::after {
  transform: scaleX(1);
}

.rail-nav .rail-cta {
  margin-top: 0.6rem;
  color: var(--brass);
}

.rail-foot {
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 4.5rem 2rem 6rem;
}

/* =====================================================
   HERO
===================================================== */

.hero {
  padding-bottom: 3.5rem;
  border-bottom: 1px solid var(--rule-soft);
  margin-bottom: 3.5rem;
  animation: rise 0.6s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 2rem;
}

.portrait {
  flex-shrink: 0;
  width: 150px;
  height: 150px;
  object-fit: cover;
  border: 1px solid var(--rule);
  padding: 5px;
  background: var(--ink-soft);
}

.hero-kicker {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--brass);
  margin-bottom: 1.1rem;
}

.hero h1 {
  font-size: clamp(2rem, 4.5vw, 2.9rem);
  font-weight: 600;
  line-height: 1.18;
  color: var(--paper);
  max-width: 16ch;
  margin-bottom: 1.5rem;
}

.hero-lede {
  max-width: var(--measure);
  color: var(--paper-dim);
  font-size: 1.05rem;
  margin-bottom: 2.25rem;
}

.ledger {
  border-top: 1px solid var(--rule-soft);
  margin-bottom: 2rem;
}

.ledger-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1.5rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 0.95rem;
}

.ledger-row dt {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--paper-dim);
}

.ledger-row dd a {
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.ledger-row dd a:hover {
  color: var(--green);
  border-color: var(--green);
}

.hero-links {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.hero-links a {
  text-decoration: none;
  color: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2px;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.hero-links a:hover {
  color: var(--green);
  border-color: var(--green);
}

.hero-links .hero-cta {
  color: var(--brass);
  border-color: var(--brass);
}

/* =====================================================
   SECTIONS
===================================================== */

.block {
  margin-bottom: 4rem;
}

.block h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--brass);
  font-family: var(--font-mono);
  margin-bottom: 1.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule-soft);
}

#about p {
  max-width: var(--measure);
  color: var(--paper-dim);
  margin-bottom: 1.1rem;
  font-size: 1.02rem;
}

#about p:last-child {
  margin-bottom: 0;
}

/* Stack */

.stack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 2rem;
}

.stack-group h3 {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--paper-dim);
  margin-bottom: 0.85rem;
}

.stack-group ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stack-group li {
  font-size: 0.95rem;
  color: var(--paper);
  padding-left: 0.9rem;
  position: relative;
}

.stack-group li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 5px;
  height: 5px;
  background: var(--green);
}

/* Experience / Education entries */

.entry {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--rule-soft);
}

.entry:first-of-type {
  padding-top: 0;
}

.entry:last-child {
  border-bottom: none;
}

.entry-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.entry-head h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--paper);
}

.entry-date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--paper-dim);
  white-space: nowrap;
}

.entry p {
  color: var(--paper-dim);
  max-width: var(--measure);
  font-size: 0.98rem;
}

.entry-kind {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--green) !important;
  margin-bottom: 0.6rem;
}

.entry-points {
  list-style: none;
  margin-top: 0.85rem;
  max-width: var(--measure);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.entry-points li {
  color: var(--paper-dim);
  font-size: 0.95rem;
  padding-left: 1.1rem;
  position: relative;
}

.entry-points li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--muted);
}

.entry a,
.case-links a,
.more-link a {
  color: var(--paper);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.entry a:hover,
.case-links a:hover,
.more-link a:hover {
  color: var(--green);
  border-color: var(--green);
}

/* Projects / case entries */

.case {
  padding: 1.75rem 0;
  border-bottom: 1px solid var(--rule-soft);
}

.case:first-of-type {
  padding-top: 0;
}

.case:last-child {
  border-bottom: none;
}

.case-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.case-head h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--paper);
}

.case-code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--green);
  border: 1px solid var(--rule);
  padding: 0.2rem 0.55rem;
  white-space: nowrap;
}

.case p {
  color: var(--paper-dim);
  max-width: var(--measure);
  font-size: 0.98rem;
  margin-bottom: 0.6rem;
}

.case-stack {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--paper-dim);
  margin-bottom: 0 !important;
}

.case-detail {
  margin: 1rem 0 1.1rem;
  max-width: var(--measure);
  display: grid;
  gap: 0.75rem;
}

.case-detail > div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 1rem;
}

.case-detail dt {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--brass);
  padding-top: 0.2rem;
}

.case-detail dd {
  color: var(--paper-dim);
  font-size: 0.95rem;
}

.case-links {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.case-note {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted) !important;
  margin-top: 0.5rem;
}

.subhead {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--paper-dim);
  margin: 2.25rem 0 0.5rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--rule-soft);
}

.block h2 + .subhead {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.subhead-note {
  font-size: 0.9rem;
  color: var(--paper-dim);
  max-width: var(--measure);
  margin-bottom: 0.5rem;
}

.subhead-note + .case {
  padding-top: 1rem;
}

.subhead + .case {
  padding-top: 1rem;
}

.more-link {
  margin-top: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--paper-dim);
}

/* Articles */

.block-lede {
  color: var(--paper-dim);
  max-width: var(--measure);
  margin-bottom: 1.5rem;
}

.article-list {
  list-style: none;
  border-top: 1px solid var(--rule-soft);
}

.subhead + .article-list {
  margin-top: 1rem;
}

.article {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 1.5rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule-soft);
}

.article-date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--paper-dim);
  padding-top: 0.15rem;
}

.article-title {
  color: var(--paper);
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.article-title:hover {
  color: var(--green);
  border-color: var(--green);
}

.article-meta {
  margin-top: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

/* Hobbies */

.hobby-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.hobby-list li {
  border-top: 2px solid var(--green);
  padding-top: 0.85rem;
}

.hobby-list h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.hobby-list p {
  color: var(--paper-dim);
  font-size: 0.95rem;
}

/* Engineering notes (articles/*.html) */

.note-back {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  margin-bottom: 2.5rem;
}

.note-back a,
.note-foot a,
.note-body a {
  color: var(--paper);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.note-back a:hover,
.note-foot a:hover,
.note-body a:hover {
  color: var(--green);
  border-color: var(--green);
}

.note-head h1 {
  font-size: clamp(1.7rem, 3.6vw, 2.3rem);
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 1.75rem;
}

.note-body {
  max-width: var(--measure);
}

.note-body h2 {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--brass);
  margin: 2.25rem 0 0.85rem;
}

.note-body p,
.note-body li {
  color: var(--paper-dim);
  font-size: 1rem;
}

.note-body p + p {
  margin-top: 0.9rem;
}

.note-body ul {
  margin: 0.9rem 0 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.note-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--ink-soft);
  border: 1px solid var(--rule-soft);
  padding: 0.05rem 0.3rem;
}

.note-body pre {
  margin-top: 0.9rem;
  padding: 1rem;
  overflow-x: auto;
  background: var(--ink-soft);
  border: 1px solid var(--rule-soft);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.55;
}

.note-body pre code {
  background: none;
  border: none;
  padding: 0;
}

.note-foot {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule-soft);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Contact */

.contact {
  margin-bottom: 0;
}

.contact > p {
  color: var(--paper-dim);
  max-width: var(--measure);
  margin-bottom: 2rem;
  font-size: 1.02rem;
}

.fine-print {
  margin-top: 2rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  max-width: none !important;
}

/* =====================================================
   RESPONSIVE
===================================================== */

@media (max-width: 860px) {
  .frame {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-right: none;
    border-bottom: 1px solid var(--rule-soft);
  }

  .rail {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .rail-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
  }

  .rail-foot {
    display: none;
  }

  main {
    padding: 3rem 1.5rem 4rem;
  }

  .rail-nav .rail-cta {
    margin-top: 0;
  }

  .ledger-row,
  .case-detail > div,
  .article {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
}

@media (max-width: 600px) {
  .hero-top {
    flex-direction: column-reverse;
    gap: 1.5rem;
  }

  .portrait {
    width: 112px;
    height: 112px;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    max-width: none;
  }

  .hero h1 br {
    display: none;
  }
}

/* =====================================================
   PRINT — so the page doubles as a CV
===================================================== */

@media print {
  :root {
    --ink: #fff;
    --paper: #111;
    --paper-dim: #333;
    --muted: #555;
    --rule-soft: #ccc;
    --green: #111;
    --brass: #111;
  }

  .rail,
  .skip-link {
    display: none;
  }

  .frame {
    display: block;
  }

  main {
    padding: 0;
    width: 100%;
  }

  .hero {
    animation: none;
  }

  .case,
  .entry,
  .article {
    break-inside: avoid;
  }

  .portrait {
    width: 96px;
    height: 96px;
    padding: 0;
  }

  .case-links a[href^="http"]::after {
    content: " (" attr(href) ")";
  }
}
