/*
  Engineering in Motion — design system
  Layer order controls cascade precedence explicitly rather than relying on
  source order, so new components can be added without specificity fights.
*/
@layer reset, base, layout, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, h4, p, figure, dl, dd, ol, ul { margin: 0; }
  ol, ul { padding: 0; }
  img, svg { max-width: 100%; display: block; }
  button, input, textarea, select { font: inherit; color: inherit; }
  button { background: none; }
  a { color: inherit; }
  table { border-collapse: collapse; width: 100%; }
}

@layer base {
  :root {
    --bg: #0a0c0f;
    --panel: #10141a;
    --panel2: #151a21;
    --text: #f5f7fa;
    --muted: #aeb7c2;
    --line: #29313c;
    --accent: #9be7c4;
    --accent2: #a8c7ff;
    --danger: #ff9b9b;
    --max: 1180px;
    --measure: 720px;
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }

  body {
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-width: 320px;
  }

  :root.light {
    --bg: #f8fafc;
    --panel: #fff;
    --panel2: #eef2f6;
    --text: #11151a;
    --muted: #56616d;
    --line: #d5dce4;
    --accent: #0b6b4f;
    --accent2: #235aa6;
    --danger: #a3241f;
    color-scheme: light;
  }

  ::selection { background: var(--accent); color: var(--bg); }
  :focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }

  .skip {
    position: absolute;
    left: 1rem;
    top: -5rem;
    background: var(--text);
    color: var(--bg);
    padding: .8rem 1rem;
    border-radius: .5rem;
    z-index: 99;
    transition: top .2s ease;
  }
  .skip:focus { top: 1rem; }

  a { text-underline-offset: .25em; }
  code, .kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

  .eyebrow, .kicker {
    font-size: .74rem;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
  }

  h1 { font-size: clamp(2.6rem, 8vw, 7.6rem); line-height: .95; letter-spacing: -.065em; max-width: 1000px; }
  h2 { font-size: clamp(2rem, 5vw, 4.4rem); line-height: 1; letter-spacing: -.045em; }
  h3 { font-size: 1.25rem; line-height: 1.2; }
  h4 { font-size: 1rem; letter-spacing: -.01em; }
  .muted { color: var(--muted); }
  .lede { font-size: clamp(1.15rem, 2.1vw, 1.55rem); color: var(--muted); max-width: var(--measure); line-height: 1.55; }
}

@layer layout {
  .wrap { width: min(calc(100% - 2rem), var(--max)); margin-inline: auto; }
  .measure { max-width: var(--measure); }
  .section { padding: clamp(4.5rem, 10vw, 9rem) 0; border-top: 1px solid var(--line); }
  .section-head {
    display: grid;
    grid-template-columns: minmax(140px, .35fr) 1fr;
    gap: 2rem;
    align-items: start;
    margin-bottom: 3rem;
  }
  .section-head h2 { max-width: 800px; }
}

