:root {
  --primary: #8a2be2;
  --secondary: #ff007f;
  --bg-dark: #0f0c29;
  --bg-mid: #302b63;
  --bg-light: #24243e;
  --text: #ffffff;
  --text-muted: #b0b0b0;
  --card-bg: rgba(20, 20, 35, 0.85);
  --success: #00e676;
  --warning: #ffea00;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Cairo', sans-serif;
}

body {
  background: linear-gradient(135deg, var(--bg-dark), var(--bg-mid), var(--bg-light));
  background-size: 400% 400%;
  animation: gradientBG 15s ease infinite;
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

@keyframes gradientBG {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Background animated shapes */
.background-animation {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  overflow: hidden;
  z-index: -1;
}

.shape {
  position: absolute;
  filter: blur(80px);
  opacity: 0.5;
  border-radius: 50%;
  animation: float 10s infinite alternate ease-in-out;
}

.shape-1 { width: 300px; height: 300px; background: var(--primary); top: -100px; left: -100px; }
.shape-2 { width: 400px; height: 400px; background: var(--secondary); bottom: -150px; right: -100px; animation-delay: -5s; }
.shape-3 { width: 250px; height: 250px; background: #00ffff; top: 50%; left: 50%; transform: translate(-50%, -50%); animation: float2 12s infinite alternate ease-in-out; }

@keyframes float {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(50px) scale(1.1); }
}
@keyframes float2 {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-40%, -60%) rotate(20deg) scale(1.2); }
}

/* Screens */
.screen {
  display: none;
  width: 100%;
  height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Login Screen */
#login-screen {
  justify-content: center;
  align-items: center;
}

.login-card {
  background: var(--card-bg);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 40px;
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  text-align: center;
  width: 90%;
  max-width: 400px;
  animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(50px); }
  to { opacity: 1; transform: translateY(0); }
}

.logo {
  margin-bottom: 30px;
}
.logo i {
  font-size: 50px;
  color: var(--secondary);
  margin-bottom: 10px;
  text-shadow: 0 0 20px var(--secondary);
}
.logo h1 {
  font-weight: 900;
  font-size: 2.5rem;
}
.logo span {
  color: var(--primary);
  text-shadow: 0 0 10px var(--primary);
}

input[type="text"] {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1.1rem;
  margin-bottom: 20px;
  outline: none;
  text-align: center;
  border: 2px solid transparent;
  transition: border-color 0.3s;
}
input[type="text"]:focus {
  border-color: var(--primary);
}

.btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.btn:active { transform: scale(0.95); }

.btn.primary {
  background: linear-gradient(45deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: 0 5px 15px rgba(255, 0, 127, 0.4);
}
.btn.primary:hover { box-shadow: 0 8px 25px rgba(255, 0, 127, 0.6); }

.btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}
.btn.secondary:hover { background: rgba(255, 255, 255, 0.2); }

.divider {
  margin: 20px 0;
  position: relative;
  text-align: center;
}
.divider::before {
  content: '';
  position: absolute;
  top: 50%; left: 0; width: 100%; height: 1px;
  background: rgba(255,255,255,0.1);
}
.divider span {
  background: var(--bg-dark);
  padding: 0 10px;
  position: relative;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.error-text {
  color: #ff4d4d;
  margin-top: 15px;
  font-size: 0.9rem;
  min-height: 20px;
}

/* Game Screen */
#game-screen {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  padding: 15px 30px;
  border-radius: 15px;
  margin-bottom: 20px;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.room-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
#displayRoomCode {
  color: var(--warning);
  font-size: 1.5rem;
  letter-spacing: 2px;
}
#btnCopyCode {
  background: none; border: none; color: white; cursor: pointer; font-size: 1.2rem;
  transition: color 0.3s;
}
#btnCopyCode:hover { color: var(--primary); }

.game-info {
  display: flex;
  align-items: center;
  gap: 30px;
}

.word-display {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 5px;
  text-shadow: 0 0 10px rgba(255,255,255,0.5);
}

.timer {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: bold;
  background: rgba(255,255,255,0.1);
  padding: 5px 15px;
  border-radius: 10px;
  color: var(--success);
}
.timer.danger { color: #ff4d4d; animation: pulse 1s infinite; }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }

.main-game-area { box-sizing: border-box; width: 100%; max-width: 1200px;
  display: flex;
  gap: 20px;
  height: calc(100vh - 120px);
}

/* Players List */
.players-list { 
  width: 20%; flex: none;
  display: flex; flex-direction: column;
  background: var(--card-bg);
  border-radius: 15px;
  padding: 20px;
  border: 1px solid rgba(255,255,255,0.1);
  overflow-y: auto;
}
.players-list h3 { margin-bottom: 15px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 10px; }
.players-list ul { list-style: none; }
.players-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  transition: background 0.3s;
}
.players-list li.drawing {
  background: rgba(138, 43, 226, 0.3);
  border-left: 4px solid var(--primary);
}
.players-list li.correct {
  background: rgba(0, 230, 118, 0.2);
  border-left: 4px solid var(--success);
}

