/* =========================================================
   leosandoval.com — "Del terreno al código"
   La página es una hoja de mapa topográfico que se recorre
   con el scroll. Papel sepia, tinta cálida, azul marino de
   hidrografía y rojo de vértice geodésico.
   ========================================================= */
:root {
  --paper:  #F3ECDD;
  --paper-2:#EAE0CB;
  --card:   #FBF7EE;
  --ink:    #211C16;
  --grey:   #625848;
  --grey-2: #8D806B;
  --rule:   #D9CCB2;
  --navy:   #1F3A6E;
  --red:    #B23A2E;
  --land:   #E2D5BB;

  --f-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --f-sans:  "Archivo", "Helvetica Neue", Arial, sans-serif;
  --gutter: clamp(1.1rem, 3.5vw, 2.6rem);
  --frame: 14px;

  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-behavior: smooth; scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--f-serif); font-size: clamp(1.02rem, .3vw + .95rem, 1.13rem); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:hover { color: var(--red); }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 3px; }
.skip { position: absolute; left: 1rem; top: -4rem; z-index: 100; background: var(--ink); color: var(--paper); padding: .6rem 1rem; font-family: var(--f-sans); text-decoration: none; }
.skip:focus { top: calc(1rem + env(safe-area-inset-top, 0px)); }

/* ---------- Escenario fijo ---------- */
.stage { position: fixed; inset: 0; z-index: 0; overflow: hidden; }
#terrain { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.realmap-wrap {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 6vh 4vw 6vh 40vw;
  opacity: var(--map-o, 0); transform: scale(calc(.92 + var(--map-o, 0) * .08));
  pointer-events: none;
}
.realmap { width: 100%; max-height: 86vh; height: auto; overflow: visible; }
.realmap .grat { fill: none; stroke: var(--rule); stroke-width: .8; }
.realmap .land path { fill: var(--land); stroke: var(--paper); stroke-width: .8; }
.realmap .on { fill: var(--navy); stroke: var(--paper); stroke-width: .8; }
.realmap .pin path { fill: var(--paper); stroke: var(--red); stroke-width: 1.6; }
.realmap .pin circle { fill: var(--red); }
.realmap .pin text { font-family: var(--f-sans); font-weight: 650; font-size: 15px; fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; }
@media (max-width: 760px) { .realmap-wrap { padding: 20vh 4vw 50vh; } }

/* ---------- Marco de hoja ---------- */
.sheet { position: fixed; inset: 0; z-index: 2; pointer-events: none; font-family: var(--f-sans); }
.neat { position: absolute; background-color: var(--ink); }
.neat-t, .neat-b { left: var(--frame); right: var(--frame); height: 5px;
  background: repeating-linear-gradient(90deg, var(--ink) 0 48px, var(--paper) 48px 96px); border: 1px solid var(--ink); }
.neat-l, .neat-r { top: var(--frame); bottom: var(--frame); width: 5px;
  background: repeating-linear-gradient(180deg, var(--ink) 0 48px, var(--paper) 48px 96px); border: 1px solid var(--ink); }
