:root {
  --bg: #f4f2ed;
  --surface: #fbfaf7;
  --line: rgba(29, 31, 28, 0.1);
  --line-strong: rgba(29, 31, 28, 0.2);
  --ink: #1d1f1c;
  --ink-soft: #52564e;
  --muted: #8a8d84;
  --accent: #4a6b57;
  --accent-soft: rgba(74, 107, 87, 0.1);
  --term-bg: #20221f;
  --term-ink: #dedbd2;
  --term-dim: #8f9288;
  --term-accent: #a7c4ae;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --serif: "Fraunces", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151614;
    --surface: #1c1e1b;
    --line: rgba(233, 231, 225, 0.09);
    --line-strong: rgba(233, 231, 225, 0.18);
    --ink: #e9e7e1;
    --ink-soft: #b4b2aa;
    --muted: #7f8279;
    --accent: #9cbfa6;
    --accent-soft: rgba(156, 191, 166, 0.12);
    --term-bg: #0f100e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151614;
  --surface: #1c1e1b;
  --line: rgba(233, 231, 225, 0.09);
  --line-strong: rgba(233, 231, 225, 0.18);
  --ink: #e9e7e1;
  --ink-soft: #b4b2aa;
  --muted: #7f8279;
  --accent: #9cbfa6;
  --accent-soft: rgba(156, 191, 166, 0.12);
  --term-bg: #0f100e;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  font-family: var(--sans); background: var(--bg); color: var(--ink);
  line-height: 1.7; font-size: 16px; -webkit-font-smoothing: antialiased; overflow-x: hidden;
  transition: background-color 0.5s var(--ease), color 0.5s var(--ease);
}
h1, h2, h3 { font-weight: 500; letter-spacing: -0.01em; line-height: 1.2; }
h1, h2 { font-family: var(--serif); }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
strong { font-weight: 600; color: var(--ink); }
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 24px; }
.muted { color: var(--muted); }

/* ---------- Nav ---------- */
.nav { position: fixed; inset: 0 0 auto; z-index: 50; transition: background-color 0.4s, box-shadow 0.4s; }
.nav.scrolled { background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 1px 0 var(--line); }
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 68px; gap: 16px; }
.brand { font-family: var(--mono); font-size: 14px; font-weight: 500; letter-spacing: 0.02em; }
.nav-links { display: flex; align-items: center; gap: 2px; }
.nav-links a { padding: 6px 12px; font-size: 14.5px; color: var(--ink-soft); border-radius: 8px; transition: color 0.3s; }
.nav-links a:hover { color: var(--ink); }
.nav-links .nav-cta { color: var(--accent); font-weight: 500; }
.nav-actions { display: flex; align-items: center; gap: 6px; }

/* Selector de idioma */
.lang { position: relative; }
.lang-btn { width: auto; padding: 0 10px; gap: 6px; display: inline-flex; align-items: center; }
.lang-code { font-family: var(--mono); font-size: 12px; font-weight: 500; }
.lang-flag { display: inline-flex; }
.flag { width: 21px; height: 14px; flex: none; border-radius: 3px; box-shadow: 0 0 0 1px var(--line-strong); display: block; }
.lang-menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 150px; padding: 6px; z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.25);
  opacity: 0; transform: translateY(-4px); pointer-events: none; transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.lang.open .lang-menu { opacity: 1; transform: none; pointer-events: auto; }
