/* ===== Fonts (self-hosted, no third-party requests) ===== */
@font-face {
  font-family: "Archivo Black";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/archivo-black-400.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-500.woff2") format("woff2");
}

/* ===== Design tokens ===== */
:root {
  /* Blueprint (dark) — default identity */
  --bg: #0b1826;
  --bg-alt: #0f2233;
  --surface: #0f2233;
  --rule: #24435b;
  --rule-strong: #3a6386;
  --text: #e9f2f6;
  --text-muted: #86a8ba;
  --accent: #ff8a3d;
  --accent-rgb: 255, 138, 61;
  --accent-ink: #2a1200;
  --glow-opacity: 0.12;
  --max-width: 1080px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    /* Blueline (light) — historical diazo-print inversion */
    --bg: #eef1ee;
    --bg-alt: #e2e7e2;
    --surface: #e2e7e2;
    --rule: #b9c6c0;
    --rule-strong: #86a196;
    --text: #142229;
    --text-muted: #4d6169;
    --accent: #c2530a;
    --accent-rgb: 194, 83, 10;
    --accent-ink: #fff4ea;
    --glow-opacity: 0;
    color-scheme: light;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1826; --bg-alt: #0f2233; --surface: #0f2233;
  --rule: #24435b; --rule-strong: #3a6386;
  --text: #e9f2f6; --text-muted: #86a8ba;
  --accent: #ff8a3d; --accent-rgb: 255, 138, 61; --accent-ink: #2a1200;
  --glow-opacity: 0.12;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eef1ee; --bg-alt: #e2e7e2; --surface: #e2e7e2;
  --rule: #b9c6c0; --rule-strong: #86a196;
  --text: #142229; --text-muted: #4d6169;
  --accent: #c2530a; --accent-rgb: 194, 83, 10; --accent-ink: #fff4ea;
  --glow-opacity: 0;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 39px, color-mix(in srgb, var(--rule) 40%, transparent) 39px, color-mix(in srgb, var(--rule) 40%, transparent) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, color-mix(in srgb, var(--rule) 40%, transparent) 39px, color-mix(in srgb, var(--rule) 40%, transparent) 40px),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

a { color: inherit; }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ===== Nav ===== */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule-strong);
}

.nav__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.nav__brand {
  font-family: "Archivo Black", ui-sans-serif, sans-serif;
  font-weight: 400;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.nav__brand span { color: var(--accent); }

.nav__links {
  display: flex;
  align-items: center;
  gap: 22px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav__links a {
  text-decoration: none;
  color: var(--text-muted);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color 0.15s ease;
}

.nav__links a:hover { color: var(--accent); }

.nav__cta {
  border: 1px solid var(--accent);
  color: var(--accent) !important;
  padding: 7px 14px;
}

.nav__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--rule-strong);
  color: var(--text);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.nav__icon-link {
  background: transparent;
  border: 1px solid var(--rule-strong);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.nav__icon-link:hover { border-color: var(--accent); color: var(--accent); }
.nav__icon-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.nav__burger {
  display: none;
  background: none;
  border: 1px solid var(--rule-strong);
  width: 36px;
  height: 36px;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

/* ===== Hero ===== */
.hero {
  position: relative;
  padding: 96px 0 64px;
  overflow: clip;
}

.hero__glow {
  position: absolute;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  width: 560px;
  height: 420px;
  background: radial-gradient(circle, rgba(var(--accent-rgb), var(--glow-opacity)) 0%, rgba(var(--accent-rgb), 0) 70%);
  pointer-events: none;
  z-index: 0;
}

.hero .container { position: relative; z-index: 1; text-align: center; }

.hero__eyebrow {
  display: inline-block;
  color: var(--accent);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-bottom: 18px;
}

.hero h1 {
  font-family: "Archivo Black", ui-sans-serif, sans-serif;
  font-weight: 400;
  text-transform: uppercase;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  line-height: 0.98;
  letter-spacing: -0.01em;
  margin: 0 0 18px;
  text-wrap: balance;
}

.hero__rule {
  width: 120px;
  height: 6px;
  margin: 0 auto 22px;
  background: var(--accent);
  box-shadow: 0 0 24px 2px rgba(var(--accent-rgb), 0.55);
}

.hero__subtitle {
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  color: var(--text-muted);
  max-width: 640px;
  margin: 0 auto 28px;
}

.hero__actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 22px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-decoration: none;
  border: 1px solid var(--accent);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.22); }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn--ghost {
  background: transparent;
  color: var(--text);
}

.hero__meta {
  color: var(--text-muted);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85rem;
}

.hero__meta noscript { display: inline; }

/* ===== Sections ===== */
section { padding: 72px 0; }

.section-head { margin-bottom: 36px; text-align: left; }

.section-head--left { text-align: left; margin-bottom: 20px; }

.section-head h2 {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-family: "Archivo Black", ui-sans-serif, sans-serif;
  font-weight: 400;
  text-transform: uppercase;
  font-size: clamp(1.3rem, 2.6vw, 1.7rem);
  margin: 0 0 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule-strong);
}

