/* ============ Color Palette ============ */
:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --secondary: #ec4899;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --dark: #1e293b;
  --light: #f8fafc;
  --gray: #64748b;
  --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
}

/* ============ Reset & Base ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Cairo', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: var(--dark);
  overflow-x: hidden;
  position: relative;
}

/* ============ Background Animation ============ */
.bg-animation {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.circle, .square {
  position: absolute;
  opacity: 0.1;
  animation: float-shapes 20s infinite ease-in-out;
}

.circle {
  border-radius: 50%;
  background: white;
}

.square {
  background: rgba(255,255,255,0.8);
  transform: rotate(45deg);
}

.circle:nth-child(1) {
  width: 200px;
  height: 200px;
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.circle:nth-child(2) {
  width: 150px;
  height: 150px;
  top: 60%;
  right: 15%;
  animation-delay: 5s;
}

.circle:nth-child(3) {
  width: 100px;
  height: 100px;
  bottom: 20%;
  left: 70%;
  animation-delay: 10s;
}

.square:nth-child(4) {
  width: 120px;
  height: 120px;
  top: 30%;
  right: 25%;
  animation-delay: 3s;
}

.square:nth-child(5) {
  width: 80px;
  height: 80px;
  bottom: 40%;
  left: 20%;
  animation-delay: 8s;
}

@keyframes float-shapes {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-30px) rotate(180deg);
  }
}

/* ============ Main Wrapper ============ */
.wrapper {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ App Header ============ */
.app-header {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border-radius: 24px;
  padding: 30px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
}

.logo-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 10px;
}

.logo-icon {
  width: 60px;
  height: 60px;
  background: var(--gradient-1);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: white;
  box-shadow: var(--shadow-md);
  animation: pulse-icon 2s infinite;
}

@keyframes pulse-icon {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.app-title {
  font-size: 3rem;
  font-weight: 900;
  background: var(--gradient-1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 2px;
}

.tagline {
  font-size: 1.1rem;
  color: var(--gray);
  font-weight: 600;
  margin-bottom: 20px;
}

.credits {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 15px;
  border-top: 2px solid rgba(99,102,241,0.2);
}

.credit-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--dark);
  font-weight: 600;
}

.credit-item i {
  color: var(--primary);
  font-size: 1.1rem;
}

.credit-item.special {
  color: var(--secondary);
  font-weight: 700;
}

.credit-item.special i {
  color: var(--secondary);
}

/* ============ Game Container ============ */
.game-container {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border-radius: 24px;
  padding: 30px;
  box-shadow: var(--shadow-lg);
  flex: 1;
  margin-bottom: 20px;
}

/* ============ Screen System ============ */
.screen {
  display: none;
  animation: fadeIn 0.4s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.screen-title {
  font-size: 1.8rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 25px;
  color: var(--primary);
}

/* ============ Mode Selection ============ */
.name-input-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 400px;
  margin: 0 auto;
}

.name-input {
  padding: 18px 24px;
  border: 3px solid var(--primary);
  border-radius: 16px;
  font-family: 'Cairo', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  transition: all 0.3s;
  background: white;
}

.name-input:focus {
  outline: none;
  border-color: var(--primary-dark);
  box-shadow: 0 0 0 4px rgba(99,102,241,0.15);
  transform: scale(1.02);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.mode-card {
  background: white;
  border: 3px solid transparent;
  border-radius: 20px;
  padding: 30px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-sm);
}

.mode-card:hover {
  transform: translateY(-8px);
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

.mode-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 15px;
  background: var(--gradient-1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: white;
}

.mode-card h3 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 8px;
}

.mode-card p {
  font-size: 0.95rem;
  color: var(--gray);
}

/* ============ Room Setup ============ */
.room-options {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 24px;
  border: none;
  border-radius: 12px;
  font-family: 'Cairo', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: var(--shadow-sm);
}

.action-btn.primary {
  background: var(--gradient-1);
  color: white;
}

