/* ==========================================================================
   TOUCHDUEL - NEON STRIKE CSS DESIGN SYSTEM
   ========================================================================== */

/* Reset & Mobile Constraints */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

:root {
  --bg-dark: #05060a;
  --bg-surface: #0a0d16;
  --bg-surface-raised: #101524;
  
  --p1-cyan: #00f3ff;
  --p1-glow: rgba(0, 243, 255, 0.5);
  --p1-glow-subtle: rgba(0, 243, 255, 0.15);
  
  --p2-magenta: #ff0077;
  --p2-glow: rgba(255, 0, 119, 0.5);
  --p2-glow-subtle: rgba(255, 0, 119, 0.15);
  
  --neon-white: #ffffff;
  --neon-red: #ff1e42;
  --neon-red-glow: rgba(255, 30, 66, 0.65);
  --text-muted: #646f8c;
  --border-subtle: rgba(255, 255, 255, 0.12);
  
  --font-display: 'Orbitron', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Rajdhani', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: #ffffff;
  font-family: var(--font-body);
  touch-action: none;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
}

/* Fullscreen Game Canvas Container */
#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
  background-color: var(--bg-dark);
  overflow: hidden;
}

/* Subtle Cyber Grid Overlay */
.grid-overlay {
  position: absolute;
  inset: 0;
  background-size: 36px 36px;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  pointer-events: none;
  z-index: 1;
}

/* Center Horizontal Divider */
.center-divider {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  transform: translateY(-50%);
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(0, 243, 255, 0.85) 30%, 
    rgba(255, 255, 255, 0.95) 50%, 
    rgba(255, 0, 119, 0.85) 70%, 
    transparent 100%
  );
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.4);
  z-index: 20;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* ==========================================================================
   GAMEPLAY HALVES
   ========================================================================== */
.player-half {
  flex: 1;
  height: 50%;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: background-color 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
  overflow: hidden;
  border: 4px solid transparent;
  padding: env(safe-area-inset-top, 14px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 14px) env(safe-area-inset-left, 16px);
}

/* Mirrored Player 1 (Top Half) */
#player1 {
  transform: rotate(180deg);
  border-bottom: 2px solid rgba(0, 243, 255, 0.2);
}

/* Normal Player 2 (Bottom Half) */
#player2 {
  border-top: 2px solid rgba(255, 0, 119, 0.2);
}

.half-content {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  width: 100%;
  max-width: 480px;
  pointer-events: none;
}

/* Half Headers */
.half-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 8px 16px 0;
}

.player-tag {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#player1 .player-tag, .p1-text {
  color: var(--p1-cyan);
  text-shadow: 0 0 10px var(--p1-glow);
}

#player2 .player-tag, .p2-text {
  color: var(--p2-magenta);
  text-shadow: 0 0 10px var(--p2-glow);
}

/* Score Dots */
.score-container {
  display: flex;
  gap: 8px;
  align-items: center;
}

.score-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid #2e3547;
  background: rgba(0, 0, 0, 0.5);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#player1 .score-dot.active {
  background-color: var(--p1-cyan);
  border-color: var(--p1-cyan);
  box-shadow: 0 0 12px var(--p1-cyan);
  transform: scale(1.2);
}

#player2 .score-dot.active {
  background-color: var(--p2-magenta);
  border-color: var(--p2-magenta);
  box-shadow: 0 0 12px var(--p2-magenta);
  transform: scale(1.2);
}

/* Center Display Text */
.main-status-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: 10px;
}

.status-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 7vw, 2.8rem);
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  line-height: 1.1;
  margin-bottom: 6px;
}

.status-subtitle {
  font-family: var(--font-body);
  font-size: clamp(1rem, 3.8vw, 1.3rem);
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.reaction-time-badge {
  display: inline-block;
  margin-top: 12px;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 5.5vw, 2.2rem);
  font-weight: 800;
  padding: 4px 20px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  letter-spacing: 1px;
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.reaction-time-badge.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Countdown Number Animation */
.countdown-number {
  font-family: var(--font-display);
  font-size: clamp(4.5rem, 18vw, 7.5rem);
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.85);
  animation: pulse-countdown 0.95s ease-out infinite;
  line-height: 1;
}

@keyframes pulse-countdown {
  0% { transform: scale(1.3); opacity: 0.5; }
  50% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.8; }
}

.half-footer {
  padding-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.35);
  text-transform: uppercase;
}

/* ==========================================================================
   FULLSCREEN OVERLAYS (Initialization, Start, Match Over)
   ========================================================================== */
.center-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 30;
  background: rgba(5, 6, 10, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: opacity 0.3s ease, visibility 0.3s ease;
  padding: 12px;
}

.center-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-split-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  max-width: 480px;
}

.overlay-top-half {
  transform: rotate(180deg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  padding: 10px 0;
}

.overlay-bottom-half {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  padding: 10px 0;
}

/* Typography & Titles */
.game-logo {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 6.5vw, 2.6rem);
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(135deg, var(--p1-cyan), #ffffff 50%, var(--p2-magenta));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.game-tagline {
  font-size: 0.9rem;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 12px;
  text-align: center;
}

/* ==========================================================================
   ARCADE INITIALS SELECTOR
   ========================================================================== */
.arcade-init-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: rgba(16, 21, 36, 0.7);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 14px 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  width: 100%;
  max-width: 380px;
}

.init-label {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.initials-slots-container {
  display: flex;
  gap: 14px;
  justify-content: center;
  align-items: center;
}

.letter-wheel-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.arrow-btn {
  width: 44px;
  height: 28px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: #ffffff;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.15s ease;
}

.arrow-btn:active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.92);
}

