* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ===================================
   THEME VARIABLES
   =================================== */

:root {
  /* Light Mode (Default) */
  --bg-gradient-1: #667eea;
  --bg-gradient-2: #764ba2;
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.9);
  --accent-primary: #667eea;
  --accent-secondary: #764ba2;
  --glass-overlay: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.3);
  --input-bg: rgba(255, 255, 255, 0.1);
  --input-border: rgba(255, 255, 255, 0.3);
  --input-border-focus: rgba(255, 255, 255, 0.6);
  --input-bg-focus: rgba(255, 255, 255, 0.15);
  --button-primary-bg: #ffffff;
  --button-primary-text: #667eea;
  --button-primary-shadow: rgba(0, 0, 0, 0.2);
  --button-primary-shadow-hover: rgba(0, 0, 0, 0.3);
  --button-secondary-bg: rgba(255, 255, 255, 0.2);
  --button-secondary-text: #ffffff;
  --button-secondary-border: rgba(255, 255, 255, 0.5);
  --button-secondary-bg-hover: rgba(255, 255, 255, 0.3);
  --error-text: #ff6b6b;
  --error-bg: rgba(255, 107, 107, 0.2);
  --error-border: rgba(255, 107, 107, 0.4);
  --spinner-border: rgba(255, 255, 255, 0.3);
  --spinner-border-top: #ffffff;
  --game-canvas-bg: #000000;
  --overlay-bg: rgba(0, 0, 0, 0.7);
  --overlay-dot: #4ade80;
  --chat-received-bg: rgba(102, 126, 234, 0.3);
  --chat-sent-bg: rgba(76, 175, 80, 0.3);
  --chat-toggle-bg: rgba(102, 126, 234, 0.9);
  --chat-toggle-bg-hover: rgba(102, 126, 234, 1);
  --chat-send-bg: rgba(102, 126, 234, 0.8);
  --chat-send-bg-hover: rgba(102, 126, 234, 1);
  --tip-bg: rgba(255, 255, 255, 0.1);
  --text-shadow: rgba(0, 0, 0, 0.3);
  --placeholder-text: rgba(255, 255, 255, 0.5);
}

body.dark-mode {
  /* Dark Mode */
  --bg-gradient-1: #1a1625;
  --bg-gradient-2: #2d1b3d;
  --text-primary: #e8e6f0;
  --text-secondary: #b8b4c8;
  --accent-primary: #8b7fc7;
  --accent-secondary: #6b5fa0;
  --glass-overlay: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --input-bg: rgba(255, 255, 255, 0.08);
  --input-border: rgba(255, 255, 255, 0.15);
  --input-border-focus: rgba(255, 255, 255, 0.3);
  --input-bg-focus: rgba(255, 255, 255, 0.12);
  --button-primary-bg: #8b7fc7;
  --button-primary-text: #ffffff;
  --button-primary-shadow: rgba(0, 0, 0, 0.4);
  --button-primary-shadow-hover: rgba(0, 0, 0, 0.6);
  --button-secondary-bg: rgba(139, 127, 199, 0.2);
  --button-secondary-text: #e8e6f0;
  --button-secondary-border: rgba(139, 127, 199, 0.4);
  --button-secondary-bg-hover: rgba(139, 127, 199, 0.3);
  --error-text: #ff8a8a;
  --error-bg: rgba(255, 107, 107, 0.15);
  --error-border: rgba(255, 107, 107, 0.3);
  --spinner-border: rgba(255, 255, 255, 0.2);
  --spinner-border-top: #8b7fc7;
  --game-canvas-bg: #000000;
  --overlay-bg: rgba(0, 0, 0, 0.8);
  --overlay-dot: #4ade80;
  --chat-received-bg: rgba(139, 127, 199, 0.25);
  --chat-sent-bg: rgba(107, 95, 160, 0.25);
  --chat-toggle-bg: rgba(139, 127, 199, 0.8);
  --chat-toggle-bg-hover: rgba(139, 127, 199, 1);
  --chat-send-bg: rgba(139, 127, 199, 0.7);
  --chat-send-bg-hover: rgba(139, 127, 199, 0.9);
  --tip-bg: rgba(255, 255, 255, 0.05);
  --text-shadow: rgba(0, 0, 0, 0.5);
  --placeholder-text: rgba(255, 255, 255, 0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 100%);
  color: var(--text-primary);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  position: fixed;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.3s ease, color 0.3s ease;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* Screen Management */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
}

.screen.active {
  display: flex;
}

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

/* Typography */
h1 {
  font-size: 4rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  text-shadow: 0 4px 8px var(--text-shadow);
}

h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

.subtitle {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.tip {
  margin-top: 2rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Login Form */
.login-form {
  margin: 2rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

#nickname-input,
#password-input {
  padding: 1rem 1.5rem;
  font-size: 1.1rem;
  border: 2px solid var(--input-border);
  border-radius: 50px;
  background: var(--input-bg);
  color: var(--text-primary);
  text-align: center;
  width: 100%;
  max-width: 300px;
  transition: all 0.3s ease;
  outline: none;
}

#nickname-input::placeholder,
#password-input::placeholder {
  color: var(--placeholder-text);
}

#nickname-input:focus,
#password-input:focus {
  border-color: var(--input-border-focus);
  background: var(--input-bg-focus);
}

.error-message {
  color: var(--error-text);
  background: var(--error-bg);
  padding: 0.75rem 1.5rem;
  border-radius: 25px;
  font-size: 0.9rem;
  margin-top: 0.5rem;
  border: 1px solid var(--error-border);
}