.action-btn.primary:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.action-btn.secondary {
  background: var(--gradient-2);
  color: white;
}

.action-btn.secondary:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.action-btn.danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
}

.action-btn.danger:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.action-btn.outline {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.action-btn.outline:hover {
  background: var(--primary);
  color: white;
}

.separator {
  text-align: center;
  color: var(--gray);
  font-weight: 600;
  position: relative;
  margin: 10px 0;
}

.separator::before,
.separator::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--gray), transparent);
}

.separator::before {
  right: 55%;
}

.separator::after {
  left: 55%;
}

.join-section {
  display: flex;
  gap: 12px;
}

.code-input {
  flex: 1;
  padding: 16px 20px;
  border: 2px solid var(--primary);
  border-radius: 12px;
  font-family: 'Cairo', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 4px;
  text-transform: uppercase;
  transition: all 0.3s;
}

.code-input:focus {
  outline: none;
  border-color: var(--primary-dark);
  box-shadow: 0 0 0 4px rgba(99,102,241,0.1);
}

.back-link {
  margin-top: 20px;
  background: none;
  border: none;
  color: var(--primary);
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  transition: all 0.3s;
}

.back-link:hover {
  color: var(--primary-dark);
  transform: translateX(5px);
}

/* ============ Room Status ============ */
.players-list,
.spectators-section {
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  padding: 20px;
  border-radius: 16px;
  margin-bottom: 20px;
}

