/* =========================================================
   I Love Power Electronics — site styles
   Themes: "Night Ops" (dark, default) and "Field Manual" (light)
   Look: old (c. 2004) Steam client — olive/tan, square corners,
   beveled edges (light top-left, dark bottom-right), royal purple CTAs.
   ========================================================= */

/* ---------- Theme tokens ---------- */
:root,
[data-theme="dark"] {
  /* Night Ops */
  --ground:      #22271D;  /* page background */
  --grid-line:   #2A3023;  /* graph-paper lines */
  --surface:     #2E3527;  /* panels, cards */
  --bevel-hi:    #5E6A4E;  /* top/left edge */
  --bevel-lo:    #14180F;  /* bottom/right edge */
  --text:        #E3E6D6;
  --muted:       #BFC6AE;
  --faint:       #A8B096;
  --tan:         #D3C27E;  /* labels, stats */
  --link:        #D3C27E;
  --fill:        #7546C4;  /* royal purple buttons */
  --fill-hi:     #A486DE;
  --on-fill:     #FFFFFF;
  --chip-border: #4A5540;
  --hot-bg:      #3A3420;
  --hot-border:  #8C7A3A;
  --hot-text:    #E8D9A0;
  --footer:      #14180F;  /* footer: a shade below the ground */
  --ph-a:        #2E3527;  /* photo placeholder stripes */
  --ph-b:        #283022;
  /* rainbow MOSFET brand mark, brightened to read on olive */
  --rb-1: #E0533F; --rb-2: #EE8030; --rb-3: #E8C83A; --rb-4: #6CBF5A;
  --rb-5: #2FAE9A; --rb-6: #4F8AD6; --rb-7: #9A72E0;
  color-scheme: dark;
}

[data-theme="light"] {
  /* Field Manual */
  --ground:      #CFC6A4;
  --grid-line:   #C4BA96;
  --surface:     #E2DABD;
  --bevel-hi:    #F3EEDB;
  --bevel-lo:    #8F8767;
  --text:        #23291B;
  --muted:       #3A4030;
  --faint:       #454A35;
  --tan:         #3F4A2C;  /* darkened olive so small labels pass 4.5:1 */
  --link:        #4E2378;
  --fill:        #5A2B8C;
  --fill-hi:     #8A63B8;
  --on-fill:     #FFFFFF;
  --chip-border: #A79E7C;
  --hot-bg:      #EADFB8;
  --hot-border:  #A08A40;
  --hot-text:    #23291B;
  --footer:      #E2DABD;
  --ph-a:        #D8CFAF;
  --ph-b:        #E2DABD;
  /* rainbow MOSFET, deepened to read on tan */
  --rb-1: #B8322A; --rb-2: #C4560F; --rb-3: #957A0C; --rb-4: #4A8A2E;
  --rb-5: #12756A; --rb-6: #2C569A; --rb-7: #5A2B8C;
  color-scheme: light;
}

/* Theme-independent */
:root {
  --font-sans: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --max-w: 75rem;
  --gutter: 2rem;
}

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

/* Global scale. Every size below is in rem (1rem = 16px at 100%), so this one
   value scales the whole page. Phones stay at 100% so the hero fits at 360px. */
html { font-size: 100%; }
@media (min-width: 641px) { html { font-size: 130%; } }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background-color: var(--ground);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 1.5rem 1.5rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }

:focus-visible {
  outline: 0.125rem solid var(--tan);
  outline-offset: 0.1875rem;
}

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--fill); color: var(--on-fill); padding: 0.75rem 1rem; z-index: 10;
}
.skip-link:focus { left: 1rem; top: 1rem; }

