/* ==========================================================================
   PORTFOLIO — julian melchior
   Direction: Persona 5 menus x PS2/Y2K. Strict palette, single diagonal
   angle rule (45deg, dx = dy on every cut, always the bottom-right corner),
   max two simultaneous textures (scanlines + grain), sharp/staggered
   motion, invisible 12-col grid. Nothing is uppercase except the name.
   ========================================================================== */

/* --- Reset --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
ul { list-style: none; }

/* --- Tokens ---------------------------------------------------------------
   Palette is locked to three values only: black, white, phosphor green.
   Everything else derives from opacity of these three. */
:root {
  --black: #000000;
  --white: #ffffff;
  --green: #00ff41;
  --green-dim: rgba(0, 255, 65, 0.35);
  --green-faint: rgba(0, 255, 65, 0.12);
  --white-dim: rgba(255, 255, 255, 0.6);
  --white-faint: rgba(255, 255, 255, 0.08);
  --black-dim: rgba(0, 0, 0, 0.6);

  /* Three fixed roles, never mixed: Tosca Zero on the name/titles only,
     a terminal-style monospace on buttons/menu/labels, a neutral body
     face for the copy that's actually meant to be read. */
  --font-display: "Tosca Zero", "Arial Narrow", sans-serif;
  --font-stretch: "Stretch Pro", "Arial Narrow", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Code", "Fira Code", Consolas, "Liberation Mono", Menlo, monospace;
  --font-body: "Open Sans", ui-sans-serif, system-ui, sans-serif;

  /* Hidden angle rule: every diagonal cut uses dx = dy (45deg) on the
     bottom-right corner only — one shape, reused everywhere, only the
     magnitude changes between sm / default / lg. */
  --cut-sm: clamp(10px, 1.4vw, 16px);
  --cut: clamp(16px, 2.2vw, 26px);
  --cut-lg: clamp(28px, 4.5vw, 56px);
  --slice-sm: polygon(0 0, 100% 0, 100% calc(100% - var(--cut-sm)), calc(100% - var(--cut-sm)) 100%, 0 100%);
  --slice: polygon(0 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%);
  --slice-lg: polygon(0 0, 100% 0, 100% calc(100% - var(--cut-lg)), calc(100% - var(--cut-lg)) 100%, 0 100%);

  --dur-fast: 140ms;
  --dur-med: 220ms;
  --ease-sharp: cubic-bezier(.4, 0, .2, 1);

  --gap: clamp(12px, 2vw, 24px);
  --edge: clamp(16px, 4vw, 48px);

  color-scheme: dark;
}

/* --- Fonts ----------------------------------------------------------------*/
@font-face {
  font-family: "Tosca Zero";
  src: url("../fonts/ToscaZero-gyA4.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Open Sans";
  src: url("../fonts/OpenSans-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Stretch Pro";
  src: url("../fonts/StretchPro.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* --- Base -------------------------------------------------------------- */
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--black);
  color: var(--white);
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.5;
  position: relative;
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 0.92;
}

/* The one exception to "nothing uppercase": the name itself. */
.brand { text-transform: uppercase; }

/* Copy that's actually meant to be read gets the neutral body face;
   everything else (labels, tags, nav, buttons) stays terminal-mono. */
.hero__sub, .p-intro p, .card p, .case__body p, .case__body li {
  font-family: var(--font-body);
  font-weight: 600;
}

::selection { background: var(--green); color: var(--black); }

/* Focus states must survive the chaotic layout: high-contrast, consistent. */
:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
}
a:focus:not(:focus-visible),
button:focus:not(:focus-visible) { outline: none; }

.skip-link {
  position: fixed;
  top: -100%;
  left: var(--edge);
  z-index: 1000;
  background: var(--green);
  color: var(--black);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 10px 16px;
  transition: top var(--dur-fast) var(--ease-sharp);
}
.skip-link:focus { top: var(--edge); }

/* --- Texture layers (2 max: scanlines + grain) --------------------------- */
.texture {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
}
.texture--scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.035) 0px,
    rgba(255, 255, 255, 0.035) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}