.section-head p {
  color: var(--text-muted);
  margin: 0;
}

.tag {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--accent-ink);
  background: var(--accent);
  padding: 3px 8px;
  flex-shrink: 0;
}

.section-alt { background: color-mix(in srgb, var(--bg-alt) 55%, transparent); border-top: 1px solid var(--rule-strong); border-bottom: 1px solid var(--rule-strong); }

/* ===== About ===== */
.about {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
}

.about p { color: var(--text-muted); margin: 0 0 16px; max-width: 60ch; }

/* ===== Title block (facts display, reused in About) ===== */
.title-block {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  border: 1px solid var(--rule-strong);
  background: rgba(var(--accent-rgb), 0.04);
}

.title-block div {
  padding: 12px 16px;
  border-left: 1px solid var(--rule-strong);
}
.title-block div:first-child { border-left: none; }

.title-block dt,
.title-block span {
  display: block;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 5px;
}

.title-block dd,
.title-block strong {
  display: block;
  margin: 0;
  font-family: "Archivo Black", ui-sans-serif, sans-serif;
  font-weight: 400;
  font-size: 0.92rem;
  text-transform: uppercase;
}

.title-block--vertical {
  grid-template-columns: 1fr;
}
.title-block--vertical div {
  border-left: none;
  border-top: 1px solid var(--rule-strong);
}
.title-block--vertical div:first-child { border-top: none; }

/* ===== Stack: bill of materials table ===== */
.bom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.bom-table thead th {
  text-align: left;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0 12px 12px 0;
  border-bottom: 1px solid var(--rule-strong);
}

.bom-table tbody td {
  padding: 11px 12px 11px 0;
  border-bottom: 1px solid var(--rule);
}

.bom-table tbody td:first-child {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  width: 54px;
}

.bom-table tbody tr:last-child td { border-bottom: none; }

/* ===== Projects ===== */
.proj-group { margin-bottom: 40px; }
.proj-group:last-child { margin-bottom: 0; }

.proj-group__label {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 16px;
}

.proj {
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  margin-bottom: 14px;
}
.proj:last-child { margin-bottom: 0; }

.proj > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  font-family: "Archivo Black", ui-sans-serif, sans-serif;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  font-size: 1rem;
}
.proj > summary::-webkit-details-marker { display: none; }

.proj__logo {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  color: var(--accent);
}

.proj__title { flex: 1; }

.proj__chevron {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  color: var(--accent);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}
.proj[open] > summary .proj__chevron { transform: rotate(90deg); }
.proj > summary:hover { color: var(--accent); }
.proj > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Smooth open/close without JS: force the content to stay rendered
   (override the browser's default display:none on closed <details>
   content) and animate its row height via the grid-template-rows
   0fr -> 1fr trick, clipping with overflow:hidden on the inner
   wrapper. Native <details>/<summary> still drives the open/close
   state and keyboard/no-JS behavior — only the visual reveal changes. */