.container {
  max-width: var(--max-w);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------- Bevels (the Steam look) ---------- */
.bevel {
  border-style: solid;
  border-width: 0.125rem;
  border-color: var(--bevel-hi) var(--bevel-lo) var(--bevel-lo) var(--bevel-hi);
}
.inset {
  border-style: solid;
  border-width: 0.125rem;
  border-color: var(--bevel-lo) var(--bevel-hi) var(--bevel-hi) var(--bevel-lo);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.75rem 1.375rem;
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  border-style: solid;
  border-width: 0.125rem;
}
.btn:active { transform: translate(1px, 1px); }
.btn-primary {
  background: var(--fill);
  color: var(--on-fill);
  border-color: var(--fill-hi) var(--bevel-lo) var(--bevel-lo) var(--fill-hi);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--bevel-hi) var(--bevel-lo) var(--bevel-lo) var(--bevel-hi);
}
.btn-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* ---------- Header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 0.125rem solid var(--bevel-lo);
  box-shadow: inset 0 -1px 0 var(--bevel-hi);
}
.header-inner {
  display: flex; flex-wrap: wrap; gap: 1rem;
  align-items: center; justify-content: space-between;
  padding-block: 1rem;
}
.brand {
  display: flex; align-items: center; gap: 0.75rem;
  text-decoration: none; font-weight: 700; font-size: 1.125rem; letter-spacing: -0.01em;
}
.brand-mark { flex: none; width: 2.125rem; height: 2.125rem; }
.rb-1 { stop-color: var(--rb-1); } .rb-2 { stop-color: var(--rb-2); }
.rb-3 { stop-color: var(--rb-3); } .rb-4 { stop-color: var(--rb-4); }
.rb-5 { stop-color: var(--rb-5); } .rb-6 { stop-color: var(--rb-6); }
.rb-7 { stop-color: var(--rb-7); }
.site-nav {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1.5rem; font-size: 0.9375rem;
}
.site-nav > a:not(.btn) {
  color: var(--muted); text-decoration: none; padding-block: 0.75rem;
}
.site-nav > a:not(.btn):hover { color: var(--text); }
.site-nav .btn { font-size: 0.9375rem; padding: 0.625rem 1.125rem; }

.theme-toggle {
  width: 2.75rem; height: 2.75rem; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.theme-toggle:active { border-color: var(--bevel-lo) var(--bevel-hi) var(--bevel-hi) var(--bevel-lo); }
.theme-toggle svg, .lightbox-btn svg { width: 1.25rem; height: 1.25rem; }
[data-theme="dark"] .icon-moon,
[data-theme="light"] .icon-sun { display: none; }

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(21.25rem, 100%), 1fr));
  gap: 3rem;
  align-items: center;
  padding-block: 4rem 3rem;
}
.hero-copy { display: flex; flex-direction: column; gap: 1.5rem; }
.eyebrow {
  font-family: var(--font-mono); font-size: 0.875rem; color: var(--tan);
  letter-spacing: 0.08em; text-transform: uppercase;
}
.hero h1 {
  font-size: clamp(2.5rem, 6.5vw, 3.75rem);
  line-height: 1.04; letter-spacing: -0.03em; font-weight: 700;
}
.lede { font-size: 1.1875rem; line-height: 1.6; color: var(--muted); max-width: 35rem; }
.status { display: flex; align-items: center; gap: 0.625rem; font-size: 0.9375rem; color: var(--muted); }
.status-dot { width: 0.625rem; height: 0.625rem; border-radius: 50%; background: #22C55E; flex: none; }

.notebook { background: var(--surface); }
.notebook-bar {
  display: flex; justify-content: space-between;
  padding: 0.625rem 1rem; border-bottom: 1px solid var(--bevel-lo);
  font-family: var(--font-mono); font-size: 0.8125rem; color: var(--faint);
}
.notebook-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1.125rem; }
/* Portrait keeps the size it had when it shared a 2:3 row with a second photo. */
.notebook .portrait { width: calc((100% - 0.75rem) * 0.4); height: 13.75rem; align-self: center; }
.portrait img { object-position: 50% 30%; }

