/* PragCore — modern / high-contrast / scroll-driven layout */
@import "./pragcore-tokens.css";
@import "./pragcore-components.css";

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
}

/* Lenis baseline (see lenis package lenis.css). Required for correct scroll height + smooth wheel. */
html.lenis,
html.lenis body {
  height: auto;
}

.lenis.lenis-smooth {
  scroll-behavior: auto !important;
}

.lenis.lenis-smooth [data-lenis-prevent] {
  overscroll-behavior: contain;
}

.lenis.lenis-stopped {
  overflow: clip;
}

.lenis.lenis-smooth iframe {
  pointer-events: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--void);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(0.9rem, 0.85rem + 0.35vw, 1rem);
  line-height: 1.65;
  overflow-x: hidden;
}

/* Reduced motion: strip motion layers, keep readable content */
@media (prefers-reduced-motion: reduce) {
  .webgl,
  .grain,
  .vignette,
  .scroll-hint,
  .loader {
    display: none !important;
  }

  body {
    background: var(--chrome-rm-body-radial);
  }

  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }
}

/* Loader */
.loader {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  background: var(--void);
  transition: opacity var(--duration-loader-fade) var(--ease-out), visibility var(--duration-loader-fade);
}

.loader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-inner {
  width: min(280px, 70vw);
  text-align: center;
}

.loader-bar {
  height: 3px;
  background: linear-gradient(90deg, var(--magenta), var(--cyan));
  border-radius: 2px;
  transform-origin: left;
  transform: scaleX(0.08);
  transition: transform 0.15s var(--ease-out);
}

.loader-label {
  display: block;
  margin-top: 1rem;
  font-size: 0.7rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
}

/* WebGL + atmosphere */
.webgl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: var(--webgl-light-opacity);
}

.grain {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  z-index: 1;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain-shift var(--duration-grain-shift) steps(4) infinite;
}

@keyframes grain-shift {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-2%, 2%);
  }
  50% {
    transform: translate(2%, -1%);
  }
  75% {
    transform: translate(-1%, -2%);
  }
  100% {
    transform: translate(0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .grain {
    animation: none;
  }
}

/*
 * Safari/WebKit scroll + full-viewport WebGL + scrubbed blur + mix-blend is a common jank stack.
 * Native scroll (see app.js) + these hints keep motion in the browser’s compositor where possible.
 */
html.safari-scroll .grain {
  animation: none;
}

html.safari-scroll .site-header {
  mix-blend-mode: normal;
  background: var(--chrome-header-safari-bg);
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: var(--chrome-vignette);
}

/* Header */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 0 clamp(1.25rem, 4vw, 3rem);
  height: var(--header-h);
  display: flex;
  align-items: center;
  mix-blend-mode: var(--chrome-header-blend);
  color: var(--chrome-header-fg);
}

.header-inner {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-tools {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.header-tools .audio-btn {
  margin-left: 0;
}

/* Optional scroll audio (user must opt in) */
.audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: 0.5rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--audio-border);
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  text-shadow: var(--audio-text-shadow);
  transition: border-color var(--duration-ui-fast), box-shadow var(--duration-ui-fast), color var(--duration-ui-fast);
}

.audio-btn:hover,
.audio-btn:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
  outline: none;
}

.audio-btn[aria-pressed="true"] {
  border-color: var(--magenta);
  color: var(--magenta);
  box-shadow: var(--audio-pressed-glow);
}

.audio-btn-glyph {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  transition: background var(--duration-ui-fast), box-shadow var(--duration-ui-fast);
}

.audio-btn[aria-pressed="true"] .audio-btn-glyph {
  background: var(--magenta);
  box-shadow: 0 0 10px var(--magenta);
}

@media (max-width: 720px) {
  :root {
    /* Approx. clearance for two-row header (brand + tools, then wrapped nav). */
    --header-h: 8.75rem;
  }

  .site-header {
    height: auto;
    min-height: unset;
    padding-top: max(0.45rem, env(safe-area-inset-top, 0px));
    padding-bottom: 0.55rem;
    align-items: flex-start;
    /* difference + busy WebGL can muddy small type; normal blend reads cleaner on phones */
    mix-blend-mode: normal;
    background: var(--chrome-header-mobile-bg);
  }

  .header-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand tools"
      "nav nav";
    column-gap: 0.75rem;
    row-gap: 0.55rem;
    align-items: center;
  }

  .brand {
    grid-area: brand;
    min-width: 0;
  }

  .header-tools {
    grid-area: tools;
    margin-left: 0;
    justify-self: end;
    gap: 0.45rem;
    max-width: 100%;
  }

  .nav {
    grid-area: nav;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0.4rem 0.85rem;
    row-gap: 0.35rem;
    padding-top: 0.15rem;
    border-top: 1px solid var(--chrome-hairline);
  }

  .nav-link {
    font-size: 0.64rem;
    letter-spacing: 0.12em;
    opacity: 0.92;
  }
}

@media (prefers-reduced-motion: reduce) {
  .audio-btn {
    display: none;
  }
}

/* Panels */
main {
  position: relative;
  z-index: 10;
}