.proj__body {
  display: grid;
  grid-template-rows: 0fr;
  min-height: 0; /* without this, a 0fr track can still size itself off
    the content's min-content instead of truly reaching 0, causing a
    visible jump at the start/end of the transition instead of smooth
    motion the whole way */
  transition: grid-template-rows 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.proj[open] > .proj__body { grid-template-rows: 1fr; }

.proj__body-inner {
  overflow: hidden;
  padding: 0 20px 24px;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.proj[open] > .proj__body .proj__body-inner {
  opacity: 1;
  transition: opacity 0.3s ease 0.08s; /* trails the height growth slightly
    so the reveal reads as fade+grow instead of the content popping in
    ahead of the box that's supposed to contain it */
}

.proj__body p { color: var(--text-muted); margin: 0 0 16px; }
.proj__body ul { margin: 0 0 16px; padding-left: 20px; color: var(--text-muted); }
.proj__body li { margin-bottom: 6px; }

figure { margin: 0 0 18px; }
figure svg {
  max-width: 100%;
  height: auto;
  display: block;
  background: var(--bg);
  border: 1px solid var(--rule);
}
figcaption {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.flow-line { stroke: var(--text-muted); stroke-width: 1.5; fill: none; }
.flow-line--hinge { stroke: var(--accent); stroke-width: 2; }
.flow-box { fill: var(--bg-alt); stroke: var(--rule-strong); stroke-width: 1.5; }
.flow-text { fill: var(--text); font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 11px; }
.flow-text--sm { font-size: 9.5px; }
.flow-label { fill: var(--text-muted); font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 9.5px; }
.flow-label--hinge { fill: var(--accent); }

.draw { stroke-dasharray: var(--len, 200); stroke-dashoffset: var(--len, 200); }
.proj[open] .draw { animation: draw 0.7s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* Per-diagram line lengths — kept as discrete classes (not inline style="")
   so the strict CSP (style-src 'self', no unsafe-inline) stays intact. */
.len-70 { --len: 70; }
.len-100 { --len: 100; }
.len-110 { --len: 110; }
.len-150 { --len: 150; }
.len-170 { --len: 170; }
.len-300 { --len: 300; } /* generous overestimate for any diagram line — dasharray only needs to be >= the path length */

.proj-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  align-items: start; /* without this, Grid stretches every card in a row to
    match the tallest one — opening one card made its row-siblings grow into
    tall empty boxes too, which read as "they all opened" */
}
.proj-grid .proj > summary { font-size: 0.85rem; padding: 15px 18px; }
.proj-grid .proj__body-inner { padding: 0 18px 18px; }

/* Takeover layout: while one compact card is open, it spans the full grid
   width and its siblings hide — instead of one card growing awkwardly next
   to 3 still-small ones. This is purely visual now: exclusivity itself
   (only one project open at a time, site-wide) is guaranteed by the shared
   `name="proyectos"` attribute on every .proj <details> — a native HTML
   accordion group, no JS. This :has() rule just gives the (necessarily
   sole) open card its full-width layout within this grid. */
.proj-grid:has(.proj[open]) .proj:not([open]) { display: none; }
.proj-grid:has(.proj[open]) .proj[open] { grid-column: 1 / -1; }
.proj-grid .proj__body p { font-size: 0.88rem; }

.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.badge {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  border: 1px solid var(--rule);
  padding: 4px 10px;
}

/* ===== Footer ===== */
.site-footer {
  padding: 32px 0;
  border-top: 1px solid var(--rule-strong);
}

.site-footer__inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.site-footer__copy {
  color: var(--text-muted);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
}

.footer__contact {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.8rem;
}
.footer__contact a { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text-muted); }
.footer__contact a:hover { color: var(--accent); }
.footer__contact noscript { color: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .about { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .nav__links { display: none; }
  .nav__burger { display: inline-flex; align-items: center; justify-content: center; }

  .nav__actions { gap: 6px; }
  .nav__icon-link, .theme-toggle, .nav__burger { width: 32px; height: 32px; }

  .nav--open .nav__links {
    display: flex;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--rule-strong);
    flex-direction: column;
    padding: 18px 24px;
    gap: 16px;
  }

  .title-block { grid-template-columns: 1fr 1fr; }

  .site-footer__inner { flex-direction: column; align-items: flex-start; }
}
