/* ============================================================
   Jaime Pericas Saez — portfolio
   "engineer's desk at night": warm ink, amber signal, plex mono
   ============================================================ */

:root {
  --ink: #0e1216;
  --ink-2: #131922;
  --panel: #161d27;
  --panel-edge: #232d3b;
  --text: #dce3ea;
  --text-dim: #8b97a5;
  --text-faint: #5b6776;
  --amber: #f0a84b;
  --amber-soft: rgba(240, 168, 75, 0.14);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", sans-serif;
  --display: "Bricolage Grotesque", sans-serif;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: dark; }

/* ---------- shared pulse clock ----------
   One animation on <body> drives every "the coin landed" glow: the coin
   label reads --pulse as its opacity and .card.resonate reads it for its
   border/shadow, so they cannot drift apart. Lit when a face lands (every
   half turn of the 5.2s coinflip), dark while edge-on — keep = coinflip / 2.
   JS phase-locks this clock to the coinflip animation on startup. */
@property --pulse {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
@keyframes pulseclock {
  0%   { --pulse: 1; }
  15%  { --pulse: 1; }
  38%  { --pulse: 0; }
  62%  { --pulse: 0; }
  85%  { --pulse: 1; }
  100% { --pulse: 1; }
}

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  animation: pulseclock 2.6s linear infinite;
}

::selection { background: var(--amber); color: var(--ink); }

a { color: inherit; }

/* ---------- atmosphere ---------- */

.grain {
  position: fixed; inset: 0; z-index: 50; pointer-events: none;
  opacity: 0.5; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0.06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.glow {
  position: fixed; z-index: 0; pointer-events: none;
  top: -30vh; left: -15vw; width: 75vw; height: 75vh;
  background: radial-gradient(ellipse at center,
    rgba(240, 168, 75, 0.07) 0%,
    rgba(86, 130, 180, 0.05) 45%,
    transparent 70%);
  filter: blur(20px);
}

body::before {
  /* faint blueprint grid */
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(140, 160, 185, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(140, 160, 185, 0.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 80% at 50% 0%, black 30%, transparent 90%);
}

/* ---------- frame ---------- */

.frame {
  position: relative; z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(16px, 2.5vh, 32px) clamp(16px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2vh, 24px);
  height: 100vh;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.identity { display: flex; align-items: center; gap: 18px; }

/* ---------- persona coin (3D, Mario-style) ---------- */

.coin3d {
  position: relative;
  flex: none;
  width: 60px; height: 60px;
  perspective: 420px;
}
.coin-label {
  position: absolute;
  top: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.13em;
  white-space: nowrap;
  color: #ffc46e;
  text-shadow: 0 0 10px rgba(240, 168, 75, 0.85), 0 0 22px rgba(240, 168, 75, 0.4);
  pointer-events: none;
  /* lit/dark in step with the coin via the shared body clock */
  opacity: var(--pulse);
}
.coin-inner {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  /* one full turn per cycle; easing lives in the keyframes */
  animation: coinflip 5.2s linear infinite;
}
/* linger at both face-on points (0deg/180deg), whip through edge-on */
@keyframes coinflip {
  0%   { transform: rotateY(0deg);   animation-timing-function: cubic-bezier(0.68, 0, 0.32, 1); }
  50%  { transform: rotateY(180deg); animation-timing-function: cubic-bezier(0.68, 0, 0.32, 1); }
  100% { transform: rotateY(360deg); }
}
.coin-face {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: contain;
  padding: 2px;
  background: var(--ink-2);
  border: 2px solid #9a7136;
  box-sizing: border-box;
  image-rendering: pixelated;
  filter: saturate(0.8) brightness(1.02);
  backface-visibility: hidden;
}
.coin-front { transform: translateZ(4.5px); }
.coin-back  { transform: rotateY(180deg) translateZ(4.5px); }
.coin-layer {
  /* thin slices stacked in Z = the coin's bronze edge */
  position: absolute; inset: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #a4763a, #6f4d20);
}

.who h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(24px, 3.2vw, 34px);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.tagline {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 5px;
  max-width: 56ch;
}
.prompt { color: var(--amber); user-select: none; }
.cursor {
  display: inline-block;
  width: 7px; height: 13px;
  margin-left: 4px;
  vertical-align: -2px;
  background: var(--amber);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.links { display: flex; gap: 8px; }
.links a {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 12.5px;
  text-decoration: none;
  color: var(--text-dim);
  padding: 8px 13px;
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  background: rgba(22, 29, 39, 0.6);
  transition: color 0.18s, border-color 0.18s, background 0.18s, transform 0.18s;
}
.links a:hover {
  color: var(--amber);
  border-color: var(--amber);
  background: var(--amber-soft);
  transform: translateY(-1px);
}

/* ---------- workbench layout ---------- */

.workbench {
  flex: 1;
  min-height: 0; /* lets children scroll instead of the page */
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 26vw, 360px);
  gap: clamp(16px, 2vw, 28px);
}

.section-label {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}
.section-label .hash { color: var(--amber); }

/* ---------- featured cards ---------- */

.featured { display: flex; flex-direction: column; min-height: 0; }

.featured-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: clamp(12px, 1.4vw, 18px);
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(170deg, var(--panel) 0%, var(--ink-2) 100%);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.2, 1), border-color 0.22s, box-shadow 0.22s;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.card:nth-child(1) { animation-delay: 0.08s; }
.card:nth-child(2) { animation-delay: 0.16s; }
.card:nth-child(3) { animation-delay: 0.24s; }
.card:nth-child(4) { animation-delay: 0.32s; }

.card:hover {
  transform: translateY(-3px);
  border-color: rgba(240, 168, 75, 0.55);
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(240, 168, 75, 0.12);
}

/* keyboard focus speaks the same amber as hover — otherwise the UA draws its
   own pale ring, which clashes with the resonate pulse */
.card:focus-visible,
.repo:focus-visible,
.links a:focus-visible {
  outline: 2px solid rgba(240, 168, 75, 0.7);
  outline-offset: 2px;
}

/* amber pulse when the coin lands on this card's theme. The fade reads
   --pulse straight off the shared body clock — the same value the coin
   label uses for its opacity — so card glow and label glow rise and fall
   together by construction; JS only swaps .resonate between cards while
   both are dark. */
.card.resonate {
  border-color: color-mix(in srgb, rgba(240, 168, 75, 0.45) calc(var(--pulse) * 100%), var(--panel-edge));
  box-shadow: 0 0 22px -6px rgba(240, 168, 75, calc(var(--pulse) * 0.35)), 0 0 0 1px rgba(240, 168, 75, calc(var(--pulse) * 0.1));
}

/* while the user is hovering a card, the automatic pulses yield to the cursor */
.featured-grid:has(.card:hover) .card.resonate {
  border-color: var(--panel-edge);
  box-shadow: none;
}
.featured-grid:has(.card:hover) .card.resonate:hover {
  border-color: rgba(240, 168, 75, 0.55);
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(240, 168, 75, 0.12);
}

.card-thumb {
  position: relative;
  flex: 1.1;
  min-height: 0;
  overflow: hidden;
  border-bottom: 1px solid var(--panel-edge);
  background:
    radial-gradient(ellipse 70% 90% at 50% 10%, rgba(140, 160, 185, 0.05), transparent 70%),
    var(--ink-2);
}
.card-thumb svg {
  display: block;
  width: 100%; height: 100%;
  transition: transform 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.card:hover .card-thumb svg { transform: scale(1.05); }
.card:hover .art-dash {
  animation: dashflow 1.2s linear infinite;
}
@keyframes dashflow { to { stroke-dashoffset: -22; } }

.card-body {
  flex: 1;
  padding: 13px 15px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.card-title .arrow {
  margin-left: auto;
  color: var(--text-faint);
  font-family: var(--sans);
  transition: transform 0.2s, color 0.2s;
}
.card:hover .card-title .arrow { transform: translate(2px, -2px); color: var(--amber); }

.card-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  margin-top: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 7px;
}
.tag {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  border: 1px solid var(--panel-edge);
  border-radius: 4px;
  padding: 2px 7px;
}
.tag.lang { color: var(--amber); border-color: rgba(240, 168, 75, 0.3); background: var(--amber-soft); }

/* ---------- rail (nested scroll) ---------- */

.rail {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) 0.2s both;
}

.rail-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--panel-edge) transparent;
}
.rail-scroll::-webkit-scrollbar { width: 6px; }
.rail-scroll::-webkit-scrollbar-thumb { background: var(--panel-edge); border-radius: 3px; }
.rail-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

