/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Base ───────────────────────────────────────────────────── */
/* Page backdrop: near-black with a faint grid, plus a scattered
   star sparkles layer (see .starfield, populated by stars.js). */
body {
  background-color: #05060b;
  background-image: url('assets/grid.svg');
  background-repeat: repeat;
  background-size: 50%;
  color: #e8f4ff;
  font-family: 'Courier New', 'Consolas', monospace;
  height: 100vh;
  overflow: hidden;
  position: relative;
  width: 100vw;
  scrollbar-width: thin;
  scrollbar-color: var(--tebex-purple) var(--store-surface);
}

/* Star sparkles layer behind the panel */
.starfield {
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  position: fixed;
  z-index: 0;
}

.star {
  animation: twinkle 3.5s ease-in-out infinite;
  filter: drop-shadow(0 0 4px currentColor);
  position: absolute;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50%      { opacity: 0.95; transform: scale(1.1); }
}

/* Scanlines overlay */
body::after {
  content: '';
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: 100;
}

/* ── Fog ────────────────────────────────────────────────────── */
.fog-container {
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  position: fixed;
  z-index: 1;
}

.fog {
  animation: fog-drift 24s ease-in-out infinite;
  height: 200%;
  left: -50%;
  position: absolute;
  top: -50%;
  width: 200%;
}

.fog-1 {
  animation-duration: 28s;
  animation-delay: 0s;
  background:
    radial-gradient(ellipse 60% 40% at 40% 50%, rgba(0, 240, 255, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse 40% 60% at 70% 30%, rgba(255, 45, 146, 0.025) 0%, transparent 60%);
}

.fog-2 {
  animation-duration: 20s;
  animation-delay: -9s;
  background:
    radial-gradient(ellipse 50% 50% at 55% 55%, rgba(0, 240, 255, 0.03) 0%, transparent 65%),
    radial-gradient(ellipse 35% 45% at 25% 60%, rgba(255, 45, 146, 0.02) 0%, transparent 55%);
  opacity: 0.8;
}

.fog-3 {
  animation-duration: 35s;
  animation-delay: -18s;
  background:
    radial-gradient(ellipse 70% 30% at 30% 40%, rgba(0, 240, 255, 0.025) 0%, transparent 60%),
    radial-gradient(ellipse 45% 55% at 65% 70%, rgba(255, 45, 146, 0.015) 0%, transparent 50%);
  opacity: 0.6;
}

@keyframes fog-drift {
  0%   { transform: translate(0%,  0%)  rotate(0deg); }
  25%  { transform: translate(4%,  2%)  rotate(0.5deg); }
  50%  { transform: translate(2%,  5%)  rotate(-0.5deg); }
  75%  { transform: translate(-3%, 2%)  rotate(0.3deg); }
  100% { transform: translate(0%,  0%)  rotate(0deg); }
}

/* ── Screens ────────────────────────────────────────────────── */
.screen {
  align-items: center;
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 10;
}

.screen.hidden {
  display: none;
}

#screen-game {
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
}

canvas.game-canvas {
  display: block;
  height: 100%;
  width: 100%;
  /* image-rendering: crisp-edges */
}

#screen-form {
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1.5rem 1rem;
}

/* ── Form screen ────────────────────────────────────────────── */
/* The panel is centred; the knight peeks out from behind its right edge. */
.form-layout {
  align-items: center;
  display: flex;
  justify-content: center;
  position: relative;
}

.form-stack {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  width: 100%;
}

.form-main {
  margin: 0 auto;
  max-width: 100%;
  position: relative;
  width: fit-content;
}

/* ── Leaderboard (matches canvas round-end panel) ─────────── */
.lb-panel {
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  background: rgba(8, 11, 22, 0.94);
  border-radius: 10px;
  font-family: 'Courier New', 'Consolas', monospace;
  max-width: 460px;
  width: 100%;
}

/* Subtle border glow around the form area */
.lb-panel::before {
  border: 1px solid rgba(0, 240, 255, 0.1);
  border-radius: 4px;
  box-shadow:
    0 0 40px rgba(0, 240, 255, 0.04),
    inset 0 0 40px rgba(0, 0, 0, 0.4);
  content: '';
  inset: 0;
  pointer-events: none;
  position: absolute;
}

