/* ── Global pixel art layout ──────────────────────────── */

* { font-family: var(--font-pixel); }

#game-viewport {
  position: relative;
  width: var(--game-width);
  max-width: 37.5rem;
  height: var(--game-height);
  margin: 0 auto;
  overflow: hidden;
  background: var(--color-bg);
}

.game-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#layer-gameplay { pointer-events: auto; }
#layer-hud { pointer-events: auto; z-index: 110; }

.input-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 100;
  pointer-events: auto;
  touch-action: none;
}
#input-zone-left  { left: 0; width: 50%; }
#input-zone-right { right: 0; width: 50%; }

/* ── Tap hint arrows (shown briefly at level start) ─── */
.tap-hint {
  position: absolute;
  bottom: 3rem;
  width: 4rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-btn-secondary, #3a2a5a);
  border: 3px solid var(--color-border, #554477);
  border-radius: 0.25rem;
  pointer-events: none;
  z-index: 105;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.tap-hint-left  { left: 1.5rem; }
.tap-hint-right { right: 1.5rem; }
.tap-hint-visible { opacity: 0.85; }
.tap-hint-fading  { opacity: 0; transition: opacity 0.5s ease; }
.tap-hint img {
  width: 2.5rem;
  height: 2.5rem;
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

/* ── Screens ─────────────────────────────────────────── */

.screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--color-bg);
  color: var(--color-text);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  font-family: var(--font-pixel);
}
.screen[hidden] { display: none; }

.screen-inner {
  width: 100%;
  max-width: 25rem;
  padding: calc(3.75rem + env(safe-area-inset-top)) 1.25rem calc(2.5rem + env(safe-area-inset-bottom));
  text-align: center;
}

/* Headings and paragraphs containing icons — flex for alignment */
.screen-inner h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin-bottom: 0.5rem;
}
.screen-inner p:has(.pxicon) {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  width: 100%;
  flex-wrap: wrap;
}

/* ── Pixel art button ────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.625rem 1.75rem;
  margin: 0.375rem;
  background: var(--color-btn-primary);
  color: #fff;
  border: 3px solid rgba(255,255,255,0.15);
  border-bottom-color: rgba(0,0,0,0.3);
  border-right-color: rgba(0,0,0,0.3);
  font-family: var(--font-pixel);
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  min-width: 2.75rem;
  min-height: 2.75rem;
  touch-action: manipulation;
  text-transform: uppercase;
  letter-spacing: 0.0625rem;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.4);
  white-space: nowrap;
  transition: transform 0.05s;
}
.btn:active {
  transform: translateY(2px);
  border-top-color: rgba(0,0,0,0.3);
  border-left-color: rgba(0,0,0,0.3);
  border-bottom-color: rgba(255,255,255,0.15);
  border-right-color: rgba(255,255,255,0.15);
}
.btn-secondary {
  background: var(--color-btn-secondary);
  border-color: var(--color-border);
  border-bottom-color: rgba(0,0,0,0.4);
  border-right-color: rgba(0,0,0,0.4);
}
.btn-large { font-size: 1.25rem; padding: 0.875rem 2.75rem; }
.btn-small { padding: 0.375rem 0.875rem; font-size: 0.8125rem; }

/* ── Pixel icon helper (inline SVG img in buttons/labels) ── */

.pxicon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}

/* ── Title Screen (epic redesign) ────────────────────── */

#screen-title {
  background: radial-gradient(ellipse at 50% 30%, #1e1440 0%, var(--color-bg) 70%);
  overflow: hidden;
}

/* ── Entry Gate (tap-to-start splash) ────────────────── */

.entry-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 2rem 1.25rem;
  text-align: center;
}

/* Hold entry gate invisible until logo loads */
.entry-gate { visibility: hidden; }
#screen-title.entry-ready .entry-gate { visibility: visible; }

.entry-logo-wrap {
  display: flex;
  line-height: 0;
  animation: titleLogoFloat 4s ease-in-out 0.8s infinite,
             titleGlow 3s ease-in-out 0.8s infinite;
  animation-play-state: paused;
}
#screen-title.entry-ready .entry-logo-wrap {
  animation-play-state: running;
}

