/* ============================================================
   Sebastián Allende — portfolio
   Type: system sans for interface, system serif for long-form.
   Light by default, dark via system preference, overridable
   by the user through [data-theme] on :root.
   ============================================================ */

:root {
  /* Palette */
  --bg:        #ffffff;
  --surface:   #f8f9fb;
  --fg:        #101319;
  --muted:     #545b6b;
  --faint:     #687287;
  --line:      #e6e9f0;
  --line-soft: #eef0f5;
  --accent:    #2a4fc4;
  --accent-lo: #eaeffb;
  --chip:      #eef1f7;
  --ok:        #1a7f4b;
  --shadow:    0 1px 2px rgba(16,19,25,.04), 0 12px 32px -8px rgba(16,19,25,.10);
  --sel:       rgba(42,79,196,.15);

  /* Type */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Charter", "Bitstream Charter", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Spacing scale */
  --s1: 8px;  --s2: 12px; --s3: 16px; --s4: 24px;
  --s5: 32px; --s6: 48px; --s7: 64px; --s8: 88px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0c0e12;
    --surface:   #14171e;
    --fg:        #e9ebf1;
    --muted:     #a2aabb;
    --faint:     #7a8293;
    --line:      #212734;
    --line-soft: #1a1f29;
    --accent:    #82a6ff;
    --accent-lo: #171e2c;
    --chip:      #1a1f2a;
    --ok:        #4ec585;
    --shadow:    0 12px 32px -8px rgba(0,0,0,.6);
    --sel:       rgba(130,166,255,.22);
  }
}

:root[data-theme="dark"] {
  --bg:        #0c0e12;
  --surface:   #14171e;
  --fg:        #e9ebf1;
  --muted:     #a2aabb;
  --faint:     #7a8293;
  --line:      #212734;
  --line-soft: #1a1f29;
  --accent:    #82a6ff;
  --accent-lo: #171e2c;
  --chip:      #1a1f2a;
  --ok:        #4ec585;
  --shadow:    0 12px 32px -8px rgba(0,0,0,.6);
  --sel:       rgba(130,166,255,.22);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s ease, color .2s ease;
}

::selection { background: var(--sel); }
a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .proj:hover { transform: none; }
}

.skip {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
  background: var(--accent); color: #fff;
  text-decoration: none; border-radius: 6px; z-index: 30;
}
.skip:focus { width: auto; height: auto; padding: 10px 16px; clip-path: none; left: 12px; top: 12px; }

.wrap { max-width: 720px; margin: 0 auto; padding: var(--s8) var(--s4) var(--s8); }

/* ---------------- Theme toggle ---------------- */

.theme-toggle {
  position: fixed; top: 20px; right: 20px;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--muted);
  cursor: pointer; z-index: 20;
  transition: border-color .15s ease, color .15s ease;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
:root[data-theme="dark"] .theme-toggle .sun  { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .moon { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .sun  { display: none; }
}
@media (max-width: 640px) {
  .theme-toggle { top: 14px; right: 14px; width: 34px; height: 34px; }
  .wrap { padding-top: var(--s7); }
}

/* ---------------- Header ---------------- */

header { margin-bottom: var(--s7); }

.status {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 5px 13px 5px 11px;
  border-radius: 999px;
  margin-bottom: var(--s4);
}
.status .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent);
  flex: none; margin: 0;
}

h1 {
  font-size: clamp(34px, 6vw, 46px);
  line-height: 1.08;
  letter-spacing: -0.032em;
  font-weight: 700;
  margin: 0 0 var(--s3);
  text-wrap: balance;
}

.role {
  font-size: 19px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 0 6px;
  max-width: 34em;
  text-wrap: pretty;
}

.loc { font-size: 14.5px; color: var(--faint); margin: 0 0 var(--s4); }

.links { display: flex; flex-wrap: wrap; gap: 9px; }