/* Scroll panels sit over WebGL bloom — default legibility shadow on copy (inherited by descendants) */
#main .panel {
  text-shadow: var(--text-legibility);
}

#main .panel .panel-content {
  -webkit-font-smoothing: antialiased;
  color: var(--text);
}

#main .panel .section-title,
#main .panel .cta-title,
#main .panel .statement {
  color: var(--text-display);
}

#main .panel .section-title,
#main .panel .hero-title,
#main .panel .statement,
#main .panel .cta-title {
  text-shadow: var(--text-legibility-display);
}

/* Don’t set text-shadow on h1 — SVG / clip quirks; target the plain-text line only. */
#main .panel.panel-hero .hero-title {
  text-shadow: none;
  color: var(--text-display);
}

#main .panel .hero-line:not(.hero-line-accent) .hero-line-inner {
  color: var(--text-display);
  text-shadow: var(--text-legibility-display);
}

#main .panel code {
  text-shadow: var(--chrome-code-shadow);
}

#main .panel .panel-bg-label {
  text-shadow: none;
}

.panel {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  padding: calc(var(--header-h) + 2rem) clamp(1.25rem, 5vw, 4rem) 4rem;
}

.panel-bg-label {
  position: absolute;
  top: 50%;
  right: clamp(0.5rem, 3vw, 2rem);
  transform: translateY(-50%);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(6rem, 22vw, 16rem);
  line-height: 1;
  color: var(--chrome-bg-label);
  pointer-events: none;
  user-select: none;
}

.panel-content {
  position: relative;
  width: 100%;
  max-width: 720px;
  /* Flex default min-width:auto lets wide headlines refuse to shrink → clipped under overflow-x:hidden */
  min-width: 0;
}

/*
 * Hero: no glass “card” — that frame fights the WebGL sphere and reads as generic UI chrome.
 * Instead: edgeless radial dim behind the copy column only + a thin editorial rail (structure, not a box).
 */
.panel-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  /* Taller ellipse avoids a horizontal “band” behind one line of the headline */
  background: var(--chrome-hero-scrim);
}

.panel-hero .panel-content {
  position: relative;
  z-index: 1;
  padding: clamp(0.35rem, 2vw, 0.85rem) clamp(1rem, 2.5vw, 1.35rem);
  max-width: min(720px, 100%);
  /* Headline font-size uses cqw so “Future is / compiled” always fits this box */
  container-type: inline-size;
  container-name: hero;
}

.panel-hero .panel-content::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0.2rem;
  bottom: 2.25rem;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(185deg, var(--cyan) 0%, var(--chrome-rail-mid) 45%, var(--magenta) 100%);
  opacity: 0.55;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .panel-hero::before {
    background: var(--chrome-hero-scrim-rm);
  }
}

.panel-wide {
  max-width: 1100px;
  min-width: 0;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 0 1.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
  text-shadow: var(--text-scene-halo-tight);
}

.eyebrow-line {
  width: 48px;
  height: 1px;
  background: var(--chrome-eyebrow-line);
}

.hero-title {
  margin: 0 0 1.5rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.75rem, 9vw, 6.5rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
  /* Same horizontal origin for both lines (SVG was visually left-heavy when text was viewBox-centered). */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

/*
 * Hero headline: vw fallback always applies; cqw overrides only when container queries work (avoids invalid
 * font-size if cqw isn’t tied to a real query container).
 */
.panel-hero .hero-title {
  max-width: 100%;
  font-size: clamp(2.05rem, calc(0.85rem + 6.5vw), 6.5rem);
}

@supports (font-size: 1cqw) {
  .panel-hero .hero-title {
    font-size: clamp(2.05rem, calc(0.65rem + 10.2cqw), 6.5rem);
  }
}

.hero-line {
  display: block;
  overflow: visible;
  padding-bottom: 0.08em;
}

.hero-line.hero-line-accent {
  padding: 0 0 0.1em;
  margin: 0;
  overflow: visible;
}

.hero-line-inner {
  display: inline-block;
  max-width: 100%;
  will-change: transform;
}

/* “compiled”: SVG text — black fill + linearGradient stroke (paint-order paints stroke under fill). */
.hero-line-accent .hero-line-inner {
  /* Match sibling line boxes: SVG was ~line-height 0 + 0.92em → tiny vs “Future is” */
  line-height: inherit;
  vertical-align: baseline;
}

.hero-compiled-svg {
  display: block;
  /* One em = same computed font-size as .hero-title (matches plain text lines) */
  height: 1em;
  width: auto;
  max-width: 100%;
  overflow: visible;
  /* Dark rim keeps glyph readable on bright specular; cyan echoes brand */
  filter: var(--chrome-compiled-drop);
}

.hero-compiled-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 100px;
  letter-spacing: -0.045em;
  fill: var(--ink);
  stroke: url(#pc-compiled-stroke);
  stroke-width: 6;
  stroke-linejoin: round;
  stroke-linecap: round;
  paint-order: stroke fill;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
}

.hero-sub {
  margin: 0 0 2.25rem;
  max-width: 36ch;
  color: var(--text);
  font-weight: 500;
  font-size: 1.06rem;
  line-height: 1.72;
  text-shadow: var(--text-scene-halo);
}

.hero-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.scroll-hint {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.65rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--muted);
  text-shadow: var(--text-scene-halo-tight);
}

