/* Ladder-diagram identity: --wire is a control wire (IEC dark blue), --live is power flow
   (TIA Portal online green). Green means "energized / current focus" everywhere on the page. */
:root {
  color-scheme: dark;
  --bg: #1a1e23;
  --surface: #232930;
  --ink: #e8eae4;
  --ink-dim: #a0a8b1;
  --rule: rgba(232, 234, 228, 0.12);
  --wire: #6b93f0;
  --live: #45d277;
  --live-soft: rgba(69, 210, 119, 0.2);
  --box: #20262d; /* function block body */
  --box-edge: rgba(232, 234, 228, 0.28);

  --rail-x: clamp(16px, 4vw, 40px);
  --gap: clamp(22px, 5vw, 56px);
  --step: 160ms;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #e2e3de; /* RAL 7035, the inside of a control cabinet */
  --surface: #ecede8;
  --ink: #1c2024;
  --ink-dim: #4f565e;
  --rule: rgba(28, 32, 36, 0.14);
  --wire: #1d4fc4;
  --live: #17853f;
  --live-soft: rgba(23, 133, 63, 0.16);
  --box: #ecede8;
  --box-edge: rgba(28, 32, 36, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Archivo", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
  background: var(--bg);
  color: var(--ink);
  transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration-color: var(--wire);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: var(--live);
}

/* ---------- Controls ---------- */

.controls {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  display: flex;
  gap: 0.4rem;
}

.controls button {
  height: 2.5rem;
  min-width: 2.5rem;
  padding: 0 0.7rem;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--ink-dim);
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: 600 0.85rem/1 "Archivo", sans-serif;
  font-stretch: 85%;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.controls button:hover {
  color: var(--ink);
  border-color: var(--wire);
}

#theme-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
}

/* ---------- Sheet with the power rail ---------- */

.sheet {
  position: relative;
  max-width: 54rem;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px) 0 calc(var(--rail-x) + var(--gap));
}

/* Left power rail, the full height of the page. */
.sheet::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--rail-x);
  width: 3px;
  background: var(--wire);
}

/* ---------- Hero ---------- */

/* Sized to its content, so the first screen carries the name, the pitch, the proof points and the
   CV, with Network 1 already in view below. */
.hero {
  padding: clamp(5rem, 14vh, 8.5rem) 0 clamp(1rem, 4vh, 2.5rem);
}

.name {
  font-size: clamp(2.75rem, 11vw, 6.75rem);
  font-weight: 700;
  font-stretch: 125%;
  line-height: 0.95;
  letter-spacing: -0.025em;
}

/* The legal name, once: set wide like the handle above it, at a size that reads as a signature. */
.legal-name {
  margin-top: 0.6rem;
  font-size: clamp(1.05rem, 2.4vw, 1.4rem);
  font-weight: 500;
  font-stretch: 125%;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
}

.role {
  margin-top: 0.5rem;
  max-width: 64ch;
  font-size: clamp(1.15rem, 2.6vw, 1.45rem);
  line-height: 1.4;
  color: var(--ink-dim);
}

.role span {
  display: block;
  text-wrap: balance;
}

.role span:first-child {
  color: var(--ink);
}

.hero-facts {
  list-style: none;
  margin: 1.5rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
  color: var(--ink);
}

/* Each fact is a closed NO contact: two short bars with a live gap, the hero rung's symbol in small. */
.hero-facts li {
  position: relative;
  padding-left: 1.6rem;
}

.hero-facts li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.4em;
  width: 0.7rem;
  height: 0.85em;
  border-inline: 2px solid var(--live);
  background: var(--live-soft);
}

.hero-meta {
  margin-top: 1.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  font-size: 0.95rem;
  color: var(--ink-dim);
}

.hero-meta a {
  color: var(--ink);
  font-weight: 600;
}

.hero-meta .cv-button {
  padding: 0.6rem 1.1rem;
  border: 1.5px solid var(--live);
  border-radius: 4px;
  background: var(--live-soft);
  text-decoration: none;
  transition: background 0.2s ease;
}

.hero-meta .cv-button:hover {
  background: transparent;
}

/* ---------- Rungs ---------- */

/* A rung starts on the left power rail and ends on its own short right rail. Every part is drawn
   energized by default (no-JS, reduced motion); the hero animates on load, networks on scroll. */
.rung {
  position: relative;
  display: flex;
  align-items: center;
  margin: 2.25rem 0 2.5rem calc(-1 * var(--gap));
  padding: 2.4rem 0;
}

.rung::after {
  content: "";
  position: absolute;
  right: 0;
  top: 1.2rem;
  bottom: 1.2rem;
  width: 3px;
  background: var(--wire);
}

.wire {
  flex: 1 1 0;
  min-width: 10px;
  height: 2px;
  position: relative;
  background: repeating-linear-gradient(90deg, var(--wire) 0 5px, transparent 5px 9px);
}

