* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Cairo", sans-serif;
}

body {
  background: linear-gradient(135deg, #2193b0, #6dd5ed, #b2f0f7);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

  .container {
    width: 100%;
    max-width: 500px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    padding: 30px;
    text-align: center;
    position: relative;
    overflow: hidden;
  }

  h1 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-weight: 600;
  }

  .status {
    font-size: 18px;
    margin: 15px 0;
    color: #34495e;
    font-weight: 500;
    min-height: 27px;
  }

  .game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 10px;
    margin: 20px auto;
    max-width: 300px;
  }

  .cell {
    background: #ecf0f1;
    border-radius: 10px;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  }

  .cell:hover {
    background: #dfe6e9;
    transform: translateY(-2px);
  }

  .cell.x {
    color: #e74c3c;
  }

  .cell.o {
    color: #3498db;
  }

  .winning-cell {
    background-color: rgba(46, 204, 113, 0.2);
    animation: pulse 1s infinite;
  }

  @keyframes pulse {
    0% {
      transform: scale(1);
    }
    50% {
      transform: scale(1.05);
    }
    100% {
      transform: scale(1);
    }
  }

  /* شاشة اختيار نوع اللعب */
  .mode-screen {
    text-align: center;
    display: none;
  }

  .mode-screen p {
    font-size: 20px;
    color: #2c3e50;
    margin-bottom: 20px;
    font-weight: 600;
  }

  .mode-choices {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
  }

  .mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 20px 30px;
    font-size: 18px;
    font-weight: bold;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  }

  .mode-ai {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
  }

  .mode-player {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
  }

  .mode-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
  }

  .mode-icon {
    font-size: 28px;
  }

  .mode-text {
    font-size: 18px;
  }

  .choice-screen {
    text-align: center;
    display: none;
  }

  .choices {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 30px 0;
  }

  .choice-btn {
    padding: 15px 30px;
    font-size: 22px;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100px;
  }

  .choice-x {
    background: #e74c3c;
    color: white;
  }

  .choice-o {
    background: #3498db;
    color: white;
  }

  .choice-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  }

  .result-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* background: rgba(255, 255, 255, 0.95); */
    border-radius: 20px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
  }

  .result-message {
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 30px;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
  }

  .win {
    background: rgba(46, 204, 113, 0.2);
    color: #27ae60;
  }

  .lose {
    background: rgba(231, 76, 60, 0.2);
    color: #c0392b;
  }

  .draw {
    background: rgba(241, 196, 15, 0.2);
    color: #d35400;
  }

  .start-btn {
    padding: 15px 40px;
    font-size: 18px;
    font-weight: bold;
    background: #2c3e50;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
  }

  .start-btn:hover {
    background: #1a252f;
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  }

  .loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
  }

  .xo-logo {
    font-size: 60px;
    font-weight: bold;
    margin-bottom: 30px;
    color: #2c3e50;
  }

  .x-part {
    color: #e74c3c;
  }

  .o-part {
    color: #3498db;
  }

  .progress-container {
    width: 80%;
    height: 20px;
    background: #ecf0f1;
    border-radius: 10px;
    overflow: hidden;
  }

  .progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #3498db, #e74c3c);
    border-radius: 10px;
    transition: width 0.3s ease;
  }

  @media (max-width: 500px) {
    .container {
      padding: 20px 15px;
      border-radius: 15px;
    }

    .cell {
      height: 80px;
      font-size: 35px;
    }

    h1 {
      font-size: 24px;
    }

    .status {
      font-size: 16px;
    }

    .result-message {
      font-size: 28px;
      padding: 15px;
    }
  }

  .rotate-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #fff;
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text-align: center;
  }

  .rotate-warning .rotate-icon {
    width: 100px;
    height: 100px;
    margin-bottom: 20px;
    animation: rotate 2s infinite ease-in-out;
  }

  @keyframes rotate {
    0%,
    100% {
      transform: rotate(0deg);
    }
    50% {
      transform: rotate(90deg);
    }
  }

  @media screen and (orientation: landscape) and (max-width: 1024px) {
    .rotate-warning {
      display: flex;
    }

    .game-container {
      display: none;
    }
  }

