/* ============================================================
   ALAM BENÍTEZ — integrated portfolio
   One scroll narrative: Hero → shared graph → Projects →
   horizontal Trayecto → converging visitor line → contact.
   Builds on styles/tokens.css.
   ============================================================ */

html { scroll-behavior: auto; }
body { background: var(--bg); overflow-x: hidden; }

/* faint engineering grid sits on the body, behind everything */
body::before {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: var(--grid) var(--grid);
}

/* ---------- top navigation (fixed) ---------- */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px clamp(20px, 4vw, 56px);
  pointer-events: none;
}
.nav > * { pointer-events: auto; }
.nav .wm { display: flex; align-items: baseline; gap: 14px; }
.nav .wm b { font-family: var(--mono); font-weight: 700; font-size: 13px; letter-spacing: 0.16em; color: var(--text); }
.nav .wm .role { display: none; }
@media (min-width: 720px) { .nav .wm .role { display: inline; } }
.nav .links { display: flex; align-items: center; gap: clamp(14px, 2vw, 30px); }
.nav .links a { transition: color .25s; }
.nav .links a:hover { color: var(--acid); }
.nav .links a.hide-sm { display: none; }
@media (min-width: 640px) { .nav .links a.hide-sm { display: inline; } }
.toggle { display: flex; gap: 2px; border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.toggle button { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; background: none; border: 0; color: var(--text-faint); padding: 4px 9px; border-radius: 999px; cursor: pointer; transition: .2s; }
.toggle button.on { background: var(--text); color: var(--bg); }

/* scroll progress hairline */
.scroll-rail { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 70; background: transparent; pointer-events: none; }
.scroll-rail i { display: block; height: 100%; width: 0; background: var(--acid); transition: width .1s linear; }

/* ============================================================
   SHARED GRAPH LAYER  — fixed, scaled by scroll
   Small + drifting in the hero, grows to centre for Projects.
   ============================================================ */
#graphLayer {
  position: fixed; inset: 0; z-index: 5;
  pointer-events: none;            /* JS turns this on when full */
  will-change: opacity;
}
#graphStage {
  position: absolute; inset: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}
svg#net { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
svg#net .link { stroke: var(--line); stroke-width: 1; fill: none; transition: stroke .2s; }
svg#net .link.hot { stroke: var(--acid); }

.node {
  position: absolute; transform: translate(-50%, -50%);
  cursor: grab; user-select: none;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: opacity .2s;
}
#graphLayer.live .node { /* labels follow --label-opacity while growing */ }
.node.drag { cursor: grabbing; }
.node .ball { border-radius: 50%; background: var(--bg-1); border: 1px solid; position: relative; transition: box-shadow .2s, transform .2s; }
.node .nm, .node .yr { transition: color .2s, opacity .35s ease; opacity: var(--label-opacity, 0); }
.node .nm { font-family: var(--mono); font-size: 10px; letter-spacing: .04em; color: var(--text-dim); white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.node.hub .nm { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--text); }
.node.hub .ball { background: transparent; }
.node:hover .nm, .node.sel .nm { color: var(--text); }
.node.faded { opacity: .16; }
.node .yr { font-family: var(--mono); font-size: 8px; color: var(--text-faint); pointer-events: none; }

