/*
 * Larcade design tokens — the single source of truth for colour, type, radius,
 * motion and spacing shared by the hub and every game shell. Loaded as a static
 * stylesheet before any page/game CSS so the custom properties are always live.
 */
:root {
  color-scheme: dark;

  /* Surfaces (deep → elevated) */
  --bg-deep: #080b11;
  --bg: #0b1017;
  --panel: #131b26;
  --panel-2: #182231;
  --elevated: #1f2c3d;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);

  /* Ink */
  --ink: #eef3f9;
  --ink-muted: #93a3b8;
  --ink-dim: #5f7089;

  /* Accents */
  --accent: #f5c84b;
  --accent-ink: #1b1500;
  --accent-cool: #5dd0c5;
  --accent-violet: #8b7cf6;
  --accent-pink: #f06d9e;
  --danger: #f0655e;

  /* Effects */
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow: 0 14px 44px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.5);
  --ring: 0 0 0 2px rgba(245, 200, 75, 0.55);

  /* Radius */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  --r-pill: 999px;

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1); /* gentle overshoot, wide support */
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;

  /* Sizing + type (system SF on Apple platforms; no shipped webfont) */
  --touch-min: 44px;
  --font:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-rounded:
    ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto,
    sans-serif;

  /* Liquid Glass material */
  --glass-tint: rgba(20, 27, 38, 0.55);
  --glass-tint-clear: rgba(12, 17, 24, 0.3);
  --glass-blur: 18px;
  --glass-blur-hud: 12px;
  --glass-saturate: 180%;
  --glass-rim-light: rgba(255, 255, 255, 0.22);
  --glass-rim-dark: rgba(0, 0, 0, 0.28);
  --glass-scrim: rgba(8, 11, 17, 0.35);

  /* Safe-area passthrough */
  --safe-t: env(safe-area-inset-top);
  --safe-r: env(safe-area-inset-right);
  --safe-b: env(safe-area-inset-bottom);
  --safe-l: env(safe-area-inset-left);

  /*
   * Layer scale — every fixed/absolute layer takes one of these. Within a game
   * shell the HUD/overlay/rotate layers stack inside the shell's own context;
   * the shell itself sits above all hub chrome so a mounted game always wins.
   */
  --z-hud: 10;
  --z-overlay: 20;
  --z-rotate: 30;
  --z-tabbar: 40;
  --z-shell: 50;
  --z-modal: 60;
  --z-toast: 70;

  /* Legacy aliases kept so existing component rules resolve during the refresh */
  --text: var(--ink);
  --muted: var(--ink-muted);
  --accent-2: var(--accent-cool);
  --panel-strong: rgba(11, 16, 23, 0.9);
  --shadow-color: rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

/*
 * Liquid Glass material — a reusable floating-layer surface: translucent tint,
 * frosted+saturated backdrop, and a specular rim (top sheen / bottom shade)
 * plus a soft drop shadow so it reads as a lit pane above content.
 *   .glass          Regular material (default chrome)
 *   .glass--clear   Clear material (over vivid content; pair with a scrim)
 *   .glass--capsule Pill radius
 */
.glass {
  position: relative;
  background: var(--glass-tint);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow:
    inset 0 1px 0 var(--glass-rim-light),
    inset 0 -1px 0 var(--glass-rim-dark),
    var(--shadow);
}

.glass--clear {
  background: var(--glass-tint-clear);
  backdrop-filter: blur(var(--glass-blur-hud)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur-hud)) saturate(var(--glass-saturate));
}

.glass--capsule {
  border-radius: var(--r-pill);
}

/* Accessibility + capability fallbacks: solid material when glass isn't wanted/supported */
@media (prefers-reduced-transparency: reduce) {
  .glass,
  .glass--clear {
    background: var(--elevated);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass,
  .glass--clear {
    background: var(--elevated);
  }
}

/* SPA-lite: a game mounted in-place over the hub, fading in fullscreen */
body.game-open {
  overflow: hidden;
}

.game-mount {
  animation: game-mount-in var(--dur-slow) var(--ease-out);
}

@keyframes game-mount-in {
  from {
    opacity: 0;
    transform: scale(1.01);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Shared "update ready" toast (service worker) */
.pwa-toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border-radius: var(--r-pill);
  background: var(--elevated);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  animation: pwa-toast-in var(--dur-slow) var(--ease-out);
}

.pwa-toast-action {
  border: 0;
  border-radius: var(--r-pill);
  padding: 8px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

@keyframes pwa-toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}