.scroll-hint-line {
  width: 1px;
  height: 48px;
  background: linear-gradient(180deg, var(--cyan), transparent);
  animation: scroll-pulse var(--duration-scroll-pulse) ease-in-out infinite;
}

@keyframes scroll-pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scaleY(0.85);
    transform-origin: top;
  }
  50% {
    opacity: 1;
    transform: scaleY(1);
    transform-origin: top;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-hint-line {
    animation: none;
  }
}

/* Doctrine (section title / pillars: Shared DesignSystem components.css) */

/* Featured projects */
.project-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 640px) {
  .project-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .project-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.project-card {
  display: block;
  padding: 1.25rem 1.2rem;
  text-decoration: none;
  color: inherit;
  background: var(--chrome-project-bg);
  border: 1px solid var(--chrome-project-border);
  border-radius: 4px;
  transition: border-color var(--duration-ui-fast), transform var(--duration-ui-fast) var(--ease-out), box-shadow var(--duration-ui-fast);
}

.project-card:hover,
.project-card:focus-visible {
  border-color: var(--cyan);
  transform: translateY(-3px);
  box-shadow: 0 12px 40px var(--chrome-project-glow);
  outline: none;
}

.project-tag {
  display: inline-block;
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--magenta);
  margin-bottom: 0.65rem;
}

.project-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
}

.project-desc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.55;
}

.project-more a {
  color: var(--cyan);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  text-shadow: var(--chrome-link-shadow);
}

.project-more a:hover,
.project-more a:focus-visible {
  text-decoration: underline;
}

.project-loading,
.project-fallback {
  color: var(--muted);
  grid-column: 1 / -1;
}

.project-fallback a {
  color: var(--cyan);
}

/* Changelog / labs */
.changelog {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.changelog-entry {
  padding-left: 1rem;
  border-left: 2px solid var(--chrome-changelog-border);
}

.changelog-date {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.changelog-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  display: block;
  margin-bottom: 0.35rem;
}

#main .panel .changelog-title {
  color: var(--text-display);
}


.changelog-meta {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#main .panel .project-title {
  color: var(--text-display);
}

#main .panel .pillar h3 {
  color: var(--text-display);
}

.changelog-body {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Statement */
.panel-statement {
  align-items: center;
}

.statement {
  margin: 0 0 1.5rem;
  padding: 0;
  border: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 4vw, 2.75rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.statement p {
  margin: 0;
}

.statement-meta {
  margin: 0;
  color: var(--muted);
  max-width: 48ch;
}

.statement-meta code {
  font-size: 0.88em;
  padding: 0.15em 0.4em;
  background: var(--chrome-code-bg);
  border-radius: 3px;
  color: var(--lime);
}

/* CTA */
.cta-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 5vw, 3.25rem);
  margin: 0 0 1rem;
  letter-spacing: -0.03em;
}

.cta-copy {
  margin: 0 0 2rem;
  max-width: 44ch;
  color: var(--muted);
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

/* Footer */
.site-footer {
  position: relative;
  z-index: 10;
  padding: 2.5rem clamp(1.25rem, 5vw, 4rem) 3rem;
  border-top: 1px solid var(--chrome-footer-border);
}

.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  text-shadow: var(--text-scene-halo-tight);
}

.footer-inner p {
  margin: 0;
}

.footer-note {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.65rem;
}

.footer-note a {
  color: var(--muted);
  text-decoration: none;
  text-shadow: var(--chrome-footer-link-shadow);
}

.footer-note a:hover,
.footer-note a:focus-visible {
  color: var(--cyan);
}

/* Legal / static subpages */
.legal-page {
  background: var(--void);
}

.legal-header.site-header {
  mix-blend-mode: normal;
  color: var(--text);
}

.shell.narrow {
  width: min(720px, 100% - 2.5rem);
  margin-inline: auto;
}

.legal-main {
  padding: calc(var(--header-h) + 2rem) 0 4rem;
  position: relative;
  z-index: 10;
}

.legal-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  margin: 0 0 0.5rem;
}

.legal-updated {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 2rem;
}

.legal-main h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin: 2rem 0 0.75rem;
}

.legal-main p {
  color: var(--muted);
  margin: 0 0 1rem;
  line-height: 1.7;
}

.legal-main a {
  color: var(--cyan);
}

.legal-main code {
  font-size: 0.88em;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background: var(--chrome-code-bg);
  color: var(--lime);
}

/* Scroll reveal baseline (JS enhances) */
[data-reveal] {
  opacity: 0.15;
  transform: translateY(2.5rem);
  filter: blur(6px);
}

html.safari-scroll [data-reveal] {
  filter: none;
}

/* Headline rows: GSAP skips these (inner uses y-scrub only) — baseline blur never clears */
.panel-hero .hero-line[data-reveal] {
  opacity: 1;
  transform: none;
  filter: none;
}
