/* ============================================================
   AIS GAMES — shared layer
   Base reset, utilities and every component that appears on all
   pages: header/nav, footer, buttons, chips, cards, reveals.
   Page-specific sections live in their own file (e.g. home.css).
   Requires: tokens.css — every value here is a token.
   ============================================================ */

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

html {
  scroll-behavior: smooth;
  overflow-x: hidden;  /* fallback for browsers without clip support */
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  /* Edge-bleeding decorations get cropped at the viewport, never cause x-scroll */
  overflow-x: hidden;
  overflow-x: clip;
  /* The footer sits at the bottom of the window even when a page is short */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Day / night switch: js adds .theming for one beat so surfaces cross-fade */
html.theming,
html.theming * {
  transition:
    background-color var(--dur-theme) var(--ease),
    color var(--dur-theme) var(--ease),
    border-color var(--dur-theme) var(--ease);
}

main { flex: 1 0 auto; }

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

/* Keep [hidden] elements truly hidden (the svg reset above would
   otherwise give hidden svg sprites a 300x150 default box) */
[hidden] { display: none !important; }

h1, h2, h3 {
  margin: 0;
  font-weight: var(--w-heading);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}
h3 { font-weight: var(--w-sub); }
strong { font-weight: var(--w-sub); }

p { margin: 0; text-wrap: pretty; }
a { color: inherit; }

/* Count-up figures keep a steady width while the digits tick */
[data-count] { font-variant-numeric: tabular-nums; }

/* Visually hidden but readable by search engines and screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

/* Slim scrollbar in the page's own colors */
::-webkit-scrollbar { width: var(--scrollbar-w); }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
  background: var(--surface);
  border: calc(var(--scrollbar-w) / 4) solid var(--bg);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-dim); }

/* ---------- Utilities ---------- */
.container-wide {
  width: min(var(--w-max), 100% - var(--gutter) * 2);
  margin-inline: auto;
}
.container-narrow {
  width: min(var(--w-narrow), 100% - var(--gutter) * 2);
  margin-inline: auto;
}

:focus-visible {
  outline: var(--border-w) solid var(--accent);
  outline-offset: var(--focus-offset);
  border-radius: var(--radius-xs);
}
/* Round glyph buttons keep a round focus ring */
.store-btn:focus-visible,
.theme-toggle:focus-visible,
.footer-stores a:focus-visible { border-radius: var(--radius-pill); }

.skip-link {
  position: absolute;
  left: var(--sp-4);
  top: calc(var(--sp-8) * -1);
  z-index: calc(var(--z-header) + 1);
  background: var(--accent);
  color: var(--on-accent);
  padding: var(--sp-2) var(--sp-4);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  font-weight: var(--w-sub);
  transition: top var(--dur-fast) var(--ease);
}
.skip-link:focus { top: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font);
  font-weight: var(--w-ui);
  font-size: var(--text-btn);
  letter-spacing: var(--tracking-ui);
  line-height: var(--lh-body);
  padding: var(--sp-3) var(--btn-pad-x);
  border: 0;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
/* Hover lifts the button and lights it one step brighter (a filter
   would clip on the saturated red, so the hover tone is its own token) */
.btn:hover {
  background: var(--accent-hover);
  transform: translateY(var(--lift-sm));
}
.btn:active { transform: translateY(0) scale(0.97); }

/* ---------- Sticky transparent header ---------- */
.site-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: var(--z-header);
  background: transparent;
  transition: background var(--dur-med) var(--ease), backdrop-filter var(--dur-med) var(--ease);
  animation: nav-drop var(--dur-reveal) var(--ease) both;
}
/* Gains a glass panel once the page is scrolled (js adds .scrolled) */
.site-header.scrolled {
  background: color-mix(in srgb, var(--bg) var(--glass-mix), transparent);
  backdrop-filter: blur(var(--blur-glass));
}

@keyframes nav-drop {
  from { opacity: 0; transform: translateY(calc(var(--slide-sm) * -1)); }
  to { opacity: 1; transform: none; }
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: var(--nav-pad-y);
}

