:root {
  --bg: linear-gradient(135deg, #f8fafc 0%, #e0f2fe 50%, #fdf4ff 100%);
  --ink: #1e293b;
  --muted: #64748b;
  --accent: #ef233c;
  --accent-2: #c1121f;
  --panel: rgba(255, 255, 255, 0.9);
  --line: #e2e8f0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #f8fafc 0%, #e0f2fe 50%, #fdf4ff 100%);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: center;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  width: min(1200px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; gap: 12px; align-items: center; }

.logo-wrap {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.logo-wrap.fallback::after {
  content: "X1";
  font-weight: 700;
  color: var(--accent);
  font-size: 14px;
}

.logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.title { 
  font-weight: 700; 
  font-size: 20px;
  color: var(--ink);
}

.subtitle { 
  font-size: 12px; 
  color: var(--muted); 
}

.actions { display: flex; gap: 10px; align-items: center; }

.backpack-hint {
  font-size: 11px;
  color: var(--muted);
}

.stage { 
  max-width: 1200px; 
  margin: 20px auto; 
  padding: 0 16px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 20px;
  align-items: start;
}

.main-panel { display: grid; gap: 16px; }
.side-panel { display: grid; gap: 16px; }

.canvas-wrap {
  position: relative;
  border: 3px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
  overflow: hidden;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.12), 
    0 0 0 1px rgba(255, 255, 255, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  aspect-ratio: 16 / 9;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 2;
}

.hud-compact {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  flex: 1;
}

.hud-chip {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s, box-shadow 0.2s;
}

/* Special styling for X1X minted chip */
.x1x-chip {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(255, 165, 0, 0.1));
  border-color: rgba(255, 165, 0, 0.3);
}

.x1x-chip .value {
  color: #b45309;
}

/* Pulse animation for HUD when values change */
.hud-overlay.pulse .hud-chip {
  animation: chipPulse 0.3s ease;
}

@keyframes chipPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.wallet-chip { min-width: 140px; }

.label { 
  font-size: 10px; 
  color: var(--muted); 
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.value { 
  font-family: "JetBrains Mono", monospace; 
  font-size: 16px; 
  font-weight: 600;
  color: var(--ink);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-align: center;
  z-index: 3;
}

.overlay-title { 
  font-size: 32px; 
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 2px 4px rgba(239, 35, 60, 0.2);
}

.overlay-subtitle { 
  color: var(--muted); 
  font-size: 15px;
  margin-top: 6px;
  letter-spacing: 0.02em;
}

.overlay-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status { 
  color: var(--muted); 
  font-size: 13px;
  padding: 8px 12px;
  background: #f1f5f9;
  border-radius: 8px;
}

.daily-banner {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  display: inline-block;
}

.hint { 
  font-size: 12px; 
  color: var(--muted);
  line-height: 1.6;
  background: rgba(255, 255, 255, 0.7);
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.hint code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.token-note {
  font-size: 12px;
  color: var(--muted);
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* Instructions list */
.instructions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.instruction-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink);
}

.instruction-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.leaderboard { display: grid; gap: 6px; }

.lb-pill {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.8);
  font-family: "JetBrains Mono", monospace;
  transition: background 0.15s ease;
}

.lb-pill:first-child {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(255, 165, 0, 0.1));
  border-color: rgba(255, 165, 0, 0.3);
}

.btn {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.15s ease, opacity 0.2s ease, box-shadow 0.15s ease;
}

.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.primary { 
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 12px rgba(239, 35, 60, 0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}

.primary:hover:not(:disabled) { 
  background: linear-gradient(135deg, var(--accent-2), #a00f1f);
  box-shadow: 0 6px 16px rgba(239, 35, 60, 0.4);
  transform: translateY(-1px);
}

.secondary { 
  background: #f1f5f9;
  color: var(--ink);
}

/* Vegas-style Claim Button */
.claim-highlight {
  background: linear-gradient(135deg, #ffd700 0%, #ff8c00 50%, #ffd700 100%);
  background-size: 200% 200%;
  color: #1c1917;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 2px solid #ffaa00;
  box-shadow: 
    0 0 20px rgba(255, 165, 0, 0.5),
    0 0 40px rgba(255, 165, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  animation: vegasGlow 2s ease-in-out infinite, shimmer 3s linear infinite;
  position: relative;
  overflow: hidden;
}

.claim-highlight::before {
  content: "🎰";
  margin-right: 6px;
}

.claim-highlight::after {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    transparent 30%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 70%
  );
  animation: shine 3s ease-in-out infinite;
}

.claim-highlight:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 
    0 0 30px rgba(255, 165, 0, 0.7),
    0 0 60px rgba(255, 165, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.claim-highlight:disabled {
  animation: none;
  background: #94a3b8;
  border-color: #64748b;
  box-shadow: none;
}

.claim-highlight:disabled::before {
  content: "";
}

.claim-highlight:disabled::after {
  display: none;
}

@keyframes vegasGlow {
  0%, 100% { box-shadow: 0 0 20px rgba(255, 165, 0, 0.5), 0 0 40px rgba(255, 165, 0, 0.3); }
  50% { box-shadow: 0 0 30px rgba(255, 215, 0, 0.8), 0 0 60px rgba(255, 165, 0, 0.5); }
}

@keyframes shimmer {
  0% { background-position: 200% center; }
  100% { background-position: -200% center; }
}

@keyframes shine {
  0%, 100% { transform: translateX(-100%) rotate(45deg); }
  50% { transform: translateX(100%) rotate(45deg); }
}

/* Claiming overlay - blocks game during claim */
.claiming-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}

.claiming-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(255, 215, 0, 0.3);
  border-top-color: #ffd700;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.claiming-text {
  color: #ffd700;
  font-size: 18px;
  font-weight: 600;
  margin-top: 16px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.claiming-subtext {
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  margin-top: 8px;
}

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

.pill { 
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  background: #fff;
}

.side-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.side-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.card-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-item {
  padding: 8px;
  background: #f8fafc;
  border-radius: 8px;
  text-align: center;
}

.stat-item .value { font-size: 14px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.hidden { display: none !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side-panel { 
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
  .hud-compact { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .topbar-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
  .actions { width: 100%; justify-content: space-between; }
  .canvas-wrap { aspect-ratio: 4 / 3; }
}

body.portrait .canvas-wrap { aspect-ratio: 9 / 16; height: 75vh; }
body.portrait .side-panel { display: none; }
body.portrait .hud-compact { grid-template-columns: 1fr 1fr; }
body.portrait .score-chip, body.portrait .jumps-chip { display: none; }

/* Reward notification - Vegas celebration style */
.reward-notify {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 24px;
  background: linear-gradient(135deg, #ffd700 0%, #ff8c00 50%, #ffd700 100%);
  background-size: 200% 200%;
  color: #1c1917;
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 
    0 4px 20px rgba(255, 165, 0, 0.5),
    0 0 40px rgba(255, 215, 0, 0.3);
  z-index: 100;
  opacity: 0;
  animation: rewardFadeIn 0.3s ease forwards, shimmer 2s linear infinite;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.reward-notify.fade-out {
  animation: rewardFadeOut 0.5s ease forwards;
}

@keyframes rewardFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes rewardFadeOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ═══════════════════════════════════════════════════════════ */
/* TOUCH CONTROLS                                              */
/* ═══════════════════════════════════════════════════════════ */
.touch-controls {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px;
  pointer-events: none;
  z-index: 20;
}
.touch-controls.hidden { display: none; }
.touch-dpad {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.touch-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.8);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  cursor: pointer;
}
.touch-btn:active {
  background: rgba(127, 255, 110, 0.3);
  border-color: rgba(127, 255, 110, 0.6);
}
.touch-jump {
  width: 72px;
  height: 72px;
  font-size: 24px;
}

/* Wave/timer/core HUD chips */
.wave-chip .value { color: #7fff6e; }
.timer-chip .value { font-family: 'JetBrains Mono', monospace; }
.core-chip .value { color: #ffd700; }