.links a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--line); border-radius: 10px;
  color: var(--fg); text-decoration: none;
  font-size: 14.5px; font-weight: 500;
  background: var(--bg);
  transition: border-color .15s ease, color .15s ease, background .15s ease, transform .1s ease;
}
.links a:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-lo); }
.links a:active { transform: translateY(1px); }
.links a.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.links a.primary:hover { filter: brightness(1.08); color: #fff; background: var(--accent); }
.links svg { width: 15px; height: 15px; flex: none; }

/* ---------------- Sections ---------------- */

section { margin-top: var(--s7); }

h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--faint);
  font-weight: 600;
  margin: 0 0 var(--s4);
  padding: 0 0 0 14px;
  border: 0;
  border-left: 2px solid var(--accent);
  scroll-margin-top: var(--s4);
}

p { margin: 0 0 var(--s3); text-wrap: pretty; }
p:last-child { margin-bottom: 0; }

.lead {
  font-size: 18px;
  line-height: 1.62;
  letter-spacing: -0.006em;
  color: var(--fg);
}

.muted { color: var(--muted); }

/* ---------------- Experience ---------------- */

.job {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 4px var(--s4);
  padding: var(--s4) 0;
  border-bottom: 1px solid var(--line-soft);
}
.job:last-child { border-bottom: 0; padding-bottom: 0; }
.job:first-of-type { padding-top: 0; }

.when {
  color: var(--faint);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
  line-height: 1.55;
  padding-top: 4px;
}

.what h3 { margin: 0 0 3px; font-size: 16.5px; font-weight: 600; letter-spacing: -0.012em; }
.org { color: var(--muted); font-size: 14px; margin: 0 0 var(--s1); }
.what p:not(.org) { margin: 0; font-size: 15px; line-height: 1.62; color: var(--muted); }

@media (max-width: 580px) {
  .job { grid-template-columns: 1fr; gap: 3px; }
  .when { order: -1; padding-top: 0; margin-bottom: 4px; }
}

/* ---------------- Cards ---------------- */

.proj {
  display: block;
  position: relative;
  padding: var(--s3) var(--s4) var(--s3) var(--s3);
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none; color: inherit;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.proj:last-child { margin-bottom: 0; }
.proj:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.proj:active { transform: translateY(0); }

.proj-top {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 14px; margin-bottom: 5px;
}

.proj-name { font-weight: 600; font-size: 15.5px; letter-spacing: -0.012em; }
.proj:hover .proj-name { color: var(--accent); }

/* Arrow affordance */
.proj-name::after {
  content: "→";
  display: inline-block;
  margin-left: 7px;
  opacity: 0;
  transform: translateX(-3px);
  transition: opacity .15s ease, transform .15s ease;
  color: var(--accent);
}
.proj:hover .proj-name::after { opacity: 1; transform: translateX(0); }

.tag {
  font-size: 11px; font-weight: 500; letter-spacing: .02em;
  color: var(--muted); background: var(--chip);
  padding: 3px 10px; border-radius: 999px;
  white-space: nowrap; flex: none;
}

.proj p { margin: 0; font-size: 14.5px; line-height: 1.55; color: var(--muted); }

/* ---------------- Skills ---------------- */

.skill-row {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: var(--s1) var(--s4);
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.skill-row:last-child { border-bottom: 0; padding-bottom: 0; }
.skill-row:first-of-type { padding-top: 0; }

.skill-row > strong {
  font-size: 13px; font-weight: 600; color: var(--faint);
  letter-spacing: .01em; padding-top: 3px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span {
  font-size: 13px; background: var(--chip); color: var(--fg);
  padding: 4px 11px; border-radius: 7px; white-space: nowrap;
}

@media (max-width: 580px) { .skill-row { grid-template-columns: 1fr; gap: 6px; } }

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

footer {
  margin-top: var(--s8);
  padding-top: var(--s4);
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 13.5px;
  display: flex; flex-wrap: wrap;
  gap: var(--s1) var(--s4);
  justify-content: space-between;
}

/* ---------------- Articles ---------------- */

.back {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13.5px; color: var(--muted);
  text-decoration: none; margin-bottom: var(--s5);
}
.back:hover { color: var(--accent); }

article { max-width: 640px; }

article h1 {
  font-size: clamp(29px, 4.6vw, 38px);
  line-height: 1.16;
  letter-spacing: -0.028em;
  margin-bottom: var(--s2);
}

.meta {
  font-family: var(--sans);
  font-size: 13.5px; color: var(--faint);
  margin: 0 0 var(--s6);
  padding-bottom: var(--s4);
  border-bottom: 1px solid var(--line);
  line-height: 1.6;
}
.meta .dot { margin: 0 9px; opacity: .45; }

/* Long-form set in a serif — the single biggest readability upgrade */
article p, article li, blockquote {
  font-family: var(--serif);
  font-size: 18.5px;
  line-height: 1.7;
  letter-spacing: -0.003em;
}

article h2 {
  font-family: var(--sans);
  font-size: 20px;
  text-transform: none;
  letter-spacing: -0.018em;
  color: var(--fg);
  font-weight: 650;
  margin: var(--s6) 0 var(--s3);
  padding: 0; border: 0;
  scroll-margin-top: var(--s4);
  text-wrap: balance;
}

article h2 .anchor {
  opacity: 0; margin-left: 9px;
  font-weight: 400; font-size: 0.78em;
  color: var(--faint); text-decoration: none;
  transition: opacity .15s ease;
}
article h2:hover .anchor { opacity: 1; }
article h2 .anchor:focus-visible { opacity: 1; }
article h2 .anchor:hover { color: var(--accent); }

article p { margin-bottom: var(--s3); }
article ul { padding-left: 24px; margin: 0 0 var(--s3); }
article li { margin-bottom: 10px; text-wrap: pretty; }
article li::marker { color: var(--faint); }

article strong { font-weight: 700; }
article em { font-style: italic; }

article code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--chip);
  padding: 2px 6px; border-radius: 5px;
}

blockquote {
  margin: var(--s5) 0;
  padding: var(--s1) 0 var(--s1) var(--s4);
  border-left: 3px solid var(--accent);
  color: var(--fg);
  font-style: italic;
}
blockquote p { margin-bottom: 0; font-size: inherit; }

.note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: var(--s3) var(--s4);
  margin: var(--s5) 0;
}
.note p {
  font-family: var(--sans);
  font-size: 15px; line-height: 1.62;
  color: var(--muted);
  margin-bottom: 0;
}

