/* ==========================================================================
   BASE — reset, document, typography, layout primitives, utilities
   ========================================================================== */

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 16px);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.65;
  color: var(--text);
  background: var(--bg-void);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* Layered ambient background: gradient wash + faint grid + canvas particles. */
.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.bg-wash {
  background:
    radial-gradient(900px 600px at 15% -10%, rgba(var(--accent-rgb), 0.16), transparent 60%),
    radial-gradient(700px 500px at 90% 8%, rgba(var(--accent-rgb), 0.1), transparent 62%),
    linear-gradient(180deg, var(--bg-void) 0%, var(--bg-deep) 45%, var(--bg-void) 100%);
  transition: background var(--t-slow);
}

.bg-grid {
  background-image:
    linear-gradient(rgba(var(--accent-rgb), 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--accent-rgb), 0.07) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 100% 70% at 50% 0%, #000 20%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 100% 70% at 50% 0%, #000 20%, transparent 80%);
  opacity: 0.6;
}

#particles {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

/* --- Typography ---------------------------------------------------------- */

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: 0.5px;
}

p {
  color: var(--text-dim);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--t-fast);
}

a:hover {
  color: var(--accent-soft);
}

code,
kbd,
.mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  background: var(--bg-sunken);
  color: var(--text-dim);
  font-size: 0.72rem;
  line-height: 1.4;
}

::selection {
  background: rgba(var(--accent-rgb), 0.35);
  color: #fff;
}

/* --- Focus --------------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-xs);
}

.skip-link {
  position: absolute;
  top: -60px;
  left: var(--sp-4);
  z-index: 3000;
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent);
  color: #000;
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  border-radius: var(--r-sm);
  transition: top var(--t-fast);
}

.skip-link:focus {
  top: var(--sp-4);
  color: #000;
}

/* --- Layout -------------------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--sp-5);
}

.section {
  padding-block: var(--sp-8);
  position: relative;
}

.section + .section {
  padding-top: var(--sp-7);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.section-head__text {
  min-width: 0;
}

.section-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--sp-2);
}

.section-eyebrow::before {
  content: '';
  width: 22px;
  height: 1px;
  background: var(--accent);
}

.section-title {
  font-size: var(--fs-xl);
  color: var(--text);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

.section-sub {
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  max-width: 60ch;
}

/* --- Utilities ----------------------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.stack {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.center {
  text-align: center;
}

[hidden] {
  display: none !important;
}

/* --- Scroll reveal ------------------------------------------------------- */

.reveal {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity var(--t-slow), transform var(--t-slow);
}

.reveal.is-visible {
  opacity: 1;
  transform: none;
}

/* --- Scrollbar ----------------------------------------------------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--accent-rgb), 0.4) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(var(--accent-rgb), 0.35);
  border-radius: var(--r-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--accent-rgb), 0.6);
  background-clip: content-box;
}

/* --- Reduced motion ------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }
}

/* Manual "reduce motion" toggle mirrors the OS preference. */
body[data-motion='off'] *,
body[data-motion='off'] *::before,
body[data-motion='off'] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

body[data-motion='off'] .reveal {
  opacity: 1;
  transform: none;
}

/* --- CRT mode (Konami reward) -------------------------------------------- */

body[data-crt='on']::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.28) 3px,
    rgba(0, 0, 0, 0.28) 4px
  );
  mix-blend-mode: multiply;
  animation: crt-flicker 4s infinite steps(60);
}

body[data-crt='on'] {
  filter: saturate(1.25) contrast(1.06);
}

@keyframes crt-flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.82; }
  98% { opacity: 1; }
  99% { opacity: 0.9; }
}