.lb-title {
  color: rgba(0, 240, 255, 0.65);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 0;
  padding: 10px 0 6px;
  text-align: center;
  text-transform: uppercase;
}

.lb-list {
  list-style: none;
  margin: 0;
  padding: 0 0 10px;
}

.lb-row {
  align-items: center;
  display: grid;
  gap: 0 8px;
  grid-template-columns: 40px 1fr auto;
  min-height: 26px;
  padding: 0 22px 0 4px;
}

.lb-row-you {
  background: rgba(0, 240, 255, 0.1);
}

.lb-rank {
  color: rgba(232, 244, 255, 0.45);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.lb-rank-1 { color: #ffd23f; }
.lb-rank-2 { color: #c8d4e8; }
.lb-rank-3 { color: #cd7f32; }

.lb-name {
  color: #e8f4ff;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-row-you .lb-name {
  color: #ffffff;
  font-weight: 700;
}

.lb-score {
  color: #00f0ff;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.5);
  white-space: nowrap;
}

.lb-row-you .lb-score {
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.6);
}

.lb-empty {
  color: rgba(232, 244, 255, 0.35);
  font-size: 12px;
  padding: 8px 0 16px;
  text-align: center;
}

.hero-art {
  animation: hero-float 5s ease-in-out infinite;
  filter: drop-shadow(0 0 30px rgba(0, 240, 255, 0.35));
  height: min(76vh, 520px);
  position: absolute;
  right: -180px;       /* sticks out to the right of the panel */
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  z-index: 1;          /* behind the panel (form-container is z-index 2) */
}

/* Float keyframes preserve the vertical centring (translateY -50%). */
@keyframes hero-float {
  0%, 100% { transform: translateY(-50%); }
  50%      { transform: translateY(calc(-50% - 12px)); }
}

@media (max-width: 1024px) {
  .hero-art { display: none; }
}

.form-container {
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  background: rgba(8, 11, 22, 0.94);
  border-radius: 10px;
  max-width: 460px;
  padding: 2rem 2rem 2.5rem;
  position: relative;
  width: 100%;
  z-index: 2;          /* above the peeking hero */
}

/* Subtle border glow around the form area */
.form-container::before {
  border: 1px solid rgba(0, 240, 255, 0.1);
  border-radius: 4px;
  box-shadow:
    0 0 40px rgba(0, 240, 255, 0.04),
    inset 0 0 40px rgba(0, 0, 0, 0.4);
  content: '';
  inset: 0;
  pointer-events: none;
  position: absolute;
}

/* ── Logo ───────────────────────────────────────────────────── */
.logo {
  margin-bottom: 2.5rem;
  text-align: center;
}

.logo-text {
  animation: logo-pulse 3.5s ease-in-out infinite;
  color: #00f0ff;
  font-size: clamp(2.6rem, 8vw, 3.9rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1.05;
  margin-bottom: 0.6rem;
  text-shadow:
    0 0 8px #00f0ff,
    0 0 25px #00f0ff,
    0 0 55px rgba(0, 240, 255, 0.6),
    0 0 110px rgba(0, 240, 255, 0.3);
}

@keyframes logo-pulse {
  0%, 100% {
    text-shadow:
      0 0 8px #00f0ff,
      0 0 25px #00f0ff,
      0 0 55px rgba(0, 240, 255, 0.6),
      0 0 110px rgba(0, 240, 255, 0.3);
  }
  50% {
    text-shadow:
      0 0 12px #00f0ff,
      0 0 40px #00f0ff,
      0 0 80px rgba(0, 240, 255, 0.7),
      0 0 160px rgba(0, 240, 255, 0.25);
  }
}

.logo-tagline {
  color: rgba(232, 244, 255, 0.45);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.token-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 1rem;
}

.token-preview {
  display: block;
  height: 48px;
  width: 48px;
}

/* ── Form elements ──────────────────────────────────────────── */
form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

label {
  color: rgba(232, 244, 255, 0.45);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.required {
  color: #00f0ff;
}

.optional {
  color: rgba(232, 244, 255, 0.25);
  font-size: 0.68rem;
}

input {
  background: rgba(58, 61, 74, 0.35);
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 2px;
  color: #e8f4ff;
  font-family: inherit;
  font-size: 0.93rem;
  outline: none;
  padding: 0.6rem 0.8rem;
  transition: border-color 0.18s, box-shadow 0.18s;
  width: 100%;
}

input::placeholder {
  color: rgba(232, 244, 255, 0.18);
}

input:focus {
  border-color: rgba(0, 240, 255, 0.7);
  box-shadow:
    0 0 0 1px rgba(0, 240, 255, 0.2),
    0 0 10px rgba(0, 240, 255, 0.12);
}

input.invalid {
  border-color: rgba(255, 45, 146, 0.7);
  box-shadow:
    0 0 0 1px rgba(255, 45, 146, 0.2),
    0 0 10px rgba(255, 45, 146, 0.1);
}

/* ── Error box ──────────────────────────────────────────────── */
.form-error {
  background: rgba(255, 45, 146, 0.08);
  border: 1px solid rgba(255, 45, 146, 0.35);
  border-radius: 2px;
  color: #ff6bb3;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  text-align: center;
}

.form-error.hidden {
  display: none;
}

/* ── Submit button ──────────────────────────────────────────── */
.btn-primary {
  align-items: center;
  background: #00ff88;
  border: 1px solid #00ff88;
  border-radius: 2px;
  box-shadow:
    0 0 14px rgba(0, 255, 136, 0.38),
    inset 0 0 10px rgba(0, 255, 136, 0.08);
  color: #0a0e1a;
  cursor: pointer;
  display: flex;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  justify-content: center;
  letter-spacing: 0.22em;
  margin-top: 0.5rem;
  padding: 0.85rem 1.5rem;
  text-transform: uppercase;
  transition: background 0.18s, box-shadow 0.18s, border-color 0.18s, color 0.18s;
  width: 100%;
}

.btn-primary:hover:not(:disabled) {
  background: #00ffaa;
  border-color: #00ff88;
  box-shadow:
    0 0 24px rgba(0, 255, 136, 0.55),
    0 0 8px rgba(0, 255, 136, 0.4),
    inset 0 0 14px rgba(0, 255, 136, 0.1);
  color: #0a0e1a;
}

.btn-primary:active:not(:disabled) {
  background: #00dd77;
}

.btn-primary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-text.hidden,
.btn-spinner.hidden {
  display: none;
}

.btn-spinner {
  animation: spin 0.65s linear infinite;
  border: 2px solid rgba(0, 255, 136, 0.25);
  border-radius: 50%;
  border-top-color: #0a0e1a;
  display: inline-block;
  height: 16px;
  width: 16px;
}

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

/* ── Placeholder game screen ────────────────────────────────── */
.placeholder-container {
  text-align: center;
}

.placeholder-title {
  animation: logo-pulse 3.5s ease-in-out infinite;
  color: #00f0ff;
  font-size: 2.2rem;
  letter-spacing: 0.25em;
  margin-bottom: 0.6rem;
  text-shadow: 0 0 20px #00f0ff;
  text-transform: uppercase;
}

.placeholder-sub {
  color: rgba(232, 244, 255, 0.35);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
}

.placeholder-player {
  color: rgba(232, 244, 255, 0.55);
  font-size: 0.82rem;
  margin-top: 1.2rem;
}

/* ════════════════════════════════════════════════════════════════
   Tebex store pop-up (Phase 4)
   Brand styling based on tebex.io — Tebex purple on a dark surface,
   clean sans-serif, rounded cards and buttons. Sits above the game
   canvas; the Tebex.js checkout overlay renders above this in turn.
   ═══════════════════════════════════════════════════════════════ */
:root {
  --tebex-purple:       #5532FA;
  --tebex-purple-hover: #6E54FF;
  --store-surface:      #15161F;
  --store-card:         #20212E;
  --store-card-hover:   #272838;
  --store-border:       rgba(255, 255, 255, 0.08);
  --store-text:         #ffffff;
  --store-muted:        #9b9eb2;
  --store-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.store-overlay {
  align-items: center;
  background: rgba(6, 7, 14, 0.74);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 1.5rem;
  position: fixed;
  z-index: 200;
  animation: store-fade 0.2s ease-out;
}

.store-overlay.hidden { display: none; }

@keyframes store-fade { from { opacity: 0; } to { opacity: 1; } }

.store-modal {
  background: var(--store-surface);
  border: 1px solid var(--store-border);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(85, 50, 250, 0.12);
  color: var(--store-text);
  display: flex;
  flex-direction: column;
  font-family: var(--store-sans);
  max-height: 86vh;
  max-width: 780px;
  position: relative;
  width: 100%;
  animation: store-pop 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}

@keyframes store-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ── Close button ─────────────────────────────────────────────── */
.store-close {
  align-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: none;
  border-radius: 50%;
  color: var(--store-muted);
  cursor: pointer;
  display: flex;
  font-size: 1.5rem;
  height: 34px;
  justify-content: center;
  line-height: 1;
  position: absolute;
  right: 16px;
  top: 16px;
  transition: background 0.15s, color 0.15s;
  width: 34px;
}

.store-close:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }

/* ── Header ────────────────────────────────────────────────────── */
.store-header {
  border-bottom: 1px solid var(--store-border);
  padding: 1.6rem 1.8rem 1.3rem;
}

.store-brand { align-items: center; display: flex; gap: 0.75rem; }

.store-logo-img {
  display: block;
  height: 30px;
  width: auto;
}

.store-divider {
  background: var(--store-border);
  height: 22px;
  width: 1px;
}

.store-title {
  color: var(--store-muted);
  font-size: 1rem;
  font-weight: 600;
}

.store-tagline {
  color: var(--store-muted);
  font-size: 0.88rem;
  margin-top: 0.5rem;
}

/* ── Body ──────────────────────────────────────────────────────── */
.store-body {
  overflow-y: auto;
  padding: 1.4rem 1.8rem;
}

.pkg-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

/* ── Package card ─────────────────────────────────────────────── */
.pkg-card {
  background: var(--store-card);
  border: 1px solid var(--store-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}

.pkg-card:hover {
  background: var(--store-card-hover);
  border-color: rgba(85, 50, 250, 0.5);
  transform: translateY(-3px);
}

.pkg-img {
  background-color: #11121a;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  width: 100%;
  aspect-ratio: 16 / 10;
}

.pkg-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.9rem 1rem 0.5rem;
}

.pkg-name {
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
}

.pkg-desc {
  color: var(--store-muted);
  display: -webkit-box;
  font-size: 0.82rem;
  line-height: 1.4;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.pkg-buy {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 1rem 1rem;
}

.pkg-price {
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
}

.pkg-btn {
  background: var(--tebex-purple);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  transition: background 0.15s, transform 0.1s;
}

.pkg-btn:hover:not(:disabled) { background: var(--tebex-purple-hover); }
.pkg-btn:active:not(:disabled) { transform: scale(0.96); }
.pkg-btn:disabled { cursor: default; opacity: 0.65; }

/* ── Loading / error states ───────────────────────────────────── */
.store-state {
  align-items: center;
  color: var(--store-muted);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  justify-content: center;
  min-height: 200px;
  text-align: center;
}

.store-state--error p { color: #ff8aa8; max-width: 320px; }

.store-spinner {
  animation: spin 0.7s linear infinite;
  border: 3px solid rgba(85, 50, 250, 0.25);
  border-radius: 50%;
  border-top-color: var(--tebex-purple);
  height: 34px;
  width: 34px;
}

.store-retry {
  background: var(--tebex-purple);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 1.4rem;
}

.store-retry:hover { background: var(--tebex-purple-hover); }

/* ── Footer ────────────────────────────────────────────────────── */
.store-footer {
  border-top: 1px solid var(--store-border);
  padding: 0.9rem 1.8rem;
  text-align: center;
}

.store-secure {
  color: var(--store-muted);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}