/* زر التعليمات */
.instructions-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  z-index: 5;
}

.instructions-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* مودل التعليمات */
.instructions-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  z-index: 1000;
  overflow-y: auto;
  padding: 20px;
}

.instructions-modal.show {
  display: flex !important;
  justify-content: center;
  align-items: center;
}

.instructions-content {
  background: white;
  border-radius: 20px;
  max-width: 500px;
  width: 100%;
  padding: 30px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.instructions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 2px solid #f0f0f0;
}

.instructions-header h2 {
  color: #2c3e50;
  font-size: 24px;
  margin: 0;
}

.close-instructions {
  background: #e74c3c;
  color: white;
  border: none;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-instructions:hover {
  background: #c0392b;
  transform: rotate(90deg);
}

.instructions-body {
  margin-bottom: 20px;
}

.instruction-item {
  display: flex;
  align-items: flex-start;
  background: #f8f9fa;
  padding: 15px;
  border-radius: 12px;
  margin-bottom: 15px;
  transition: all 0.3s ease;
}

.instruction-item:hover {
  background: #e9ecef;
  transform: translateX(5px);
}

.instruction-icon {
  font-size: 32px;
  margin-left: 15px;
  min-width: 40px;
}

.instruction-text h3 {
  color: #2c3e50;
  font-size: 18px;
  margin: 0 0 8px 0;
}

.instruction-text p {
  color: #7f8c8d;
  font-size: 14px;
  margin: 0;
  line-height: 1.6;
}

.instructions-footer {
  text-align: center;
  padding-top: 15px;
  border-top: 2px solid #f0f0f0;
}

.start-playing-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 15px 40px;
  border-radius: 25px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  width: 100%;
}

.start-playing-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* تحسين البوب أب */
.result-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.result-content {
  text-align: center;
  position: relative;
}

.result-icon {
  font-size: 80px;
  margin-bottom: 20px;
  animation: bounceIn 0.6s ease-out;
}

@keyframes bounceIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-message {
  font-size: 36px;
  font-weight: bold;
  margin-bottom: 20px;
  padding: 20px;
  border-radius: 15px;
  text-align: center;
  animation: slideInUp 0.5s ease-out;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

@keyframes slideInUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.result-score {
  font-size: 20px;
  color: white;
  margin-top: 10px;
  font-weight: 600;
}

.win {
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: white;
  box-shadow: 0 10px 40px rgba(56, 239, 125, 0.4);
}

.win .result-icon::before {
  content: "🏆";
}

.lose {
  background: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%);
  color: white;
  box-shadow: 0 10px 40px rgba(238, 9, 121, 0.4);
}

.lose .result-icon::before {
  content: "😢";
}

.draw {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
  box-shadow: 0 10px 40px rgba(240, 147, 251, 0.4);
}

.draw .result-icon::before {
  content: "🤝";
}

/* تأثير الكونفيتي */
.confetti-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #f0f;
  animation: confetti-fall 3s linear infinite;
}

@keyframes confetti-fall {
  to {
    transform: translateY(100vh) rotate(360deg);
    opacity: 0;
  }
}

/* تأثير اهتزاز للخسارة */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
  20%, 40%, 60%, 80% { transform: translateX(10px); }
}

.lose .result-message {
  animation: shake 0.5s ease-in-out, slideInUp 0.5s ease-out;
}

/* تحسينات responsive */
@media (max-width: 500px) {
  .instructions-content {
    padding: 20px;
  }

  .instructions-header h2 {
    font-size: 20px;
  }

  .instruction-icon {
    font-size: 28px;
  }

  .instruction-text h3 {
    font-size: 16px;
  }

  .instruction-text p {
    font-size: 13px;
  }

  .result-message {
    font-size: 28px;
    padding: 15px;
  }

  .result-icon {
    font-size: 60px;
  }
}
