@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700;800&family=Tajawal:wght@400;500;700;900&display=swap');

:root {
  --bg-dark: #090d16;
  --bg-card: rgba(17, 25, 40, 0.75);
  --border-color: rgba(255, 255, 255, 0.1);
  --text-primary: #ffffff;
  --text-secondary: #a0aec0;
  
  /* Player 1: Neon Cyan/Green */
  --p1-color: #00ffd5;
  --p1-glow: 0 0 15px rgba(0, 255, 213, 0.6);
  --p1-bg: rgba(0, 255, 213, 0.15);
  
  /* Player 2: Neon Red/Pink */
  --p2-color: #ff0055;
  --p2-glow: 0 0 15px rgba(255, 0, 85, 0.6);
  --p2-bg: rgba(255, 0, 85, 0.15);
  
  /* Neutral/System Colors */
  --accent-color: #7928ca;
  --correct-color: #2ec4b6;
  --wrong-color: #e71d36;
  --timer-color: #ff9f1c;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Cairo', 'Tajawal', sans-serif;
  user-select: none;
}

body {
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(121, 40, 202, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(0, 255, 213, 0.08) 0px, transparent 50%),
    radial-gradient(at 50% 50%, rgba(255, 0, 85, 0.05) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  direction: rtl;
  overflow-x: hidden;
}

header {
  padding: 1.5rem;
  background: rgba(9, 13, 22, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, #00ffd5 0%, #ff0055 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 20px rgba(0, 255, 213, 0.2);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo span {
  font-size: 1.2rem;
  color: var(--text-secondary);
  -webkit-text-fill-color: var(--text-secondary);
}

.players-indicator {
  display: flex;
  gap: 2rem;
}

.player-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.6rem 1.2rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: all 0.4s ease;
  backdrop-filter: blur(5px);
}

.player-card.p1 {
  border-left: 4px solid var(--p1-color);
}

.player-card.p2 {
  border-left: 4px solid var(--p2-color);
}

.player-card.active.p1 {
  border-color: var(--p1-color);
  box-shadow: var(--p1-glow), inset 0 0 10px rgba(0, 255, 213, 0.1);
  transform: translateY(-2px);
}

.player-card.active.p2 {
  border-color: var(--p2-color);
  box-shadow: var(--p2-glow), inset 0 0 10px rgba(255, 0, 85, 0.1);
  transform: translateY(-2px);
}

.player-indicator-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--text-secondary);
}

.p1 .player-indicator-dot { background-color: var(--p1-color); }
.p2 .player-indicator-dot { background-color: var(--p2-color); }

.player-card.active.p1 .player-indicator-dot {
  animation: pulse-p1 1.5s infinite alternate;
}

.player-card.active.p2 .player-indicator-dot {
  animation: pulse-p2 1.5s infinite alternate;
}

.player-info {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 700;
  font-size: 1rem;
}

.player-score {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Setup Screen */
.setup-screen {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 2.5rem;
  width: 100%;
  max-width: 550px;
  text-align: center;
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.setup-title {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, #ffffff 0%, #a0aec0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.setup-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 2rem;
  line-height: 1.6;
}

.input-group {
  margin-bottom: 1.5rem;
  text-align: right;
}

.input-group label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.color-preview {
  position: absolute;
  right: 15px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.p1-preview { background-color: var(--p1-color); box-shadow: var(--p1-glow); }
.p2-preview { background-color: var(--p2-color); box-shadow: var(--p2-glow); }

.setup-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 1rem 3rem 1rem 1rem;
  color: var(--text-primary);
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.3s ease;
}

.setup-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.06);
}

#p1_name:focus { border-color: var(--p1-color); box-shadow: 0 0 10px rgba(0, 255, 213, 0.2); }
#p2_name:focus { border-color: var(--p2-color); box-shadow: 0 0 10px rgba(255, 0, 85, 0.2); }

.btn {
  background: linear-gradient(135deg, var(--accent-color) 0%, #5b21b6 100%);
  border: none;
  color: #fff;
  padding: 1rem 2.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 10px 20px rgba(121, 40, 202, 0.3);
  width: 100%;
  margin-top: 1rem;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 25px rgba(121, 40, 202, 0.4);
  filter: brightness(1.1);
}

.btn:active {
  transform: translateY(1px);
}

/* Instructions Card */
.instructions-card {
  margin-top: 2rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 1.2rem;
  text-align: right;
}

.instructions-card h4 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.instructions-card ul {
  list-style-type: none;
}

.instructions-card li {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  padding-right: 1.2rem;
  position: relative;
}

.instructions-card li::before {
  content: "•";
  color: var(--p1-color);
  position: absolute;
  right: 0;
  font-weight: bold;
}

/* Game Interface */
.game-container {
  width: 100%;
  max-width: 700px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  animation: fadeIn 0.5s ease forwards;
}

.status-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1rem 1.5rem;
}

