/* ==========================================================================
   scroll-portfolio — Zaky Shadra Ibnu Hibban
   --------------------------------------------------------------------------
   A demo of scroll-driven motion. No video, no pre-rendered animation:
   the WebGL planet and every transition are generated from scroll position.

   Typography: Fraunces (display) / DM Sans (UI) / Space Mono (metadata).
   Colours: two themes, both verified against WCAG AA. The palette avoids
   the default "purple→blue gradient" look; the accent is a warm vermillion
   with a teal secondary so the page has colour without being loud.

   Every colour is a semantic token. Nothing below hard-codes a hex value,
   so switching themes is a single attribute change on <html>.
   ========================================================================== */

/* --- Tokens: LIGHT (default) --------------------------------------------
   Warm paper, near-black ink. This is the default because it is the most
   readable in bright rooms and on cheap panels, which is where the earlier
   dark-only version drew "I can't read it" complaints.
   ------------------------------------------------------------------------ */
:root {
  color-scheme: light;

  --bg: #f4f1ea;            /* page paper */
  --bg-raised: #fffefb;     /* cards, panels that should lift */
  --bg-sunken: #e9e5db;     /* inset wells, image frames */
  --fg: #14130f;            /* headings, primary text   — 16.5:1 */
  --fg-2: #3d3a33;          /* body text                — 10.1:1 */
  --fg-muted: #6b675d;      /* metadata, captions       — 5.0:1  */
  --rule: #d8d3c6;
  --rule-strong: #b3ad9d;

  --accent: #c93a12;        /* vermillion — fills, marks  */
  --accent-ink: #a82f0d;    /* vermillion for small text — 6.1:1 */
  --accent-2: #0f6b6b;      /* teal — secondary accent   — 5.6:1 */
  --accent-wash: rgba(201, 58, 18, 0.10);

  --on-accent: #fffefb;     /* text placed on an accent fill */
  --scrim: rgba(20, 19, 15, 0.72);

  --grain-opacity: 0.035;
  --grain-blend: multiply;
}

/* --- Tokens: DARK --------------------------------------------------------
   Same hues, inverted surfaces. Secondary text is lifted well above the
   old #6f6c66 (which failed at 3.8:1) so nothing is a strain to read.
   ------------------------------------------------------------------------ */
[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b0b0d;
  --bg-raised: #16161a;
  --bg-sunken: #070708;
  --fg: #f4f1ea;            /* 17.4:1 */
  --fg-2: #cdc9bf;          /* 11.9:1 */
  --fg-muted: #96928a;      /*  6.3:1 */
  --rule: #2a2a30;
  --rule-strong: #414149;

  --accent: #ff5c2e;
  --accent-ink: #ff8156;    /* 8.0:1 */
  --accent-2: #4fd1c5;      /* teal, brightened for dark — 10.5:1 */
  --accent-wash: rgba(255, 92, 46, 0.12);

  --on-accent: #14130f;
  --scrim: rgba(7, 7, 8, 0.66);

  --grain-opacity: 0.05;
  --grain-blend: overlay;
}

/* --- Tokens: shared ------------------------------------------------------ */
:root {
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-prose: "Alegreya Sans", "Helvetica Neue", Arial, sans-serif;
  --font-ui: "DM Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Space Mono", ui-monospace, Menlo, monospace;

  --text-display: clamp(3rem, 11vw, 9rem);
  --text-title: clamp(2rem, 5vw, 4rem);
  --text-lead: clamp(1.05rem, 1.5vw, 1.35rem);
  --text-body: 1.0625rem;
  --text-small: 0.9rem;
  --text-meta: 0.72rem;

  --gutter: clamp(1.25rem, 5vw, 5rem);
  --shell: 90rem;
  --masthead-h: 4.5rem;

  --ease-out: cubic-bezier(0.22, 0.68, 0.32, 1);
  --ease-inout: cubic-bezier(0.76, 0, 0.24, 1);
}

/* --- Reset --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-ui);
  font-size: var(--text-body);
  line-height: 1.6;
  color: var(--fg-2);
  background: var(--bg);
  overflow-x: hidden;
  transition: background 400ms var(--ease-out), color 400ms var(--ease-out);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
::selection { background: var(--accent); color: var(--on-accent); }

.skip-link {
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  transform: translateY(-120%);
  transition: transform var(--ease-out) 160ms;
}
.skip-link:focus { transform: none; }

/* --- Backdrop layers ----------------------------------------------------- */
#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
  pointer-events: none;
}