.error-message.hidden {
  display: none;
}

/* Buttons */
.btn-primary,
.btn-secondary {
  padding: 1rem 2.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 0.5rem;
  min-width: 200px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn-primary {
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
  box-shadow: 0 4px 15px var(--button-primary-shadow);
}

.btn-primary:hover,
.btn-primary:active {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--button-primary-shadow-hover);
}

.btn-secondary {
  background: var(--button-secondary-bg);
  color: var(--button-secondary-text);
  border: 2px solid var(--button-secondary-border);
}

.btn-secondary:hover,
.btn-secondary:active {
  background: var(--button-secondary-bg-hover);
}

/* Spinner */
.spinner {
  width: 50px;
  height: 50px;
  margin: 2rem auto;
  border: 4px solid var(--spinner-border);
  border-top: 4px solid var(--spinner-border-top);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Game Screen */
#game-screen {
  background: var(--game-canvas-bg);
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  background: var(--game-canvas-bg);
  max-width: 100%;
  max-height: 100%;
  image-rendering: crisp-edges;
}

#touch-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Connection Indicator */
#connection-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--overlay-bg);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

#connection-indicator .dot {
  width: 8px;
  height: 8px;
  background: var(--overlay-dot);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#connection-indicator.hidden {
  display: none;
}

/* Game Over Screen */
.score-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  margin: 2rem 0;
  font-size: 1.5rem;
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-item .label {
  font-size: 0.9rem;
  opacity: 0.7;
  margin-bottom: 0.5rem;
}

.score-item .score {
  font-size: 3rem;
  font-weight: 800;
}

.score-divider {
  font-size: 2rem;
  opacity: 0.5;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
  h1 {
    font-size: 3rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .btn-primary,
  .btn-secondary {
    padding: 0.8rem 2rem;
    font-size: 1rem;
    min-width: 160px;
  }

  .score-item .score {
    font-size: 2.5rem;
  }

  #password-input {
    font-size: 1rem;
    padding: 0.8rem 1.2rem;
  }
}

/* Landscape Recommendation for Mobile */
@media (max-width: 768px) and (orientation: portrait) {
  .tip {
    background: var(--tip-bg);
    padding: 1rem;
    border-radius: 10px;
    font-size: 1rem;
  }
}

/* Prevent pull-to-refresh and other touch behaviors */
body {
  overscroll-behavior: none;
}

/* Handle safe areas on mobile devices (notch, etc.) */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* Player Names */
#player-names {
  position: absolute;
  top: 50px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  pointer-events: none;
}

.player-name {
  background: var(--overlay-bg);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
}

#your-name {
  text-align: left;
}

#opponent-name {
  text-align: right;
}

/* Chat */
#chat-container {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 400px;
  background: var(--overlay-bg);
  border-radius: 10px;
  padding: 10px;
  max-height: 200px;
  display: flex;
  flex-direction: column;
}

#chat-container.hidden {
  display: none;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 10px;
  max-height: 150px;
}

.chat-message {
  margin-bottom: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  word-wrap: break-word;
}

.chat-message.received {
  background: var(--chat-received-bg);
  text-align: left;
}

.chat-message.sent {
  background: var(--chat-sent-bg);
  text-align: right;
}

.chat-sender {
  font-weight: 600;
  margin-bottom: 2px;
  font-size: 0.75rem;
  opacity: 0.8;
}

#chat-input-container {
  display: flex;
  gap: 8px;
}

#chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--input-border);
  border-radius: 20px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}

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

#send-chat-btn {
  padding: 8px 16px;
  background: var(--chat-send-bg);
  border: none;
  border-radius: 20px;
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s ease;
}

#send-chat-btn:hover {
  background: var(--chat-send-bg-hover);
}

.chat-toggle {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--chat-toggle-bg);
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 15px var(--button-primary-shadow);
  transition: all 0.3s ease;
}

.chat-toggle:hover {
  transform: scale(1.1);
  background: var(--chat-toggle-bg-hover);
}

.chat-toggle.hidden {
  display: none;
}

/* Mobile adjustments for chat */
@media (max-width: 768px) {
  #chat-container {
    width: 95%;
    max-width: none;
  }
  
  #chat-input {
    font-size: 0.85rem;
  }
  
  .chat-message {
    font-size: 0.8rem;
  }
}

/* ===================================
   THEME TOGGLE
   =================================== */

#theme-toggle {
  position: fixed;
  top: 20px;
  left: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--button-secondary-bg);
  border: 2px solid var(--button-secondary-border);
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px var(--button-primary-shadow);
  z-index: 1000;
  -webkit-tap-highlight-color: transparent;
}

#theme-toggle:hover,
#theme-toggle:active {
  transform: scale(1.1);
  background: var(--button-secondary-bg-hover);
  box-shadow: 0 6px 20px var(--button-primary-shadow-hover);
}

#theme-toggle:active {
  transform: scale(0.95);
}

/* Icon styling */
.theme-icon {
  width: 24px;
  height: 24px;
  transition: transform 0.3s ease;
}

body.dark-mode #theme-toggle .theme-icon {
  transform: rotate(180deg);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  #theme-toggle {
    top: 15px;
    left: 15px;
    width: 45px;
    height: 45px;
    font-size: 1.3rem;
  }
}

/* Ensure toggle doesn't overlap with connection indicator on game screen */
#game-screen #theme-toggle {
  top: 10px;
  left: 10px;
}



html {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    var(--bg-gradient-1) 0%,
    var(--bg-gradient-2) 100%
  );
}