/* Brand logo from the sprite: the red mark is fixed, the AIS letters
   take the page ink so the logo reads in both themes */
.logo {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
}
/* Hovering sends the mark's dot around the wordmark and onto the I; the trip
   is animated in js/site.js, which hands it over as custom properties the
   shadow tree inherits. overflow lets the dot leave the artwork's box on the
   way. Without js the logo just dims instead. */
.logo-mark {
  height: var(--logo-h);
  width: calc(var(--logo-h) * var(--logo-ratio));
  overflow: visible;
  --dot-dur: var(--dur-med);
  --dot-ease: var(--ease-pop);
}
html:not(.js) .logo {
  transition: opacity var(--dur-fast) var(--ease);
}
html:not(.js) .logo:hover { opacity: 0.75; }

.nav-menu {
  display: flex;
  align-items: center;
  gap: var(--gap-links);
  list-style: none;
  margin: 0;
  padding: 0;
}
/* Nav and footer links share the animated accent underline */
.nav-menu a,
.footer-links a {
  position: relative;
  color: var(--ink);
  text-decoration: none;
  font-weight: var(--w-ui);
  font-size: var(--text-nav);
  letter-spacing: var(--tracking-ui);
}
.nav-menu a::after,
.footer-links a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 100%;
  bottom: calc(var(--underline-gap) * -1);
  height: var(--border-w);
  background: var(--accent);
  transition: right var(--dur-draw) var(--ease);
}
/* The current page stays underlined in the header only; the footer just hovers */
.nav-menu a:hover::after,
.footer-links a:hover::after,
.nav-menu a[aria-current="page"]::after { right: 0; }

/* Day / night toggle (glyphs come from assets/icons/ui.svg).
   Sun and moon sit on top of each other; switching spins one out and
   the other in. The glyph is sized to the menu type next to it. */
.theme-toggle {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--toggle-box);
  height: var(--toggle-box);
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease);
}
.theme-toggle:hover { color: var(--accent-text); }
.theme-toggle svg {
  grid-area: 1 / 1;
  width: var(--icon-toggle);
  height: var(--icon-toggle);
  transition: transform var(--dur-med) var(--ease-pop), opacity var(--dur-med) var(--ease);
}
.theme-toggle .icon-moon { opacity: 0; transform: rotate(var(--toggle-spin)) scale(var(--pop-from)); }
[data-theme="light"] .theme-toggle .icon-sun { opacity: 0; transform: rotate(calc(var(--toggle-spin) * -1)) scale(var(--pop-from)); }
[data-theme="light"] .theme-toggle .icon-moon { opacity: 1; transform: none; }

/* ---------- Cards ---------- */
/* Whole card is the link: hovering anywhere lights up its button.
   --card-ink is the text color over the art: white by default,
   dark on cards with light artwork (.card-light). */
.card {
  --card-ink: var(--ink-on-art);
  position: relative;
  display: block;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background-color: var(--surface);
  background-size: cover;
  background-position: center;
  color: inherit;
  text-decoration: none;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.card-light { --card-ink: var(--ink-dark); }
/* Soft top scrim keeps chips and titles readable on any art */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--grad-card-scrim);
  pointer-events: none;
}
/* Only a card that is itself the link lifts; a card holding its own buttons
   (games page, about) stays put, so nothing promises a click it won't take. */
a.card:hover {
  transform: translateY(var(--lift-md));
  box-shadow: var(--shadow-card);
}
/* Group hover only when the whole card IS the link (a.card);
   cards containing multiple buttons need direct button hover */
a.card:hover .btn { background: var(--accent-hover); }

.card-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  text-align: center;
  padding: var(--pad-card-top) var(--sp-5) var(--sp-6);
}
.card-content .btn { margin-top: var(--sp-5); }

/* Eyebrows are punchy pill badges */
.card-eyebrow {
  display: inline-block;
  padding: var(--chip-pad-y) var(--chip-pad-x);
  border-radius: var(--radius-pill);
  background: var(--scrim);
  backdrop-filter: blur(var(--blur-chip));
  color: var(--ink-on-art);
  font-weight: var(--w-sub);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}