/* Faint film grain via an SVG turbulence data-URI — cheap, no image asset. */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 1;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Content sits above the canvas. */
.masthead, main, .footer, .progress { position: relative; z-index: 2; }

/* --- Scroll progress bar ------------------------------------------------- */
.progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--rule);
  z-index: 20;
}
.progress span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transform-origin: left;
}

/* --- Masthead ------------------------------------------------------------ */
.masthead {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--masthead-h);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 var(--gutter);
  z-index: 15;
  color: var(--fg);
}
.brand {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-dot { color: var(--accent); }
.nav {
  display: flex;
  gap: 1.75rem;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.nav a { position: relative; padding-bottom: 2px; }
.nav a::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  width: 100%; height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 320ms var(--ease-out);
}
.nav a:hover::after { transform: scaleX(1); transform-origin: left; }

.nav-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.nav-status i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-2) 60%, transparent);
  animation: pulse 2.4s var(--ease-out) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-2) 50%, transparent); }
  70%  { box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent-2) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-2) 0%, transparent); }
}

/* --- Theme toggle -------------------------------------------------------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 260ms var(--ease-out), color 260ms var(--ease-out), background 260ms var(--ease-out);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent-ink); }
.theme-toggle svg { width: 14px; height: 14px; display: block; }
/* The button shows the theme you would switch TO, so it reads as an action. */
.theme-toggle .icon-light { display: none; }   /* sun shown only in dark mode */
.theme-toggle .icon-dark { display: block; }    /* moon shown in light mode */
.theme-toggle .label-light { display: none; }
.theme-toggle .label-dark { display: inline; }
[data-theme="dark"] .theme-toggle .icon-light { display: block; }
[data-theme="dark"] .theme-toggle .icon-dark { display: none; }
[data-theme="dark"] .theme-toggle .label-light { display: inline; }
[data-theme="dark"] .theme-toggle .label-dark { display: none; }

/* --- Shared type helpers ------------------------------------------------- */
.kicker {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-ink);
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2);
}

/* Reveal: elements start hidden only when JS confirms motion is allowed.
   See main.js — the class is added to <html> so a JS failure leaves content
   fully visible. */
.js [data-reveal] { opacity: 0; will-change: transform, opacity; }

/* While the globe is being spun, suppress text selection and the text cursor
   so the drag feels like handling an object, not highlighting a paragraph. */
body.is-spinning { user-select: none; }
body.is-spinning * { cursor: grabbing !important; }

/* --- Hero ---------------------------------------------------------------- */
.hero {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 var(--gutter);
  max-width: var(--shell);
  margin: 0 auto;
}
.hero-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-display);
  line-height: 0.94;
  letter-spacing: -0.02em;
  margin: 1.25rem 0 2rem;
  color: var(--fg);
}
.hero-title .line { display: block; }
.hero-title .line:last-child {
  font-style: italic;
  padding-left: clamp(1rem, 12vw, 10rem);
  color: var(--fg);
}
.hero-lead {
  max-width: 44ch;
  font-size: var(--text-lead);
  color: var(--fg-2);
  line-height: 1.55;
}
.hero-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  margin-top: clamp(2.5rem, 6vw, 5rem);
  flex-wrap: wrap;
}
.scroll-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  text-transform: uppercase;
}
.scroll-hint-track {
  position: relative;
  width: 42px; height: 1px;
  background: var(--rule-strong);
  overflow: hidden;
}
.scroll-hint-track i {
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: translateX(-100%);
  animation: slide 2.6s var(--ease-inout) infinite;
}
@keyframes slide {
  0%   { transform: translateX(-100%); }
  55%  { transform: translateX(100%); }
  100% { transform: translateX(100%); }
}
.hud {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  color: var(--fg-muted);
  letter-spacing: 0.03em;
}
.hud b { color: var(--accent-ink); font-weight: 700; }

/* --- Statement ----------------------------------------------------------- */
.statement {
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding: 6rem var(--gutter);
  max-width: var(--shell);
  margin: 0 auto;
}
.statement-inner { max-width: 46rem; }
.statement-text {
  font-family: var(--font-prose);
  font-size: clamp(1.35rem, 2.4vw, 1.9rem);
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0;
  margin: 1.5rem 0 3rem;
  color: var(--fg);
}
.statement-text em {
  font-style: italic;
  color: var(--accent-ink);
}
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 1.5rem 2rem;
  border-top: 1px solid var(--rule-strong);
  padding-top: 1.75rem;
}
.facts dt {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 0.35rem;
}
.facts dd { font-size: var(--text-body); color: var(--fg); }