.stats {
  margin: 0;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem;
}
.stats > div { border-top: 0.125rem solid var(--bevel-lo); padding-top: 0.625rem; }
.stats dt { font-family: var(--font-mono); font-size: 1.625rem; font-weight: 600; color: var(--tan); }
.stats dd { margin: 0; font-size: 0.875rem; color: var(--faint); }

/* ---------- Photos (striped placeholder shows until/unless the image loads) ---------- */
.photo {
  position: relative;
  overflow: hidden;
  background-image: repeating-linear-gradient(45deg, var(--ph-a) 0 0.625rem, var(--ph-b) 0.625rem 1.25rem);
}
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo.is-missing::after {
  content: '[photo]';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 0.75rem; color: var(--faint);
}

/* ---------- Sections ---------- */
.section { padding-block: 3.5rem; }
.section h2 { font-size: 2rem; letter-spacing: -0.02em; margin-bottom: 1.5rem; }
.section-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end;
  gap: 0.75rem; margin-bottom: 1.25rem;
}
.section-head h2 { margin-bottom: 0; }
.section-note { font-family: var(--font-mono); font-size: 0.875rem; color: var(--faint); }
#tools { padding-top: 2.5rem; }

.grid { display: grid; gap: 1.25rem; }
.grid-tools { grid-template-columns: repeat(auto-fit, minmax(min(17.5rem, 100%), 1fr)); }
.grid-areas { grid-template-columns: repeat(auto-fit, minmax(min(26rem, 100%), 1fr)); }
.grid-projects { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 600px) {
  .grid-projects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Rows of three. A short last row gets wider tiles instead of a gap. */
@media (min-width: 1200px) {
  .grid-projects { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .grid-projects > .project { grid-column: span 2; }
  .grid-projects > .project:nth-child(3n+1):nth-last-child(2),
  .grid-projects > .project:nth-child(3n+1):nth-last-child(2) + .project { grid-column: span 3; }
  .grid-projects > .project:nth-child(3n+1):last-child { grid-column: 3 / span 2; }
  .grid-projects > .project:nth-child(3n+1):nth-last-child(2) .photo,
  .grid-projects > .project:nth-child(3n+1):nth-last-child(2) + .project .photo { aspect-ratio: 3 / 2; }
}

.card {
  background: var(--surface);
  padding: 1.75rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}
.card h3 { font-size: 1.375rem; }
.card p { font-size: 1rem; line-height: 1.6; color: var(--muted); }
.card-kicker {
  font-family: var(--font-mono); font-size: 0.8125rem; color: var(--tan) !important;
  text-transform: uppercase;
}

/* Tool cards */
.tool { padding: 1.5rem; gap: 0.625rem; text-decoration: none; color: var(--text); }
.tool:hover .tool-cta { text-decoration: underline; }
.tool:active { border-color: var(--bevel-lo) var(--bevel-hi) var(--bevel-hi) var(--bevel-lo); }
.tool-path { font-family: var(--font-mono); font-size: 0.8125rem; color: var(--tan); }
.tool-name { font-size: 1.375rem; font-weight: 700; }
.tool-desc { font-size: 1rem; line-height: 1.55; color: var(--muted); }
/* Preview sits at the same height in every card, whatever the description length. */
.tool-preview { display: block; margin-top: auto; aspect-ratio: 4 / 3; }
.tool-preview img { transition: filter 0.15s; }
.tool:hover .tool-preview img { filter: brightness(1.12); }
.tool-cta { font-weight: 600; color: var(--link); }

/* Skills tray: labeled rows of chips */
.skills {
  margin-top: 1.25rem; padding: 0 1.25rem;
  background: var(--surface);
}
.chip-row {
  display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); gap: 0.625rem 1.25rem;
  align-items: start; padding-block: 1.25rem;
}
.chip-row + .chip-row { border-top: 1px solid var(--chip-border); }
.chip-row .card-kicker { font-weight: 600; letter-spacing: 0.08em; padding-top: 0.5rem; }
.chips {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 0.625rem;
}
.chips li {
  font-family: var(--font-mono); font-size: 0.875rem;
  padding: 0.4375rem 0.75rem; border: 1px solid var(--chip-border);
}
.chips .chip-hot { background: var(--hot-bg); border-color: var(--hot-border); color: var(--hot-text); }
@media (max-width: 640px) {
  .chip-row { grid-template-columns: minmax(0, 1fr); }
  .chip-row .card-kicker { padding-top: 0; }
}

/* Projects */
.project { margin: 0; background: var(--surface); padding: 0.5rem; }
.project .photo { display: block; aspect-ratio: 4 / 3; cursor: zoom-in; }
.project .photo img { transition: filter 0.15s; }
.project .photo:hover img { filter: brightness(1.12); }
.project figcaption { padding: 0.75rem 0.375rem 0.375rem; font-size: 1rem; font-weight: 600; line-height: 1.4; }

/* About */
.about {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(21.25rem, 100%), 1fr));
  gap: 2.5rem;
}
.about-copy { display: flex; flex-direction: column; gap: 1rem; }
.about-copy h2 { margin-bottom: 0; }
.about-copy p { font-size: 1.0625rem; line-height: 1.7; color: var(--muted); max-width: 68ch; }

