/* ==========================================================================
   ethanfleming.dev
   Design tokens first; light is the default, dark follows the OS unless the
   visitor picks a theme with the toggle (stored as data-theme on <html>).
   ========================================================================== */

:root {
  --bg: #ffffff;
  --surface: #f6f7f9;
  --surface-2: #eef0f4;
  --text: #14161a;
  --muted: #5b6270;
  --border: #e3e6eb;
  --accent: #1d5fd1;
  --accent-strong: #164aa6;
  --accent-soft: #e8f0fd;
  --good: #15803d;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);

  --font: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --radius: 12px;
  --max: 1060px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f13;
    --surface: #15181e;
    --surface-2: #1c2028;
    --text: #e9ebef;
    --muted: #9aa2b1;
    --border: #262b34;
    --accent: #6ea8ff;
    --accent-strong: #9cc3ff;
    --accent-soft: #16233a;
    --good: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 18px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0f13;
  --surface: #15181e;
  --surface-2: #1c2028;
  --text: #e9ebef;
  --muted: #9aa2b1;
  --border: #262b34;
  --accent: #6ea8ff;
  --accent-strong: #9cc3ff;
  --accent-soft: #16233a;
  --good: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 18px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

img, svg { max-width: 100%; height: auto; display: block; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-strong); }

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

h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 0.5em; }
h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); font-weight: 700; letter-spacing: -0.03em; }
h2 { font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 700; }
h3 { font-size: 1.2rem; font-weight: 650; }
p { margin: 0 0 1em; }

.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 24px; }
@media (max-width: 600px) { .container { padding: 0 16px; } }

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

