* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Tahoma', 'Segoe UI', sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  background: #021424;
  overflow: hidden;
}

#game-container {
  width: 100%;
  height: 100vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #eaf6fb;
  padding: 20px;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 0%, #0b4d72 0%, #062f4a 45%, #021424 100%);
}

/* Menu-type screens: stay centred when they fit, scroll (instead of clipping) when they don't */
.screen:not(#game-screen) {
  overflow-x: hidden;
  overflow-y: auto;
  justify-content: safe center;
}

.hidden {
  display: none !important;
}

.overlay-screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(2, 20, 36, 0.8);
  z-index: 30;
  gap: 20px;
  backdrop-filter: blur(2px);
}

.pause-title {
  font-size: 2.2rem;
}

/* ===== شاشة التحميل ===== */
#loading-screen {
  gap: 18px;
}

.loader-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 5px solid rgba(127, 216, 232, 0.2);
  border-top-color: #7fd8e8;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: #9fd3e3;
  font-size: 1rem;
  letter-spacing: 1px;
}

/* ===== فقاعات الخلفية ===== */
.bg-bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-bubbles::before, .bg-bubbles::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(127, 216, 232, 0.08);
}

.bg-bubbles::before {
  width: 380px;
  height: 380px;
  top: -100px;
  left: -80px;
}

.bg-bubbles::after {
  width: 300px;
  height: 300px;
  bottom: -80px;
  right: -60px;
}

.rising-bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.rising-bubbles span {
  position: absolute;
  bottom: -40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  animation: rise linear infinite;
}

.rising-bubbles span:nth-child(1) { left: 8%;  width: 14px; height: 14px; animation-duration: 9s;  animation-delay: 0s; }
.rising-bubbles span:nth-child(2) { left: 22%; width: 8px;  height: 8px;  animation-duration: 7s;  animation-delay: 1.5s; }
.rising-bubbles span:nth-child(3) { left: 38%; width: 18px; height: 18px; animation-duration: 11s; animation-delay: 0.5s; }
.rising-bubbles span:nth-child(4) { left: 58%; width: 10px; height: 10px; animation-duration: 8s;  animation-delay: 2.5s; }
.rising-bubbles span:nth-child(5) { left: 74%; width: 15px; height: 15px; animation-duration: 10s; animation-delay: 1s; }
.rising-bubbles span:nth-child(6) { left: 90%; width: 9px;  height: 9px;  animation-duration: 7.5s; animation-delay: 3s; }

@keyframes rise {
  0%   { transform: translateY(0) translateX(0); opacity: 0; }
  10%  { opacity: 0.8; }
  100% { transform: translateY(-110vh) translateX(20px); opacity: 0; }
}

.best-score-badge {
  position: absolute;
  top: 68px;
  right: 18px;
  z-index: 5;
  background: rgba(255,215,106,0.12);
  border: 1px solid rgba(255,215,106,0.4);
  color: #ffd76a;
  padding: 6px 14px;
  border-radius: 16px;
  font-weight: bold;
  font-size: 0.85rem;
}

/* ===== شاشات البداية والنهاية ===== */
.title-wrap {
  margin-bottom: 4px;
  z-index: 2;
}

