:root {
  --bg: #0b1120;
  --bg-2: #020617;
  --card: #0f172a;
  --line: #1e293b;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --faint: #64748b;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --glow: rgba(56, 189, 248, 0.15);
  --screen: #000;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg-2: #e2e8f0;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --faint: #64748b;
  --accent: #0284c7;
  --glow: rgba(2, 132, 199, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--mono);
  background: radial-gradient(circle at 50% 0, var(--bg), var(--bg-2) 70%) fixed;
  background-color: var(--bg-2);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

html[lang="es"] .en, html[lang="en"] .es { display: none !important; }

a { color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  gap: 6px;
}
.topbar button {
  background: color-mix(in srgb, var(--card) 70%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
}
.topbar button[aria-pressed="true"] { background: var(--accent); color: var(--bg-2); }

/* ---------- hero ---------- */
.hero {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 80px 16px 40px;
}
.hero-card {
  max-width: 620px;
  width: 100%;
  padding: 48px 40px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 0 40px var(--glow);
  text-align: center;
  animation: rise 0.9s ease-out both;
}
.avatar {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid var(--accent);
  margin-bottom: 16px;
}
.hero h1 { margin: 8px 0 0; font-size: clamp(22px, 5vw, 30px); }
.hero h2 { margin: 6px 0 20px; font-weight: 400; color: var(--muted); font-size: 18px; }
.hero p { margin: 0 0 12px; }
.hero .side { color: var(--muted); font-size: 14px; }
.links { margin-top: 22px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; }
.links a { text-decoration: none; }
.links a:hover { text-decoration: underline; }

.live {
  margin-top: 26px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 var(--ok);
  animation: pulse 2s infinite;
  flex: none;
}
.scroll-hint {
  display: block;
  margin: 34px auto 0;
  width: max-content;
  color: var(--faint);
  font-size: 12px;
  text-decoration: none;
  animation: bob 2.4s ease-in-out infinite;
}

/* ---------- sections ---------- */
.intro {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 16px 10px;
  text-align: center;
}
.intro h2 { font-size: clamp(22px, 4vw, 30px); margin: 0 0 12px; }
.intro p { color: var(--muted); margin: 0; }

.group-title {
  max-width: 1100px;
  margin: 70px auto 0;
  padding: 0 16px;
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 14px;
}
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.project {
  max-width: 1100px;
  margin: 0 auto;
  padding: 50px 16px;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 44px;
  align-items: start;
}
.project.flip .visual { order: 2; }
.project + .project { border-top: 1px solid var(--line); }

.visual { display: grid; gap: 14px; min-width: 0; position: sticky; top: 70px; }

.text { min-width: 0; }
.text h3 { margin: 0 0 4px; font-size: clamp(20px, 3vw, 26px); }
.text .tagline { margin: 0 0 18px; color: var(--muted); }
.text h4 {
  margin: 18px 0 4px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.text p { margin: 0; font-family: var(--sans); font-size: 15px; }
.text ul { margin: 6px 0 0; padding-left: 18px; font-family: var(--sans); font-size: 15px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 20px; }
.chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.status {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
  border: 1px solid currentColor;
}
.status.ok { color: var(--ok); }
.status.wip { color: var(--warn); }

.frame {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 0 40px var(--glow);
}
.frame img { display: block; width: 100%; height: auto; }
.caption { font-size: 12px; color: var(--faint); text-align: center; margin: 0; }

.disclaimer {
  margin-top: 18px;
  padding: 12px 14px;
  border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  font-family: var(--sans);
  font-size: 14px;
  border-radius: 0 8px 8px 0;
}

/* ---------- 3D viewer ---------- */
.viewer {
  aspect-ratio: 4 / 3;
  cursor: grab;
  touch-action: pan-y;
}
.viewer:active { cursor: grabbing; }
.viewer canvas { display: block; width: 100% !important; height: 100% !important; }
.viewer .hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 11px;
  color: var(--faint);
  pointer-events: none;
}
.viewer .loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--faint);
  font-size: 12px;
}