.repo {
  display: block;
  text-decoration: none;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-left: 2px solid var(--panel-edge);
  border-radius: 0 8px 8px 0;
  background: rgba(22, 29, 39, 0.45);
  transition: border-color 0.16s, background 0.16s, transform 0.16s;
}
.repo:hover {
  background: var(--panel);
  border-left-color: var(--amber);
  transform: translateX(3px);
}

.repo-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
}
.lang-dot {
  flex: none;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-left: auto;
}
.repo-lang {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
}
.repo-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 3px;
  line-height: 1.4;
}

/* ---------- footer ---------- */

.baseline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  border-top: 1px solid var(--panel-edge);
  padding-top: 14px;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) 0.35s both;
}
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--text-dim); }
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #5dc97a;
  box-shadow: 0 0 0 0 rgba(93, 201, 122, 0.5);
  animation: pulse 2.2s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(93, 201, 122, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(93, 201, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(93, 201, 122, 0); }
}
.sig a { color: var(--text-dim); text-decoration: none; }
.sig a:hover { color: var(--amber); }

/* ---------- entrance ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- responsive ---------- */

@media (max-width: 940px) {
  .frame { height: auto; min-height: 100vh; }
  .workbench { grid-template-columns: 1fr; }
  .featured-grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto; }
  .card-thumb { aspect-ratio: 2 / 1; flex: none; }
  .rail-scroll { max-height: 420px; }
}

@media (max-width: 600px) {
  .featured-grid { grid-template-columns: 1fr; }
  .masthead { flex-direction: column; align-items: flex-start; }
  .tagline { max-width: none; }
}

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