.players-list h3,
.spectators-section h3 {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-item,
.spectator-item {
  background: white;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.player-item i,
.spectator-item i {
  color: var(--primary);
  font-size: 1.2rem;
}

.player-role {
  margin-right: auto;
  font-size: 0.85rem;
  color: var(--secondary);
  background: rgba(236,72,153,0.1);
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 700;
}

.kick-btn,
.spectator-actions button {
  background: var(--danger);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.3s;
  margin-right: auto;
}

.kick-btn:hover,
.spectator-actions button:hover {
  background: #dc2626;
  transform: scale(1.05);
}

.spectator-actions {
  display: flex;
  gap: 8px;
  margin-right: auto;
}

.spectator-actions .approve-btn {
  background: var(--success);
}

.spectator-actions .approve-btn:hover {
  background: #059669;
}

.pending-request {
  background: #fef3c7;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.pending-request i {
  color: var(--warning);
}

.banned-user-item {
  background: #fee2e2;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.banned-user-item i {
  color: #ef4444;
}

.unban-btn {
  background: #10b981;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: auto;
  transition: all 0.3s;
}

.unban-btn:hover {
  background: #059669;
  transform: translateY(-2px);
}

.room-info-box {
  display: flex;
  flex-direction: column;
  gap: 25px;
  margin-bottom: 25px;
}

.room-code-section {
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  padding: 25px;
  border-radius: 16px;
  text-align: center;
}

.room-code-section label {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 12px;
  text-align: center;
}

.code-display {
  font-size: 2.5rem;
  font-weight: 900;
  font-family: 'Courier New', monospace;
  color: var(--primary);
  letter-spacing: 8px;
  margin-bottom: 15px;
  padding: 15px;
  background: white;
  border-radius: 12px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.05);
}

.copy-code-btn {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 12px;
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.copy-code-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.copy-code-btn:active {
  transform: translateY(0);
}

.status-box {
  background: #fef3c7;
  color: #92400e;
  padding: 20px;
  border-radius: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.status-box.success {
  background: #d1fae5;
  color: #065f46;
}

.status-box i {
  font-size: 2rem;
}

.loader {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(251,191,36,0.3);
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============ Game Screen ============ */
.game-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}

.game-layout.with-chat {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.game-side {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-side {
  width: 100%;
  max-width: 500px;
}

.chat-container {
  background: white;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  height: 450px;
  border: 1px solid #e2e8f0;
}

.chat-header {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  padding: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  position: relative;
}

.minimize-chat-btn {
  background: rgba(255, 255, 255, 0.25);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  font-size: 1rem;
}

.minimize-chat-btn:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.1);
}

.minimize-chat-btn:active {
  transform: scale(0.95);
}

.chat-container.minimized .chat-messages,
.chat-container.minimized .chat-input-section {
  display: none !important;
}

.chat-container.minimized {
  height: auto !important;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  animation: messageSlide 0.3s ease;
  max-width: 75%;
}

@keyframes messageSlide {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message.own {
  align-self: flex-end;
}

.chat-message.other {
  align-self: flex-start;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-message.own .message-bubble {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.other .message-bubble {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}

.message-sender {
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: #6366f1;
  padding: 0 4px;
}

.message-text {
  font-size: 0.95rem;
  line-height: 1.5;
}

.chat-message.own .message-text {
  color: white;
}

.chat-message.other .message-text {
  color: #1e293b;
}

.message-time {
  font-size: 0.7rem;
  margin-top: 4px;
  padding: 0 4px;
}

.chat-message.own .message-time {
  color: rgba(255, 255, 255, 0.75);
  text-align: left;
}

.chat-message.other .message-time {
  color: #64748b;
  text-align: left;
}

.chat-input-section {
  padding: 20px;
  background: #f8fafc;
  border-top: 2px solid #e2e8f0;
  display: flex;
  gap: 12px;
}

.chat-input {
  flex: 1;
  padding: 14px 18px;
  border: 2px solid #cbd5e1;
  border-radius: 14px;
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  background: white;
  color: #1e293b;
  transition: all 0.3s;
}

.chat-input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.chat-input::placeholder {
  color: #94a3b8;
}

.send-btn {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  border: none;
  padding: 14px 24px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.send-btn:active {
  transform: translateY(0);
}

.score-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.score-item {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  padding: 15px;
  border-radius: 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.score-item.tie {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.score-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.9;
  margin-bottom: 5px;
}

.score-num {
  display: block;
  font-size: 1.8rem;
  font-weight: 900;
}

.turn-indicator {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 20px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
}

.turn-indicator span {
  color: var(--secondary);
  font-size: 1.5rem;
}

.timer {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  padding: 6px 14px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  min-width: 70px;
  display: inline-block;
}

.timer.warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  animation: pulse 1s infinite;
}

.timer.danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  animation: pulse 0.5s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ============ Game Grid ============ */
.game-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 auto 20px;
  max-width: 400px;
  width: 100%;
}

.grid-cell {
  aspect-ratio: 1;
  background: white;
  border: 3px solid #cbd5e1;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  color: transparent;
}

.grid-cell:hover:not(.filled) {
  background: #f8fafc;
  border-color: #6366f1;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.grid-cell.filled {
  cursor: not-allowed;
}

.grid-cell.x {
  color: #6366f1 !important;
  animation: pop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.grid-cell.o {
  color: #ec4899 !important;
  animation: pop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.grid-cell.win {
  background: var(--gradient-1);
  color: white;
  animation: winner-bounce 0.6s infinite alternate;
}

@keyframes pop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes winner-bounce {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(1.08);
    box-shadow: 0 8px 32px rgba(99,102,241,0.5);
  }
}

/* ============ Game Actions ============ */
.game-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

/* ============ Result Modal ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(30,41,59,0.9);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: white;
  padding: 50px 40px;
  border-radius: 24px;
  text-align: center;
  max-width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: slideUp 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.result-icon {
  font-size: 4rem;
  margin-bottom: 20px;
}

.result-text {
  font-size: 2rem;
  font-weight: 900;
  color: var(--primary);
  margin-bottom: 30px;
}

/* ============ Footer ============ */
.app-footer {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  color: var(--dark);
}

.app-footer p {
  margin: 8px 0;
}

.app-footer strong {
  color: var(--primary);
  font-weight: 800;
}

.footer-dedication {
  color: var(--secondary);
  font-weight: 700;
}

.footer-dedication strong {
  color: var(--secondary);
}

.footer-copy {
  color: var(--gray);
  font-size: 0.85rem;
  margin-top: 10px;
}

/* ============ Responsive ============ */
@media (max-width: 968px) {
  .game-layout.with-chat {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .game-side {
    order: 1;
  }

  .chat-side {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    z-index: 999;
    order: 2;
    max-height: 80vh;
  }

  .chat-side.hidden {
    display: none !important;
  }

  .chat-container {
    height: 70vh;
    max-height: 70vh;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    border-radius: 20px 20px 0 0;
  }

  /* زر إظهار الشات للموبايل */
  .show-chat-btn {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
    cursor: pointer;
    z-index: 998;
    transition: all 0.3s;
  }

  .show-chat-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.6);
  }

  .show-chat-btn:active {
    transform: scale(0.95);
  }

  .show-chat-btn.hidden {
    display: none;
  }

  .chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    border: 2px solid white;
  }

  .chat-badge.hidden {
    display: none;
  }
}

@media (min-width: 969px) {
  .show-chat-btn {
    display: none !important;
  }
}

@media (max-width: 600px) {
  .app-title {
    font-size: 2.5rem;
  }

  .logo-icon {
    width: 50px;
    height: 50px;
    font-size: 28px;
  }

  .mode-grid {
    grid-template-columns: 1fr;
  }

  .game-actions {
    grid-template-columns: 1fr;
  }

  .grid-cell {
    font-size: 2.5rem;
  }

  .result-text {
    font-size: 1.5rem;
  }

  .score-bar {
    gap: 8px;
  }

  .chat-container {
    height: 400px;
  }

  .game-layout.with-chat {
    gap: 15px;
  }

  .score-item {
    padding: 12px;
  }

  .code-display {
    font-size: 2rem;
    letter-spacing: 5px;
  }

  .game-layout.with-chat {
    grid-template-columns: 1fr;
  }

  .chat-container {
    height: 400px;
  }
}

/* ============ New Styles for Home Screen ============ */
.game-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
  margin-bottom: 25px;
}

.info-item {
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  padding: 15px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--dark);
}

.info-item i {
  font-size: 1.8rem;
  color: var(--primary);
}

.game-rules {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  padding: 25px;
  border-radius: 16px;
  margin-bottom: 25px;
  border: 3px solid #fbbf24;
}

.game-rules h3 {
  font-size: 1.3rem;
  font-weight: 800;
  color: #92400e;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-rules ul {
  list-style: none;
  padding: 0;
}

.game-rules li {
  padding: 10px 0;
  padding-right: 25px;
  position: relative;
  color: #78350f;
  font-weight: 600;
  line-height: 1.6;
}

.game-rules li::before {
  content: "✓";
  position: absolute;
  right: 0;
  color: #f59e0b;
  font-weight: 900;
  font-size: 1.2rem;
}

.btn-primary,
.btn-secondary {
  width: 100%;
  padding: 16px 32px;
  border: none;
  border-radius: 14px;
  font-family: 'Cairo', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.btn-primary {
  background: var(--gradient-1);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 3px solid var(--primary);
}

.btn-secondary:hover {
  background: var(--primary);
  color: white;
  transform: translateY(-2px);
}

.input-field {
  width: 100%;
  padding: 16px 24px;
  border: 3px solid rgba(99,102,241,0.3);
  border-radius: 14px;
  font-family: 'Cairo', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  transition: all 0.3s;
  background: white;
  margin-bottom: 20px;
}

.input-field:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99,102,241,0.1);
}

.separator {
  text-align: center;
  margin: 25px 0;
  position: relative;
}

.separator::before,
.separator::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 2px;
  background: linear-gradient(to right, transparent, rgba(99,102,241,0.3), transparent);
}

.separator::before {
  right: 55%;
}

.separator::after {
  left: 55%;
}

.separator span {
  background: white;
  padding: 0 15px;
  color: var(--gray);
  font-weight: 700;
  font-size: 0.95rem;
}

.join-section {
  margin-top: 20px;
}

/* ============ Desktop Optimization ============ */
@media (min-width: 768px) {
  .wrapper {
    max-width: 900px;
    padding: 30px;
  }

  .app-header {
    padding: 40px;
  }

  .logo-icon {
    width: 80px;
    height: 80px;
    font-size: 42px;
  }

  .app-title {
    font-size: 3.5rem;
  }

  .tagline {
    font-size: 1.3rem;
  }

  .game-container {
    padding: 40px 50px;
  }

  .screen-title {
    font-size: 2.2rem;
    margin-bottom: 35px;
  }

  .game-info {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
  }

  .info-item {
    padding: 20px;
  }

  .info-item i {
    font-size: 2.2rem;
  }

  .info-item span {
    font-size: 1rem;
  }

  .game-rules {
    padding: 30px;
    margin-bottom: 35px;
  }

  .game-rules h3 {
    font-size: 1.5rem;
    margin-bottom: 20px;
  }

  .game-rules li {
    font-size: 1.05rem;
    padding: 12px 0;
    padding-right: 30px;
  }

  .btn-primary,
  .btn-secondary {
    padding: 18px 40px;
    font-size: 1.2rem;
    margin-bottom: 15px;
  }

  .input-field {
    padding: 18px 28px;
    font-size: 1.15rem;
  }

  .room-info-box {
    padding: 30px;
  }

  .room-code-section {
    margin-bottom: 30px;
  }

  .code-display {
    font-size: 3rem;
    letter-spacing: 12px;
    padding: 25px;
  }

  .copy-code-btn {
    padding: 14px 28px;
    font-size: 1.1rem;
  }

  .players-list,
  .spectators-section {
    padding: 25px;
  }

  .player-item {
    padding: 16px 20px;
    font-size: 1.1rem;
  }

  .game-side {
    max-width: 600px;
  }

  .grid-cell {
    font-size: 3.5rem;
  }

  .game-grid {
    gap: 15px;
    max-width: 500px;
  }

  .score-bar {
    gap: 15px;
    margin-bottom: 25px;
  }

  .score-item {
    padding: 18px 24px;
  }

  .score-label {
    font-size: 1rem;
  }

  .score-num {
    font-size: 2rem;
  }

  .turn-indicator {
    font-size: 1.4rem;
    padding: 16px;
    margin-bottom: 25px;
  }

  .game-actions {
    gap: 15px;
    margin-top: 25px;
  }

  .action-btn {
    padding: 14px 24px;
    font-size: 1.05rem;
  }
}

/* ============ Large Desktop Optimization ============ */
@media (min-width: 1024px) {
  .wrapper {
    max-width: 1200px;
  }

  .game-layout.with-chat {
    display: grid;
    grid-template-columns: 1fr 450px;
    gap: 40px;
    align-items: start;
    max-width: 100%;
  }

  .game-side {
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
  }

  .chat-side {
    position: sticky;
    top: 20px;
    width: 100%;
    max-width: 450px;
  }

  .chat-container {
    height: 650px;
  }

  .grid-cell {
    font-size: 4rem;
  }

  .game-grid {
    max-width: 550px;
    gap: 18px;
  }

  .result-modal .modal-content {
    padding: 50px;
    max-width: 500px;
  }

  .result-icon {
    font-size: 5rem;
  }

  .result-text {
    font-size: 2rem;
  }

  .screen-title {
    font-size: 2.5rem;
  }
}

@media (max-width: 767px) {
  .wrapper {
    max-width: 600px;
  }

  .app-header {
    padding: 25px 20px;
  }

  .game-container {
    padding: 25px 20px;
  }

  .game-side {
    max-width: 100%;
  }

  .game-grid {
    max-width: 350px;
  }
}