@layer components {
  /* Header / navigation */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  }
  .nav { min-height: 70px; display: flex; align-items: center; gap: 1.2rem; }
  .brand { text-decoration: none; font-weight: 850; font-size: 1.2rem; letter-spacing: -.04em; margin-right: auto; }
  .brand b { color: var(--accent); }
  .navlinks { display: flex; gap: 1rem; align-items: center; }
  .navlinks a { text-decoration: none; color: var(--muted); font-size: .9rem; padding: .3rem 0; }
  .navlinks a:hover, .navlinks a:focus-visible { color: var(--text); }
  .navlinks a[aria-current="page"] { color: var(--text); border-bottom: 2px solid var(--accent); }
  .lang-switch { text-decoration: none; font-size: .8rem; font-weight: 700; border: 1px solid var(--line); border-radius: 999px; padding: .4rem .7rem; color: var(--muted); }
  .lang-switch:hover, .lang-switch:focus-visible { color: var(--text); border-color: var(--muted); }
  .lang-suggestion { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .8rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
  .lang-suggestion p { margin: 0; color: var(--muted); }

  .iconbtn, .pill, .btn {
    min-height: 44px;
    min-width: 44px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    border-radius: 999px;
    padding: .65rem 1rem;
    cursor: pointer;
    font-size: .9rem;
  }
  .iconbtn:hover, .pill:hover, .btn:hover { border-color: var(--muted); }
  .btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); text-decoration: none; font-weight: 750; display: inline-flex; align-items: center; }
  .btn.primary:hover { opacity: .88; }
  .btn.ghost { text-decoration: none; display: inline-flex; align-items: center; gap: .4rem; }

  .mobile-menu { display: none; }
  .mobile-drawer[hidden] { display: none; }
  .mobile-drawer { padding: 0 1rem 1rem; }
  .mobile-drawer-controls { display: flex; gap: .6rem; flex-wrap: wrap; padding: 1rem 0; }
  .mobile-drawer a { display: block; padding: .9rem 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--text); }
  .mobile-drawer a[aria-current="page"] { color: var(--accent); }

  /* Breadcrumbs (subpages) */
  .breadcrumbs { padding: 1.2rem 0 0; }
  .breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; font-size: .85rem; color: var(--muted); }
  .breadcrumbs a { color: var(--muted); text-decoration: none; }
  .breadcrumbs a:hover, .breadcrumbs a:focus-visible { color: var(--text); }
  .breadcrumbs li:not(:last-child)::after { content: "/"; margin-left: .4rem; color: var(--line); }
  .breadcrumbs [aria-current="page"] { color: var(--text); }

  /* Hero (home) */
  .hero { padding: clamp(3rem, 9vw, 8rem) 0 3rem; min-height: 760px; display: flex; flex-direction: column; justify-content: center; }
  .hero h1 span { color: var(--muted); }
  .hero-copy { margin-top: 2rem; display: grid; grid-template-columns: 1fr .65fr; gap: 3rem; align-items: end; }
  .hero-actions { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: 1.6rem; }
  .signal { border-left: 1px solid var(--line); padding-left: 1.5rem; color: var(--muted); }
  .signal strong { color: var(--text); display: block; font-size: 1.05rem; }

  /* Page hero (subpages) */
  .page-hero { padding: clamp(2.5rem, 7vw, 5rem) 0 clamp(2.5rem, 6vw, 4rem); }
  .page-hero .kicker { margin-bottom: 1rem; }
  .page-hero h1 { font-size: clamp(2.4rem, 6vw, 4.6rem); }
  .page-hero .lede { margin-top: 1.2rem; }

  /* Proof bar */
  .proofbar { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .proofbar div { padding: 1.4rem 1rem; border-right: 1px solid var(--line); }
  .proofbar div:last-child { border-right: 0; }
  .proofbar strong { display: block; font-size: 1.35rem; }
  .proofbar span { color: var(--muted); font-size: .82rem; }

  /* Filter pills (impact lens, journey theme, work filter) */
  .filterbar { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 2rem; }
  .filterbar .pill[aria-pressed=true] { background: var(--accent); color: var(--bg); border-color: var(--accent); }

  /* Impact grid */
  .impact-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1rem; }
  .impact {
    grid-column: span 4;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1.3rem;
    padding: 1.5rem;
    min-height: 300px;
    display: flex;
    flex-direction: column;
  }
  .impact:nth-child(1) { grid-column: span 7; }
  .impact:nth-child(2) { grid-column: span 5; }
  .impact h3 { font-size: clamp(1.45rem, 3vw, 2.3rem); margin: .8rem 0; }
  .impact p { color: var(--muted); }
  .impact .tags { margin-top: auto; padding-top: 2rem; display: flex; flex-wrap: wrap; gap: .45rem; }
  .tag { font-size: .74rem; border: 1px solid var(--line); border-radius: 999px; padding: .35rem .6rem; color: var(--muted); }

  /* Case studies (/work/) */
  .case-list { display: grid; gap: 1.25rem; }
  .case-study {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1.3rem;
    padding: clamp(1.5rem, 3vw, 2.5rem);
  }
  .case-study > .kicker { margin-bottom: .6rem; }
  .case-study h3 { font-size: clamp(1.5rem, 3vw, 2.2rem); margin-bottom: .6rem; }
  .case-study .tags { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1.5rem; }
  .case-facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem 2rem; }
  .case-facts dt { font-size: .74rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 700; margin-bottom: .35rem; }
  .case-facts dd { color: var(--text); max-width: 60ch; }
  .case-facts .full { grid-column: 1 / -1; }

  /* Timeline (/journey/ and home teaser) */
  .timeline { list-style: none; }
  .timeline li { display: grid; grid-template-columns: .32fr 1fr; gap: 2rem; padding: 2rem 0; border-top: 1px solid var(--line); }
  .timeline li[hidden] { display: none; }
  .timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }
  .timeline h3 { font-size: 1.65rem; margin-bottom: .35rem; }
  .timeline p { color: var(--muted); max-width: 780px; }
  .timeline .tags { margin-top: .8rem; display: flex; flex-wrap: wrap; gap: .4rem; }

  /* Writing */
  .writing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
  .writing-card { background: var(--panel); border: 1px solid var(--line); border-radius: 1.3rem; padding: 1.5rem; min-height: 260px; display: flex; flex-direction: column; }
  .writing-card h3 { font-size: clamp(1.4rem, 2.8vw, 2rem); margin: .8rem 0; }
  .writing-card p { color: var(--muted); }
  .writing-card a { margin-top: auto; font-weight: 700; }

  /* Lab */
  .lab { display: grid; grid-template-columns: .75fr 1.25fr; gap: 2rem; }
  .lab-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
  .lab-card { background: var(--panel); border: 1px solid var(--line); border-radius: 1.3rem; padding: 1.5rem; display: flex; flex-direction: column; gap: .6rem; }
  .status-badge {
    align-self: flex-start;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    font-weight: 700;
    border: 1px solid var(--accent2);
    color: var(--accent2);
    border-radius: 999px;
    padding: .3rem .7rem;
  }
  .terminal {
    background: #050607;
    border: 1px solid var(--line);
    border-radius: 1.3rem;
    padding: 1rem;
    min-height: 300px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #d5ffe9;
  }
  .terminal .dots { color: #77808b; margin-bottom: 1rem; }
  .terminal p { margin: .35rem 0; }
  .terminal .prompt { color: var(--accent); }
  .terminal .muted { color: #8aa39b; font-size: .85rem; margin-top: 1rem; }

  /* About */
  .about-grid { display: grid; grid-template-columns: .65fr 1fr; gap: 3rem; }
  .portrait { border-radius: 1.5rem; overflow: hidden; border: 1px solid var(--line); background: var(--panel); aspect-ratio: 4/5; }
  .portrait img { width: 100%; height: 100%; object-fit: cover; }
  .about-copy p { font-size: 1.08rem; color: var(--muted); margin-bottom: 1rem; }
  .membership { padding: 1rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-top: 2rem; }

  .recognition-list { list-style: none; display: grid; gap: 1rem; margin-top: 1.5rem; }
  .recognition-list li { border-top: 1px solid var(--line); padding-top: 1rem; color: var(--muted); }
  .recognition-list strong { color: var(--text); display: block; }

  .skills-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem 2rem; margin-top: 1.5rem; }
  .skills-grid h3 { font-size: .95rem; margin-bottom: .6rem; }
  .skills-grid ul { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; }
  .skills-grid li { font-size: .82rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: .3rem .65rem; }

  /* Quality strip (Under the Hood) */
  .quality { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-top: 2rem; }
  .quality div { border-top: 1px solid var(--line); padding-top: 1rem; }
  .quality strong { display: block; font-size: 1.4rem; }
  .quality span { color: var(--muted); font-size: .84rem; }

  /* Accessibility page */
  .a11y-table { margin-top: 1rem; }
  .a11y-table th, .a11y-table td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
  .a11y-table th { color: var(--muted); font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
  .kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: .4rem; padding: .1rem .45rem; font-size: .85rem; }

  /* CTA band */
  .cta-band { text-align: center; padding: clamp(3rem, 8vw, 6rem) 0; }
  .cta-band h2 { max-width: 720px; margin-inline: auto; }
  .cta-band .hero-actions { justify-content: center; margin-top: 2rem; }

  /* Footer */
  .footer { padding: 3rem 0 5rem; border-top: 1px solid var(--line); }
  .footer-grid { display: flex; gap: 1rem; justify-content: space-between; flex-wrap: wrap; }
  .footer a { color: var(--muted); }
  .footer-links { display: flex; gap: 1rem; flex-wrap: wrap; }

  /* Career dialog */
  dialog {
    width: min(680px, calc(100% - 2rem));
    border: 1px solid var(--line);
    border-radius: 1.4rem;
    background: var(--panel);
    color: var(--text);
    padding: 0;
  }
  dialog::backdrop { background: rgba(0, 0, 0, .72); }
  .dialog-inner { padding: 1.4rem; }
  .dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
  .dialog-head button { font-size: 1.4rem; }
  .query { display: flex; gap: .6rem; margin: 1rem 0; }
  .query input { min-width: 0; flex: 1; min-height: 48px; border: 1px solid var(--line); border-radius: .8rem; background: var(--bg); color: var(--text); padding: 0 .9rem; font-size: 16px; }
  .answer { border-top: 1px solid var(--line); padding-top: 1rem; color: var(--muted); min-height: 90px; }
  .topic-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .8rem; }
  .topic-chips button { font-size: .78rem; padding: .35rem .7rem; min-height: auto; }

  /* Secondary page headings (About, Accessibility, Résumé section titles) */
  .subhead { font-size: 1.75rem; letter-spacing: -.02em; }
  .about-title { font-size: clamp(2.2rem, 5vw, 3.6rem); letter-spacing: -.04em; line-height: 1.02; }
  .check-list { margin-top: 1rem; padding-left: 1.2rem; color: var(--muted); display: grid; gap: .6rem; }
  .cta-band .lede { margin-inline: auto; }

  /* Recommendations — editorial cards; provenance sits behind progressive disclosure */
  .rec-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
  .rec-card { background: var(--panel); border: 1px solid var(--line); border-radius: 1.3rem; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
  .rec-card-head { display: flex; flex-direction: column; gap: .2rem; }
  .rec-name { font-weight: 750; font-size: 1.05rem; }
  .rec-role { font-size: .9rem; }
  .rec-text { margin: 0; font-size: 1.05rem; line-height: 1.6; border-left: 2px solid var(--line); padding-left: 1rem; }
  .rec-translation-note { font-size: .82rem; }
  .rec-translation-note button { font: inherit; background: none; border: 0; padding: 0; color: var(--accent2); text-decoration: underline; cursor: pointer; min-height: auto; }
  .rec-badges { display: flex; flex-wrap: wrap; gap: .4rem; }
  .rec-details summary { cursor: pointer; font-size: .85rem; font-weight: 700; color: var(--muted); }
  .rec-details summary:hover, .rec-details summary:focus-visible { color: var(--text); }
  .rec-details[open] summary { margin-bottom: .8rem; }
  .rec-provenance { display: grid; grid-template-columns: 1fr; gap: .6rem 0; font-size: .88rem; }
  .rec-provenance dt { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
  .rec-provenance dd { margin: .1rem 0 .5rem; }
  .rec-empty, .rec-error { color: var(--muted); }
}

@layer utilities {
  .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; }
  .reveal { transition: opacity .6s ease, transform .6s ease; }
  .js .reveal:not(.seen) { opacity: 0; transform: translateY(16px); }
  .mt-08 { margin-top: .8rem; }
  .mt-1 { margin-top: 1rem; }
  .mt-1-5 { margin-top: 1.5rem; }
  .mt-2 { margin-top: 2rem; }
  .mb-1-5 { margin-bottom: 1.5rem; }
  .ml-06 { margin-left: .6rem; }
  .pt-2 { padding-top: 2rem; }
  .page-pad { padding: clamp(2.5rem, 6vw, 5rem) 0; }
  .page-title-sm { font-size: clamp(2rem, 5vw, 3rem); }
  .chooser-main { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 1.5rem; }
  .break-all { word-break: break-all; }
  .max-420 { max-width: 420px; }
  .max-480 { max-width: 480px; }
  .form-grid { display: grid; gap: 1.2rem; margin-top: 1.5rem; }
  .field label { display: block; margin-bottom: .3rem; }
  .field-input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: .6rem;
    background: var(--bg);
    color: var(--text);
    padding: 0 .8rem;
  }
  textarea.field-input { min-height: auto; padding: .8rem; font: inherit; }
  .checkbox-row { display: flex; gap: .6rem; align-items: flex-start; }
  .checkbox-row.center { align-items: center; }
}

