/* =============================================
   FLIP CHALLENGE - PREMIUM CSS
   ============================================= */

:root {
  --bg-dark: #080810;
  --bg-card: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-bg: rgba(255, 255, 255, 0.04);
  --accent: #ef4444;
  --accent-light: #f87171;
  --accent-glow: rgba(239, 68, 68, 0.3);
  --success: #22c55e;
  --gold: #fbbf24;
  --text: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.55);
  --text-muted: rgba(255, 255, 255, 0.35);
  --radius: 16px;
  --radius-sm: 12px;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Back Home Button */
.back-home-btn {
  position: fixed;
  top: max(15px, env(safe-area-inset-top));
  left: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  z-index: 1000;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.back-home-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
  transform: translateX(-3px);
}

.back-home-btn svg {
  flex-shrink: 0;
}

/* =============================================
   UTILITY CLASSES
   ============================================= */
.glass-effect {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* =============================================
   SCREEN SYSTEM
   ============================================= */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  background: var(--bg-dark);
}

.screen.active {
  display: flex;
}

/* =============================================
   MENU SCREEN
   ============================================= */
#loginScreen {
  justify-content: flex-start;
  align-items: center;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 10%, rgba(239, 68, 68, 0.1) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(100, 100, 180, 0.05) 0%, transparent 40%),
    var(--bg-dark);
}

.menu-container {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: auto;
}

/* Hero */
.hero {
  text-align: center;
  padding: 10px 0 20px;
}

.hero-icon-wrapper {
  position: relative;
  display: inline-block;
  margin-bottom: 16px;
}

.hero-glow {
  position: absolute;
  width: 100px;
  height: 100px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.6;
  }

  50% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0.3;
  }
}

.hero-icon {
  font-size: 4rem;
  position: relative;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0) rotate(-3deg);
  }

  50% {
    transform: translateY(-10px) rotate(3deg);
  }
}

h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
}

h1 .accent {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 6px;
  color: var(--accent);
  margin-top: 6px;
}

.tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 10px;
  letter-spacing: 1px;
}

/* Cards */
.card {
  border-radius: var(--radius);
  padding: 18px;
}

/* Input */
input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
  transition: 0.2s;
  margin-bottom: 12px;
}

input::placeholder {
  color: var(--text-muted);
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

/* Primary Button */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 18px 24px;
  background: linear-gradient(135deg, var(--accent), #dc2626);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow:
    0 6px 0 #991b1b,
    0 8px 25px var(--accent-glow);
}

.btn-primary svg {
  width: 20px;
  height: 20px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #991b1b, 0 12px 35px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #991b1b, 0 4px 15px var(--accent-glow);
}

/* Selectors */
.selector-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.selector-box {
  border-radius: var(--radius);
  padding: 14px;
}

.selector-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-align: center;
}

.selector-scroll {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) rgba(255, 255, 255, 0.1);
  justify-items: center;
}

.selector-scroll::-webkit-scrollbar {
  width: 6px;
}

.selector-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.selector-scroll::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 3px;
}

.selector-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--accent-light);
}

.sel-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 12px 8px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;
}

.sel-item span {
  font-size: 1.4rem;
}

.sel-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text);
}

.sel-item.active {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 20px var(--accent-glow);
}

/* Leaderboard */
.leaderboard {
  padding: 0;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
}

.trophy-icon {
  font-size: 1rem;
}

#top5List {
  list-style: none;
  padding: 8px;
}

#top5List li {
  display: flex;
  align-items: center;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: 0.15s;
}

#top5List li:not(.loading):hover {
  background: rgba(255, 255, 255, 0.03);
}

#top5List li.loading {
  justify-content: center;
  color: var(--text-muted);
}

.rank-num {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--glass-border);
  margin-right: 12px;
}

.rank-1 .rank-num {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #000;
}

.rank-2 .rank-num {
  background: linear-gradient(135deg, #9ca3af, #6b7280);
  color: #000;
}

.rank-3 .rank-num {
  background: linear-gradient(135deg, #cd7f32, #a0522d);
  color: #fff;
}

#top5List .name {
  flex: 1;
}

#top5List .pts {
  font-weight: 700;
  color: var(--accent-light);
}

/* =============================================
   GAME SCREEN
   ============================================= */
#gameScreen {
  flex-direction: column;
}

/* Game HUD */
.game-hud {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  z-index: 100;
  pointer-events: none;
}

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

.game-hud.top {
  top: 0;
  padding-top: max(20px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(8, 8, 16, 0.95) 0%, rgba(8, 8, 16, 0.5) 70%, transparent 100%);
  min-height: 90px;
}

