/* ============ Color Palette ============ */
:root {
  --primary: #3b82f6;
  --primary-light: #60a5fa;
  --primary-dark: #2563eb;
  --secondary: #8b5cf6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --dark: #1f2937;
  --light: #f8fafc;
  --gray: #6b7280;
  --gradient-main: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
  --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 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, #3b82f6 0%, #06b6d4 50%, #8b5cf6 100%);
  min-height: 100vh;
  color: var(--dark);
  overflow-x: hidden;
  position: relative;
}

/* ============ Background Shapes ============ */
.bg-shapes {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.shape {
  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);
}

.triangle {
  width: 0;
  height: 0;
  border-left: 60px solid transparent;
  border-right: 60px solid transparent;
  border-bottom: 100px solid rgba(255,255,255,0.6);
}

.shape:nth-child(1) {
  width: 200px;
  height: 200px;
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.shape:nth-child(2) {
  width: 120px;
  height: 120px;
  top: 30%;
  right: 25%;
  animation-delay: 3s;
}

.shape:nth-child(3) {
  top: 60%;
  right: 15%;
  animation-delay: 6s;
}

.shape:nth-child(4) {
  width: 150px;
  height: 150px;
  bottom: 20%;
  left: 70%;
  animation-delay: 9s;
}

.shape:nth-child(5) {
  width: 100px;
  height: 100px;
  bottom: 35%;
  right: 35%;
  animation-delay: 12s;
}

@keyframes float-shapes {
  0%, 100% {
    transform: translate(0, 0) rotate(0deg);
  }
  33% {
    transform: translate(30px, -30px) rotate(120deg);
  }
  66% {
    transform: translate(-20px, 20px) rotate(240deg);
  }
}

/* ============ Screens ============ */
.screen {
  display: none;
  min-height: 100vh;
  padding: 20px;
  animation: fadeIn 0.5s ease;
  position: relative;
  z-index: 1;
}

.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

@keyframes fadeIn {
  from { 
    opacity: 0; 
    transform: translateY(20px); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

.container {
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
}

/* ============ Card ============ */
.card {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 30px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* ============ Game Header ============ */
.game-header {
  text-align: center;
  margin-bottom: 30px;
  animation: slideDown 0.6s ease;
}

@keyframes slideDown {
  from { 
    transform: translateY(-30px); 
    opacity: 0; 
  }
  to { 
    transform: translateY(0); 
    opacity: 1; 
  }
}

.logo-icon {
  width: 100px;
  height: 100px;
  background: var(--gradient-main);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 52px;
  color: white;
  margin: 0 auto 20px;
  box-shadow: var(--shadow-lg);
  animation: pulse-icon 2s infinite;
}

@keyframes pulse-icon {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.4);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(59, 130, 246, 0.6);
  }
}

.game-title {
  font-size: 2.8rem;
  font-weight: 900;
  color: white;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.game-subtitle {
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.95);
  font-weight: 600;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* ============ Input Sections ============ */
.name-input-section,
.code-input-section {
  margin-bottom: 25px;
}

input[type="text"] {
  width: 100%;
  padding: 18px 20px;
  font-size: 1.2rem;
  font-family: 'Cairo', sans-serif;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-radius: 16px;
  background: white;
  text-align: center;
  font-weight: 600;
  transition: all 0.3s;
  color: var(--dark);
}

input[type="text"]::placeholder {
  color: var(--gray);
  opacity: 0.6;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
  transform: translateY(-2px);
}

/* ============ Buttons ============ */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 25px;
}

.menu-btn,
.action-btn {
  width: 100%;
  padding: 18px 30px;
  font-size: 1.2rem;
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.menu-btn::before,
.action-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.menu-btn:hover::before,
.action-btn:hover::before {
  width: 300px;
  height: 300px;
}

.create-btn {
  background: var(--gradient-success);
  color: white;
}

.create-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(16, 185, 129, 0.4);
}

.join-btn {
  background: var(--gradient-main);
  color: white;
}

.join-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(59, 130, 246, 0.4);
}

.start-btn {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
}

.start-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(245, 158, 11, 0.4);
}

.leave-btn,
.home-btn {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
}

.leave-btn:hover,
.home-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(239, 68, 68, 0.4);
}

.play-again-btn {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: white;
}

.play-again-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(139, 92, 246, 0.4);
}