/* projects header / legend / hint — fixed overlay, fades in with the graph */
.proj-ui { position: fixed; inset: 0; z-index: 20; pointer-events: none; opacity: 0; }
.proj-ui > * { pointer-events: auto; }
.proj-head { position: absolute; top: clamp(78px, 11vh, 120px); left: clamp(20px, 4vw, 56px); max-width: 440px; }
.proj-head .mono { display: block; margin-bottom: 12px; }
.proj-head h2 { margin: 0; font-family: var(--display); font-weight: 500; font-size: clamp(28px, 3.4vw, 40px); letter-spacing: -0.02em; }
.proj-head p { margin: 10px 0 0; font-size: 14px; color: var(--text-dim); line-height: 1.5; max-width: 380px; }
.legend { position: absolute; top: clamp(78px, 11vh, 120px); right: clamp(20px, 4vw, 56px); display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: flex-end; max-width: 420px; }
.legend button { display: flex; align-items: center; gap: 7px; background: none; border: 0; cursor: pointer; font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-dim); transition: .2s; padding: 3px 4px; }
.legend button .sw { width: 8px; height: 8px; border-radius: 50%; }
.legend button:hover, .legend button.active { color: var(--text); }
.legend button.dim { opacity: .35; }
.graph-hint { position: absolute; left: clamp(20px, 4vw, 56px); bottom: 34px; font-family: var(--mono); font-size: 11px; letter-spacing: .08em; color: var(--text-faint); display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.graph-hint .k { border: 1px solid var(--line); border-radius: 4px; padding: 2px 7px; color: var(--text-dim); }

/* node detail card (shared style w/ journey card) */
.detail-card {
  position: fixed; right: clamp(20px, 4vw, 56px); bottom: 84px; z-index: 40;
  width: min(380px, calc(100vw - 40px));
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 6px;
  padding: 24px; transform: translateY(10px); opacity: 0; pointer-events: none;
  transition: .25s; box-shadow: 0 24px 70px rgba(0,0,0,0.5);
}
.detail-card.show { transform: none; opacity: 1; pointer-events: auto; }
.detail-card .dk { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; color: var(--acid); text-transform: uppercase; display: flex; justify-content: space-between; gap: 12px; }
.detail-card h3 { margin: 13px 0 0; font-family: var(--display); font-weight: 500; font-size: 22px; line-height: 1.15; letter-spacing: -0.01em; }
.detail-card p { margin: 12px 0 16px; font-size: 13.5px; line-height: 1.55; color: var(--text-dim); }
.detail-card .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.detail-card .tags span { font-family: var(--mono); font-size: 10px; letter-spacing: .06em; color: var(--text-dim); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; }
.detail-card .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.btn-more { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--bg); background: var(--acid); border: 0; border-radius: 999px; padding: 9px 16px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: transform .2s, filter .2s; }
.btn-more:hover { filter: brightness(1.08); transform: translateX(2px); }
.card-close { position: absolute; top: 14px; right: 14px; width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 50%; background: none; color: var(--text-dim); cursor: pointer; font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center; transition: .2s; }
.card-close:hover { color: var(--text); border-color: var(--line-hard); }

/* ============================================================
   PAGE SECTIONS (normal flow, transparent over graph)
   ============================================================ */
section { position: relative; z-index: 10; }