.game-title {
  font-size: 3.4rem;
  font-weight: bold;
  background: linear-gradient(180deg, #ff8a90, #d4232c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 4px 18px rgba(212, 35, 44, 0.45);
  letter-spacing: 2px;
}

.game-subtitle {
  font-size: 1.25rem;
  color: #7fd8e8;
  margin-top: 4px;
  margin-bottom: 16px;
  z-index: 2;
}

.hero-frame {
  position: relative;
  z-index: 2;
  margin-bottom: 18px;
  border-radius: 18px;
  padding: 5px;
  background: linear-gradient(135deg, rgba(255,215,106,0.55), rgba(127,216,232,0.35), rgba(212,35,44,0.45));
  animation: float 3.5s ease-in-out infinite, frameglow 3s ease-in-out infinite;
}

.hero-frame.small {
  margin-bottom: 12px;
}

@keyframes frameglow {
  0%, 100% { box-shadow: 0 0 18px rgba(255,215,106,0.25); }
  50% { box-shadow: 0 0 28px rgba(127,216,232,0.35); }
}

.hero-image {
  max-height: 42vh;
  max-width: 100%;
  object-fit: contain;
  display: block;
  margin-bottom: 0;
  z-index: 2;
  border-radius: 14px;
}

.hero-frame .hero-image {
  animation: none;
}

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

.hero-image.small {
  max-height: 22vh;
}

.btn-row {
  display: flex;
  gap: 14px;
  z-index: 2;
  flex-wrap: wrap;
  justify-content: center;
}

.secondary-btn {
  background: linear-gradient(180deg, #4dd8ff, #1a8fd1);
  box-shadow: 0 6px 0 #0d5c85, 0 12px 24px rgba(0,0,0,0.4);
}

.corner-btn {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 5;
}

.right-corner {
  left: auto;
  right: 18px;
}

.icon-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  color: #eaf6fb;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.2);
}

.pearls-badge {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 5;
  background: rgba(255,215,106,0.15);
  border: 1px solid rgba(255,215,106,0.4);
  color: #ffd76a;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 1rem;
}

#pearls-badge-shop {
  position: static;
  margin-bottom: 10px;
}

.pearl-card .stat-value {
  color: #7fe8b0;
}

.best-card .stat-value {
  color: #ffd76a;
}

.best-card {
  border-color: rgba(255,215,106,0.35);
}

.main-btn {
  background: linear-gradient(180deg, #ff5a67, #d4232c);
  color: white;
  border: none;
  border-radius: 32px;
  padding: 15px 50px;
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 6px 0 #8f1319, 0 12px 24px rgba(0,0,0,0.45);
  transition: transform 0.1s;
  z-index: 2;
  letter-spacing: 1px;
}

.main-btn:hover {
  filter: brightness(1.08);
}

.main-btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #8f1319, 0 4px 10px rgba(0,0,0,0.4);
}

.instructions {
  margin-top: 22px;
  color: #a9c9d6;
  font-size: 0.92rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 2;
}

.instruction-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.key-icon {
  font-style: normal;
  font-size: 0.95rem;
}

.final-stats {
  display: flex;
  gap: 16px;
  margin: 18px 0 26px 0;
  z-index: 2;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 480px;
}

.stat-card {
  background: rgba(127, 216, 232, 0.08);
  border: 1px solid rgba(127, 216, 232, 0.25);
  border-radius: 14px;
  padding: 14px 26px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 110px;
}

.stat-label {
  font-size: 0.8rem;
  color: #a9c9d6;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: bold;
  color: #ffd76a;
}

/* ===== شاشة اللعب ===== */
#game-screen {
  padding: 0;
  position: relative;
  background: none;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  z-index: 10;
  background: linear-gradient(180deg, rgba(2,20,36,0.9), transparent);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 110px;
}

.hud-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,215,106,0.7);
}

.hud-controls {
  display: flex;
  gap: 8px;
}

.score-item {
  transform: scale(1.05);
}

.hud-label {
  font-size: 0.72rem;
  color: #a9c9d6;
  letter-spacing: 0.5px;
}

#score-display {
  font-size: 1.5rem;
  font-weight: bold;
  color: #ffd76a;
  text-shadow: 0 2px 8px rgba(255, 215, 106, 0.4);
}

.bar-bg {
  width: 130px;
  height: 15px;
  background: rgba(255,255,255,0.12);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.28);
}

.bar-fill {
  height: 100%;
  width: 100%;
  transition: width 0.2s linear;
}

