/* ============================================
   AirPunch - Styles
   Dark, minimal, bold. Mobile-first.
   ============================================ */

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

:root {
  --bg: #000000;
  --bg-subtle: #141414;
  --accent: #ff2d2d;
  --accent-glow: rgba(255, 45, 45, 0.4);
  --text: #ffffff;
  --text-muted: #666666;
  --text-dim: #444444;
  --success: #22c55e;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: #000000;
}

/* --- Screens --- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  z-index: 10;
}

.screen-content {
  width: 100%;
  max-width: 400px;
  padding: 2rem 1.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

/* --- Landing --- */
.punch-illustration {
  display: block;
  margin: -0.5rem auto 0.5rem;
  opacity: 0.9;
}

.punch-illustration.small {
  margin: 0 auto;
}

.brand {
  margin-bottom: 0.5rem;
}

.logo {
  font-size: 3.5rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
}

.logo .accent {
  color: var(--accent);
}

.tagline {
  margin-top: 0.75rem;
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 400;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* --- Buttons --- */
.btn {
  display: block;
  width: 100%;
  padding: 1rem 2rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  min-height: 56px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--text);
  box-shadow: 0 0 30px var(--accent-glow);
}

.btn-primary:active {
  opacity: 0.9;
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--text-dim);
}

.btn-secondary:active {
  background: var(--bg-subtle);
}

/* --- Permission Denied --- */
.error-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  color: var(--accent);
}

.instructions {
  background: var(--bg-subtle);
  border-radius: var(--radius);
  padding: 1rem;
  width: 100%;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.instructions strong {
  color: var(--text);
}

/* --- Countdown --- */
.countdown-label {
  font-size: 1.2rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.countdown-number {
  font-size: 10rem;
  font-weight: 900;
  line-height: 1;
  color: var(--text);
  transition: transform 0.15s ease;
  will-change: transform, opacity;
}

.countdown-number.pulse {
  animation: countdownPulse 0.6s ease-out;
}

.countdown-number.punch-text {
  font-size: 4rem;
  color: var(--accent);
  text-shadow: 0 0 40px var(--accent-glow);
}

.countdown-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  max-width: 250px;
}

@keyframes countdownPulse {
  0% { transform: scale(1.3); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Detecting --- */
.detecting-ring {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  animation: detectPulse 0.8s ease-in-out infinite;
  will-change: transform, opacity;
  position: absolute;
}

.detecting-text {
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-glow);
  z-index: 2;
}

.live-g {
  font-size: 1.2rem;
  color: var(--text-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  z-index: 2;
  margin-top: 1rem;
}

@keyframes detectPulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 1; }
}

/* --- Result --- */
.result-score {
  font-size: 8rem;
  font-weight: 900;
  line-height: 1;
  color: var(--text);
  will-change: transform, opacity;
  font-variant-numeric: tabular-nums;
}

.result-score.animate-in {
  animation: scoreReveal 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.result-g {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.result-tier {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.result-message {
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--text-muted);
}

.result-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.input-name {
  width: 100%;
  padding: 0.9rem 1rem;
  border: 1px solid var(--text-dim);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s ease;
}

.input-name:focus {
  border-color: var(--accent);
}

.input-name::placeholder {
  color: var(--text-dim);
}

@keyframes scoreReveal {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Shockwave --- */
.shockwave {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
}

.shockwave.active {
  animation: shockwaveExpand 0.7s ease-out forwards;
  border: 4px solid var(--accent);
}

@keyframes shockwaveExpand {
  0% { transform: scale(0); opacity: 1; border-width: 6px; }
  100% { transform: scale(4); opacity: 0; border-width: 1px; }
}

/* --- Leaderboard --- */
.leaderboard-title {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 0.5rem;
}

.leaderboard-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-subtle);
  border-radius: var(--radius);
  width: 100%;
}

.leaderboard-entry.highlight {
  border: 1px solid var(--accent);
  box-shadow: 0 0 15px rgba(255, 45, 45, 0.15);
}

.leaderboard-rank {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-dim);
  min-width: 28px;
  text-align: center;
}

.leaderboard-entry:nth-child(1) .leaderboard-rank { color: #ffd700; }
.leaderboard-entry:nth-child(2) .leaderboard-rank { color: #c0c0c0; }
.leaderboard-entry:nth-child(3) .leaderboard-rank { color: #cd7f32; }

.leaderboard-name {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-score-val {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.leaderboard-empty {
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 2rem 0;
  display: none;
}

.leaderboard-empty.visible {
  display: block;
}

/* --- Home Leaderboard --- */
.home-leaderboard {
  width: 100%;
  margin-top: 0.75rem;
  display: none;
}

.home-leaderboard.visible {
  display: block;
}

.home-leaderboard-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.home-leaderboard .leaderboard-entry {
  padding: 0.55rem 0.75rem;
}

.home-leaderboard .leaderboard-rank {
  font-size: 0.85rem;
  min-width: 24px;
}

.home-leaderboard .leaderboard-name {
  font-size: 0.85rem;
}

.home-leaderboard .leaderboard-score-val {
  font-size: 0.95rem;
}

/* --- Landing screen scrollable for leaderboard --- */
#screen-landing {
  overflow-y: auto;
  align-items: flex-start;
  -webkit-overflow-scrolling: touch;
}

#screen-landing .screen-content {
  padding-top: 3rem;
  padding-bottom: 3rem;
  min-height: 100%;
  justify-content: center;
}

/* --- Landscape Warning --- */
.landscape-warning {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 2rem;
  text-align: center;
}

.landscape-warning p {
  font-size: 1.2rem;
  color: var(--text-muted);
}

@media (orientation: landscape) and (max-height: 500px) {
  .landscape-warning {
    display: flex;
  }
}

/* --- Punch Active Lock --- */
html.punch-active {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

html.punch-active body {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .detecting-ring {
    animation: none;
    opacity: 0.5;
  }
}

/* --- Safe area padding for notched phones --- */
@supports (padding: env(safe-area-inset-top)) {
  .screen-content {
    padding-top: calc(2rem + env(safe-area-inset-top));
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
  }
}