.lang-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 12px; border: none; border-radius: 8px; background: none;
  font: 14px var(--sans); color: var(--ink-soft); cursor: pointer; transition: background-color 0.2s, color 0.2s;
}
.lang-menu button:hover { background: var(--accent-soft); color: var(--ink); }
.lang-menu button[aria-current="true"] { color: var(--accent); font-weight: 500; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line); background: transparent; color: var(--ink-soft); cursor: pointer; transition: color 0.3s, border-color 0.3s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.menu-btn { display: none; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; padding: 11px 22px; border-radius: 10px;
  font: 500 15px var(--sans); cursor: pointer; border: 1px solid transparent;
  transition: transform 0.4s var(--ease), background-color 0.3s, border-color 0.3s, color 0.3s;
}
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { transform: translateY(-1px); background: var(--accent); }
.btn-ghost { border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { transform: translateY(-1px); border-color: var(--ink); }

/* ---------- Hero ---------- */
.hero {
  min-height: 100vh; min-height: 100svh; display: grid; grid-template-columns: 1.15fr 1fr;
  align-items: center; gap: 56px; padding-top: 100px; padding-bottom: 60px;
}
.kicker { font-family: var(--mono); font-size: 13px; color: var(--accent); letter-spacing: 0.02em; }
.hero h1 { font-size: clamp(2.8rem, 6.5vw, 4.6rem); margin-top: 14px; font-weight: 400; letter-spacing: -0.025em; }
.hero-lead { margin-top: 22px; max-width: 520px; color: var(--ink-soft); font-size: 1.07rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 32px; }
.socials { display: flex; flex-wrap: wrap; gap: 22px; margin-top: 30px; }
.socials a { font-size: 14px; color: var(--muted); transition: color 0.3s; }
.socials a:hover { color: var(--ink); }

/* Terminal */
.term { background: var(--term-bg); color: var(--term-ink); border-radius: 14px; overflow: hidden; box-shadow: 0 30px 60px -30px rgba(20, 22, 18, 0.45); font-family: var(--mono); font-size: 13.5px; }
.term-bar { display: flex; align-items: center; gap: 7px; padding: 12px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.term-bar span { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); }
.term-bar em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--term-dim); }
.term-body { padding: 20px 22px 24px; line-height: 1.85; }
.term .prompt { color: var(--term-accent); margin-right: 6px; }
.term .out { color: var(--term-dim); margin-bottom: 8px; }
.term .conf { display: grid; grid-template-columns: max-content 1fr; column-gap: 18px; }
.term .conf dt { color: var(--term-ink); }
.term .conf dd { color: var(--term-dim); }
.term .line { opacity: 0; transform: translateY(4px); transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); }
.term.in .line { opacity: 1; transform: none; }
.term.in .line:nth-child(1) { transition-delay: 0.5s; }
.term.in .line:nth-child(2) { transition-delay: 0.9s; }
.term.in .line:nth-child(3) { transition-delay: 1.4s; }
.term.in .line:nth-child(4) { transition-delay: 1.8s; }
.term.in .line:nth-child(5) { transition-delay: 2.3s; }
.caret { display: inline-block; width: 8px; height: 15px; vertical-align: -2px; background: var(--term-accent); animation: blink 1.2s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Secciones ---------- */
.section { padding: 96px 24px; }
.section-head { margin-bottom: 44px; max-width: 640px; }
.eyebrow { display: block; font-family: var(--mono); font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.section h2 { font-size: clamp(1.9rem, 3.6vw, 2.6rem); }
.section-sub { margin-top: 12px; color: var(--ink-soft); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { padding: 4px 12px; border: 1px solid var(--line-strong); border-radius: 999px; font-size: 13.5px; color: var(--ink-soft); transition: border-color 0.3s, color 0.3s; }
.tags li:hover { border-color: var(--accent); color: var(--accent); }

/* Sobre mí */
.about-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 56px; align-items: start; }
.about-text p { color: var(--ink-soft); font-size: 1.04rem; }
.about-text p + p { margin-top: 16px; }
.skills { display: grid; gap: 24px; }
.skill-group h3 { font-family: var(--mono); font-size: 12.5px; font-weight: 400; color: var(--muted); margin-bottom: 10px; }

/* Timeline */
.timeline { border-top: 1px solid var(--line); }
.tl-item { display: grid; grid-template-columns: 200px 1fr; gap: 24px; padding: 30px 0; border-bottom: 1px solid var(--line); }
.tl-meta { font-family: var(--mono); font-size: 13px; color: var(--muted); padding-top: 3px; }
.tl-body h3 { font-size: 1.15rem; }
.tl-org { color: var(--accent); font-size: 14.5px; margin: 2px 0 10px; }
.tl-body p { color: var(--ink-soft); }
.bullets li { position: relative; padding-left: 18px; color: var(--ink-soft); }
.bullets li + li { margin-top: 4px; }
.bullets li::before { content: "–"; position: absolute; left: 0; color: var(--muted); }

/* Certificaciones */
.cert-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.cert {
  padding: 24px 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  transition: transform 0.5s var(--ease), border-color 0.4s;
}
.cert:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.cert-year { font-family: var(--mono); font-size: 12.5px; color: var(--accent); }
.cert h3 { font-size: 1.05rem; margin-top: 6px; }
.cert p { font-size: 13.5px; color: var(--muted); margin-top: 4px; }
.in-progress { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; margin-top: 28px; }
.ip-label { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }

/* Labs */
.lab-diagram { padding: 28px; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.lab-diagram svg { width: 100%; height: auto; display: block; }
.diag-narrow { display: none !important; max-width: 420px; margin: 0 auto; }
.seg rect { fill: none; stroke: var(--line-strong); stroke-width: 1; }
.seg .name { fill: var(--ink); font-family: var(--sans); font-weight: 500; font-size: 14.5px; dominant-baseline: middle; }
.seg .tag { fill: var(--muted); font-family: var(--mono); font-size: 11.5px; text-anchor: end; dominant-baseline: middle; }
.links path { fill: none; stroke: var(--line-strong); stroke-width: 1.5; }
.links.flow path { stroke: var(--accent); stroke-dasharray: 3 10; animation: flow 3.5s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -26; } }
.node rect { fill: var(--bg); stroke: var(--line-strong); stroke-width: 1; }
.node.key rect { stroke: var(--accent); stroke-width: 1.4; }
.node text, .svc text { fill: var(--ink); font-family: var(--sans); font-weight: 500; font-size: 14.5px; text-anchor: middle; dominant-baseline: middle; }
.node text.sub { fill: var(--muted); font-family: var(--mono); font-weight: 400; font-size: 11.5px; }
.svc rect { fill: var(--accent-soft); stroke: none; }
.svc text { fill: var(--accent); font-size: 13.5px; }
.zone { fill: none; stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 5 5; }
.zone-label, .group-label { fill: var(--muted); font-family: var(--mono); font-size: 11.5px; }

.lab-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.lab { padding: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; transition: transform 0.5s var(--ease), border-color 0.4s; }
.lab:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.lab-n { font-family: var(--mono); font-size: 12.5px; color: var(--accent); }
.lab h3 { font-size: 1.1rem; margin: 4px 0 8px; }
.lab p { color: var(--ink-soft); font-size: 15px; }

.github-link { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 14px; padding: 18px 26px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink-soft); transition: border-color 0.4s, color 0.3s; }
.github-link:hover { border-color: var(--line-strong); color: var(--ink); }
.github-link .arrow { color: var(--accent); transition: transform 0.5s var(--ease); }
.github-link:hover .arrow { transform: translateX(4px); }

/* Contacto */
.contact { display: grid; grid-template-columns: 1fr 1.1fr; gap: 56px; padding: 48px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.contact-info p { color: var(--ink-soft); margin-top: 14px; }
.contact-form { display: grid; gap: 16px; position: relative; }
.contact-form .botcheck { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.contact-form label { display: grid; gap: 6px; }
.contact-form label span { font-size: 13.5px; font-weight: 500; color: var(--ink-soft); }
.contact-form input, .contact-form textarea {
  font: 15px var(--sans); color: var(--ink); width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--bg); resize: vertical; transition: border-color 0.3s, box-shadow 0.3s;
}
.contact-form input:focus, .contact-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.contact-form .invalid { border-color: #b5655a; }
.contact-form .btn { justify-self: start; }
.contact-form .btn:disabled { opacity: 0.6; cursor: wait; }
.form-note { font-size: 13px; color: var(--muted); transition: color 0.3s; }
.form-note.is-success { color: var(--accent); }
.form-note.is-error { color: var(--ink); }

/* Footer */
.footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding-top: 28px; padding-bottom: 40px; border-top: 1px solid var(--line); font-size: 14px; color: var(--ink-soft); }

/* ---------- Aparición suave ---------- */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 1.1s var(--ease), transform 1.1s var(--ease); transition-delay: var(--d, 0s); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- Responsive ---------- */
/* Tablet y menor: menú desplegable */
@media (max-width: 1024px) {
  .menu-btn { display: grid; }
  .nav-links {
    position: absolute; top: 68px; left: 24px; right: 24px; flex-direction: column; align-items: stretch; gap: 0; padding: 8px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.25);
    opacity: 0; transform: translateY(-6px); pointer-events: none; transition: opacity 0.35s var(--ease), transform 0.35s var(--ease);
  }
  .nav-links.open { opacity: 1; transform: none; pointer-events: auto; }
  .nav-links a { padding: 12px; font-size: 15.5px; }
  .section { padding: 80px 24px; }
}

/* Tablet vertical */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 44px; padding-top: 120px; min-height: auto; }
  .term { max-width: 560px; }
  .about-grid, .contact { grid-template-columns: 1fr; gap: 32px; }
  .contact { padding: 36px 28px; }
  .tl-item { grid-template-columns: 160px 1fr; }
}