/* ---------- HERO ---------- */
#hero { min-height: 100vh; display: flex; align-items: center; padding: 0 clamp(20px, 4vw, 56px); }
#hero .col { max-width: 880px; position: relative; z-index: 12; }
.kicker { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.kicker .ln { width: 46px; height: 1px; background: var(--line-hard); }
#hero h1 { margin: 0; font-family: var(--display); font-weight: 500; letter-spacing: -0.035em; line-height: 0.9; font-size: clamp(46px, 7vw, 80px); color: var(--text); }
#hero h1 .l { display: block; overflow: hidden; }
#hero h1 .dim { color: var(--text-faint); }
.cur { color: var(--acid); display: inline-block; transform: translateY(-0.06em); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
#hero .sub { margin: 26px 0 0; max-width: 540px; font-size: clamp(15px, 1.4vw, 18px); line-height: 1.5; color: var(--text-dim); }
.hero-meta { position: absolute; left: clamp(20px, 4vw, 56px); bottom: 40px; display: flex; gap: clamp(28px, 4vw, 56px); flex-wrap: wrap; z-index: 12; }
.hero-meta .cell { display: flex; flex-direction: column; gap: 7px; }
.hero-meta .k { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; color: var(--text-faint); }
.hero-meta .v { font-family: var(--mono); font-size: 13px; letter-spacing: .04em; color: var(--text); display: flex; align-items: center; gap: 9px; }
.scroll-cue { position: absolute; right: clamp(20px, 4vw, 56px); bottom: 40px; display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 12; }
.scroll-cue .mono { writing-mode: vertical-rl; letter-spacing: .2em; }
.scroll-cue .bar { width: 1px; height: 46px; background: linear-gradient(var(--line-hard), transparent); position: relative; overflow: hidden; }
.scroll-cue .bar::after { content: ''; position: absolute; left: 0; top: -50%; width: 100%; height: 50%; background: var(--acid); animation: cue 1.8s ease-in-out infinite; }
@keyframes cue { to { top: 110%; } }

/* spacer that gives the graph room to grow + stay interactive (Projects) */
#projects { height: 240vh; }

/* ============================================================
   TRAYECTO — horizontal scroll driven by vertical scroll
   ============================================================ */
#tray { position: relative; }
.tray-pin { position: sticky; top: 0; height: 100vh; overflow: hidden; background: var(--bg); }
.tray-track { position: absolute; top: 0; left: 0; height: 100vh; will-change: transform; }

/* heading rides at the front of the track */
.tray-head { position: absolute; left: 64px; top: clamp(80px, 12vh, 130px); width: 420px; }
.tray-head .mono { display: block; margin-bottom: 12px; }
.tray-head h2 { margin: 0; font-family: var(--display); font-weight: 500; font-size: clamp(34px, 4vw, 52px); letter-spacing: -0.025em; }
.tray-head p { margin: 12px 0 0; font-size: 15px; color: var(--text-dim); line-height: 1.55; max-width: 360px; }

/* main horizontal line */
.tray-line { position: absolute; left: 0; top: 50%; height: 1px; background: var(--line-hard); transform: translateY(-50%); }
.tray-line .tick { position: absolute; top: 0; width: 1px; height: 7px; background: var(--line); transform: translateY(-3px); }
.tray-line .ylab { position: absolute; top: 16px; transform: translateX(-50%); font-family: var(--mono); font-size: 10px; letter-spacing: .12em; color: var(--text-faint); }

/* markers — zero-size anchors sitting on the main line */
.mk { position: absolute; top: 50%; width: 0; height: 0; cursor: pointer; }
.mk .dot { position: absolute; left: -6.5px; top: -6.5px; width: 13px; height: 13px; border-radius: 50%; background: var(--bg); border: 1.5px solid; z-index: 2; transition: transform .2s, box-shadow .2s; }
.mk:hover .dot { transform: scale(1.4); }
.mk.active .dot { transform: scale(1.4); }
.mk .stem { position: absolute; left: -0.5px; width: 1px; background: var(--line); }
.mk.up .stem { top: -72px; height: 66px; }
.mk.dn .stem { top: 6px; height: 66px; }
.mk .cap { position: absolute; left: 0; width: 188px; text-align: center; transition: opacity .3s; }
.mk.up .cap { top: -80px; transform: translate(-50%, -100%); }
.mk.dn .cap { top: 80px; transform: translateX(-50%); }
.mk .cap .type { font-family: var(--mono); font-size: 9px; letter-spacing: .14em; text-transform: uppercase; margin-bottom: 8px; }
.mk .cap .org { font-family: var(--display); font-weight: 500; font-size: 18px; letter-spacing: -0.01em; color: var(--text); line-height: 1.12; }
.mk .cap .role { font-family: var(--mono); font-size: 10px; letter-spacing: .05em; color: var(--text-dim); margin-top: 6px; }
.mk .cap .loc { font-family: var(--mono); font-size: 9px; letter-spacing: .08em; color: var(--text-faint); margin-top: 5px; }
.mk:hover .cap .org { color: var(--acid); }
.mk .yr { position: absolute; left: 0; transform: translateX(-50%); font-family: var(--mono); font-size: 10px; letter-spacing: .1em; color: var(--text-faint); }
.mk.up .yr { top: 16px; } .mk.dn .yr { top: -16px; transform: translate(-50%, -100%); }

/* journey detail card — centered overlay */
.tray-card-scrim { position: fixed; inset: 0; z-index: 45; background: rgba(8,8,6,0.55); backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: .25s; }
.tray-card-scrim.show { opacity: 1; pointer-events: auto; }
.tray-card {
  position: fixed; z-index: 46; left: 50%; top: 50%;
  width: min(620px, calc(100vw - 40px));
  transform: translate(-50%, -48%) scale(.98); opacity: 0; pointer-events: none;
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 8px;
  padding: 30px; transition: .28s cubic-bezier(.16,1,.3,1);
  box-shadow: 0 40px 100px rgba(0,0,0,0.6);
}
.tray-card.show { transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto; }
.tray-card .dk { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; display: flex; justify-content: space-between; gap: 12px; }
.tray-card h3 { margin: 12px 0 2px; font-family: var(--display); font-weight: 500; font-size: 28px; letter-spacing: -0.02em; }
.tray-card .role2 { font-family: var(--mono); font-size: 12px; letter-spacing: .06em; color: var(--text-dim); }
.tray-card .loc2 { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; color: var(--text-faint); margin-top: 6px; display: flex; align-items: center; gap: 7px; }
.tray-card p { font-size: 14px; line-height: 1.6; color: var(--text-dim); margin: 16px 0 18px; }
.tray-card .photos { display: grid; gap: 8px; }
.tray-card .photos.n2 { grid-template-columns: 1fr 1fr; }
.tray-card .photos.n3 { grid-template-columns: 1fr 1fr 1fr; }
.tray-card image-slot { width: 100%; height: 120px; display: block; }

/* ============================================================
   VISITOR LINE + PRESENT / CTA  (end of the track)
   ============================================================ */
.endzone { position: absolute; top: 0; height: 100vh; }
.visitor-svg { position: absolute; left: 0; top: 0; height: 100vh; overflow: visible; }
.visitor-path { fill: none; stroke: var(--line-hard); stroke-width: 1.4; stroke-dasharray: 5 6; }
.visitor-path.draw { stroke-dashoffset: 0; }
.visitor-label { position: absolute; font-family: var(--mono); font-size: 11px; letter-spacing: .08em; color: var(--text-faint); width: 200px; line-height: 1.5; }

/* present node — the "now" where lines meet */
.present { position: absolute; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; }
.present .core { width: 18px; height: 18px; border-radius: 50%; background: var(--coral); box-shadow: 0 0 0 0 rgba(255,106,61,0.5); animation: pulse 2.4s ease-out infinite; }
.present .now { font-family: var(--mono); font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--coral); margin-top: 12px; }

/* CTA panel */
.cta { position: absolute; top: 50%; transform: translateY(-50%); width: 460px; }
.cta .mono { display: block; margin-bottom: 16px; }
.cta h2 { margin: 0; font-family: var(--display); font-weight: 500; font-size: clamp(34px, 4vw, 50px); line-height: 1.02; letter-spacing: -0.025em; }
.cta h2 em { font-style: normal; color: var(--acid); }
.cta p { font-size: 15px; color: var(--text-dim); line-height: 1.6; margin: 18px 0 28px; max-width: 380px; }
.cta-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.cta-actions a { display: inline-flex; align-items: center; gap: 9px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; padding: 12px 18px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); transition: .22s; }
.cta-actions a:hover { border-color: var(--acid); color: var(--acid); transform: translateY(-2px); }
.cta-actions a.primary { background: var(--acid); color: var(--bg); border-color: var(--acid); }
.cta-actions a.primary:hover { color: var(--bg); filter: brightness(1.08); }
.cta .sign { margin-top: 30px; font-family: var(--mono); font-size: 10px; letter-spacing: .14em; color: var(--text-faint); }

/* ============================================================
   MOBILE  — drop the choreography, go vertical
   ============================================================ */
.m-only { display: none; }
@media (max-width: 820px) {
  #graphLayer, .proj-ui, .scroll-cue, .visitor-svg, .tray-card-scrim, .tray-card { display: none !important; }
  #projects { height: auto; }
  #tray .tray-pin { position: static; height: auto; overflow: visible; }
  #tray .tray-track { position: static; width: 100% !important; height: auto; transform: none !important; }
  .tray-line, .endzone, .mk { display: none; }
  .m-only { display: block; }
  .desk-only { display: none !important; }
}
