@import url('./tokens.css');
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700;800&family=Inter:wght@400;500;600&display=swap');

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--gw-bg-dark);
  background-image: var(--gw-bg-radial);
  color: var(--gw-text-light);
  font-family: var(--gw-font-family);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  cursor: url('/assets/cursor.svg') 16 16, crosshair !important;
}

/* App Container */
#app-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: url('/assets/cursor.svg') 16 16, crosshair !important;
}

/* Canvas Element */
#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
  cursor: url('/assets/cursor.svg') 16 16, crosshair !important;
}

button, .btn, .icon-btn, .modal-close-btn, a {
  cursor: url('/assets/cursor.svg') 16 16, pointer !important;
}

/* HUD Header Bar */
.game-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gw-space-3) var(--gw-space-4);
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--gw-space-3));
  background: linear-gradient(180deg, rgba(10, 12, 20, 0.9) 0%, rgba(10, 12, 20, 0) 100%);
  pointer-events: none; /* Let clicks pass through to buttons/canvas */
}

.game-header > * {
  pointer-events: auto;
}

/* Branding Logo */
.brand-logo {
  display: flex;
  align-items: center;
  gap: var(--gw-space-2);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: var(--gw-text-light);
  text-decoration: none;
}

.brand-logo .logo-dot {
  width: 14px;
  height: 14px;
  border-radius: var(--gw-radius-full);
  background: var(--gw-brand-600);
  box-shadow: 0 0 12px var(--gw-brand-600);
  animation: pulseLogo 2s infinite ease-in-out;
}

@keyframes pulseLogo {
  0%, 100% { transform: scale(1); box-shadow: 0 0 10px var(--gw-brand-600); }
  50% { transform: scale(1.15); box-shadow: 0 0 18px var(--gw-brand-600); }
}

/* HUD Stat Indicators */
.hud-stats {
  display: flex;
  align-items: center;
  gap: var(--gw-space-4);
  background: var(--gw-surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--gw-line-glass);
  padding: var(--gw-space-2) var(--gw-space-4);
  border-radius: var(--gw-radius-full);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.hud-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gw-text-muted);
  font-weight: 600;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--gw-text-light);
}

.stat-value.highlight {
  color: var(--gw-neon-cyan);
  text-shadow: 0 0 8px rgba(0, 242, 254, 0.5);
}

/* Header Action Buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--gw-space-2);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--gw-radius-full);
  background: var(--gw-surface-glass);
  border: 1px solid var(--gw-line-glass);
  color: var(--gw-text-light);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all var(--gw-duration-sm) var(--gw-ease-in-out);
}

.icon-btn:hover {
  background: var(--gw-surface-glass-light);
  border-color: var(--gw-neon-cyan);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px) scale(0.95);
}

/* Modal System */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gw-space-4);
  background: rgba(5, 7, 12, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--gw-duration-md) var(--gw-ease-in-out);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--gw-surface-glass);
  border: 1px solid var(--gw-line-glass);
  border-radius: var(--gw-radius-xl);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  overflow: hidden;
  transform: scale(0.92) translateY(10px);
  transition: transform var(--gw-duration-md) var(--gw-ease-in-out);
}

.modal-overlay.active .modal-card {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gw-space-6) var(--gw-space-6) var(--gw-space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gw-text-light);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--gw-text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color var(--gw-duration-sm) var(--gw-ease-in-out);
}

.modal-close-btn:hover {
  color: var(--gw-brand-600);
}

.modal-body {
  padding: var(--gw-space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-body p {
  color: var(--gw-text-muted);
  line-height: 1.6;
  margin-bottom: var(--gw-space-4);
}

/* Leaderboard Top 10 High Scores Table */
.leaderboard-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 var(--gw-space-2);
}

.leaderboard-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--gw-text-muted);
  padding: var(--gw-space-2) var(--gw-space-3);
  letter-spacing: 0.06em;
}

.leaderboard-table th.text-right,
.leaderboard-table td.text-right {
  text-align: right;
}

.leaderboard-row {
  background: rgba(255, 255, 255, 0.03);
  transition: background var(--gw-duration-sm) var(--gw-ease-in-out);
}

.leaderboard-row td {
  padding: var(--gw-space-3);
  font-size: 0.95rem;
  font-weight: 600;
}