.next-up { margin-top: var(--s7); padding-top: var(--s4); border-top: 1px solid var(--line); }
.next-up .label {
  font-size: 12px; text-transform: uppercase; letter-spacing: .13em;
  color: var(--faint); font-weight: 600; margin-bottom: var(--s2);
}

/* Article index */
.post {
  display: block; padding: var(--s4) 0;
  border-bottom: 1px solid var(--line-soft);
  text-decoration: none; color: inherit;
}
.post:last-of-type { border-bottom: 0; }
.post h3 {
  margin: 0 0 6px; font-size: 19px; font-weight: 650;
  letter-spacing: -0.018em; text-wrap: balance;
}
.post:hover h3 { color: var(--accent); }
.post p { margin: 0; font-size: 15px; line-height: 1.6; color: var(--muted); }
.post .when { margin-bottom: 6px; padding-top: 0; }

/* ---------------- Print ---------------- */

@media print {
  :root {
    --bg:#fff; --fg:#000; --muted:#333; --faint:#555;
    --line:#ccc; --line-soft:#ddd; --surface:#fff; --chip:#f2f2f2; --accent:#000;
  }
  .links, .skip, .theme-toggle, .back, .next-up, .status { display: none; }
  .wrap { max-width: none; padding: 0; }
  .proj, .job, article h2, blockquote { break-inside: avoid; }
  a { text-decoration: none; }
  article h2 .anchor, .proj-name::after { display: none; }
}

/* ---------------- Language switch ---------------- */

.lang-switch {
  position: fixed;
  top: 20px; right: 68px;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  z-index: 20;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .03em;
}

.lang-switch a {
  padding: 0 10px;
  height: 36px;
  display: flex; align-items: center;
  color: var(--faint);
  text-decoration: none;
  transition: color .15s ease, background .15s ease;
}