.card-title {
  font-size: var(--text-title);
  font-weight: var(--w-heading);
  font-stretch: var(--stretch-display);
  letter-spacing: var(--tracking-display);
  color: var(--card-ink);
  text-shadow: var(--shadow-title);
  margin-bottom: var(--sp-2);
}
.card-light .card-title { text-shadow: none; }

/* ---------- Round icon buttons (player toolbar, reel arrows) ---------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--ink) var(--tag-mix), var(--surface));
  color: var(--ink);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.icon-btn:hover {
  background: color-mix(in srgb, var(--ink) var(--tag-mix-hover), var(--surface));
  transform: translateY(var(--lift-sm));
}
.icon-btn svg { width: var(--icon-sm); height: var(--icon-sm); }
/* A cast vote or an open panel lights the button up */
.icon-btn[aria-pressed="true"],
.icon-btn[aria-expanded="true"] {
  background: var(--accent);
  color: var(--on-accent);
}
.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

/* ---------- Store buttons + square game tiles (games, play) ---------- */
.store-btns {
  display: flex;
  gap: var(--sp-2);
}
/* Plain glyphs, no plate behind them (like the store badges);
   inside a card they take the card's ink so they read on the art */
.store-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  color: var(--card-ink, var(--ink));
  transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.store-btn:hover {
  color: var(--accent-text);
  transform: translateY(var(--lift-sm));
}
.card .store-btn:hover { color: var(--accent); }
.store-btn svg { width: var(--store-icon); height: var(--store-icon); }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap-cards);
}
.game-tile img {
  width: 100%;
  border-radius: var(--radius-icon);
}
/* The icon gives a small hop on hover (one tap, one jump) */
.game-tile:hover img { animation: hop var(--dur-hop) var(--ease); }
@keyframes hop {
  35% { transform: translateY(var(--hop-lift)) scale(1.015, 0.985); }
  70% { transform: translateY(0) scale(0.995, 1.005); }
  100% { transform: none; }
}
/* On the player page the whole tile links to that game's player */
.tile-link {
  display: block;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-icon);
}
.game-tile h3 {
  font-size: var(--text-md);
  margin: var(--sp-3) 0 var(--sp-2);
}
/* A game's name links to its page; it reads as a title, not as a link. */
.game-tile h3 a,
.card-title a { color: inherit; }

/* Accent arrow links ("See our games →", "← All games") */
.arrow-links {
  display: flex;
  justify-content: center;
  gap: var(--gap-links);
  margin-top: var(--sp-5);
  flex-wrap: wrap;
}
.arrow-link {
  color: var(--accent-text);
  font-weight: var(--w-ui);
  font-size: var(--text-nav);
  letter-spacing: var(--tracking-ui);
}

/* Text links (a game's name, "Show more", the arrow and mail links) draw their
   underline left to right on hover, as the menu does. A background line rather
   than ::after, so a name that wraps is underlined line by line. */
.game-tile h3 a,
.card-title a,
.arrow-link,
.link-draw {
  text-decoration: none;
  background-image: var(--underline-draw);
  background-repeat: no-repeat;
  background-position: left bottom;
  background-size: 0 var(--underline-w);
  transition: background-size var(--dur-draw) var(--ease);
}
.game-tile h3 a:hover,
.card-title a:hover,
.arrow-link:hover,
.link-draw:hover,
.game-tile h3 a:focus-visible,
.card-title a:focus-visible,
.arrow-link:focus-visible,
.link-draw:focus-visible { background-size: 100% var(--underline-w); }
.game-tile .store-btn {
  width: var(--tap-sm);
  height: var(--tap-sm);
}
.game-tile .store-btn svg { width: var(--store-icon-sm); height: var(--store-icon-sm); }