/* Móvil grande / tablet pequeña: esquema vertical */
@media (max-width: 720px) {
  .diag-wide { display: none !important; }
  .diag-narrow { display: block !important; }
  .lab-diagram { padding: 20px 12px; }
}

/* Móvil */
@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .nav-links { left: 16px; right: 16px; }
  .section { padding: 64px 16px; }
  .section-head { margin-bottom: 32px; }
  .hero { padding-top: 104px; gap: 36px; }
  .hero-actions .btn { flex: 1 1 auto; }
  .tl-item { grid-template-columns: 1fr; gap: 6px; padding: 24px 0; }
  .cert-grid, .lab-grid { grid-template-columns: 1fr; }
  .cert, .lab { padding: 22px; }
  .github-link { padding: 16px 20px; }
  .contact { padding: 28px 20px; border-radius: 14px; }
  .contact-form .btn { justify-self: stretch; }
  .term { font-size: 12.5px; }
  .term-body { padding: 16px 16px 20px; }
  .term .conf { column-gap: 12px; }
  .footer { padding-left: 16px; padding-right: 16px; }
}

/* Móvil pequeño */
@media (max-width: 380px) {
  .brand { font-size: 13px; }
  .nav-actions { gap: 4px; }
  .term { font-size: 11.5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
  .reveal, .term .line { opacity: 1; transform: none; }
}