.entry-logo-img {
  display: block;
  width: 14rem;
  max-width: 80vw;
  height: auto;
  opacity: 0;
  animation: titleLogoReveal 1.2s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-play-state: paused;
}
#screen-title.entry-ready .entry-logo-img {
  animation-play-state: running;
}

.entry-tagline {
  font-size: 0.875rem;
  color: var(--color-text-dim);
  letter-spacing: 0.0625rem;
  opacity: 0;
  animation: titleTaglineFade 0.8s ease 0.6s forwards;
  animation-play-state: paused;
  margin-top: 0.75rem;
  margin-bottom: 2rem;
}
#screen-title.entry-ready .entry-tagline {
  animation-play-state: running;
}

.entry-start-btn {
  opacity: 0;
  animation: menuItemSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) 0.9s both;
  animation-play-state: paused;
  font-size: 1.5rem;
  padding: 1rem 3.5rem;
}
#screen-title.entry-ready .entry-start-btn {
  animation-play-state: running;
}

.entry-hint {
  font-size: 0.75rem;
  color: var(--color-text-dim);
  opacity: 0;
  animation: titleTaglineFade 0.6s ease 1.2s forwards;
  animation-play-state: paused;
  margin-top: 1rem;
}
#screen-title.entry-ready .entry-hint {
  animation-play-state: running;
}

/* ── Preload progress bar (shown inside entry gate after tap) ──── */
.preload-bar-track {
  width: min(80%, 18rem);
  height: 0.375rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin: 0 auto;
}
.preload-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--color-btn-primary) 0%, #66aaff 100%);
  border-radius: 3px;
  transition: width 0.15s ease-out;
}
.preload-label {
  color: var(--color-text-dim);
  font-size: 0.75rem;
  text-align: center;
  margin-top: 0.5rem;
  letter-spacing: 0.0625rem;
}

/* Hold all title content invisible until logo image has loaded */
#screen-title .title-hero,
#screen-title .title-buttons {
  visibility: hidden;
}
#screen-title.title-ready .title-hero,
#screen-title.title-ready .title-buttons {
  visibility: visible;
}

/* Atmospheric particle layer behind content — plays immediately */
#screen-title .title-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
#screen-title .title-particle {
  position: absolute;
  width: 0.25rem;
  height: 0.25rem;
  border-radius: 50%;
  background: rgba(68, 136, 255, 0.5);
}

.title-hero {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: calc(2rem + env(safe-area-inset-top));
  margin-bottom: 1rem;
}

/* Logo image — cinematic entrance, paused until .title-ready */
.title-logo-img {
  display: block;
  width: 14rem;
  max-width: 80vw;
  height: auto;
  opacity: 0;
  animation: titleLogoReveal 1.2s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-play-state: paused;
}
#screen-title.title-ready .title-logo-img {
  animation-play-state: running;
}

/* Shimmer sweeps across the logo — masked to logo pixel shape */
.title-logo-wrap {
  position: relative;
  display: flex;
  line-height: 0;
  /* Float + glow live on the wrapper so the ::after shimmer moves with the logo */
  animation: titleLogoFloat 4s ease-in-out 1.5s infinite,
             titleGlow 3s ease-in-out 1.5s infinite;
  animation-play-state: paused;
}
#screen-title.title-ready .title-logo-wrap {
  animation-play-state: running;
}
.title-logo-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 35%,
    rgba(255, 255, 255, 0.2) 45%,
    rgba(255, 255, 255, 0.08) 55%,
    transparent 65%
  );
  background-size: 200% 100%;
  /* Mask to logo shape — shimmer only appears on opaque logo pixels */
  -webkit-mask-image: url('../assets/logo.webp');
  mask-image: url('../assets/logo.webp');
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  animation: titleShimmerBar 3.5s ease-in-out 2s infinite;
  animation-play-state: paused;
  pointer-events: none;
}
#screen-title.title-ready .title-logo-wrap::after {
  animation-play-state: running;
}

.title-tagline {
  font-size: 0.875rem;
  color: var(--color-text-dim);
  letter-spacing: 0.0625rem;
  opacity: 0;
  animation: titleTaglineFade 0.8s ease 0.8s forwards;
  animation-play-state: paused;
  margin-top: 0.5rem;
}
#screen-title.title-ready .title-tagline {
  animation-play-state: running;
}