/* --- Stage (pinned 3D) --------------------------------------------------- */
.stage { position: relative; }
.stage-pin {
  height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 3rem;
  padding: 0 var(--gutter);
  max-width: var(--shell);
  margin: 0 auto;
}
.stage-copy { max-width: 34rem; }
.stage-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-title);
  line-height: 1.02;
  margin: 1.25rem 0 1.5rem;
  color: var(--fg);
}
.stage-body {
  color: var(--fg-2);
  max-width: 40ch;
  font-size: var(--text-lead);
}
.readout {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.4rem 1rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule-strong);
  width: fit-content;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
}
.readout span { color: var(--fg-muted); letter-spacing: 0.1em; text-transform: uppercase; }
.readout b { color: var(--accent-ink); font-weight: 700; text-align: right; }
.stage-hint {
  align-self: end;
  justify-self: end;
  padding-bottom: 3rem;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* --- Work (horizontal) --------------------------------------------------- */
.work { position: relative; }
.work-pin {
  height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.work-head, .work-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gutter);
  height: 4.5rem;
  flex: 0 0 auto;
}
.work-head { border-bottom: 1px solid var(--rule); }
.work-count {
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.1em;
  color: var(--fg-muted);
}
.work-count b { color: var(--fg); font-weight: 700; }
.work-foot {
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.work-bar {
  width: 180px; height: 2px;
  background: var(--rule-strong);
  display: inline-block;
}
.work-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
}

.work-track {
  display: flex;
  align-items: center;
  gap: clamp(1.5rem, 3vw, 3rem);
  padding: 0 var(--gutter);
  flex: 1 1 auto;
  will-change: transform;
}
.card {
  flex: 0 0 auto;
  width: clamp(19rem, 34vw, 30rem);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 1.25rem;
  align-content: start;
}
.card-figure {
  position: relative;
  aspect-ratio: 1400 / 788;
  overflow: hidden;
  background: var(--bg-sunken);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.card-figure img {
  width: 100%; height: 100%;
  object-fit: cover;
  filter: contrast(1.04);
  transition: filter 500ms var(--ease-out), transform 700ms var(--ease-out);
}
.card:hover .card-figure img { transform: scale(1.03); }
.card-index {
  position: absolute;
  top: 0.75rem; left: 0.75rem;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.1em;
  color: var(--on-accent);
  background: var(--accent);
  padding: 0.25rem 0.5rem;
}
.card-body { display: flex; flex-direction: column; gap: 0.7rem; }
.card-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.5rem, 2.4vw, 2.1rem);
  line-height: 1.05;
  color: var(--fg);
}
.card-tagline { color: var(--fg); font-size: var(--text-body); line-height: 1.55; max-width: 40ch; }
.card-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}
.card-specs span {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--on-accent);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}

/* --- Contact ------------------------------------------------------------- */
.contact {
  min-height: 92svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6rem var(--gutter);
  max-width: var(--shell);
  margin: 0 auto;
}
.contact-mail {
  font-family: var(--font-display);
  font-size: clamp(2.25rem, 8vw, 6.5rem);
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 1.5rem 0;
  display: inline-block;
  position: relative;
  width: fit-content;
  color: var(--fg);
}
.contact-mail::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0.08em;
  width: 100%; height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 520ms var(--ease-out);
}
.contact-mail:hover { color: var(--accent-ink); }
.contact-mail:hover::after { transform: scaleX(1); }
.contact-note { max-width: 42ch; color: var(--fg-2); }
.contact-links {
  display: flex;
  gap: 2rem;
  margin-top: 2.5rem;
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.contact-links a { border-bottom: 1px solid var(--rule-strong); padding-bottom: 3px; transition: border-color 300ms var(--ease-out), color 300ms var(--ease-out); }
.contact-links a:hover { color: var(--accent-2); border-color: var(--accent-2); }

/* --- Footer -------------------------------------------------------------- */
.footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 2rem var(--gutter);
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: var(--text-meta);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 820px) {
  .nav-status { display: none; }
  .nav { gap: 1.1rem; }
  .stage-pin { grid-template-columns: 1fr; align-content: center; gap: 1.5rem; }
  .stage-hint { justify-self: start; padding-bottom: 0; }
  .hero-title .line:last-child { padding-left: 1.5rem; }
  .work-track { gap: 1.25rem; }
  .card { width: 78vw; }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-hint-track i, .nav-status i { animation: none; }
  * { scroll-behavior: auto !important; }
  body { transition: none; }
}