.texture--grain {
  opacity: 0.5;
  mix-blend-mode: overlay;
}
.texture--grain svg { width: 100%; height: 100%; }

@media (prefers-reduced-motion: no-preference) {
  .texture--scanlines { animation: scan-drift 9s linear infinite; }
}
@keyframes scan-drift {
  from { background-position: 0 0; }
  to { background-position: 0 120px; }
}

/* --- Page transitions: native View Transitions API -------------------
   The browser owns the timing here — perfectly synced to the real
   navigation, no hand-rolled JS delay to keep in sync with page load.
   We only supply a direction: every destination has a fixed spot in an
   implied larger space (home = left, projects = right, a project's own
   page = further right, contact = bottom), so moving between them always
   slides the matching way — the site reads as one continuous surface,
   not a series of separate loads. Direction is written to sessionStorage
   by the click handler in main.js and read by a blocking <head> script
   (includes/header.php) before first paint; the arriving page's CSS
   controls the whole transition, old snapshot and new page alike, which
   is what makes this reliable. No direction set (a fresh arrival, or
   browser back/forward) just falls back to the default crossfade. */
@view-transition {
  navigation: auto;
}

::view-transition-group(root) {
  animation-duration: 0.45s;
}
::view-transition-old(root),
::view-transition-new(root) {
  animation-timing-function: var(--ease-sharp);
}

@keyframes vt-out-left { to { transform: translateX(-18%); opacity: 0; } }
@keyframes vt-in-left { from { transform: translateX(18%); opacity: 0; } }
@keyframes vt-out-right { to { transform: translateX(18%); opacity: 0; } }
@keyframes vt-in-right { from { transform: translateX(-18%); opacity: 0; } }
@keyframes vt-out-bottom { to { transform: translateY(-18%); opacity: 0; } }
@keyframes vt-in-bottom { from { transform: translateY(18%); opacity: 0; } }
@keyframes vt-out-top { to { transform: translateY(18%); opacity: 0; } }
@keyframes vt-in-top { from { transform: translateY(-18%); opacity: 0; } }

html[data-vt-dir="left"]::view-transition-old(root) { animation: 0.45s var(--ease-sharp) both vt-out-left; }
html[data-vt-dir="left"]::view-transition-new(root) { animation: 0.45s var(--ease-sharp) both vt-in-left; }
html[data-vt-dir="right"]::view-transition-old(root) { animation: 0.45s var(--ease-sharp) both vt-out-right; }
html[data-vt-dir="right"]::view-transition-new(root) { animation: 0.45s var(--ease-sharp) both vt-in-right; }
html[data-vt-dir="bottom"]::view-transition-old(root) { animation: 0.45s var(--ease-sharp) both vt-out-bottom; }
html[data-vt-dir="bottom"]::view-transition-new(root) { animation: 0.45s var(--ease-sharp) both vt-in-bottom; }
html[data-vt-dir="top"]::view-transition-old(root) { animation: 0.45s var(--ease-sharp) both vt-out-top; }
html[data-vt-dir="top"]::view-transition-new(root) { animation: 0.45s var(--ease-sharp) both vt-in-top; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(root),
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none !important;
  }
}

/* --- Layout: invisible 12-col grid -----------------------------------------
   The whole page is exactly one viewport tall, no exceptions: everything
   must read on arrival, nothing scrolls. #main takes the flexible row,
   the footer pins to the bottom; any section with more content than fits
   (e.g. a long project list) scrolls inside its own box, never the page. */
.page {
  height: 100dvh;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: 1fr auto;
  gap: var(--gap);
  padding: var(--edge);
  position: relative;
  z-index: 1;
  overflow: hidden;
}
#main {
  grid-column: 1 / -1;
  grid-row: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}


/* --- Corner nav: home / projects / contact pinned to three corners of the
   viewport, always visible regardless of scroll — this IS the fixed anchor
   point the brief requires, so the visitor is never lost in the scattered
   layout without needing a separate logo badge. No border, no box: plain
   text, and only the current page gets a solid flag (the one slice shape,
   same rule as everywhere else). --------------------------------------- */