.game-hud.bottom {
  bottom: 0;
  padding: 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  flex-direction: column;
  gap: 18px;
  background: linear-gradient(to top, rgba(8, 8, 16, 0.98) 0%, rgba(8, 8, 16, 0.85) 50%, transparent 100%);
}

/* HUD Buttons - BIGGER */
.hud-btn {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 30, 0.8);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  transition: 0.2s;
  backdrop-filter: blur(10px);
}

.hud-btn svg {
  width: 22px;
  height: 22px;
}

.hud-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.hud-btn.exit:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--accent);
  color: var(--accent);
}

.hud-group {
  display: flex;
  gap: 12px;
}

/* Score Panel */
.score-panel {
  background: rgba(8, 8, 16, 0.9);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 14px 36px;
  text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.combo-text {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--success);
  min-height: 18px;
}

.score-value {
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, #fff, var(--accent-light));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.score-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 4px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Canvas */
.game-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Floating Message */
.floating-message {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  font-size: 3rem;
  font-weight: 800;
  text-shadow: 0 4px 40px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.floating-message.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Power Bar - Compact Centered */
.power-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.power-bar-track {
  width: 100%;
  height: 16px;
  background: rgba(20, 20, 30, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
  box-shadow:
    inset 0 3px 6px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.3);
}

.power-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg,
      #22c55e 0%,
      #84cc16 30%,
      #fbbf24 60%,
      #f97316 80%,
      #ef4444 100%);
  border-radius: 8px;
  transition: width 0.05s linear;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
}

.power-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Flip Button - Premium */
.flip-button {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  height: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: linear-gradient(180deg, #ef4444 0%, #dc2626 50%, #b91c1c 100%);
  border: none;
  border-radius: 14px;
  color: white;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s ease;
  position: relative;
  box-shadow:
    0 6px 0 #7f1d1d,
    0 6px 20px rgba(239, 68, 68, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.flip-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.15), transparent);
  border-radius: 14px 14px 0 0;
  pointer-events: none;
}

.flip-text {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.flip-hint {
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.8;
  letter-spacing: 1px;
}

.flip-button:hover {
  background: linear-gradient(180deg, #f87171 0%, #ef4444 50%, #dc2626 100%);
  box-shadow:
    0 6px 0 #7f1d1d,
    0 10px 30px rgba(239, 68, 68, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.flip-button:active,
.flip-button.pressing {
  transform: translateY(4px);
  box-shadow:
    0 2px 0 #7f1d1d,
    0 4px 10px rgba(239, 68, 68, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, #dc2626 0%, #b91c1c 50%, #991b1b 100%);
}

.flip-button:disabled {
  background: linear-gradient(180deg, #374151 0%, #1f2937 100%);
  box-shadow: 0 3px 0 #111827;
  color: rgba(255, 255, 255, 0.4);
  cursor: not-allowed;
  transform: translateY(4px);
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 480px) {
  .hero-icon {
    font-size: 3.5rem;
  }

  h1 {
    font-size: 2rem;
  }

  h1 .accent {
    font-size: 0.8rem;
    letter-spacing: 4px;
  }

  .card {
    padding: 14px;
  }

  input {
    padding: 14px;
  }

  .btn-primary {
    padding: 16px 20px;
  }

  .sel-item {
    padding: 10px 8px;
  }

  .selector-scroll {
    grid-template-columns: repeat(3, 1fr);
    max-height: 150px;
  }

  .sel-item span {
    font-size: 1.2rem;
  }

  .hud-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }

  .score-panel {
    padding: 10px 22px;
  }

  .score-value {
    font-size: 2.2rem;
  }

  .flip-button {
    height: 70px;
  }

  .flip-text {
    font-size: 1.1rem;
  }

  .floating-message {
    font-size: 2.4rem;
  }
}

@media (max-height: 680px) {
  .hero {
    padding: 0 0 12px;
  }

  .hero-icon {
    font-size: 3rem;
  }

  .hero-glow {
    width: 80px;
    height: 80px;
  }

  h1 {
    font-size: 1.8rem;
  }

  .menu-container {
    gap: 12px;
  }

  .card {
    padding: 12px;
  }

  input {
    padding: 12px;
    margin-bottom: 10px;
  }

  .btn-primary {
    padding: 14px;
  }

  .selector-box {
    padding: 10px;
  }

  .selector-label {
    margin-bottom: 8px;
  }

  .sel-item {
    padding: 8px 6px;
  }

  .selector-scroll {
    grid-template-columns: repeat(3, 1fr);
    max-height: 130px;
  }

  .flip-button {
    height: 64px;
  }
}