.lab {
  background: var(--surface); color: var(--text);
  padding: 1.75rem; display: flex; flex-direction: column; gap: 0.875rem;
  align-self: start;
}
.lab p { font-size: 1.125rem; line-height: 1.5; }
.lab .lab-kicker {
  font-family: var(--font-mono); font-size: 0.8125rem; color: var(--tan);
  letter-spacing: 0.08em; text-transform: uppercase;
}

/* ---------- Photo viewer ---------- */
.lightbox {
  padding: 0; margin: auto;
  width: min(87.5rem, calc(100vw - 2rem));
  height: calc(100vh - 2rem); height: calc(100dvh - 2rem);
  max-width: none; max-height: none;
  background: var(--surface); color: var(--text);
}
.lightbox[open] { display: flex; flex-direction: column; }
.lightbox::backdrop { background: rgba(10, 12, 8, 0.88); }
.lightbox-open { overflow: hidden; }
.lightbox-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.375rem 0.375rem 0.375rem 1rem; border-bottom: 1px solid var(--bevel-lo);
  font-family: var(--font-mono); font-size: 0.8125rem; color: var(--faint);
}
.lightbox-controls { display: flex; gap: 0.375rem; }
.lightbox-btn {
  width: 2.75rem; height: 2.75rem; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.lightbox-btn:active { border-color: var(--bevel-lo) var(--bevel-hi) var(--bevel-hi) var(--bevel-lo); }
.lightbox-stage { flex: 1; min-height: 0; background: var(--ground); }
.lightbox-stage img { width: 100%; height: 100%; object-fit: contain; }
.lightbox-caption {
  padding: 0.75rem 1rem; border-top: 1px solid var(--bevel-lo);
  font-size: 1rem; font-weight: 600; line-height: 1.4;
}

@media (prefers-reduced-motion: reduce) {
  .project .photo img, .tool-preview img { transition: none; }
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 3rem;
  background: var(--footer);
  color: var(--text);
  border-top: 0.125rem solid var(--bevel-hi);
}
.footer-inner {
  display: flex; flex-wrap: wrap; gap: 1.5rem;
  justify-content: space-between; align-items: center;
  padding-block: 3.5rem;
}
.footer-title { font-size: 1.875rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 0.5rem; }
.footer-note { font-size: 1rem; color: var(--muted); max-width: 38.75rem; line-height: 1.5; }
.copyright { padding-bottom: 2rem; font-size: 0.875rem; color: var(--faint); }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  :root { --gutter: 1.25rem; }
  .hero { padding-block: 2.5rem 2rem; }
  .section { padding-block: 2.5rem; }
  .site-nav { gap: 0.25rem 1rem; }
}