.corner-nav {
  position: fixed;
  z-index: 900;
  font-family: var(--font-stretch);
  font-size: clamp(14px, 1.6vw, 17px);
  letter-spacing: 0.02em;
  padding: 6px 10px;
  color: var(--white);
  transition: color var(--dur-fast) var(--ease-sharp), background var(--dur-fast) var(--ease-sharp);
}
.corner-nav:hover, .corner-nav:focus-visible { color: var(--green); }
.corner-nav[aria-current="page"] {
  color: var(--green);
  outline: none;
}
.corner-nav[aria-current="page"]::after {
  content: "";
  display: block;
  margin-top: 3px;
  width: 14px;
  height: 2px;
  background: var(--green);
}
.corner-nav[aria-current="page"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--green);
}
.corner-nav--home { top: var(--edge); left: var(--edge); }
.corner-nav--contact { bottom: var(--edge); right: var(--edge); }
.corner-nav--projects { top: var(--edge); right: var(--edge); }

/* --- Diagonal tile primitive ----------------------------------------------
   No boxed-in border: an open top+left bracket instead of a closed frame,
   one sliced corner (the hidden angle rule), a bare fill. */
.tile {
  position: relative;
  border-top: 3px solid var(--white);
  border-left: 3px solid var(--white);
  padding: clamp(18px, 3vw, 32px);
  clip-path: var(--slice);
  background: rgba(255, 255, 255, 0.025);
  transition: border-color var(--dur-fast) var(--ease-sharp), background var(--dur-fast) var(--ease-sharp);
}
.tile:hover, .tile:focus-within { border-color: var(--green); background: var(--green-faint); }
.tile--green {
  border-color: var(--green);
  background: var(--green-faint);
}

/* --- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px;
  font-family: var(--font-stretch);
  font-size: 20px;
  letter-spacing: 0.02em;
  background: none;
  color: var(--green);
  outline: none;
  border-bottom: 2px solid var(--green);
  transition: color var(--dur-fast) var(--ease-sharp), transform var(--dur-fast) var(--ease-sharp), gap var(--dur-fast) var(--ease-sharp);
}
.btn:hover, .btn:focus-visible { color: var(--white); border-color: var(--white); gap: 16px; }
.btn:focus-visible { box-shadow: 0 0 0 2px var(--green); }

/* --- 3D letter flip (home CTA only) ----------------------------------
   Each letter is a box that rotates back and up on hover, revealing a
   duplicate (already white) coming up from underneath — one rotation
   per box does both halves of the flip via 3D transform composition,
   no separate in/out animations to keep in sync. */
[data-flip] { perspective: 500px; gap: 0; }
[data-flip]:hover, [data-flip]:focus-visible { gap: 0; }
.flip-box {
  display: inline-block;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s var(--ease-sharp);
  transition-delay: calc(var(--i, 0) * 32ms);
}
.flip-box > span {
  display: inline-block;
  transform: translateZ(0.5em);
  backface-visibility: hidden;
  color: var(--green);
}
.flip-box::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  transform: rotateX(90deg) translateZ(0.5em);
  backface-visibility: hidden;
  color: var(--white);
}
[data-flip]:hover .flip-box,
[data-flip]:focus-visible .flip-box { transform: rotateX(-90deg); }
@media (prefers-reduced-motion: reduce) {
  .flip-box, .flip-box > span, .flip-box::before { transition: none; }
}
.btn--ghost {
  background: transparent;
  color: var(--green);
  border-top: 2px solid var(--green);
  border-left: 2px solid var(--green);
}
.btn--ghost:hover, .btn--ghost:focus-visible { background: var(--green); color: var(--black); }

/* --- Eyebrow / labels ---------------------------------------------------- */
.eyebrow {
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--green);
}
.eyebrow::before { content: "// "; opacity: 0.7; }

