/* ==========================================================================
   Base: reset, typography, utilities, focus, selection, reveal,
   view transitions and reduced motion.
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-gutter: stable;
  background: var(--bg);
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: 400;
  font-stretch: 100%;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

/* Hide the page until the first translation pass when the visitor's
   language differs from the HTML default (set by the inline head script). */
html.is-translating body {
  opacity: 0;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
figure,
blockquote,
dl,
dd {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

img,
svg,
canvas {
  display: block;
  max-width: 100%;
}

em {
  font-style: normal;
}

[hidden] {
  display: none !important;
}

/* Controls that only work with JavaScript. */
html:not(.js) [data-js-only] {
  display: none !important;
}

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

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.nowrap {
  white-space: nowrap;
}

.mono {
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  font-weight: 400;
  font-stretch: var(--stretch-mono);
  letter-spacing: 0;
  line-height: 1.4;
}

/* Small uppercase mono label. Rationed: only the hero stage caption and the
   ticker band use it. */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  font-stretch: var(--stretch-mono);
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-transform: uppercase;
  color: var(--ink-2);
}

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

section[id] {
  scroll-margin-top: var(--scroll-offset);
}

section[tabindex="-1"]:focus,
main:focus {
  outline: none;
}

.section-title {
  font-size: var(--fs-section);
  font-weight: 760;
  font-stretch: var(--stretch-title);
  letter-spacing: var(--tracking-title);
  line-height: 0.96;
  text-wrap: balance;
}

/* CSS dot pattern: the board's holes, used wherever there is no canvas. */
.dot-field {
  background-image: radial-gradient(circle at center, var(--hole) 0 var(--dot-size), transparent calc(var(--dot-size) + 0.6px));
  background-size: var(--dot-grid) var(--dot-grid);
  background-position: center top;
}

/* Horizontal scroller with faded edges (filters, reduced-motion ticker).
   JS adds .is-overflowing when the content does not fit. */
@property --fade-l {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

@property --fade-r {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

.scroller {
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.scroller::-webkit-scrollbar {
  display: none;
}

.scroller.is-overflowing {
  --fade-l: 0px;
  --fade-r: 40px;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--fade-l), #000 calc(100% - var(--fade-r)), transparent);
  mask-image: linear-gradient(to right, transparent, #000 var(--fade-l), #000 calc(100% - var(--fade-r)), transparent);
}

@supports (animation-timeline: scroll()) {
  .scroller.is-overflowing {
    animation: scroller-fade linear both;
    animation-timeline: scroll(self inline);
  }
}

@keyframes scroller-fade {
  0% {
    --fade-l: 0px;
    --fade-r: 40px;
  }
  12% {
    --fade-l: 40px;
  }
  88% {
    --fade-r: 40px;
  }
  100% {
    --fade-l: 40px;
    --fade-r: 0px;
  }
}

/* --------------------------------------------------------------------------
   Focus and selection
   -------------------------------------------------------------------------- */

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

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: var(--z-skip);
  display: inline-flex;
  align-items: center;
  height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-stretch: var(--stretch-ui);
  transform: translateY(-160%);
  transition: transform var(--dur-ui) var(--ease-out);
}

.skip-link:focus {
  transform: none;
}

/* --------------------------------------------------------------------------
   Scroll reveal. Content is only hidden when JS runs and motion is allowed.
   -------------------------------------------------------------------------- */

html.js .reveal {
  transition:
    opacity 700ms var(--ease-out),
    transform 700ms var(--ease-out);
  transition-delay: calc(var(--i, 0) * 70ms);
}

@media (prefers-reduced-motion: no-preference) {
  html.js .reveal:not(.is-in) {
    opacity: 0;
    transform: translateY(18px);
  }
}

@media print {
  html.js .reveal {
    opacity: 1 !important;
    transform: none !important;
  }
}

/* --------------------------------------------------------------------------
   Theme switch: freeze CSS transitions for the frame the tokens flip, so
   every surface changes at once (the view transition does the choreography).
   -------------------------------------------------------------------------- */

html.is-switching-theme *:not(.theme-toggle__icon):not(.segmented__layer),
html.is-switching-theme *::before,
html.is-switching-theme *::after {
  transition: none !important;
}

/* --------------------------------------------------------------------------
   View transitions
   theme:  circular reveal driven from JS on ::view-transition-new(root)
   lang:   quick root crossfade, the old snapshot blurs out
   filter: per-row names are assigned only during the transition
   -------------------------------------------------------------------------- */

::view-transition-group(*) {
  animation-duration: 360ms;
  animation-timing-function: var(--ease-in-out);
}

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

:root[data-vt="lang"]::view-transition-old(root) {
  animation: vt-blur-out 280ms var(--ease-out) both;
}

:root[data-vt="lang"]::view-transition-new(root) {
  animation: vt-fade-in 280ms var(--ease-out) both;
}

@keyframes vt-blur-out {
  to {
    opacity: 0;
    filter: blur(4px);
  }
}

@keyframes vt-fade-in {
  from {
    opacity: 0;
  }
}