.turn-text {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.turn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.turn-p1 .turn-dot {
  background-color: var(--p1-color);
  box-shadow: var(--p1-glow);
  animation: pulse-p1 1.2s infinite alternate;
}

.turn-p2 .turn-dot {
  background-color: var(--p2-color);
  box-shadow: var(--p2-glow);
  animation: pulse-p2 1.2s infinite alternate;
}

/* Board Grid */
.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 12px;
  width: 100%;
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 16px;
  backdrop-filter: blur(5px);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3);
}

.cell {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  overflow: hidden;
  color: var(--text-primary);
}

.cell::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 100%);
  opacity: 1;
  transition: opacity 0.3s ease;
}

.cell:hover:not(.claimed) {
  transform: scale(1.05);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
}

.cell:active:not(.claimed) {
  transform: scale(0.95);
}

.cell.claimed.p1 {
  background: linear-gradient(135deg, #09201d 0%, #00ffd5 100%);
  border-color: var(--p1-color);
  box-shadow: var(--p1-glow);
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
  animation: claimCell 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  color: #000;
}

.cell.claimed.p2 {
  background: linear-gradient(135deg, #250310 0%, #ff0055 100%);
  border-color: var(--p2-color);
  box-shadow: var(--p2-glow);
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
  animation: claimCell 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  color: #fff;
}

/* Question Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 6, 12, 0.85);
  backdrop-filter: blur(15px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 28px;
  width: 100%;
  max-width: 600px;
  padding: 2.5rem;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  position: relative;
  transform: scale(0.9) translateY(20px);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.modal-overlay.active .question-card {
  transform: scale(1) translateY(0);
}

.question-card.p1-turn { border: 2px solid var(--p1-color); box-shadow: 0 0 30px rgba(0, 255, 213, 0.15); }
.question-card.p2-turn { border: 2px solid var(--p2-color); box-shadow: 0 0 30px rgba(255, 0, 85, 0.15); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.letter-badge {
  font-size: 2rem;
  font-weight: 900;
  width: 60px;
  height: 60px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

.p1-turn .letter-badge { background: var(--p1-bg); border: 1px solid var(--p1-color); box-shadow: var(--p1-glow); color: var(--p1-color); }
.p2-turn .letter-badge { background: var(--p2-bg); border: 1px solid var(--p2-color); box-shadow: var(--p2-glow); color: var(--p2-color); }

.timer-container {
  position: relative;
  width: 50px;
  height: 50px;
}

.timer-circle {
  width: 100%;
  height: 100%;
}

.timer-circle circle {
  fill: none;
  stroke-width: 4;
  stroke: rgba(255, 255, 255, 0.05);
}

.timer-circle .timer-progress {
  stroke: var(--timer-color);
  stroke-linecap: round;
  stroke-dasharray: 126;
  stroke-dashoffset: 0;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 0.1s linear, stroke 0.3s ease;
}

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.95rem;
  font-weight: 800;
}

.timer-danger {
  color: var(--wrong-color);
  animation: shake 0.3s infinite;
}

.question-text {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.7;
  color: var(--text-primary);
  margin: 1rem 0;
}

/* Voice Panel */
.voice-panel {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.5rem;
}

.mic-btn {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  transition: all 0.3s ease;
  position: relative;
}

.mic-btn::after {
  content: '';
  position: absolute;
  top: -5px;
  left: -5px;
  right: -5px;
  bottom: -5px;
  border-radius: 50%;
  border: 2px dashed transparent;
  transition: all 0.3s ease;
}

.mic-btn.listening {
  color: var(--text-primary);
  transform: scale(1.05);
}

.p1-turn .mic-btn.listening {
  background: var(--p1-color);
  border-color: var(--p1-color);
  box-shadow: var(--p1-glow);
  color: #000;
}

.p1-turn .mic-btn.listening::after {
  border-color: var(--p1-color);
  animation: rotateMic 4s linear infinite;
}

.p2-turn .mic-btn.listening {
  background: var(--p2-color);
  border-color: var(--p2-color);
  box-shadow: var(--p2-glow);
  color: #fff;
}

.p2-turn .mic-btn.listening::after {
  border-color: var(--p2-color);
  animation: rotateMic 4s linear infinite;
}

.voice-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
  min-height: 1.2rem;
}

.voice-recognized-text {
  font-size: 1.1rem;
  color: #ffffff;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  min-height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-color);
}

.divider:not(:empty)::before {
  margin-left: .5em;
}

.divider:not(:empty)::after {
  margin-right: .5em;
}

/* Options Grid */
.options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
}