.bar-fill.oxygen {
  background: linear-gradient(90deg, #4dd8ff, #1a8fd1);
}

.bar-fill.power {
  background: linear-gradient(90deg, #ffd76a, #ff9a3d);
}

#game-canvas {
  display: block;
  background: #073350;
}

/* ===== المتجر ===== */
.shop-title {
  font-size: 2.2rem;
  margin-top: 30px;
}

.shop-scroll {
  width: 100%;
  max-width: 720px;
  height: 62vh;
  overflow-y: auto;
  z-index: 2;
  padding: 0 8px;
}

.shop-section {
  margin-bottom: 22px;
}

.shop-section-title {
  font-size: 1.05rem;
  color: #7fd8e8;
  text-align: right;
  margin-bottom: 10px;
  border-right: 3px solid #d4232c;
  padding-right: 10px;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.shop-item {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
}

.shop-item:hover {
  transform: translateY(-3px);
}

.shop-item.equipped {
  border-color: #7fe8b0;
  background: rgba(127, 232, 176, 0.12);
  box-shadow: 0 0 16px rgba(127, 232, 176, 0.25);
}

.shop-item.rarity-common {
  border-color: rgba(169, 201, 214, 0.35);
}

.shop-item.rarity-rare {
  border-color: rgba(77, 216, 255, 0.55);
  box-shadow: 0 0 14px rgba(77, 216, 255, 0.12);
}

.shop-item.rarity-epic {
  border-color: rgba(201, 139, 255, 0.6);
  box-shadow: 0 0 16px rgba(201, 139, 255, 0.18);
}

.shop-item.rarity-legendary {
  border-color: rgba(255, 215, 106, 0.75);
  box-shadow: 0 0 20px rgba(255, 215, 106, 0.28);
}

.shop-item.rarity-legendary::before {
  content: '★';
  position: absolute;
  top: 6px;
  right: 10px;
  color: #ffd76a;
  font-size: 0.8rem;
}

.shop-item-swatch {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
}

.shop-item-name {
  font-size: 0.9rem;
  font-weight: bold;
}

.shop-item-desc {
  font-size: 0.75rem;
  color: #a9c9d6;
}

.shop-item-btn {
  border: none;
  border-radius: 16px;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  color: white;
}

.shop-item-btn.buy {
  background: linear-gradient(180deg, #ffd76a, #d4a83a);
  color: #3a2a05;
}

.shop-item-btn.equip {
  background: linear-gradient(180deg, #4dd8ff, #1a8fd1);
}

.shop-item-btn.equipped-label {
  background: #7fe8b0;
  color: #05392;
  cursor: default;
}

.shop-item-btn.disabled {
  background: rgba(255,255,255,0.15);
  color: #7f97a3;
  cursor: not-allowed;
}

.shop-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  z-index: 2;
  flex-wrap: wrap;
  justify-content: center;
}

.shop-tab {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: #a9c9d6;
  padding: 7px 18px;
  border-radius: 18px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: bold;
}

.shop-tab.active {
  background: linear-gradient(180deg, #ff5a67, #d4232c);
  color: white;
  border-color: transparent;
}

/* ===== الملتيبلاير ===== */
.mp-btn {
  background: linear-gradient(180deg, #7fe8b0, #2f9a6a);
  box-shadow: 0 6px 0 #1c6e48, 0 12px 24px rgba(0,0,0,0.4);
}

.mp-title {
  font-size: 2.1rem;
  margin-top: 20px;
  z-index: 2;
}

.mp-options {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 2;
  margin-top: 20px;
}

.mp-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 18px;
  padding: 22px;
  width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.mp-card h3 {
  color: #ffd76a;
  font-size: 1.1rem;
}

.mp-card p {
  color: #a9c9d6;
  font-size: 0.85rem;
}

.mp-code-input {
  width: 100%;
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: 6px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.25);
  color: white;
}

.mp-error {
  color: #ff8a8a;
  margin-top: 16px;
  z-index: 2;
  font-weight: bold;
}

.mp-code-display {
  font-size: 3.4rem;
  font-weight: bold;
  letter-spacing: 10px;
  color: #ffd76a;
  background: rgba(255,215,106,0.1);
  border: 2px dashed rgba(255,215,106,0.5);
  border-radius: 18px;
  padding: 14px 30px;
  margin: 14px 0 22px 0;
  z-index: 2;
}

.character-grid {
  max-width: 560px;
  margin: 18px 0;
  z-index: 2;
}

.shop-item.taken {
  opacity: 0.35;
  pointer-events: none;
}

.shop-item.selected-mine {
  border-color: #7fe8b0;
  box-shadow: 0 0 18px rgba(127,232,176,0.4);
}

.mp-status {
  color: #a9c9d6;
  font-size: 0.9rem;
  z-index: 2;
  margin-top: 10px;
}

/* ===== حالة الخصم والتحدي داخل اللعب ===== */
.opponent-hud {
  position: absolute;
  top: 66px;
  left: 20px;
  z-index: 10;
  background: rgba(0,0,0,0.35);
  border-radius: 14px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: bold;
  color: #ffd76a;
}

.opponent-marker {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.challenge-banner {
  position: absolute;
  top: 66px;
  right: 20px;
  z-index: 10;
  background: rgba(2,20,36,0.75);
  border: 1px solid rgba(255,215,106,0.4);
  border-radius: 14px;
  padding: 8px 16px;
  text-align: center;
  max-width: 220px;
}

.challenge-title {
  font-size: 0.9rem;
  font-weight: bold;
  color: #ffd76a;
}

.challenge-desc {
  font-size: 0.75rem;
  color: #eaf6fb;
  margin-top: 2px;
}

.challenge-timer {
  font-size: 0.75rem;
  color: #7fe8b0;
  margin-top: 3px;
  font-weight: bold;
}

/* ===== طبقة إعلان/نتيجة التحدي بمنتصف الشاشة ===== */
.challenge-center {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: challengeCenterFade 0.3s ease-out;
}

@keyframes challengeCenterFade {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.challenge-center-box {
  background: rgba(2, 20, 36, 0.88);
  border: 2px solid rgba(255, 215, 106, 0.5);
  border-radius: 22px;
  padding: 26px 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  max-width: 340px;
  box-shadow: 0 0 30px rgba(0,0,0,0.5);
}

.challenge-center-icon {
  font-size: 3.4rem;
  line-height: 1;
}

.challenge-center-text {
  font-size: 1.1rem;
  font-weight: bold;
  color: #eaf6fb;
}

.challenge-center.win .challenge-center-box {
  border-color: rgba(255, 215, 106, 0.9);
  box-shadow: 0 0 40px rgba(255, 215, 106, 0.4);
}

.challenge-center.win .challenge-center-text {
  color: #ffd76a;
}

.challenge-center.lose .challenge-center-box {
  border-color: rgba(127, 216, 232, 0.4);
}

.challenge-center.lose .challenge-center-text {
  color: #a9c9d6;
}

.challenge-center.draw .challenge-center-box {
  border-color: rgba(127, 232, 176, 0.6);
}

#challenge-next-btn {
  pointer-events: auto;
}

.challenge-progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: bold;
  margin-top: 4px;
}

.challenge-progress-me {
  color: #7fe8b0;
}

.challenge-progress-opp {
  color: #ffd76a;
}

/* ===== أزرار التحكم باللمس (موبايل) ===== */
.touch-controls {
  position: absolute;
  bottom: 22px;
  left: 22px;
  z-index: 15;
  width: 168px;
  height: 168px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 6px;
  direction: ltr;
}

.touch-btn {
  background: rgba(255,255,255,0.14);
  border: 2px solid rgba(255,255,255,0.32);
  border-radius: 16px;
  font-size: 1.6rem;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  padding: 0;
  cursor: pointer;
}

.touch-btn:active {
  background: rgba(255,255,255,0.32);
}

.touch-up { grid-column: 2; grid-row: 1; }
.touch-left { grid-column: 1; grid-row: 2; }
.touch-right { grid-column: 3; grid-row: 2; }
.touch-down { grid-column: 2; grid-row: 3; }

@media (max-width: 700px) {
  #hud {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .bar-bg { width: 90px; }
  .hud-label { font-size: 0.65rem; }
  .opponent-hud { top: 90px; }
  .challenge-banner { top: 90px; max-width: 160px; padding: 6px 10px; }
}

/* ===== تنبيه قلب الجهاز للوضع الأفقي (موبايل بالطول) ===== */
#rotate-prompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #021424;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #eaf6fb;
  text-align: center;
  gap: 10px;
  padding: 20px;
}

.rotate-icon {
  font-size: 4rem;
  animation: rotateHint 1.6s ease-in-out infinite;
}

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

.rotate-text {
  font-size: 1.2rem;
  font-weight: bold;
  color: #ffd76a;
}

.rotate-subtext {
  font-size: 0.9rem;
  color: #a9c9d6;
}

@media (max-width: 900px) and (orientation: portrait) {
  #rotate-prompt {
    display: flex;
  }
  #game-container {
    display: none;
  }
}