.view-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: color-mix(in srgb, var(--card) 80%, transparent);
}
.view-toggle button {
  font: inherit;
  font-size: 12px;
  padding: 5px 11px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.view-toggle button[aria-pressed="true"] { background: var(--accent); color: var(--bg-2); }

/* ---------- MQTT hub ---------- */
.diagram .acl { fill: var(--card); stroke: var(--accent); stroke-width: 1.2; transition: fill 0.3s; }
.diagram .acl.allow { animation: acl-ok 0.9s ease-out; }
.diagram .acl.deny { animation: acl-no 0.9s ease-out; }
.diagram .acl-t { font-size: 10px; fill: var(--accent); font-weight: 700; }
.diagram .pkt.deny { fill: var(--bad); }
.diagram .topic { font-size: 10px; fill: var(--muted); }
@keyframes acl-ok { 0% { fill: var(--ok); } 100% { fill: var(--card); } }
@keyframes acl-no { 0% { fill: var(--bad); } 100% { fill: var(--card); } }
.mqtt-log {
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  min-height: calc(4 * 1.5em + 20px);
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.mqtt-log .ok { color: var(--ok); }
.mqtt-log .no { color: var(--bad); }

/* ---------- TCDB ---------- */
.tcdb { padding: 12px 14px 14px; font-size: 12px; }
.tcdb-head { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: 8px; }
.tcdb-round { color: var(--accent); font-weight: 700; }
.tcdb-cols { display: flex; gap: 0; }
.tcdb-cols span { width: 34px; text-align: right; }
.tcdb-table { list-style: none; margin: 0; padding: 0; position: relative; }
.tcdb-table li {
  position: absolute; left: 0; right: 0; height: 22px;
  display: grid; grid-template-columns: 22px 92px 1fr 34px 34px 34px; align-items: center; gap: 0 6px;
  transition: transform 0.7s ease;
}
.tcdb-table .pos { color: var(--faint); text-align: right; }
.tcdb-table .team { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcdb-table .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.tcdb-table .bar i { display: block; height: 100%; background: var(--accent); opacity: 0.55; transition: width 0.7s ease; }
.tcdb-table .n { text-align: right; color: var(--muted); }
.tcdb-table .pts { color: var(--text); font-weight: 700; }
.tcdb-table li.lead .team { color: var(--accent); font-weight: 700; }

/* ---------- invoicer ---------- */
.invoicer { display: grid; grid-template-columns: 1fr 1fr; font-size: 12px; }
.inv-title { font-size: 11px; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); }
.inv-sheet { border-right: 1px solid var(--line); }
.inv-sheet table { width: 100%; border-collapse: collapse; }
.inv-sheet th, .inv-sheet td { padding: 4px 8px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.inv-sheet th { color: var(--faint); font-weight: 400; }
.inv-sheet tr.cur td { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.inv-sheet tr.ok td { color: var(--ok); }
.inv-portal { padding-bottom: 10px; }
.inv-portal label { display: grid; gap: 2px; padding: 6px 12px 0; color: var(--faint); font-size: 11px; }
.inv-portal label b { font-weight: 400; color: var(--text); font-size: 12px; min-height: 24px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 5px; }
.inv-btn { margin: 10px 12px 0; text-align: center; padding: 7px; border-radius: 6px; background: var(--line); color: var(--muted); transition: background 0.15s, color 0.15s; }
.inv-btn.press { background: var(--accent); color: var(--bg-2); }
.inv-done { margin: 8px 12px 0; color: var(--ok); min-height: 18px; opacity: 0; transition: opacity 0.3s; }
.inv-done.show { opacity: 1; }
.inv-foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-top: 1px solid var(--line); color: var(--muted); }
.inv-bar { flex: 1; height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; }
.inv-bar i { display: block; height: 100%; width: 0; background: var(--warn); transition: width 0.4s; }

/* ---------- NanyCam ---------- */
.nanycam { display: grid; grid-template-columns: 1.4fr 1fr; }
.nc-scene { width: 100%; height: auto; display: block; }
.nc-side { padding: 12px; font-size: 12px; display: grid; align-content: space-between; gap: 10px; }
.nc-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.nc-steps li { padding: 5px 8px; border-radius: 6px; color: var(--faint); border: 1px solid transparent; display: flex; justify-content: space-between; transition: all 0.2s; }
.nc-steps li small { color: var(--faint); }
.nc-steps li.on { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.nc-msg { padding: 8px 10px; border-radius: 10px 10px 10px 2px; background: color-mix(in srgb, var(--accent) 18%, var(--card)); opacity: 0; transform: translateY(6px); transition: all 0.3s; display: grid; gap: 2px; }
.nc-msg.show { opacity: 1; transform: none; }
.nc-msg b { color: var(--accent); font-size: 11px; }
@media (max-width: 820px) {
  .invoicer, .nanycam { grid-template-columns: 1fr; }
  .inv-sheet { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ---------- radar ---------- */
.radar-wrap {
  display: grid;
  grid-template-columns: 1fr 150px;
  background: #020a05;
  color: #4ade80;
  font-size: 12px;
}
.radar-wrap canvas { width: 100%; aspect-ratio: 1; display: block; }
.radar-list { padding: 12px; border-left: 1px solid #14532d; }
.radar-list b { display: block; color: #86efac; margin-bottom: 8px; }
.radar-list div { margin-bottom: 8px; line-height: 1.25; }
.radar-list span { color: #16a34a; }

/* ---------- reloj peronista screen ---------- */
.lcd {
  aspect-ratio: 3 / 2;
  background: var(--screen);
  color: #f2f2ee;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  display: grid;
  grid-template-rows: 1.55fr auto auto auto;
  padding: 3% 4.5%;
  container-type: inline-size;
}
.lcd .time { font-size: 30cqw; font-weight: 200; line-height: 1; text-align: center; letter-spacing: -0.02em; align-self: center; }
.lcd .colon { color: #f5c400; animation: blink 1s steps(1) infinite; }
.lcd .row { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #333; padding: 2.2cqw 0; font-size: 4.4cqw; }
.lcd .row:last-child { border: 0; }
.lcd .alarm { color: #888; }
.lcd .alarm i { color: #f5c400; font-style: normal; }
.lcd .wx { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.lcd .wx b { display: block; font-weight: 300; font-size: 9cqw; line-height: 1.1; }
.lcd .wx small { color: #888; font-size: 3.4cqw; }
.lcd .fc { color: #888; }
.lcd .fc em { color: #f2f2ee; font-style: normal; }
.lcd .efem { overflow: hidden; white-space: nowrap; color: #7dd3fc; font-size: 4cqw; }
.lcd .efem span { display: inline-block; padding-left: 100%; animation: marquee 18s linear infinite; }

/* ---------- AB1 dial ---------- */
.ab1 { display: grid; place-items: center; padding: 30px; background: radial-gradient(circle, #1c1c1c, #0a0a0a); }
.ab1 svg { width: min(100%, 340px); height: auto; }

/* ---------- spectrum ---------- */
.spectrum { background: #000; padding: 12px; font-size: 12px; color: #ddd; }
.spectrum .banner {
  text-align: center;
  font-weight: 700;
  font-size: 22px;
  padding: 6px;
  border-radius: 6px;
  background: #15803d;
  color: #fff;
  transition: background 0.2s;
}
.spectrum.jammed .banner { background: #b91c1c; }
.spectrum .stats { display: flex; justify-content: space-between; margin: 8px 2px; color: #aaa; }
.spectrum canvas { width: 100%; height: 170px; display: block; }
.spectrum .axis { display: flex; justify-content: space-between; color: #666; font-size: 10px; }
.jam-toggle {
  justify-self: center;
  font: inherit;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--warn);
  background: transparent;
  color: var(--warn);
  cursor: pointer;
}
.jam-toggle[aria-pressed="true"] { background: var(--warn); color: #000; }

/* ---------- traffic light ---------- */
.netmon-visual { position: relative; }
.traffic {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  gap: 6px;
  padding: 8px;
  background: #111;
  border-radius: 10px;
  border: 1px solid #333;
}
.traffic i { width: 16px; height: 16px; border-radius: 50%; background: #333; transition: background 0.3s, box-shadow 0.3s; }
.traffic i.on.g { background: var(--ok); box-shadow: 0 0 12px var(--ok); }
.traffic i.on.y { background: var(--warn); box-shadow: 0 0 12px var(--warn); }
.traffic i.on.r { background: var(--bad); box-shadow: 0 0 12px var(--bad); }

/* ---------- network diagram ---------- */
.diagram svg { width: 100%; height: auto; display: block; }
.diagram text { font-family: var(--mono); font-size: 11px; fill: var(--text); }
.diagram .sub { fill: var(--faint); font-size: 9.5px; }
.diagram .box { fill: var(--card); stroke: var(--line); stroke-width: 1.2; }
.diagram .box.hl { stroke: var(--accent); }
.diagram .wire { fill: none; stroke: var(--line); stroke-width: 1.4; }
.diagram .pkt { fill: var(--accent); }
.diagram .pkt.mqtt { fill: var(--ok); }

.timeline { list-style: none; padding: 0; margin: 8px 0 0; font-family: var(--sans); font-size: 14px; }
.timeline li { position: relative; padding: 0 0 12px 22px; border-left: 1px solid var(--line); margin-left: 5px; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline b { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 400; display: block; }

.closing { text-align: center; padding: 60px 16px 80px; color: var(--muted); font-size: 14px; }

/* ---------- motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes bob { 50% { transform: translateY(6px); } }
@keyframes blink { 50% { opacity: 0.15; } }
@keyframes marquee { to { transform: translateX(-100%); } }

.reveal { opacity: 0; transform: translateY(30px); transition: opacity 0.8s ease, transform 0.8s ease; }
.reveal.in { opacity: 1; transform: none; }

@supports (animation-timeline: view()) {
  .reveal, .reveal.in {
    opacity: 1;
    transform: none;
    transition: none;
    animation: rise linear both;
    animation-timeline: view();
    animation-range: entry 0% cover 28%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
}

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .project { grid-template-columns: 1fr; gap: 26px; padding: 40px 16px; }
  .project.flip .visual { order: 0; }
  .visual { position: static; }
  .hero-card { padding: 40px 22px; }
  .radar-wrap { grid-template-columns: 1fr; }
  .radar-list { border-left: 0; border-top: 1px solid #14532d; display: flex; flex-wrap: wrap; gap: 4px 16px; }
  .radar-list b { width: 100%; margin: 0; }
}

/* ---------- share ---------- */
.share { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 18px; font-size: 13px; }
.share-btn {
  font: inherit;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}
.share-btn.done { background: var(--accent); color: var(--bg-2); }
.share a { text-decoration: none; }
.share-link { color: var(--faint); }

/* ---------- single project page ---------- */
.page-head { max-width: 1100px; margin: 0 auto; padding: 22px 16px 0; }
.back { text-decoration: none; font-size: 14px; }
.single .project { padding-top: 60px; }
.more { max-width: 1100px; margin: 0 auto; padding: 30px 16px 80px; border-top: 1px solid var(--line); }
.more h2 { font-size: 13px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); margin: 0 0 14px; }
.more-list { display: flex; flex-wrap: wrap; gap: 8px; }
.more-list a {
  text-decoration: none;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
}
.more-list a:hover { border-color: var(--accent); }

/* ---------- link preview card (rendered to og/<slug>.png) ---------- */
body.og { width: 1200px; height: 630px; overflow: hidden; background: radial-gradient(circle at 20% 0, #0f1d3a, #020617 75%); }
.og-card { display: grid; grid-template-columns: 470px 1fr; gap: 40px; align-items: center; height: 630px; padding: 50px 56px; }
.og-site { color: var(--accent); font-size: 20px; letter-spacing: 0.04em; }
.og-text h1 { font-size: 54px; line-height: 1.1; margin: 18px 0 18px; }
.og-text p { font-family: var(--sans); font-size: 25px; line-height: 1.4; color: var(--muted); margin: 0; }
.og-by { margin-top: 34px; color: var(--faint); font-size: 18px; }
.og-visual { position: static; max-height: 530px; overflow: hidden; }
.og-visual > :not(:first-child) { display: none; }
.og-visual .viewer { aspect-ratio: 1 / 1; }
.og-visual .view-toggle, .og-visual .hint, .og .topbar { display: none; }
.og-visual .radar-wrap { grid-template-columns: 1fr 150px; }

/* ---------- hardware & integration ---------- */
details.hw { margin-top: 18px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
details.hw summary { cursor: pointer; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; list-style: none; }
details.hw summary::-webkit-details-marker { display: none; }
details.hw summary::before { content: "▸ "; color: var(--accent); }
details.hw[open] summary::before { content: "▾ "; }
details.hw summary b { color: var(--accent); font-weight: 600; margin-right: 6px; }
details.hw[open] summary { white-space: normal; }
details.hw ul { list-style: none; padding: 0; margin: 8px 0 2px; font-family: var(--sans); font-size: 14px; }
details.hw li { padding: 4px 0; border-top: 1px dashed var(--line); }
details.hw li b { font-family: var(--mono); font-weight: 600; font-size: 12.5px; }
.chips.integ { margin-top: 8px; }
.chip.link { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); text-decoration: none; }
.chip.link::before { content: "↔ "; }
.chip.link:hover { border-color: var(--accent); }
.chip.ext::before { content: "☁ "; }