.neat-t { top: calc(var(--frame) + env(safe-area-inset-top, 0px)); }
.neat-b { bottom: calc(var(--frame) + env(safe-area-inset-bottom, 0px)); }
.neat-l { left: var(--frame); } .neat-r { right: var(--frame); }
.coord { position: absolute; font-size: .72rem; font-weight: 600; color: var(--grey); font-feature-settings: "tnum"; background: var(--paper); padding: 0 .35rem; }
.coord-tl { top: calc(var(--frame) - 8px + env(safe-area-inset-top, 0px)); left: 18%; }
.coord-tr { top: calc(var(--frame) - 8px + env(safe-area-inset-top, 0px)); right: 18%; }
.coord-bl { bottom: calc(var(--frame) - 8px + env(safe-area-inset-bottom, 0px)); left: 18%; }
.coord-br { bottom: calc(var(--frame) - 8px + env(safe-area-inset-bottom, 0px)); right: 18%; }
.compass { position: absolute; top: calc(4.6rem + env(safe-area-inset-top, 0px)); right: calc(var(--frame) + 1.6rem); width: 54px; height: 54px; }
.compass .c-ring { fill: rgba(243, 236, 221, .8); stroke: var(--ink); stroke-width: 1; }
.compass .c-n { fill: var(--red); } .compass .c-s { fill: var(--ink); }
.compass text { font-size: 7px; font-weight: 700; fill: var(--ink); }
.altimeter {
  position: absolute; left: calc(var(--frame) + 1.6rem); bottom: calc(var(--frame) + 4.2rem + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; line-height: 1;
}
.alt-label { font-size: .75rem; font-weight: 600; color: var(--grey); margin-bottom: .3rem; }
.alt-val { font-size: clamp(2.2rem, 4vw, 3.4rem); font-weight: 800; font-stretch: 95%; letter-spacing: -.03em; color: var(--ink); font-feature-settings: "tnum"; }
.scalebar { position: absolute; left: calc(var(--frame) + 1.6rem); bottom: calc(var(--frame) + 1.6rem + env(safe-area-inset-bottom, 0px)); width: 150px; }
.sb { display: flex; height: 6px; border: 1px solid var(--ink); }
.sb i { flex: 1; } .sb i:nth-child(odd) { background: var(--ink); }
.sb-lab { display: flex; justify-content: space-between; font-size: .68rem; font-weight: 600; color: var(--grey); margin-top: .25rem; }
.sb-lab b { font-weight: 600; }
.legend { position: absolute; right: calc(var(--frame) + 1.6rem); bottom: calc(var(--frame) + 1.4rem + env(safe-area-inset-bottom, 0px));
  list-style: none; margin: 0; padding: .7rem .9rem; background: rgba(251, 247, 238, .9); border: 1px solid var(--ink);
  font-size: .75rem; font-weight: 600; color: var(--ink); display: grid; gap: .35rem; }
.legend li { display: flex; align-items: center; gap: .55rem; }
.lg { display: inline-block; width: 22px; }
.lg-v { height: 12px; background: var(--red); -webkit-mask: var(--tri) center / contain no-repeat; mask: var(--tri) center / contain no-repeat; }
.lg-r { height: 0; border-top: 2.5px dashed var(--red); }
.lg-c { height: 0; border-top: 1.5px solid var(--grey-2); }
:root { --tri: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 1 23 21H1Z' fill='none' stroke='black' stroke-width='2.6'/%3E%3Ccircle cx='12' cy='14.5' r='3'/%3E%3C/svg%3E"); }

/* ---------- Cabecera ---------- */
.top {
  position: fixed; z-index: 5; left: calc(var(--frame) + 1rem); right: calc(var(--frame) + 1rem);
  top: calc(var(--frame) + .9rem + env(safe-area-inset-top, 0px));
  display: flex; justify-content: space-between; align-items: center; pointer-events: none;
  font-family: var(--f-sans);
}
.top a { pointer-events: auto; }
.mark { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; font-weight: 700; background: rgba(243, 236, 221, .85); padding: .3rem .6rem .3rem .35rem; }
.mark svg { width: 34px; height: 31px; }
.mark .m-tri { fill: var(--paper); stroke: var(--red); stroke-width: 2.4; stroke-linejoin: round; }
.mark text { font-size: 11px; font-weight: 800; fill: var(--ink); letter-spacing: -.02em; }
.top-cta { text-decoration: none; font-weight: 700; padding: .55rem 1rem; background: var(--ink); color: var(--paper); }
.top-cta:hover { background: var(--red); color: #fff; }

/* ---------- Índice de hitos ---------- */
.rail { position: fixed; z-index: 4; right: calc(var(--frame) + 1.4rem); top: 50%; transform: translateY(-50%); font-family: var(--f-sans); }
.rail ol { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.rail a { display: flex; align-items: center; justify-content: flex-end; gap: .55rem; text-decoration: none; font-size: .78rem; font-weight: 600; color: var(--grey-2); flex-direction: row-reverse; }
.rail a span:last-child { opacity: 0; transform: translateX(6px); transition: opacity .25s, transform .25s; background: var(--paper); padding: 0 .3rem; }
.rail a:hover span:last-child, .rail a.on span:last-child { opacity: 1; transform: none; }
.rail .tri { width: 14px; height: 13px; background: var(--grey-2); -webkit-mask: var(--tri) center / contain no-repeat; mask: var(--tri) center / contain no-repeat; transition: background-color .25s, transform .25s; }
.rail a.done .tri { background: var(--ink); }
.rail a.on { color: var(--red); }
.rail a.on .tri { background: var(--red); transform: scale(1.35); }

/* ---------- Paradas (contenido) ---------- */
main { position: relative; z-index: 3; }
.stop { position: relative; min-height: 170vh; padding: 0 var(--gutter); }
.stop-hero { min-height: 140vh; }
.card {
  position: sticky; top: 22vh;
  width: min(31rem, 40vw); margin-left: calc(var(--frame) + 4.5rem);
  background: var(--card); border: 1.5px solid var(--ink);
  padding: clamp(1.4rem, 2.5vw, 2.1rem);
  box-shadow: 8px 8px 0 rgba(33, 28, 22, .12);
}
/* Esquina doblada de cuaderno de campo: la parte cortada es transparente
   y deja ver el mapa; la sombra se recorta con la misma forma */
.card {
  clip-path: polygon(0 0, calc(100% - 26px) 0, 100% 26px, calc(100% + 10px) 34px,
                     calc(100% + 10px) calc(100% + 10px), 0 calc(100% + 10px));
}
.card::before {
  content: ""; position: absolute; top: -1.5px; right: -1.5px; width: 27.5px; height: 27.5px;
  background: linear-gradient(225deg, transparent calc(50% - 1px), var(--ink) calc(50% - 1px) calc(50% + .5px), var(--rule) calc(50% + .5px));
  border-left: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink);
  box-shadow: -2px 2px 4px rgba(33, 28, 22, .12);
}
.card-year { display: flex; align-items: center; gap: .55rem; font-family: var(--f-sans); font-weight: 800; font-size: 1rem; color: var(--red); font-feature-settings: "tnum"; }
.tri { display: inline-block; width: 16px; height: 15px; background: var(--red); -webkit-mask: var(--tri) center / contain no-repeat; mask: var(--tri) center / contain no-repeat; }
.card h2 { margin-top: .6rem; font-weight: 600; font-size: clamp(1.6rem, 2.6vw, 2.25rem); line-height: 1.1; letter-spacing: -.02em; }
.card p { margin-top: .9rem; }
.card h2 + p { margin-top: 1.1rem; }
.figs { margin: 1.4rem 0 0; display: flex; flex-wrap: wrap; gap: 1rem 1.8rem; border-top: 1.5px solid var(--ink); padding-top: 1rem; }
.figs dd { margin: 0; font-family: var(--f-sans); font-weight: 800; font-size: clamp(1.9rem, 3vw, 2.6rem); line-height: 1; letter-spacing: -.03em; color: var(--navy); font-feature-settings: "tnum"; }
.figs dt { font-family: var(--f-sans); font-size: .85rem; color: var(--grey); margin-top: .3rem; }

/* Portada */
.hero-card { position: sticky; top: 0; height: 100vh; height: 100svh; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 6rem var(--gutter) 5rem; }
.hero-coords { font-family: var(--f-sans); font-size: .9rem; font-weight: 600; color: var(--grey); background: var(--paper); padding: .1rem .5rem; }
.hero-card h1 {
  margin-top: 1rem; font-weight: 600; font-size: clamp(3rem, 9vw, 7.4rem); line-height: .95; letter-spacing: -.035em;
  text-shadow: 0 0 18px var(--paper), 0 0 6px var(--paper), 0 0 2px var(--paper);
}
.hero-tag { margin-top: .9rem; font-style: italic; font-size: clamp(1.4rem, 2.8vw, 2.2rem); color: var(--red); text-shadow: 0 0 12px var(--paper), 0 0 4px var(--paper); }
.hero-sub { margin-top: 1.4rem; max-width: 40ch; font-size: clamp(1.05rem, 1.3vw, 1.2rem); background: rgba(243, 236, 221, .82); padding: .5rem .8rem; }
.hero-hint { margin-top: 2.2rem; font-family: var(--f-sans); font-size: .9rem; font-weight: 600; color: var(--grey); }
.hero-hint span { display: inline-block; margin-right: .3rem; animation: bob 1.8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(5px); } }

/* Mapa real */
.map-note { display: flex; align-items: center; gap: .55rem; font-family: var(--f-sans); font-size: .9rem; font-weight: 600; }
.map-note .dot { width: 14px; height: 14px; background: var(--navy); }

/* Contacto */
.stop-contact { min-height: 120vh; padding-bottom: 4rem; }
.card-contact { width: min(52rem, calc(100% - 2 * var(--frame) - 9rem)); display: grid; grid-template-columns: 210px 1fr; gap: 1.8rem; align-items: start; }
.portrait { margin: 0; }
.portrait img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; object-position: 50% 15%; border: 1.5px solid var(--ink); }
.contact-body h2 { margin-top: 0; }
.mail { display: inline-block; margin-top: 1.3rem; font-family: var(--f-sans); font-weight: 750; font-size: clamp(1.15rem, 2.2vw, 1.7rem); letter-spacing: -.02em; text-decoration: none; border-bottom: 2.5px solid var(--red); overflow-wrap: anywhere; }
.links { font-family: var(--f-sans); font-weight: 650; }
.creds { font-size: .9rem; color: var(--grey); border-top: 1px solid var(--rule); padding-top: .9rem; margin-top: 1.2rem !important; }
.foot { margin-top: .9rem !important; font-family: var(--f-sans); font-size: .8rem; color: var(--grey-2); }

/* ---------- Móvil ---------- */
@media (max-width: 760px) {
  :root { --frame: 8px; }
  .neat-t, .neat-b { height: 4px; background-size: auto; }
  .coord-tl, .coord-bl { left: 12%; } .coord-tr, .coord-br { right: 12%; }
  .compass { width: 40px; height: 40px; top: calc(4rem + env(safe-area-inset-top, 0px)); right: calc(var(--frame) + .8rem); }
  .legend, .scalebar, .rail { display: none; }
  .altimeter { left: auto; right: calc(var(--frame) + 1rem); bottom: auto; top: calc(7.2rem + env(safe-area-inset-top, 0px)); align-items: flex-end; }
  .alt-val { font-size: 2rem; }
  .mark span { display: none; }
  .top { left: calc(var(--frame) + .6rem); right: calc(var(--frame) + .6rem); top: calc(var(--frame) + .6rem + env(safe-area-inset-top, 0px)); }
  .stop { min-height: 165vh; padding: 0 calc(var(--frame) + .7rem); }
  .stop:not(.stop-hero) { padding-top: 62vh; }
  .card { width: 100%; margin-left: 0; position: relative; top: auto; margin-top: 0; box-shadow: 5px 5px 0 rgba(33, 28, 22, .12); }
  .card h2 { font-size: 1.5rem; }
  .card-contact { grid-template-columns: 1fr; width: 100%; max-height: none; }
  .portrait { max-width: 160px; }
}

/* Sin JS o con "reducir movimiento": contenido legible sin escenario animado */
.no-js .stage, .no-js .rail { display: none; }
.no-js .stop { min-height: auto; padding-block: 3rem; }
.no-js .card { position: relative; top: auto; margin-top: 0; }
.no-js .hero-card { position: relative; height: auto; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .hero-hint span { animation: none; }
}
@media print {
  .stage, .sheet, .rail, .top { display: none !important; }
  .stop { min-height: auto; padding: 1rem 0; }
  .card, .hero-card { position: relative; top: auto; height: auto; box-shadow: none; width: 100%; margin: 0; }
}


/* ---------- Perfil de etapa ---------- */
.stage-profile {
  position: fixed; z-index: 4; left: 50%; transform: translateX(-50%);
  top: calc(var(--frame) + .9rem + env(safe-area-inset-top, 0px));
  width: min(560px, 42vw);
  background: rgba(251, 247, 238, .92); border: 1.5px solid var(--ink);
  padding: .45rem .7rem .3rem; font-family: var(--f-sans);
  box-shadow: 4px 4px 0 rgba(33, 28, 22, .1);
  pointer-events: none;
}
.pf-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; font-size: .78rem; font-weight: 700; line-height: 1.2; }
#pfTramo { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pfGrade { font-feature-settings: "tnum"; white-space: pre; font-weight: 800; }
#profile { display: block; width: 100%; height: 74px; margin-top: .15rem; }
.no-js .stage-profile { display: none; }
@media (max-width: 760px) {
  .stage-profile { left: calc(var(--frame) + .6rem); right: calc(var(--frame) + .6rem); transform: none; width: auto; top: calc(var(--frame) + 3.6rem + env(safe-area-inset-top, 0px)); padding: .35rem .55rem .2rem; }
  #profile { height: 58px; }
  .compass { display: none; }
  .altimeter { display: none; }   /* en móvil el año ya va en el vértice y en la ficha; libera el mapa */
}
@media print { .stage-profile { display: none !important; } }