.muted { color: var(--muted); }
.eyebrow {
  font: 600 0.78rem/1 var(--font); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 14px;
}

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 16px; }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -0.01em;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: var(--text); color: var(--bg); font-size: 0.8rem; font-weight: 800; letter-spacing: 0;
}
.nav-links { display: flex; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.nav-links a {
  color: var(--muted); text-decoration: none; font-size: 0.95rem; font-weight: 500;
  padding: 8px 12px; border-radius: 8px;
}
.nav-links a:hover, .nav-links a[aria-current="page"] { color: var(--text); background: var(--surface); }
.theme-toggle {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer; display: grid; place-items: center;
  margin-left: 6px;
}
.theme-toggle:hover { color: var(--text); background: var(--surface); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
@media (max-width: 640px) {
  .brand-name { display: none; }
  .nav-links a { padding: 8px 8px; font-size: 0.9rem; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px; font-weight: 600; font-size: 0.97rem;
  text-decoration: none; border: 1px solid transparent; transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #0b1220; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #0b1220; } }
.btn-ghost { border-color: var(--border); color: var(--text); background: var(--bg); }
.btn-ghost:hover { background: var(--surface); color: var(--text); }
.btn svg { width: 16px; height: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- Sections ---------- */
section { padding: 88px 0; }
section + section { border-top: 1px solid var(--border); }
.section-head { max-width: 680px; margin-bottom: 40px; }
.section-head p:not(.eyebrow) { color: var(--muted); font-size: 1.05rem; }
@media (max-width: 600px) { section { padding: 64px 0; } }

/* ---------- Hero ---------- */
.hero { padding: 96px 0 72px; }
.hero-grid { display: grid; grid-template-columns: 1fr auto; gap: 48px; align-items: center; }
.hero h1 { margin-bottom: 18px; }
.hero .lead { font-size: 1.2rem; color: var(--muted); max-width: 640px; margin-bottom: 30px; }
.hero .lead strong { color: var(--text); font-weight: 600; }
.role-line { font-size: 1.05rem; color: var(--text); font-weight: 550; margin-bottom: 18px; }
.role-line span { color: var(--muted); font-weight: 400; }

.avatar {
  width: 220px; height: 220px; border-radius: 50%; overflow: hidden; flex: none;
  background: linear-gradient(140deg, var(--accent-soft), var(--surface-2));
  border: 1px solid var(--border); display: grid; place-items: center; box-shadow: var(--shadow);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-initials { font-size: 4.2rem; font-weight: 750; color: var(--accent); letter-spacing: -0.04em; }
@media (max-width: 760px) {
  .hero { padding: 56px 0 48px; }
  .hero-grid { grid-template-columns: 1fr; gap: 28px; }
  .hero-grid .avatar { order: -1; width: 112px; height: 112px; }
  .avatar-initials { font-size: 2.2rem; }
}

/* Stat boxes (F1 case study facts) */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-value { font-size: 1.9rem; font-weight: 750; letter-spacing: -0.03em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 0.9rem; margin-top: 6px; line-height: 1.4; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.project-feature { display: grid; grid-template-columns: 1.15fr 1fr; }
.project-feature .media { background: var(--surface); border-right: 1px solid var(--border); }
.project-feature .media img { width: 100%; height: 100%; object-fit: cover; object-position: top left; }
.project-feature .body { padding: 32px; display: flex; flex-direction: column; }
.project-feature .body p { color: var(--muted); }
.project-feature .btn-row { margin-top: auto; padding-top: 8px; }
@media (max-width: 860px) {
  .project-feature { grid-template-columns: 1fr; }
  .project-feature .media { border-right: 0; border-bottom: 1px solid var(--border); max-height: 280px; }
}

.tags { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0 0 20px; }
.tags li {
  font: 500 0.8rem/1 var(--font); color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); padding: 6px 10px; border-radius: 999px;
}

.coming-soon {
  margin-top: 20px; border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 22px 24px; color: var(--muted); display: flex; gap: 14px; align-items: center;
}
.coming-soon svg { width: 22px; height: 22px; flex: none; color: var(--accent); }

/* ---------- Case studies ---------- */
.case { padding: 44px 0; }
.section-head + .case { padding-top: 0; }
.case + .case { border-top: 1px solid var(--border); }
.case-meta { color: var(--muted); font-size: 0.92rem; margin-bottom: 8px; }
.prb { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; margin: 22px 0 28px; }
.prb div { padding-left: 16px; border-left: 3px solid var(--border); }
.prb dt { font: 650 0.75rem/1 var(--font); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.prb dd { margin: 0; font-size: 0.98rem; }
.prb .result { border-left-color: var(--good); }
.prb .result dt { color: var(--good); }
@media (max-width: 860px) { .prb { grid-template-columns: 1fr; gap: 18px; } }

/* ---------- Flow diagrams ----------
   HTML boxes + CSS arrows: horizontal on wide screens, vertical on phones,
   real text at real sizes in both themes. A step can hold a .branch of
   several stacked nodes (e.g. one service writing to two systems). */
.diagram {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin: 0;
}
.diagram figcaption { color: var(--muted); font-size: 0.86rem; margin-top: 16px; }
.flow { display: flex; align-items: stretch; gap: 30px; list-style: none; margin: 0; padding: 0; }
.flow > li { flex: 1 1 0; position: relative; display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.flow > li + li::before {
  content: ""; position: absolute; left: -24px; top: 50%; width: 18px; height: 2px;
  background: var(--muted); transform: translateY(-50%);
}
.flow > li + li::after {
  content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  border: 5px solid transparent; border-left: 6px solid var(--muted); border-right: 0;
}
.node {
  background: var(--bg); border: 1.5px solid var(--border); border-radius: 10px;
  padding: 12px 14px; line-height: 1.35;
}
.node strong { display: block; font-size: 0.95rem; font-weight: 650; }
.node span { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.node.accent { border-color: var(--accent); background: var(--accent-soft); }
.node.outcome { border-color: var(--good); }
.branch { display: grid; gap: 10px; }
@media (max-width: 760px) {
  .flow { flex-direction: column; gap: 26px; }
  .flow > li + li::before { left: 50%; top: -20px; width: 2px; height: 14px; transform: translateX(-50%); }
  .flow > li + li::after {
    left: 50%; top: -8px; transform: translateX(-50%);
    border: 5px solid transparent; border-top: 6px solid var(--muted); border-bottom: 0;
  }
}

/* ---------- Schema diagram (F1 case study) ----------
   Inline SVG styled from the theme tokens. On narrow screens it keeps a
   readable minimum width and scrolls inside its frame. */
.erd { padding: 20px 20px 18px; }
.erd-scroll { overflow-x: auto; }
.erd-hint { display: none; margin: 0 0 10px; color: var(--muted); font-size: 0.82rem; }
@media (max-width: 860px) { .erd-hint { display: block; } }
.erd svg { width: 100%; min-width: 820px; height: auto; }
.erd .tbl { fill: var(--bg); stroke: var(--border); stroke-width: 1.5; }
.erd .hdr { fill: var(--surface-2); }
.erd .sep { stroke: var(--border); stroke-width: 1.5; }
.erd .fact .tbl { stroke: var(--accent); }
.erd .fact .hdr { fill: var(--accent-soft); }
.erd .fact .sep { stroke: var(--accent); }
.erd .name { font: 700 13.5px var(--mono); fill: var(--text); }
.erd .meta { font: 600 10.5px var(--font); fill: var(--muted); letter-spacing: 0.04em; }
.erd .col { font: 12.5px var(--mono); fill: var(--text); }
.erd .col.more { fill: var(--muted); font-style: italic; }
.erd .key { font: 700 10px var(--font); fill: var(--muted); letter-spacing: 0.05em; }
.erd .key.pk { fill: var(--accent); }
.erd .link { stroke: var(--muted); stroke-width: 1.5; fill: none; }
.erd .card { font: 700 12px var(--font); fill: var(--muted); }
.erd-also { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; color: var(--muted); font-size: 0.86rem; }
.erd-also .tags { margin: 0; }
.erd-also .tags li { font-family: var(--mono); }

/* ---------- How I work (home) ---------- */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; margin-top: 64px; list-style: none; padding: 0; }
.steps li { border-top: 2px solid var(--border); padding-top: 18px; }
.steps li:nth-child(2) { border-top-color: var(--accent); }
.step-num { font: 600 0.8rem/1 var(--mono); color: var(--accent); letter-spacing: 0.08em; }
.steps h3 { font-size: 1.1rem; margin: 10px 0 8px; }
.steps p { color: var(--muted); font-size: 0.97rem; margin: 0; }
@media (max-width: 760px) { .steps { grid-template-columns: 1fr; gap: 22px; margin-top: 44px; } }

/* ---------- About ---------- */
.about-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 48px; }
.about-grid p { font-size: 1.05rem; }
.interests { display: grid; gap: 12px; list-style: none; padding: 0; margin: 0; }
.interests li {
  display: flex; gap: 12px; align-items: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
}
.interests .emoji { font-size: 1.3rem; width: 28px; text-align: center; }
@media (max-width: 860px) { .about-grid { grid-template-columns: 1fr; gap: 28px; } }

/* ---------- Skills ---------- */
.skills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.skill-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.skill-group h3 { font-size: 0.95rem; margin-bottom: 12px; }
.skill-group .tags { margin: 0; }
.skill-group .tags li { background: var(--bg); }
@media (max-width: 860px) { .skills { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .skills { grid-template-columns: 1fr; } }

/* ---------- Contact ---------- */
.contact-card { padding: 40px; text-align: center; background: var(--surface); }
.contact-card p { color: var(--muted); max-width: 520px; margin: 0 auto 26px; }
.contact-card .btn-row { justify-content: center; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 32px 0; color: var(--muted); font-size: 0.9rem; }
.site-footer .container { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.site-footer a { color: var(--muted); }

/* ---------- Article (case study pages) ---------- */
.article { padding: 64px 0 88px; }
.article-head { max-width: 760px; margin-bottom: 40px; }
.article-head .lead { font-size: 1.15rem; color: var(--muted); }
.prose { max-width: 760px; }
.prose h2 { margin-top: 56px; }
.prose h3 { margin-top: 32px; }
.prose ul { padding-left: 1.2em; }
.prose li { margin-bottom: 6px; }
.prose code { font: 0.9em var(--mono); background: var(--surface-2); padding: 2px 6px; border-radius: 5px; }
.wide { max-width: var(--max); margin: 32px 0; }
.shot { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin: 0; background: var(--surface); }
.shot figcaption { padding: 12px 16px; color: var(--muted); font-size: 0.88rem; border-top: 1px solid var(--border); background: var(--bg); }
.shot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) { .shot-grid { grid-template-columns: 1fr; } }
.facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 32px 0; }
@media (max-width: 760px) { .facts { grid-template-columns: repeat(2, 1fr); } }
.callout { background: var(--accent-soft); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: 16px 20px; border-radius: 10px; margin: 24px 0; }
.callout p:last-child { margin: 0; }
.back-link { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); text-decoration: none; font-size: 0.95rem; margin-bottom: 28px; }
.back-link:hover { color: var(--text); }

/* ---------- Resume ---------- */
.resume { padding: 56px 0 88px; }
.resume-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 24px; margin-bottom: 32px; }
.resume-head h1 { font-size: clamp(2rem, 4vw, 2.6rem); margin-bottom: 4px; }
.resume-head .role { font-size: 1.15rem; color: var(--muted); margin: 0; }
.resume-contact { list-style: none; padding: 0; margin: 0; text-align: right; color: var(--muted); font-size: 0.95rem; line-height: 1.7; }
@media (max-width: 640px) { .resume-contact { text-align: left; } }
.resume-grid { display: grid; grid-template-columns: 1fr 280px; gap: 48px; }
@media (max-width: 860px) { .resume-grid { grid-template-columns: 1fr; gap: 24px; } }
.resume h2 { font-size: 0.82rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin: 32px 0 16px; }
.resume h2:first-child { margin-top: 0; }
.job { margin-bottom: 26px; }
.job h3 { font-size: 1.05rem; margin-bottom: 2px; }
.job .when { color: var(--muted); font-size: 0.88rem; margin-bottom: 8px; }
.job ul { margin: 0; padding-left: 1.1em; }
.job li { margin-bottom: 6px; font-size: 0.97rem; }
.side-block { margin-bottom: 20px; }
.side-block h3 { font-size: 0.92rem; margin-bottom: 4px; }
.side-block p { color: var(--muted); font-size: 0.92rem; margin: 0; }

/* ---------- Print (resume PDF) ---------- */
@media print {
  :root, :root[data-theme="dark"] {
    --bg: #fff; --surface: #fff; --surface-2: #f3f4f6; --text: #111; --muted: #444;
    --border: #ddd; --accent: #1d5fd1; color-scheme: light;
  }
  @page { size: Letter; margin: 0.55in 0.6in; }
  body { font-size: 10.5pt; line-height: 1.45; }
  .site-header, .site-footer, .no-print, .skip-link { display: none !important; }
  .resume { padding: 0; }
  .container { padding: 0; max-width: none; }
  .resume-grid { grid-template-columns: 1fr 2.1in; gap: 0.35in; }
  .resume-head { padding-bottom: 12px; margin-bottom: 16px; }
  .resume-contact { text-align: right; }
  .resume h2 { margin: 16px 0 8px; font-size: 8.5pt; }
  .job, .side-block { margin-bottom: 12px; break-inside: avoid; }
  .job li { font-size: 10pt; margin-bottom: 3px; }
  a { color: inherit; text-decoration: none; }
}