/* --- Blinking cursor: the one bit of copy on the home page gets to move. */
.cursor { color: var(--green); }
@media (prefers-reduced-motion: no-preference) {
  .cursor { animation: blink 1s steps(2, jump-none) infinite; }
}
@keyframes blink { 50% { opacity: 0.2; } }

/* --- Reveal-on-load ---------------------------------------------------
   Entrance motion is driven entirely by GSAP (assets/js/main.js) so each
   content family gets its own distinct animation instead of one reused
   everywhere. Content is visible by default here on purpose: if GSAP
   fails to load, nothing is ever stuck hidden waiting on a script — the
   animation is cosmetic, never a gate content waits behind. */
.letter { display: inline-block; }

/* --- Footer ---------------------------------------------------------------*/
.foot {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--gap);
  padding-top: clamp(12px, 2vw, 20px);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--white-dim);
}

/* ==========================================================================
   HOME
   ========================================================================== */
.hero {
  flex: 1;
  min-height: 0;
  padding-top: clamp(24px, 4vw, 48px);
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
  align-content: center;
  position: relative;
}
.hero__title {
  grid-column: 1 / span 10;
  font-size: clamp(48px, 11vw, 148px);
  margin-top: 18px;
}
.hero__sub {
  grid-column: 2 / span 8;
  margin-top: 22px;
  font-size: 15px;
  color: var(--white-dim);
}
.hero__cta {
  grid-column: 2 / span 4;
  margin-top: 32px;
}

/* ==========================================================================
   PROJECTS
   ========================================================================== */
.p-intro {
  flex: 0 0 auto;
  padding-top: clamp(28px, 5vw, 56px);
  max-width: 58%;
}
.p-intro p { color: var(--white-dim); max-width: 56ch; }

/* Scrolls internally if the list (managed from /admin) outgrows the
   viewport — the page itself never does. Plain rows, not cards: a
   marker, the title, one tag, the year — nothing else. */
.proj-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin-top: clamp(20px, 4vw, 36px);
  border-top: 1px solid var(--white-faint);
}
.proj-list--top { margin-top: clamp(64px, 11vw, 120px); }
.proj-row {
  display: flex;
  align-items: center;
  gap: clamp(12px, 3vw, 28px);
  padding: clamp(14px, 2.4vw, 20px) 2px;
  border-bottom: 1px solid var(--white-faint);
  transition: border-color var(--dur-fast) var(--ease-sharp), padding-left var(--dur-fast) var(--ease-sharp), color var(--dur-fast) var(--ease-sharp);
}
.proj-row:hover, .proj-row:focus-visible { border-color: var(--green); padding-left: 10px; }
.proj-row__title {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: clamp(16px, 2vw, 21px);
  flex: 1 1 auto;
  min-width: 0;
}
.proj-row__tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--green);
  white-space: nowrap;
}
.proj-row__year {
  font-family: var(--font-stretch);
  font-size: 14px;
  color: var(--white-dim);
  white-space: nowrap;
}

/* Floating cursor-following preview (hover.fr-style), shown only for rows
   with a cover image. Follows the pointer via GSAP quickTo in main.js. */
.row-preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1200;
  width: 220px;
  aspect-ratio: 4 / 3;
  pointer-events: none;
  opacity: 0;
  border: 2px solid var(--green);
  /* Centering + follow transforms are set entirely by GSAP (main.js) so
     x/y/xPercent/yPercent/scale compose correctly — mixing GSAP tweens
     with a CSS percentage transform here would fight over the matrix. */
}
.row-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* --- Project detail page ------------------------------------------------
   Same rule as every other page: fits the viewport, no page scroll. A
   long case study scrolls inside its own box instead — content should
   still be written to mostly fit without needing that. */