/* ---------- Subpage head (games, about, contact…) ---------- */
.page-head {
  width: var(--w-cards);
  margin-inline: auto;
  padding-block: calc(var(--header-h) + var(--page-head-gap)) var(--sp-5);
}
.page-title {
  font-size: var(--text-page-title);
  font-weight: var(--w-display);
  font-stretch: var(--stretch-display);
  letter-spacing: var(--tracking-display);
  word-spacing: var(--word-display);
}
.page-lead {
  max-width: var(--w-lead);
  margin-top: var(--sp-5);
  font-size: var(--text-lead);
  font-weight: var(--w-ui);
  letter-spacing: var(--tracking-lead);
  line-height: var(--lh-copy);
}
/* Links under a page head (the 404) line up with the title and lead */
.page-head .arrow-links { justify-content: flex-start; }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--bg);
  padding-block: var(--pad-intro-bottom) var(--sp-5);
}

.footer-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-6);
  flex-wrap: wrap;
}

.footer-brand {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.footer-tagline {
  color: var(--ink-dim);
  font-size: var(--text-sm);
  max-width: var(--w-tagline);
}
/* Studio coordinates: a small signature of where the games come from */
.footer-meta {
  color: var(--ink-dim);
  font-size: var(--text-hud);
  font-weight: var(--w-ui);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

/* Right column: links + store glyphs on one line, the studio signature under them */
.footer-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-3);
}
.footer-row {
  display: flex;
  align-items: center;
  gap: var(--gap-footer);
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: var(--gap-links);
  flex-wrap: wrap;
}

.footer-stores {
  display: flex;
  gap: var(--sp-5);
}
.footer-stores a {
  color: var(--ink);
  transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
/* The same answer as the store buttons elsewhere */
.footer-stores a:hover {
  color: var(--accent-text);
  transform: translateY(var(--lift-sm));
}
.footer-stores svg {
  width: var(--store-icon);
  height: var(--store-icon);
}

/* ---------- Reveal on scroll (js adds .in) ----------
   Content is only hidden while js is running (html.js), so crawlers
   and no-script visitors always see the full page. The entrance is a
   keyframe animation, not a transition, so hover transforms on cards
   stay snappy once the element has arrived. */
.js .reveal { opacity: 0; }
.js .reveal.in {
  opacity: 1;
  animation: reveal-in var(--dur-reveal) var(--ease) backwards;
}
@keyframes reveal-in {
  from { opacity: 0; transform: translateY(var(--reveal-shift)); }
}
/* Siblings arrive one beat apart */
.reveal:nth-child(2) { animation-delay: var(--stagger); }
.reveal:nth-child(3) { animation-delay: calc(var(--stagger) * 2); }
.reveal:nth-child(4) { animation-delay: calc(var(--stagger) * 3); }

/* ---------- Cross-page transitions ----------
   Pages fade into each other; the header stays put across the swap. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: var(--dur-page); }
  .site-header { view-transition-name: site-header; }
}

/* ---------- Responsive (shared) ---------- */
@media (max-width: 860px) {
  .page-head { width: calc(100% - var(--gutter) * 2); }

  /* Compact inline menu next to the logo — no hamburger needed for 3 links.
     Sizes and gaps come from the mobile token overrides in tokens.css; if a
     phone is too narrow for one row, the menu wraps under the logo. */
  .nav {
    padding-block: var(--sp-4);
    gap: var(--sp-2) var(--sp-3);
    flex-wrap: wrap;
  }
  .nav-menu a { white-space: nowrap; }
  .theme-toggle { padding: var(--sp-1); }

  /* Footer stacks and centers on small screens */
  .footer-inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--sp-5);
  }
  .footer-brand { align-items: center; }
  .footer-right { align-items: center; }
  .footer-row {
    flex-direction: column;
    align-items: center;
    gap: var(--sp-5);
  }
  .footer-links { justify-content: center; gap: var(--sp-5); }
  .tile-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Reduced motion (shared) ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  html.theming, html.theming * { transition: none; }
  .js .reveal { opacity: 1; animation: none; }
  .site-header { animation: none; }
  .btn, .card, .store-btn, .icon-btn, .theme-toggle svg { transition: none; }
  .game-tile h3 a, .card-title a, .arrow-link, .link-draw, .nav-menu a::after, .footer-links a::after { transition: none; }
  a.card:hover { transform: none; }
  .game-tile:hover img { animation: none; }
  /* the dot stays put, so the logo answers a hover by dimming instead */
  .logo:hover { opacity: 0.75; }
}
