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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #fff;
  touch-action: none;
  overscroll-behavior: none;
}

/* Screens */
.screen {
  display: none;
  width: 100%;
  height: 100%;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Back Button */
.back-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  background: #0f3460;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  z-index: 100;
  transition: background 0.2s;
}

.back-btn:hover {
  background: #1a4a7a;
}

/* Matchmaking Screen */
#matchmaking {
  align-items: center;
  justify-content: center;
}

.matchmaking-content {
  text-align: center;
  max-width: 400px;
  padding: 20px;
}

.matchmaking-content h1 {
  font-size: 3rem;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #e94560 0%, #ff6b6b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.matchmaking-content .subtitle {
  color: #7f8c8d;
  margin-bottom: 40px;
  font-size: 1.1rem;
}

.matchmaking-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.matchmaking-form input {
  background: #0f3460;
  color: white;
  border: 2px solid #4ecca3;
  padding: 14px 20px;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  width: 100%;
  max-width: 280px;
  text-align: center;
  -webkit-appearance: none;
}

.matchmaking-form input::placeholder {
  color: #7f8c8d;
}

.matchmaking-form input:focus {
  outline: none;
  border-color: #e94560;
}

.primary-btn {
  background: linear-gradient(135deg, #e94560 0%, #ff6b6b 100%);
  color: white;
  border: none;
  padding: 14px 40px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 20px rgba(233, 69, 96, 0.4);
}

.primary-btn:active {
  transform: scale(0.98);
}

.queue-status {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: #4ecca3;
}

.queue-status.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(78, 204, 163, 0.3);
  border-top-color: #4ecca3;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.cancel-btn {
  background: transparent;
  color: #7f8c8d;
  border: 1px solid #7f8c8d;
  padding: 8px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.cancel-btn:hover {
  color: #e94560;
  border-color: #e94560;
}

/* Game Screen */
#game {
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: rgba(15, 52, 96, 0.6);
  border-radius: 12px;
  margin-bottom: 15px;
}

.player-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-info.player-opponent {
  text-align: right;
  align-items: flex-end;
}

.player-name {
  font-weight: 600;
  font-size: 14px;
  color: #fff;
}

.vs-divider {
  padding: 0 20px;
  font-weight: 700;
  color: #e94560;
  font-size: 18px;
}

.score-bar {
  width: 100%;
  max-width: 200px;
  height: 24px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.score-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4ecca3 0%, #6fe8bd 100%);
  border-radius: 12px;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(78, 204, 163, 0.5);
}

.score-fill.opponent {
  background: linear-gradient(90deg, #e94560 0%, #ff6b6b 100%);
  box-shadow: 0 0 10px rgba(233, 69, 96, 0.5);
}

.score-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Game Content */
.game-content {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 10px;
  min-height: 0;
}

.canvas-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.canvas-label {
  font-size: 12px;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.canvas-container canvas {
  background: #0f3460;
  border: 2px solid #4ecca3;
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none;
}

.canvas-container.blueprint canvas {
  border-color: #e94560;
  cursor: default;
}

/* Palette */
.palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 15px;
  padding: 15px;
  background: rgba(15, 52, 96, 0.6);
  border-radius: 12px;
}

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

.palette-label {
  font-size: 12px;
  color: #7f8c8d;
  text-transform: uppercase;
}

.shape-buttons {
  display: flex;
  gap: 6px;
}

.shape-btn {
  width: 40px;
  height: 40px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.shape-btn:hover {
  border-color: #4ecca3;
}

.shape-btn.active {
  border-color: #4ecca3;
  background: rgba(78, 204, 163, 0.2);
}

.shape-preview {
  background: #4ecca3;
}

.shape-preview.square.small { width: 12px; height: 12px; }
.shape-preview.square.medium { width: 18px; height: 18px; }
.shape-preview.square.large { width: 24px; height: 24px; }

.shape-preview.triangle {
  width: 0;
  height: 0;
  background: transparent;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 12px solid #4ecca3;
}
.shape-preview.triangle.medium {
  border-left-width: 9px;
  border-right-width: 9px;
  border-bottom-width: 18px;
}
.shape-preview.triangle.large {
  border-left-width: 12px;
  border-right-width: 12px;
  border-bottom-width: 24px;
}

.shape-preview.circle { border-radius: 50%; }
.shape-preview.circle.small { width: 12px; height: 12px; }
.shape-preview.circle.medium { width: 18px; height: 18px; }
.shape-preview.circle.large { width: 24px; height: 24px; }

.rotation-section {
  gap: 8px;
}

.rotation-slider {
  width: 100px;
  -webkit-appearance: none;
  height: 6px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 3px;
  outline: none;
}

.rotation-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: #4ecca3;
  border-radius: 50%;
  cursor: pointer;
}

.rotation-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #4ecca3;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

#rotationValue {
  width: 30px;
  text-align: right;
  font-size: 12px;
  color: #4ecca3;
}

.action-btn {
  background: #0f3460;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s;
}

.action-btn:hover {
  background: #1a4a7a;
}

/* Overlays */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(26, 26, 46, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.overlay.hidden {
  display: none;
}

.countdown-number {
  font-size: 10rem;
  font-weight: 700;
  color: #e94560;
  animation: pulse 1s ease infinite;
  text-shadow: 0 0 40px rgba(233, 69, 96, 0.5);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.result-content {
  text-align: center;
  padding: 40px;
  background: rgba(15, 52, 96, 0.8);
  border-radius: 20px;
  border: 2px solid #4ecca3;
}

.result-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 30px;
  background: linear-gradient(135deg, #4ecca3 0%, #6fe8bd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-title.lost {
  background: linear-gradient(135deg, #e94560 0%, #ff6b6b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-scores {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 30px;
}

.result-score {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-name {
  font-size: 14px;
  color: #7f8c8d;
}

.result-value {
  font-size: 2rem;
  font-weight: 700;
  color: #4ecca3;
}

/* Responsive */
@media (max-width: 900px) {
  .game-content {
    flex-direction: column;
  }

  .canvas-container canvas {
    width: 300px;
    height: 300px;
  }

  .game-header {
    padding: 8px 15px;
  }

  .score-bar {
    max-width: 150px;
    height: 20px;
  }
}

@media (max-width: 600px) {
  .matchmaking-content h1 {
    font-size: 2rem;
  }

  .canvas-container canvas {
    width: 250px;
    height: 250px;
  }

  .palette {
    flex-direction: column;
    gap: 10px;
  }

  .shape-buttons {
    flex-wrap: wrap;
    justify-content: center;
  }

  .shape-btn {
    width: 36px;
    height: 36px;
  }

  .vs-divider {
    padding: 0 10px;
    font-size: 14px;
  }

  .player-name {
    font-size: 12px;
  }

  .score-bar {
    max-width: 100px;
    height: 18px;
  }

  .result-title {
    font-size: 2rem;
  }

  .result-scores {
    gap: 20px;
  }

  .result-value {
    font-size: 1.5rem;
  }
}

/* Prevent pull-to-refresh on mobile */
@supports (-webkit-overflow-scrolling: touch) {
  html, body {
    -webkit-overflow-scrolling: touch;
  }
}