.option-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-radius: 14px;
  padding: 1rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.option-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.option-prefix {
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.08);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.option-btn.correct {
  background: rgba(46, 196, 182, 0.15) !important;
  border-color: var(--correct-color) !important;
  color: var(--correct-color) !important;
  box-shadow: 0 0 10px rgba(46, 196, 182, 0.2);
}

.option-btn.wrong {
  background: rgba(231, 29, 54, 0.15) !important;
  border-color: var(--wrong-color) !important;
  color: var(--wrong-color) !important;
  box-shadow: 0 0 10px rgba(231, 29, 54, 0.2);
}

.option-btn.correct .option-prefix {
  background: var(--correct-color);
  color: #000;
}

.option-btn.wrong .option-prefix {
  background: var(--wrong-color);
  color: #fff;
}

/* Win Screen Overlay */
.win-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 6, 12, 0.9);
  backdrop-filter: blur(20px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.win-overlay.active {
  display: flex;
  opacity: 1;
}

.win-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 32px;
  width: 100%;
  max-width: 500px;
  padding: 3rem;
  text-align: center;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
  transform: scale(0.8);
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.win-overlay.active .win-card {
  transform: scale(1);
}

.win-crown {
  font-size: 4rem;
  animation: float 2s infinite ease-in-out;
}

.win-title {
  font-size: 2.4rem;
  font-weight: 900;
  background: linear-gradient(135deg, #ffffff 0%, #a0aec0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.winner-banner {
  font-size: 1.5rem;
  font-weight: 800;
  padding: 0.8rem 2rem;
  border-radius: 20px;
  margin: 0.5rem 0;
  width: 100%;
}

.win-overlay.p1-wins .win-card { border: 2px solid var(--p1-color); box-shadow: 0 0 30px rgba(0, 255, 213, 0.2); }
.win-overlay.p1-wins .winner-banner { background: var(--p1-bg); border: 1px solid var(--p1-color); color: var(--p1-color); box-shadow: var(--p1-glow); }

.win-overlay.p2-wins .win-card { border: 2px solid var(--p2-color); box-shadow: 0 0 30px rgba(255, 0, 85, 0.2); }
.win-overlay.p2-wins .winner-banner { background: var(--p2-bg); border: 1px solid var(--p2-color); color: var(--p2-color); box-shadow: var(--p2-glow); }

.win-stats {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 201;
}

/* Audio Controls */
.audio-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.3s ease;
}

.audio-toggle:hover {
  color: var(--text-primary);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-p1 {
  0% { box-shadow: 0 0 5px rgba(0, 255, 213, 0.4); }
  100% { box-shadow: 0 0 20px rgba(0, 255, 213, 0.8); }
}

@keyframes pulse-p2 {
  0% { box-shadow: 0 0 5px rgba(255, 0, 85, 0.4); }
  100% { box-shadow: 0 0 20px rgba(255, 0, 85, 0.8); }
}

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

@keyframes claimCell {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Responsive adjust */
@media (max-width: 600px) {
  .header-container {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  .players-indicator {
    width: 100%;
    justify-content: center;
  }
  .setup-screen, .question-card, .win-card {
    padding: 1.5rem;
  }
  .setup-title {
    font-size: 1.8rem;
  }
  .board {
    gap: 8px;
    padding: 10px;
    border-radius: 16px;
  }
  .cell {
    font-size: 1.4rem;
    border-radius: 10px;
  }
  .options-grid {
    grid-template-columns: 1fr;
  }
  .letter-badge {
    width: 50px;
    height: 50px;
    font-size: 1.6rem;
  }
}

@keyframes pulse-active {
  0% { transform: scale(1); filter: brightness(1); }
  100% { transform: scale(1.08); filter: brightness(1.3); box-shadow: 0 0 25px currentColor; }
}