/* Divider line with glow */
.title-divider {
  width: 6rem;
  height: 0.125rem;
  margin: 0.75rem auto 0;
  background: linear-gradient(90deg, transparent, var(--color-btn-primary), transparent);
  opacity: 0;
  animation: titleTaglineFade 0.6s ease 1s forwards;
  animation-play-state: paused;
}
#screen-title.title-ready .title-divider {
  animation-play-state: running;
}

.title-buttons {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  max-width: 17.5rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Each button animates in with stagger — delay set via inline style */
.title-buttons .btn {
  display: flex;
  width: 100%;
  text-align: center;
  box-sizing: border-box;
  margin: 0;
  opacity: 0;
  animation: menuItemSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-play-state: paused;
}
#screen-title.title-ready .title-buttons .btn {
  animation-play-state: running;
}

.title-user {
  font-size: 0.8125rem;
  color: var(--color-text-dim);
  margin-top: 0.625rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  width: 100%;
  opacity: 0;
  animation: menuItemSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-play-state: paused;
}
#screen-title.title-ready .title-user {
  animation-play-state: running;
}

.title-version {
  font-size: 0.6875rem;
  color: var(--color-text-dim);
  opacity: 0.4;
  text-align: center;
  margin-top: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  letter-spacing: 0.05rem;
}

/* ── Auth Screen ─────────────────────────────────────── */

.auth-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.625rem;
  margin-top: 1.25rem;
  max-width: 17.5rem;
  margin-left: auto;
  margin-right: auto;
}

.auth-form .btn {
  display: flex;
  width: 100%;
  text-align: center;
  box-sizing: border-box;
  margin: 0;
  border-width: 2px;
}

.auth-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--color-panel);
  border: 2px solid var(--color-border);
  color: var(--color-text);
  font-family: var(--font-pixel);
  font-size: 1rem;
  outline: none;
  min-height: 2.75rem;
  box-sizing: border-box;
}
.auth-input:focus { border-color: var(--color-btn-primary); }

/* ── Settings Screen ─────────────────────────────────── */

.settings-list {
  text-align: left;
  margin: 1.25rem 0;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.625rem 0;
  border-bottom: 2px solid var(--color-panel);
  color: var(--color-text);
  font-size: 0.9375rem;
}

.settings-row > span {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.settings-account {
  margin-top: 1.75rem;
  padding-top: 0.875rem;
  border-top: 2px solid var(--color-panel);
}

/* ── Volume Slider (shared by Settings + Pause) ──────── */

.settings-volume-row {
  padding: 0.25rem 0 0.625rem;
  gap: 0.625rem;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 2.75rem;        /* 44px touch target */
  background: transparent;
  cursor: pointer;
  margin: 0;
}

/* ── Track ── */
.volume-slider::-webkit-slider-runnable-track {
  height: 0.375rem;
  background: var(--color-panel);
  border: 2px solid var(--color-border);
}
.volume-slider::-moz-range-track {
  height: 0.375rem;
  background: var(--color-panel);
  border: 2px solid var(--color-border);
}

/* ── Thumb ── */
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: -0.5rem;     /* center on track: -(thumb-track)/2 */
  background: var(--color-btn-primary);
  border: 3px solid rgba(255,255,255,0.2);
  border-bottom-color: rgba(0,0,0,0.3);
  border-right-color: rgba(0,0,0,0.3);
  cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 1.25rem;
  height: 1.25rem;
  background: var(--color-btn-primary);
  border: 3px solid rgba(255,255,255,0.2);
  border-bottom-color: rgba(0,0,0,0.3);
  border-right-color: rgba(0,0,0,0.3);
  border-radius: 0;
  cursor: pointer;
}

.volume-slider:active::-webkit-slider-thumb {
  transform: scale(1.15);
}
.volume-slider:active::-moz-range-thumb {
  transform: scale(1.15);
}

.volume-label {
  min-width: 2.75rem;
  text-align: right;
  font-size: 0.8125rem;
  color: var(--color-text-dim);
  font-variant-numeric: tabular-nums;
}

/* ── Leaderboard Screen ──────────────────────────────── */

.lb-list {
  margin-top: 0.875rem;
  text-align: left;
}

.lb-entry {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.625rem;
  border-bottom: 2px solid var(--color-panel);
  color: var(--color-text-dim);
  font-size: 0.875rem;
}
.lb-entry.lb-me { background: var(--color-surface); color: var(--color-fruit); }