.project {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: clamp(24px, 4vw, 48px);
  max-width: 72ch;
}
.project__meta { flex: 0 0 auto; display: flex; gap: 14px; font-size: 12px; color: var(--green); }
.project__meta span:not(:last-child)::after { content: " \00b7"; margin-left: 14px; color: var(--white-dim); }
.project h1 {
  flex: 0 0 auto;
  font-family: var(--font-body);
  font-weight: 600;
  letter-spacing: normal;
  font-size: clamp(24px, 4vw, 42px);
  margin-top: 6px;
}
.project__desc { flex: 0 0 auto; margin-top: 10px; color: var(--white-dim); font-size: 15px; }
.project__link { flex: 0 0 auto; margin-top: 14px; }

/* Compact horizontal strip so a gallery never competes with the case
   study for the page's fixed height — it scrolls sideways on its own
   if there are more thumbnails than fit. */
.project__gallery {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  margin-top: 18px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.gallery-thumb {
  flex: 0 0 auto;
  width: 120px;
  height: 90px;
  border: 1px solid var(--white-faint);
  padding: 0;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-sharp);
}
.gallery-thumb:hover, .gallery-thumb:focus-visible { border-color: var(--green); }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 4000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  opacity: 0;
  visibility: hidden;
}
.lightbox.is-open { visibility: visible; }
.lightbox img { max-width: 100%; max-height: 100%; border: 2px solid var(--green); }

.project__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin-top: 20px;
  padding-right: 10px;
  font-size: 13px;
}
.project__back { flex: 0 0 auto; margin-top: 14px; }
.project__back a { color: var(--green); font-family: var(--font-mono); font-size: 13px; }
.project__back a:hover { color: var(--white); }

.case__body h3 { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.04em; color: var(--white); margin-top: 20px; margin-bottom: 6px; }
.case__body h3:first-child { margin-top: 0; }
.case__body ul { margin-top: 6px; }
.case__body li { padding-left: 14px; position: relative; margin-top: 6px; }
.case__body li::before { content: "›"; position: absolute; left: 0; color: var(--green); }
.case__body code { font-family: var(--font-mono); font-size: 0.9em; color: var(--green); }

/* ==========================================================================
   CONTACT
   ========================================================================== */
.contact {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-content: center;
  padding-top: clamp(56px, 10vw, 96px);
  overflow: hidden;
}
.contact__list {
  grid-column: 8 / span 5;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.contact__list--solo { grid-column: 3 / span 8; gap: 22px; }

.contact__row {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 0;
  border-bottom: 1px solid var(--white-faint);
  font-size: 14px;
}
.contact__list--solo .contact__row { padding: 20px 0; }
.contact__row a {
  font-family: var(--font-stretch);
  font-size: 24px;
  transition: color var(--dur-fast) var(--ease-sharp);
  display: inline-block;
}
/* Height-aware so three rows always fit one viewport — vh is part of the
   flexible bound, not just vw, so a short-but-wide window can't force an
   overflow the way a pure vw clamp could. */
.contact__list--solo .contact__row a { font-size: clamp(22px, min(3.2vw, 6vh), 40px); }
.contact__row a:hover, .contact__row a:focus-visible { color: var(--green); }
.contact__label { color: var(--white-dim); font-size: 11px; letter-spacing: 0.04em; }
.contact__list--solo .contact__label { font-size: 13px; }

/* The hover line draws in from the middle outward instead of just
   recoloring in place — was too quiet before. */
.contact__row::after {
  content: "";
  position: absolute;
  left: 50%;
  right: 50%;
  bottom: -1px;
  height: 2px;
  background: var(--green);
  transition: left 0.35s var(--ease-sharp), right 0.35s var(--ease-sharp);
}
.contact__row:hover::after,
.contact__row:focus-within::after { left: 0; right: 0; }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 860px) {
  .page { padding: clamp(14px, 5vw, 24px); }
  .corner-nav { font-size: 12px; padding: 4px 7px; }
  .hero__title,
  .hero__sub,
  .hero__cta,
  .contact__list {
    grid-column: 1 / -1 !important;
  }
  .p-intro { max-width: 100%; }
  .card,
  .card:nth-child(odd),
  .card:nth-child(even) { grid-column: 1 / -1; }
}

@media (prefers-contrast: more) {
  .tile { border-color: var(--white); }
  .eyebrow { color: var(--white); }
}