@media (max-width: 780px) {
  .navlinks { display: none; }
  .mobile-menu { display: inline-flex; }
  .nav-control { display: none; }
  .hero { min-height: auto; }
  .hero-copy, .section-head, .about-grid, .lab, .case-facts, .skills-grid { grid-template-columns: 1fr; }
  .signal { border-left: 0; border-top: 1px solid var(--line); padding: 1rem 0 0; }
  .proofbar { grid-template-columns: 1fr 1fr; }
  .proofbar div:nth-child(2) { border-right: 0; }
  .proofbar div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .impact, .impact:nth-child(1), .impact:nth-child(2) { grid-column: span 12; }
  .writing-grid, .lab-grid { grid-template-columns: 1fr; }
  .rec-grid { grid-template-columns: 1fr; }
  .timeline li { grid-template-columns: 1fr; gap: .5rem; }
  .quality { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { transition: none !important; transform: none !important; }
  .js .reveal:not(.seen) { opacity: 1; }
}

/* Manual override always wins, regardless of system preference */
html.reduce-motion * { scroll-behavior: auto !important; animation: none !important; transition: none !important; }

@media print {
  /* Print must be legible regardless of which theme was active on screen —
     override the palette instead of relying on the dark-mode variables. */
  :root, :root.light {
    --bg: #fff;
    --panel: #fff;
    --panel2: #f4f4f4;
    --text: #000;
    --muted: #333;
    --line: #ccc;
    --accent: #000;
    --accent2: #000;
  }
  .site-header, .footer, .mobile-drawer, .breadcrumbs, .lang-suggestion, dialog,
  .hero-actions, .filterbar, [data-command], .skip { display: none !important; }
  body { background: #fff; color: #000; }
  .section { border-top: 0; padding: 1rem 0; }
  .page-hero { padding: .5rem 0 1.5rem; }
  a { color: #000; text-decoration: underline; }
  .wrap { width: 100%; }
  .reveal { opacity: 1 !important; transform: none !important; transition: none !important; }
}