.wire::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--live);
  transform-origin: left center;
}

.contact,
.coil {
  position: relative;
  flex: none;
}

.sym {
  display: block;
  width: 30px;
  height: 32px;
  border-left: 3px solid var(--live);
  border-right: 3px solid var(--live);
  background: var(--live-soft);
}

.coil .sym {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
}

.addr,
.tag {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-stretch: 80%;
  line-height: 1;
}

.addr {
  bottom: calc(100% + 0.5rem);
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.tag {
  top: calc(100% + 0.5rem);
  font-size: 0.95rem;
  font-weight: 600;
}

.coil .tag {
  color: var(--live);
}

@media (prefers-reduced-motion: no-preference) {
  .hero .wire::after {
    animation: wire-on 260ms ease-out both;
    animation-delay: calc(400ms + var(--i) * var(--step));
  }

  .hero .sym {
    animation: contact-on 200ms ease-out both;
    animation-delay: calc(400ms + var(--i) * var(--step));
  }

  .hero .coil .tag {
    animation: tag-on 200ms ease-out both;
    animation-delay: calc(400ms + var(--i) * var(--step));
  }
}

@keyframes wire-on {
  from { transform: scaleX(0); }
}

@keyframes contact-on {
  from {
    border-left-color: var(--wire);
    border-right-color: var(--wire);
    background-color: transparent;
  }
}

@keyframes tag-on {
  from { color: var(--ink); }
}

/* Parallel branch: legs of equal height joined by a vertical wire on each side. */
.rung-net {
  --leg-h: 5.75rem;
  margin: 2rem 0 0 calc(-1 * var(--gap));
  padding: 1rem 0;
}

@media (max-width: 640px) {
  .rung-net {
    --leg-h: 6.25rem;
  }

  .rung-net .tag {
    width: 4.75rem;
    white-space: normal;
    text-align: center;
    font-size: 0.82rem;
    line-height: 1.1;
  }
}

.rung-net::after {
  top: 0;
  bottom: 0;
}

.branch {
  position: relative;
  flex: 4 1 0;
  display: flex;
  flex-direction: column;
}

.leg {
  display: flex;
  align-items: center;
  height: var(--leg-h);
}

.branch::before,
.branch::after {
  content: "";
  position: absolute;
  top: calc(var(--leg-h) / 2 - 1px);
  bottom: calc(var(--leg-h) / 2 - 1px);
  width: 2px;
  background: var(--live);
}

.branch::before {
  left: 0;
}

.branch::after {
  right: 0;
}

/* ---------- Networks ---------- */

main {
  padding-bottom: 4rem;
}

section {
  margin-bottom: 5.5rem;
}

/* Each network title is a branch off the power rail; the junction energizes once the
   network scrolls into view (reveal observer in script.js), then its rungs follow. */
section h2 {
  position: relative;
  font-size: clamp(1.6rem, 3.6vw, 2rem);
  font-weight: 700;
  font-stretch: 112%;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin-bottom: 1.5rem;
}

.net-no {
  font-size: 0.55em;
  font-weight: 500;
  font-stretch: 85%;
  letter-spacing: 0;
  color: var(--ink-dim);
}

section h2::before,
section h2::after {
  content: "";
  position: absolute;
  top: 0.6em;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

section h2::before {
  left: calc(-1 * var(--gap));
  width: calc(var(--gap) - 0.75rem);
  height: 2px;
  background: var(--live);
}

section h2::after {
  left: calc(-1 * var(--gap) - 4.5px);
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--live);
}

.js .reveal:not(.visible) h2::before {
  background: repeating-linear-gradient(90deg, var(--wire) 0 5px, transparent 5px 9px);
}

.js .reveal:not(.visible) h2::after {
  background: var(--wire);
}

.js .network:not(.visible) .wire::after {
  transform: scaleX(0);
}

.js .network:not(.visible) .sym {
  border-left-color: var(--wire);
  border-right-color: var(--wire);
  background-color: transparent;
}

.js .network:not(.visible) .coil .tag {
  color: var(--ink);
}

.js .network:not(.visible) .branch::before,
.js .network:not(.visible) .branch::after {
  background: var(--wire);
}

@media (prefers-reduced-motion: no-preference) {
  .network .wire::after {
    transition: transform 260ms ease-out;
    transition-delay: calc(300ms + var(--i, 0) * var(--step));
  }

  .network .sym,
  .network .coil .tag,
  .network .branch::before,
  .network .branch::after {
    transition: border-color 200ms ease-out, background-color 200ms ease-out, color 200ms ease-out;
    transition-delay: calc(300ms + var(--i, 0) * var(--step));
  }
}

.net-comment p {
  max-width: 64ch;
  color: var(--ink-dim);
}

.net-comment p + p {
  margin-top: 1em;
}

/* ---------- Skills: a PLC tag table ---------- */

.tag-table + .tag-table {
  margin-top: 2.25rem;
}

.tag-table h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.skill-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tag-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6rem 4.5rem 3.5rem;
  gap: 1rem;
  align-items: baseline;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-dim);
}

