/* Reset, page shell, backdrops and shared components (buttons, pills).
   Theme values arrive as CSS variables: --color-*, --type-*, --font-*, --img-* (see ui/applyTheme.js).
   Layout values arrive from ui/layout.js: --header-h, --app-width/height, --ui-scale, --area-left/width, --hint-bottom. */

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

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--color-surface, #fff);
  color: var(--color-text);
  font-family: var(--font-body);
}

h1, h2, p {
  margin: 0;
  font-weight: inherit;
}

img {
  -webkit-user-drag: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ---- Loading ---------------------------------------------------------------- */

.loader {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 4px solid rgba(0, 0, 0, 0.12);
  border-top-color: rgba(0, 0, 0, 0.4);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

#app[data-state="loading"] .loader { display: block; }
#app[data-state="loading"] > :not(.loader) { visibility: hidden; }

/* ---- Backdrops -------------------------------------------------------------- */

.backdrop {
  position: absolute;
  inset: 0;
}

.backdrop--menu {
  background: var(--img-paper) top left / var(--type-paper-size) repeat, var(--color-surface);
}

/* Optional watercolour blot at the bottom (only themes that define assets.watercolor). */
.backdrop--menu::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -163px;
  width: 479.73px;
  height: 515px;
  transform: translateX(-50%);
  background: var(--img-watercolor, none) center / 100% 100% no-repeat;
}
#app[data-state="splash"] .backdrop--menu::after { display: none; }   /* the splash draws its own blot (theme splashDecor) */

.backdrop--play {
  background: var(--img-gameplay-background) center bottom / cover no-repeat;
}

/* Backdrop layers 2 and foreground (see game/rendering/parallax.js). They are wider than the viewport by their
   maximum sideways shift (--parallax-max), so their edges never show while they move. Layer 1 is .backdrop--play.
   The foreground comes after the scene in the markup and therefore covers catcher and objects. */
.parallax {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--parallax-max, 0px) * -1);
  right: calc(var(--parallax-max, 0px) * -1);
  background: center bottom / cover no-repeat;
  pointer-events: none;
  will-change: transform;
}
.parallax[data-parallax="layer2"] { background-image: var(--img-gameplay-layer2); }
.parallax[data-parallax="foreground"] { background-image: var(--img-gameplay-foreground); z-index: 1; }

/* On wide screens the sides fade to dark so the gameplay area stays the focus (desktop artboard).
   Drawn over the scene and the foreground (later in the markup, same z-index), below HUD and top bar. */
.backdrop--fade { z-index: 1; pointer-events: none; }
.backdrop--fade::before,
.backdrop--fade::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: max(400px, calc(var(--area-left) + 120px));
  opacity: 0.5;
  display: none;
}
.backdrop--fade::before { left: 0; background: linear-gradient(to right, #000 50%, transparent); }
.backdrop--fade::after { right: 0; background: linear-gradient(to left, #000 50%, transparent); }
#app[data-orientation="landscape"][data-view="play"] .backdrop--fade::before,
#app[data-orientation="landscape"][data-view="play"] .backdrop--fade::after { display: block; }

/* The gameplay backdrop stays painted (invisible) in menus, so its large images are already decoded when a round starts. */
#app[data-view="menu"] .backdrop--play,
#app[data-view="menu"] .parallax { opacity: 0; }

#app[data-view="menu"] :is(.scene, .hud, .hint),
#app[data-view="play"] .backdrop--menu { display: none; }

/* ---- Buttons ---------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 240px;
  height: 56px;
  padding: 0 24px;
  border: 2px solid var(--color-primary);
  border-radius: 8px;
  font: 32px / 1 var(--font-display);
  text-transform: var(--type-button-transform, var(--type-display-transform));
  letter-spacing: var(--type-button-letter-spacing);
  text-decoration: none;
  text-box: trim-both cap alphabetic;   /* centres the capitals optically where supported */
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.1s ease-out, filter 0.15s;
}

.button--solid {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.button--ghost {
  background: var(--color-surface);
  color: var(--color-primary);
  font-size: 20px;
}

.button:hover { filter: brightness(1.06); }
.button:active { transform: scale(0.97); }
.button:focus-visible,
.icon-button:focus-visible { outline: 3px solid currentColor; outline-offset: 2px; }

/* ---- Pills (HUD, hint) ------------------------------------------------------ */

.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 8px;
  border-radius: 24px;
  background: var(--color-hud-bg);
  color: var(--color-hud-fg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  font: var(--type-hud-size) / 1 var(--font-display);
  text-transform: var(--type-display-transform);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---- Motion ----------------------------------------------------------------- */

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
