/* Reset + page */
* { box-sizing: border-box; }
:root {
  /* Safe-area insets exposed for any JS code (render.js layout) that needs
     to read them. The variables are -0 on browsers that don't support
     env(), letting layout work as-is. */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0e0a1f;
  color: #f3f0ff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* Slow drifting gradient — applies to ALL scenes (title, zen, classic, daily, result).
   45s cycle, ease-in-out so motion feels organic. Theme classes override the palette. */
@keyframes bgDrift {
  0%   { background-position:   0%   0%; }
  25%  { background-position: 100%   0%; }
  50%  { background-position: 100% 100%; }
  75%  { background-position:   0% 100%; }
  100% { background-position:   0%   0%; }
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2a1a4a, #4a1a3a, #1a2a4a, #1a4a3a, #4a3a1a, #2a1a4a);
  background-size: 400% 400%;
  animation: bgDrift 45s ease-in-out infinite;
}

/* Visually-hidden but screen-reader-perceivable. */
.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;
}

canvas#game {
  display: block;
  width: 100vw;
  /* iOS Safari quirk: 100vh includes the URL bar; the dynamic viewport unit
     follows the actual visible area. Fallback to 100vh on browsers that
     don't yet support dvh. */
  height: 100vh;
  height: 100dvh;
  will-change: transform;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Daily has its own cool-toned palette, same drift animation. */
body.daily-bg {
  background: linear-gradient(135deg, #0e1a3a, #1a3a5a, #2a1a5a, #1a3a4a, #0a2a3a, #0e1a3a);
  background-size: 400% 400%;
}

/* Name-entry modal input — single DOM element we keep */
#name-input-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 10, 31, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
}
#name-input-wrap > div {
  background: #1a1530;
  padding: 24px 28px;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  text-align: center;
  min-width: 280px;
}
#name-input-wrap label {
  display: block;
  margin-bottom: 12px;
  font-size: 18px;
  font-weight: 500;
}
#name-input-wrap input {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 16px;
  font-family: inherit;
  background: #0e0a1f;
  color: #f3f0ff;
  border: 2px solid #4a3a7a;
  border-radius: 8px;
  outline: none;
  margin-bottom: 14px;
  /* Explicit text selection — the body has user-select: none on the canvas
     but the input must still accept paste / long-press / IME. */
  user-select: text;
  -webkit-user-select: text;
}
#name-input-wrap input:focus { border-color: #7c3aed; }
#name-input-wrap button {
  padding: 8px 24px;
  font-size: 15px;
  font-family: inherit;
  background: #7c3aed;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
#name-input-wrap button:hover { background: #8d4cf0; }

/* === Boot splash — visible until main.js finishes initial setup === */
#boot-splash {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2a1a4a, #1a2a4a, #2a1a4a);
  background-size: 200% 200%;
  animation: bgDrift 20s ease-in-out infinite;
  transition: opacity 350ms ease;
}
#boot-splash.fade-out { opacity: 0; pointer-events: none; }
.boot-gem {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, #e94560, #b14aed, #5468ff);
  transform: rotate(45deg);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.6);
  animation: bootGemSpin 2.4s ease-in-out infinite;
  margin-bottom: 28px;
}
@keyframes bootGemSpin {
  0%, 100% { transform: rotate(45deg) scale(1); }
  50%      { transform: rotate(225deg) scale(1.08); }
}
.boot-title {
  font-size: 38px; font-weight: 900;
  letter-spacing: 6px;
  margin-bottom: 24px;
  background: linear-gradient(135deg, #ff9ec0, #d59bff, #8fd1ff, #d59bff, #ff9ec0);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(180, 110, 255, 0.55));
  animation: bootTitleShimmer 4.5s ease-in-out infinite;
}
@keyframes bootTitleShimmer {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}
.boot-dots { display: flex; gap: 8px; }
.boot-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,0.6);
  animation: bootDot 1.2s ease-in-out infinite;
}
.boot-dots span:nth-child(2) { animation-delay: 0.15s; }
.boot-dots span:nth-child(3) { animation-delay: 0.30s; }
@keyframes bootDot {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50%      { opacity: 1;   transform: scale(1.1); }
}

/* Honor user's reduced-motion preference: stop the background drift, freeze
   the boot splash gem, and stop the dots from pulsing. JS additionally
   short-circuits sheen / glow pulses and screen shake. */
@media (prefers-reduced-motion: reduce) {
  body, body.daily-bg, #boot-splash {
    animation: none !important;
    background-position: 0% 0% !important;
  }
  .boot-gem, .boot-dots span, .boot-title { animation: none !important; }
}