.back-btn {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(10px);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.4);
  padding: 12px 24px;
  font-size: 1rem;
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: translateX(5px);
  box-shadow: var(--shadow-md);
}

/* ============ Game Info ============ */
.game-info {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(6, 182, 212, 0.15));
  border-radius: 16px;
  padding: 20px;
  backdrop-filter: blur(10px);
  border: 2px solid rgba(59, 130, 246, 0.2);
  margin-bottom: 25px;
}

.game-info p {
  color: var(--dark);
  font-size: 1rem;
  margin-bottom: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-info p:last-child {
  margin-bottom: 0;
}

.game-info p i {
  color: var(--primary);
  font-size: 1.1rem;
}

/* ============ Settings Card ============ */
.screen-title {
  font-size: 2rem;
  color: white;
  text-align: center;
  margin-bottom: 25px;
  font-weight: 800;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.settings-card {
  margin-bottom: 25px;
}

.setting-item {
  margin-bottom: 20px;
}

.setting-item:last-child {
  margin-bottom: 0;
}

.setting-item label {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 10px;
}

.setting-item select {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  font-family: 'Cairo', sans-serif;
  font-weight: 600;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-radius: 14px;
  background: white;
  cursor: pointer;
  transition: all 0.3s;
  color: var(--dark);
}

.setting-item select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* ============ Room Info ============ */
.room-info-card {
  background: white;
  border-radius: 20px;
  padding: 25px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
  text-align: center;
  border: 3px solid rgba(59, 130, 246, 0.2);
}

.room-code-display span {
  display: block;
  font-size: 1rem;
  color: var(--gray);
  margin-bottom: 10px;
  font-weight: 600;
}

.code-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  padding: 20px;
  border-radius: 16px;
  margin-bottom: 15px;
  border: 2px solid rgba(59, 130, 246, 0.2);
}

.code-box span {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: 8px;
  text-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.copy-btn {
  background: var(--gradient-main);
  color: white;
  border: none;
  padding: 12px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.3s;
  box-shadow: var(--shadow-sm);
}

.copy-btn:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow: var(--shadow-md);
}

.share-hint {
  font-size: 0.95rem;
  color: var(--gray);
  font-weight: 600;
}

/* ============ Players List ============ */
.players-list {
  background: white;
  border-radius: 20px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
  max-height: 320px;
  overflow-y: auto;
  border: 3px solid rgba(59, 130, 246, 0.2);
}

.player-card {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  padding: 16px 20px;
  border-radius: 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: var(--shadow-sm);
  border: 2px solid rgba(59, 130, 246, 0.15);
  transition: all 0.3s;
  position: relative;
}

.player-card:hover {
  transform: translateX(-5px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.player-card:last-child {
  margin-bottom: 0;
}

.player-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--gradient-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  font-weight: 800;
  box-shadow: var(--shadow-sm);
}

.player-info {
  flex: 1;
}

.player-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 3px;
}

.admin-badge {
  display: inline-block;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  padding: 4px 12px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 8px;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
}

/* زر الاستبعاد */
.kick-btn {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.kick-btn:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.5);
}

.kick-btn:active {
  transform: scale(0.95);
}

/* ============ Waiting Actions ============ */
.waiting-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.join-hint {
  text-align: center;
  margin-top: 20px;
  padding: 15px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(6, 182, 212, 0.1));
  border-radius: 12px;
  border: 2px solid rgba(59, 130, 246, 0.2);
}

.join-hint p {
  color: var(--dark);
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

/* ============ Game Screen ============ */
#screen-game {
  padding: 10px;
  align-items: flex-start;
}

.game-container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.game-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.95);
  padding: 15px 20px;
  border-radius: 15px;
  margin-bottom: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.timer-box,
.score-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.2rem;
  font-weight: 700;
  color: #1f2937;
}

.timer-box i {
  color: #ef4444;
}

.score-box i {
  color: #f59e0b;
}

.leave-game-btn {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.3s;
}

.leave-game-btn:hover {
  transform: scale(1.1);
}

/* ============ Word Grid ============ */
.grid-container {
  margin-bottom: 15px;
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: rgba(255, 255, 255, 0.95);
  padding: 15px;
  border-radius: 15px;
  box-shadow: var(--shadow-md);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.grid-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--dark);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.grid-cell:active {
  transform: scale(0.95);
}