.letter-box {
  width: 52px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 900;
  background: rgba(5, 6, 10, 0.85);
  border: 2px solid #2a334a;
  border-radius: 10px;
  color: #ffffff;
  transition: all 0.2s ease;
  cursor: pointer;
  pointer-events: auto;
}

.letter-wheel-slot.active .letter-box {
  border-color: #ffffff;
  transform: scale(1.05);
}

#p1InitBox .letter-wheel-slot.active .letter-box {
  border-color: var(--p1-cyan);
  box-shadow: 0 0 18px var(--p1-glow);
  color: var(--p1-cyan);
}

#p2InitBox .letter-wheel-slot.active .letter-box {
  border-color: var(--p2-magenta);
  box-shadow: 0 0 18px var(--p2-glow);
  color: var(--p2-magenta);
}

.init-controls-row {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

.init-btn {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 10px 18px;
  border-radius: 25px;
  cursor: pointer;
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transition: all 0.2s ease;
}

.init-btn:active {
  transform: scale(0.95);
}

.ready-btn.confirmed {
  background: #00ff66 !important;
  color: #000 !important;
  border-color: #00ff66 !important;
  box-shadow: 0 0 18px rgba(0, 255, 102, 0.6);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.action-btn {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 3.8vw, 1.2rem);
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 13px 30px;
  border-radius: 40px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.action-btn:active {
  transform: scale(0.94);
}

.action-btn.btn-p1 {
  border-color: var(--p1-cyan);
  box-shadow: 0 0 24px var(--p1-glow);
}
.action-btn.btn-p1:active {
  background: var(--p1-cyan);
  color: #000;
}

.action-btn.btn-p2 {
  border-color: var(--p2-magenta);
  box-shadow: 0 0 24px var(--p2-glow);
}
.action-btn.btn-p2:active {
  background: var(--p2-magenta);
  color: #000;
}

.action-btn.btn-primary {
  background: linear-gradient(135deg, rgba(0, 243, 255, 0.25), rgba(255, 0, 119, 0.25));
  border: 2px solid #ffffff;
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.35);
}

/* Floating Controls */
.floating-controls {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(10, 13, 22, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  pointer-events: auto;
  box-shadow: 0 0 12px rgba(0,0,0,0.6);
  transition: all 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ==========================================================================
   GAME STATE VISUAL MODIFIERS
   ========================================================================== */

/* READY STATE */
.state-ready .status-title {
  color: #ffffff;
  text-shadow: 0 0 25px rgba(255, 255, 255, 0.85);
  animation: pulse-ready 0.8s alternate infinite;
}

@keyframes pulse-ready {
  0% { transform: scale(0.95); opacity: 0.8; }
  100% { transform: scale(1.05); opacity: 1; }
}

/* WAIT STATE (Screen Pitch Black) */
.state-wait #player1,
.state-wait #player2 {
  background-color: #000000 !important;
  border-color: transparent !important;
  box-shadow: none !important;
}
.state-wait .center-divider {
  opacity: 0;
}
.state-wait .half-content {
  opacity: 0;
}

/* STIMULUS FLASH */
.flash-active #player1,
.flash-active #player2 {
  background-color: var(--neon-white) !important;
  border-color: var(--neon-white) !important;
  box-shadow: inset 0 0 60px rgba(255, 255, 255, 1), 0 0 90px rgba(255, 255, 255, 0.9) !important;
}
.flash-active .half-content {
  opacity: 0;
}

/* WINNER HALF HIGHLIGHT */
.winner-p1 #player1 {
  border: 6px solid var(--p1-cyan) !important;
  box-shadow: inset 0 0 35px var(--p1-glow), 0 0 50px var(--p1-cyan) !important;
  background: radial-gradient(circle at center, rgba(0, 243, 255, 0.24) 0%, rgba(5, 6, 10, 0.9) 80%) !important;
}

.winner-p2 #player2 {
  border: 6px solid var(--p2-magenta) !important;
  box-shadow: inset 0 0 35px var(--p2-glow), 0 0 50px var(--p2-magenta) !important;
  background: radial-gradient(circle at center, rgba(255, 0, 119, 0.24) 0%, rgba(5, 6, 10, 0.9) 80%) !important;
}

/* FALSE START ERROR */
.false-start-p1 #player1 {
  background-color: rgba(255, 30, 66, 0.35) !important;
  border: 6px solid var(--neon-red) !important;
  box-shadow: inset 0 0 45px var(--neon-red-glow), 0 0 50px var(--neon-red) !important;
}

.false-start-p2 #player2 {
  background-color: rgba(255, 30, 66, 0.35) !important;
  border: 6px solid var(--neon-red) !important;
  box-shadow: inset 0 0 45px var(--neon-red-glow), 0 0 50px var(--neon-red) !important;
}

/* MATCH WINNER BANNER */
.match-winner-banner {
  font-family: var(--font-display);
  font-size: clamp(2rem, 7.5vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 6px;
  text-align: center;
  animation: pulse-winner 1s infinite alternate;
}

@keyframes pulse-winner {
  0% { transform: scale(0.98); opacity: 0.85; }
  100% { transform: scale(1.03); opacity: 1; }
}

/* PINCH RESET TOAST */
.pinch-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  padding: 10px 24px;
  border-radius: 30px;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 2px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
}

.pinch-toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Desktop Hint */
.desktop-hint {
  display: none;
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: 1px;
  z-index: 50;
  pointer-events: none;
  white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) {
  .desktop-hint {
    display: block;
  }
}