.lang-switch a:hover { color: var(--accent); background: var(--accent-lo); }

.lang-switch a[aria-current="true"] {
  color: var(--bg);
  background: var(--accent);
}

.lang-switch a + a { border-left: 1px solid var(--line); }

@media (max-width: 640px) {
  .lang-switch { top: 14px; right: 58px; }
  .lang-switch a { height: 32px; padding: 0 9px; font-size: 12px; }
}

@media print { .lang-switch { display: none; } }

/* ---------------- Section navigation (wide screens only) ---------------- */

.toc {
  position: fixed;
  top: 140px;
  left: calc(50% - 360px - 214px);
  width: 178px;
  z-index: 15;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

.toc.ready { opacity: 1; pointer-events: auto; }

.toc-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 600;
  color: var(--faint);
  margin-bottom: 12px;
  padding-left: 13px;
}

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

.toc a {
  display: block;
  padding: 5px 0 5px 13px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--faint);
  text-decoration: none;
  border-left: 2px solid var(--line);
  transition: color .15s ease, border-color .15s ease;
}

.toc a:hover { color: var(--fg); border-left-color: var(--muted); }

.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* Only when there is genuinely room to spare */
@media (max-width: 1279px) { .toc { display: none; } }
@media print { .toc { display: none; } }

/* ================= Motion & depth ================= */

/* Hero glow — subtle, breathing */
.wrap::before {
  content: "";
  position: fixed;
  top: -280px; left: 50%;
  width: 900px; height: 620px;
  margin-left: -450px;
  background: radial-gradient(ellipse at center,
              color-mix(in srgb, var(--accent) 13%, transparent) 0%,
              transparent 66%);
  pointer-events: none;
  z-index: -1;
  animation: breathe 14s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: .75; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.08); }
}

/* Reveal on scroll — only applied when JS is present, so no-JS keeps content visible */
.js-reveal [data-reveal] {
  opacity: 0;
  transform: translateY(14px);
}

.js-reveal [data-reveal].shown {
  opacity: 1;
  transform: none;
  transition: opacity .55s cubic-bezier(.22,.61,.36,1),
              transform .55s cubic-bezier(.22,.61,.36,1);
}

/* Stat row */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s3);
  margin: var(--s5) 0 0;
  padding: var(--s4) 0 0;
  border-top: 1px solid var(--line-soft);
}

.stat-n {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.stat-l {
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--faint);
  margin-top: 3px;
}

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, 1fr); gap: var(--s4) var(--s3); }
  .stat-n { font-size: 24px; }
}

/* Experience rows come alive on hover */
.job {
  transition: background .18s ease;
  border-radius: 8px;
  margin-left: -12px;
  padding-left: 12px;
  padding-right: 12px;
  margin-right: -12px;
}
.job:hover { background: var(--surface); }
.job:hover .when { color: var(--accent); }

/* Reading progress on articles */
.progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 40;
  transition: width .08s linear;
}

/* Section headers: the accent bar grows in */
h2 { position: relative; }

/* Chips and tags lift slightly on hover */
.chips span {
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.chips span:hover {
  background: var(--accent-lo);
  color: var(--accent);
  transform: translateY(-1px);
}

/* Contact buttons: icon nudges */
.links a svg { transition: transform .15s ease; }
.links a:hover svg { transform: translateY(-1px); }

@media (prefers-reduced-motion: reduce) {
  .wrap::before { animation: none; }
  .js-reveal [data-reveal] { opacity: 1; transform: none; }
  .progress { display: none; }
  .chips span:hover, .links a:hover svg { transform: none; }
}

@media print {
  .wrap::before, .progress { display: none; }
  .js-reveal [data-reveal] { opacity: 1; transform: none; }
}

/* Tables inside posts */
.table-wrap { overflow-x: auto; margin: var(--s4) 0; }
article table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 15px; }
article th, article td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); }
article th { font-weight: 600; color: var(--faint); font-size: 12.5px;
             text-transform: uppercase; letter-spacing: .06em; }
article pre { background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
              padding: var(--s3); overflow-x: auto; margin: var(--s4) 0; }
article pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.6; }