.grid-cell.selecting {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  transform: scale(1.1);
  border-color: #1d4ed8;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.6);
  z-index: 10;
  position: relative;
  font-weight: 900;
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 20px;
  position: relative; /* مهم لوضع SVG */
}

.grid-cell.found {
  /* إزالة التنسيقات القديمة - الخطوط الآن SVG */
  font-weight: 900;
  animation: foundCellPulse 0.5s;
}

/* إزالة ::after لأننا نستخدم SVG الآن */
.grid-cell.found::after {
  display: none;
}

/* طبقة الخطوط */
.word-lines-overlay {
  pointer-events: none;
}

/* تأثير رسم الخط */
@keyframes drawLine {
  from {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    opacity: 0;
  }
  to {
    stroke-dasharray: 1000;
    stroke-dashoffset: 0;
    opacity: 0.8;
  }
}

@keyframes foundCellPulse {
  0%, 100% { 
    transform: scale(1); 
  }
  50% { 
    transform: scale(1.15); 
  }
}

.grid-cell.locked {
  cursor: not-allowed;
  opacity: 0.9;
}

.grid-cell.locked:hover {
  transform: none;
}

@keyframes foundPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ============ Words Section ============ */
.words-section {
  background: rgba(255, 255, 255, 0.95);
  padding: 15px;
  border-radius: 15px;
  margin-bottom: 15px;
  box-shadow: var(--shadow-md);
}

.words-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 12px;
  text-align: center;
}

.words-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  max-height: 150px;
  overflow-y: auto;
}

.word-item {
  background: #f3f4f6;
  padding: 10px;
  border-radius: 10px;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--dark);
  transition: all 0.3s;
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.word-item.found {
  /* الخلفية والحدود ستُحدد من JavaScript */
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: foundWordPulse 0.5s;
  border-right: 4px solid;
}

@keyframes foundWordPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.word-item .word-text {
  font-size: 1rem;
  font-weight: 700;
}

.word-item.found .word-text {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.word-item .finder {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 8px;
  margin-right: 8px;
  font-weight: 600;
}

/* ============ Scoreboard ============ */
.scoreboard {
  background: rgba(255, 255, 255, 0.95);
  padding: 15px;
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.scoreboard-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 12px;
  text-align: center;
}

.scoreboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.score-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f9fafb;
  padding: 12px 15px;
  border-radius: 10px;
  border-right: 4px solid transparent;
}

.score-item.rank-1 {
  border-right-color: #f59e0b;
  background: linear-gradient(90deg, #fef3c7, #f9fafb);
}

.score-item.rank-2 {
  border-right-color: #9ca3af;
}

.score-item.rank-3 {
  border-right-color: #cd7f32;
}

.score-player-name {
  font-size: 1rem;
  font-weight: 700;
  color: #1f2937;
}

.score-value {
  font-size: 1rem;
  font-weight: 700;
  color: white;
  padding: 4px 12px;
  border-radius: 8px;
  min-width: 40px;
  text-align: center;
}

/* ============ Results Screen ============ */
.results-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 30px;
  margin-bottom: 25px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.winner-section {
  margin-bottom: 30px;
}

.winner-trophy {
  font-size: 5rem;
  margin-bottom: 15px;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.winner-name {
  font-size: 2rem;
  font-weight: 900;
  color: #f59e0b;
  margin-bottom: 10px;
}

.winner-score {
  font-size: 1.5rem;
  font-weight: 700;
  color: #6b7280;
}

.final-scores {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.final-score-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px;
  background: #f9fafb;
  border-radius: 12px;
}

.final-rank {
  font-size: 1.5rem;
  font-weight: 900;
  width: 40px;
}

.final-player-name {
  flex: 1;
  font-size: 1.2rem;
  font-weight: 700;
  color: #1f2937;
}

.final-score {
  font-size: 1.3rem;
  font-weight: 700;
  color: #3b82f6;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ============ Mobile Responsive ============ */
@media (max-width: 480px) {
  .game-title {
    font-size: 2rem;
  }

  .word-grid {
    padding: 10px;
    gap: 3px;
  }

  .grid-cell {
    font-size: 1.2rem;
    border-radius: 6px;
  }

  .words-list {
    max-height: 120px;
  }

  .code-box span {
    font-size: 2rem;
    letter-spacing: 5px;
  }
}

/* ============ Animations ============ */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.shake {
  animation: shake 0.3s;
}