.leaderboard-row td:first-child {
  border-top-left-radius: var(--gw-radius-md);
  border-bottom-left-radius: var(--gw-radius-md);
}

.leaderboard-row td:last-child {
  border-top-right-radius: var(--gw-radius-md);
  border-bottom-right-radius: var(--gw-radius-md);
}

.leaderboard-row.rank-1 td {
  background: rgba(255, 184, 0, 0.12);
  color: var(--gw-neon-gold);
}

.leaderboard-row.rank-2 td {
  background: rgba(226, 232, 240, 0.1);
  color: #e2e8f0;
}

.leaderboard-row.rank-3 td {
  background: rgba(217, 119, 6, 0.1);
  color: #fb923c;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--gw-radius-full);
  background: rgba(255, 255, 255, 0.1);
  font-weight: 800;
  font-size: 0.8rem;
}

.rank-1 .rank-badge {
  background: var(--gw-neon-gold);
  color: #000;
  box-shadow: 0 0 12px rgba(255, 184, 0, 0.6);
}

.rank-2 .rank-badge {
  background: #cbd5e1;
  color: #000;
}

.rank-3 .rank-badge {
  background: #d97706;
  color: #fff;
}

/* Modal Footer & Buttons */
.modal-footer {
  padding: var(--gw-space-4) var(--gw-space-6) var(--gw-space-6);
  display: flex;
  gap: var(--gw-space-3);
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gw-space-2);
  padding: var(--gw-space-3) var(--gw-space-6);
  border-radius: var(--gw-radius-full);
  font-family: var(--gw-font-family);
  font-weight: 700;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  transition: all var(--gw-duration-sm) var(--gw-ease-in-out);
  text-decoration: none;
}

.btn-primary {
  background: var(--gw-brand-600);
  color: #fff;
  box-shadow: 0 4px 15px rgba(248, 76, 85, 0.4);
}

.btn-primary:hover {
  background: #ff5e67;
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(248, 76, 85, 0.6);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--gw-text-light);
  border: 1px solid var(--gw-line-glass);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* Instruction Cards on Start Screen */
.instruction-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gw-space-3);
  margin: var(--gw-space-4) 0;
}

.instruction-item {
  display: flex;
  align-items: flex-start;
  gap: var(--gw-space-3);
  background: rgba(255, 255, 255, 0.04);
  padding: var(--gw-space-3);
  border-radius: var(--gw-radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.instruction-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.instruction-text h4 {
  font-size: 0.95rem;
  color: var(--gw-text-light);
  margin-bottom: 2px;
}

.instruction-text p {
  font-size: 0.85rem;
  color: var(--gw-text-muted);
  margin-bottom: 0;
}

/* Floating Game Messages / Tap to Start Banner */
.floating-hud {
  position: absolute;
  bottom: var(--gw-space-8);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--gw-space-2);
  background: var(--gw-surface-glass);
  border: 1px solid var(--gw-line-glass);
  padding: var(--gw-space-2) var(--gw-space-6);
  border-radius: var(--gw-radius-full);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: pulseFloat 2.5s infinite ease-in-out;
}

@keyframes pulseFloat {
  0%, 100% { transform: translate(-50%, 0); opacity: 0.9; }
  50% { transform: translate(-50%, -6px); opacity: 1; }
}

.floating-hud.hidden {
  display: none;
}

/* Visual Background Flash & HUD Glow when Target is Met */
body.target-met-flash {
  animation: targetFlashBg 1.5s ease-out;
}

@keyframes targetFlashBg {
  0% { background-color: rgba(0, 230, 118, 0.4); }
  50% { background-color: rgba(0, 242, 254, 0.2); }
  100% { background-color: #0a0c14; }
}

.hud-stat-item.target-met .stat-value {
  color: #00e676 !important;
  text-shadow: 0 0 14px rgba(0, 230, 118, 0.9) !important;
  transform: scale(1.15);
  transition: all 0.3s ease;
}

@media (max-width: 480px) {
  .hud-stats {
    gap: var(--gw-space-2);
    padding: 6px 12px;
  }
  .stat-value {
    font-size: 0.95rem;
  }
  .stat-label {
    font-size: 0.58rem;
  }
}