/* Canvas Area */
.canvas-container { 
  width: 55%; flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tools-bar {
  display: flex;
  justify-content: space-between;
  background: var(--card-bg);
  padding: 10px 20px;
  border-radius: 15px;
  border: 1px solid rgba(255,255,255,0.1);
}

.tool-group { display: flex; gap: 10px; align-items: center; }

.tool-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 40px; height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: 0.3s;
}
.tool-btn:hover { background: rgba(255,255,255,0.2); }
.tool-btn.active { background: var(--primary); box-shadow: 0 0 10px var(--primary); }
.tool-btn.action { color: #ff4d4d; }
.tool-btn.action:hover { background: rgba(255, 77, 77, 0.2); }

.color-swatch {
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.5);
  transition: transform 0.2s;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border: 2px solid white; transform: scale(1.2); box-shadow: 0 0 10px white; }

#customColorPicker {
  width: 30px; height: 30px;
  border: none; padding: 0;
  border-radius: 50%; cursor: pointer;
  overflow: hidden;
}

.canvas-wrapper { min-width: 0; min-height: 0;
  flex: 1;
  background: white;
  border-radius: 15px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  cursor: crosshair;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.overlay-message {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  text-align: center;
  opacity: 1;
  transition: opacity 0.5s;
}
.overlay-message.hidden {
  opacity: 0;
  pointer-events: none;
}
#overlayText {
  font-size: 3rem;
  color: var(--warning);
  text-shadow: 0 0 20px var(--warning);
  animation: bounce 1s infinite alternate;
}
@keyframes bounce { from { transform: scale(1); } to { transform: scale(1.1); } }

/* Chat Container */
.chat-container {
  width: 25%; flex: none;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-radius: 15px;
  border: 1px solid rgba(255,255,255,0.1);
  overflow: hidden;
}

.chat-messages { min-height: 0;
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  background: rgba(255,255,255,0.05);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  word-wrap: break-word;
}
.chat-msg span { font-weight: bold; color: var(--primary); }
.sys-msg { background: rgba(0, 230, 118, 0.1); color: var(--success); font-weight: bold; text-align: center; }

.chat-input-area {
  display: flex;
  padding: 10px;
  background: rgba(0,0,0,0.2);
}
.chat-input-area input {
  margin-bottom: 0;
  border-radius: 0 10px 10px 0; /* Right side for Arabic RTL */
  flex: 1;
  min-width: 0;
}
.chat-input-area button {
  width: 50px;
  flex: none;
  background: var(--primary);
  border: none;
  color: white;
  border-radius: 10px 0 0 10px; /* Left side for Arabic RTL */
  cursor: pointer;
  transition: 0.3s;
}
.chat-input-area button:hover { background: var(--secondary); }

/* Prevent tools usage for non-drawer */
.disabled-tools {
  opacity: 0.5;
  pointer-events: none;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  body {
    height: auto;
    min-height: 100vh;
    padding: 5px;
    align-items: flex-start;
  }
  
  .logo h1 { font-size: 1.8rem; }
  
  #game-screen {
    padding: 5px;
  }
  
  .top-bar {
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    margin-bottom: 10px;
  }
  
  .word-display { font-size: 1.2rem; letter-spacing: 2px; }
  .timer { font-size: 1.2rem; }
  
  .main-game-area { box-sizing: border-box; width: 100%; max-width: 1200px;
    flex-direction: column;
    height: auto;
    gap: 10px;
  }
  
  .players-list { min-width: 0; min-height: 0;
    flex: none;
    width: 100%;
    max-height: 120px;
    padding: 10px;
  }
  .players-list li { padding: 5px; font-size: 0.9rem; }
  
  .canvas-container { min-width: 0;
    flex: none;
    width: 100%;
    height: 400px; /* Fixed height for canvas on mobile */
  }
  
  .tools-bar {
    flex-wrap: wrap;
    justify-content: center;
    padding: 5px;
    gap: 5px;
  }
  .tool-group { flex-wrap: wrap; justify-content: center; gap: 5px; }
  .tool-btn { width: 35px; height: 35px; font-size: 1rem; }
  .color-swatch { width: 25px; height: 25px; }
  #customColorPicker { width: 25px; height: 25px; }
  
  .chat-container { min-width: 0;
    flex: none;
    width: 100%;
    height: 300px;
  }
  
  #overlayText {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .canvas-container { min-width: 0; height: 350px; }
  .chat-container { min-width: 0; height: 250px; }
}