.lb-rank {
  width: 1.75rem;
  font-weight: 700;
  color: var(--color-text-dim);
}
.lb-alias { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: #fff; }

/* ── Treasure Screen ─────────────────────────────────── */

.treasure-grid {
  text-align: left;
  margin-top: 0.625rem;
}

.treasure-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0;
  border-bottom: 2px solid var(--color-panel);
}

.treasure-level {
  width: 2.125rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--color-text-dim);
}

.treasure-star {
  font-size: 1.25rem;
  color: #443366;
}
.treasure-star.found { color: #FFD700; }

/* ── Animation / Splash Slots ────────────────────────── */

.animation-slot {
  position: absolute;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
}
.animation-slot[hidden] { display: none; }
.animation-slot.fullscreen {
  background: rgba(10,5,20,0.85);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.animation-slot.banner { bottom: auto; height: 30%; background: rgba(10,5,20,0.8); }

/* ── Title Meta (coin counter + language toggle) ──── */

.title-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0.5rem auto 0.75rem;
  max-width: 17.5rem;
  padding: 0 1.25rem;
  opacity: 0;
  animation: menuItemSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) 0.28s forwards;
  animation-play-state: paused;
}
#screen-title.title-ready .title-meta {
  animation-play-state: running;
}

.title-wallet {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--color-coin);
  font-size: 1rem;
  font-weight: 700;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.4);
}
.title-wallet .pxicon {
  filter: brightness(0) saturate(100%) invert(75%) sepia(60%) saturate(500%) hue-rotate(10deg);
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.625rem;
  background: var(--color-btn-secondary);
  color: var(--color-text);
  border: 2px solid var(--color-border);
  font-family: var(--font-pixel);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.05rem;
  min-height: 2rem;
  touch-action: manipulation;
  transition: transform 0.05s;
}
.lang-toggle:active {
  transform: translateY(2px);
}

/* ── Dedication Line ──────────────────────────────── */

.dedication-line {
  font-size: 0.75rem;
  color: var(--color-text-dim);
  opacity: 0;
  animation: titleTaglineFade 0.8s ease 1.4s forwards;
  animation-play-state: paused;
  margin-top: 1.25rem;
  cursor: pointer;
  letter-spacing: 0.03rem;
  transition: color 0.2s;
}
.dedication-line:hover {
  color: var(--color-fruit);
}

/* Entry gate dedication — paused until .entry-ready */
#screen-title.entry-ready .dedication-line {
  animation-play-state: running;
}
/* Title screen dedication — paused until .title-ready */
.title-dedication {
  animation-delay: 0.9s;
  text-align: center;
}
#screen-title.title-ready .title-dedication {
  animation-play-state: running;
}

/* ── Dedication Overlay ───────────────────────────── */

.dedication-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 5, 20, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.dedication-overlay[hidden] { display: none; }

.dedication-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.dedication-content {
  position: relative;
  max-width: 20rem;
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--color-text);
  font-family: var(--font-pixel);
  z-index: 1;
}

.dedication-title {
  font-size: 1.75rem;
  color: #fff;
  margin-bottom: 1.25rem;
  text-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  letter-spacing: 0.1rem;
}

.dedication-body {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--color-text);
  margin-bottom: 1.5rem;
  opacity: 0.9;
}

.dedication-signoff {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-fruit);
  margin-bottom: 1.5rem;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.4);
}

.dedication-close-btn {
  margin: 0 auto;
}

/* ── Install Prompt ─────────────────────────────────── */

/* Hide install button when running as installed PWA */
@media (display-mode: standalone), (display-mode: fullscreen) {
  .btn-install { display: none !important; }
}

.install-steps {
  text-align: left;
  margin-bottom: 1.5rem;
}

.install-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-btn-primary);
  margin-bottom: 0.5rem;
  letter-spacing: 0.05rem;
}

.install-step {
  font-size: 0.875rem;
  color: var(--color-text);
  line-height: 1.6;
  padding: 0.125rem 0;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.install-share-icon {
  display: inline-block;
  vertical-align: middle;
  width: 1rem;
  height: 1rem;
}

.install-divider {
  width: 4rem;
  height: 0.125rem;
  margin: 0.75rem 0;
  background: linear-gradient(90deg, transparent, var(--color-border), transparent);
}