.tag-head {
  padding: 0.3rem 0;
  border-bottom: 2px solid var(--ink);
  font-size: 0.8rem;
  font-stretch: 80%;
}

.t-type,
.t-addr,
.t-val {
  font-size: 0.9rem;
  font-stretch: 80%;
}

.t-val {
  font-weight: 600;
}

.tag-row.is-focus {
  color: var(--ink);
}

.is-focus > :first-child {
  font-weight: 600;
}

.is-focus .t-val {
  color: var(--live);
}

.tag-note {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--ink-dim);
}

.tag-note::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 0.6rem;
  border-radius: 50%;
  background: var(--live);
  vertical-align: 0.1em;
}

@media (max-width: 640px) {
  .tag-row {
    grid-template-columns: minmax(0, 1fr) 4rem 3rem;
    gap: 0.75rem;
  }

  .t-type {
    display: none;
  }
}

/* ---------- Projects: function blocks ---------- */

.project-meta {
  font-size: 0.9rem;
  font-stretch: 85%;
  font-weight: 500;
  color: var(--ink-dim);
}

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

.fb:first-of-type {
  padding-top: 0.5rem;
}

.fb-db {
  font-size: 0.8rem;
  font-stretch: 80%;
  color: var(--ink-dim);
}

.fb h3 {
  max-width: 48ch;
  margin: 0.1rem 0 1rem;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.35;
}

/* The block sits on the rung: EN comes from the rail, ENO drives the coil, inputs enter on the left. */
.fb-net {
  --row: 2.15rem;
  display: grid;
  grid-template-columns: calc(var(--gap) + 9rem) minmax(11rem, 15rem) minmax(8rem, 1fr);
  grid-template-rows: repeat(3, var(--row));
  margin-left: calc(-1 * var(--gap));
}

.fb-en {
  grid-area: 2 / 1;
  align-self: center;
}

.fb-box {
  grid-column: 2;
  grid-row: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: repeat(3, 1fr);
  padding: 0 0.6rem;
  border: 1.5px solid var(--box-edge);
  background: var(--box);
}

.fb-name {
  grid-column: 1 / -1;
  align-self: center;
  justify-self: center;
  font-size: 0.9rem;
  font-weight: 600;
  font-stretch: 85%;
}

.fb-pin {
  align-self: center;
  font-size: 0.8rem;
  font-stretch: 80%;
  color: var(--ink-dim);
}

.fb-pin-out {
  justify-self: end;
}

.fb-pin-in {
  grid-area: 3 / 1;
}

.fb-in {
  grid-area: 3 / 1;
  align-self: center;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-left: calc(var(--gap) + 0.5rem);
  text-align: right;
  line-height: 1.15;
  color: var(--ink);
}

.fb-in::after {
  content: "";
  flex: none;
  width: 1.25rem;
  height: 1.5px;
  background: var(--ink-dim);
}

.fb-out {
  grid-area: 2 / 3;
  position: relative;
  display: flex;
  align-items: center;
}

.fb-out .wire {
  min-width: 1.25rem;
}

.fb-out::after {
  content: "";
  position: absolute;
  right: 0;
  top: -0.75rem;
  bottom: -0.75rem;
  width: 3px;
  background: var(--wire);
}

.fb-comment {
  max-width: 64ch;
  margin-top: 1.25rem;
  color: var(--ink-dim);
}

@media (max-width: 640px) {
  /* No room for operands outside the block: the input value moves inside, next to its pin. */
  .fb-net {
    grid-template-columns: var(--gap) minmax(0, 1fr) 6.5rem;
  }

  .fb-in {
    grid-area: 3 / 2;
    position: relative;
    max-width: 70%;
    padding: 0 0.6rem 0 0;
    font-size: 0.85rem;
  }

  .fb-in::after {
    display: none;
  }
}

.fb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}

.fb-mini {
  padding: 0 1rem 1.1rem;
  border: 1.5px solid var(--box-edge);
  background: var(--box);
}

.fb-mini .fb-db {
  margin: 0 -1rem 0.75rem;
  padding: 0.45rem 1rem;
  border-bottom: 1px solid var(--rule);
  font-weight: 600;
  color: var(--ink);
}

.fb-db span {
  margin-right: 0.4rem;
  font-weight: 500;
  color: var(--ink-dim);
}

.fb-mini h3 {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
}

.fb-mini .project-meta {
  margin-bottom: 0.5rem;
}

.fb-mini p:last-child {
  font-size: 0.95rem;
  color: var(--ink-dim);
}

/* ---------- Footer ---------- */

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  padding: 2rem 0 2.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
  color: var(--ink-dim);
}

/* ---------- Motion & accessibility ---------- */

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

  section h2::before,
  section h2::after {
    transition: none;
  }
}

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