/* ===== Match Masters-inspired Abalone ===== */

:root {
  /* Base palette */
  --bg-deep: #1a0f2e;
  --bg-mid: #2d1b4e;
  --bg-glow: #4a2980;

  /* Player colors - Blue vs Red (Match Masters style) */
  --p1-color: #2bb3ff;        /* blue stars */
  --p1-glow: #66d9ff;
  --p1-deep: #0d6dba;
  --p1-bg: #1a4d8f;

  --p2-color: #ff3d6e;        /* red/pink chips */
  --p2-glow: #ff7a9e;
  --p2-deep: #b01a47;
  --p2-bg: #8f1a3d;

  /* Accents */
  --gold: #ffc94a;
  --gold-bright: #ffe186;
  --gold-deep: #b88a1f;
  --purple: #8b5cf6;
  --purple-bright: #a78bfa;

  --text: #ffffff;
  --text-muted: rgba(255,255,255,0.7);
  --text-dim: rgba(255,255,255,0.45);

  --board-bg: #1a0f2e;
  --cell-empty: #2d1b4e;
  --cell-empty-light: #3d2868;

  --shadow-deep: 0 20px 60px rgba(0,0,0,0.7);
  --shadow-glow-blue: 0 0 30px rgba(43, 179, 255, 0.5);
  --shadow-glow-red: 0 0 30px rgba(255, 61, 110, 0.5);
  --shadow-glow-gold: 0 0 24px rgba(255, 201, 74, 0.6);

  --vh: 1vh; /* set by JS to handle mobile viewport */
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; touch-action: manipulation; }

body {
  font-family: 'Tajawal', sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(43, 179, 255, 0.25) 0%, transparent 60%),
    radial-gradient(ellipse 80% 60% at 80% 90%, rgba(255, 61, 110, 0.25) 0%, transparent 60%),
    radial-gradient(ellipse at center, var(--bg-glow) 0%, var(--bg-deep) 70%);
  background-attachment: fixed;
}

/* Subtle starfield */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 20% 30%, white, transparent),
    radial-gradient(1px 1px at 60% 70%, white, transparent),
    radial-gradient(2px 2px at 80% 10%, white, transparent),
    radial-gradient(1px 1px at 30% 80%, white, transparent),
    radial-gradient(2px 2px at 90% 50%, white, transparent),
    radial-gradient(1px 1px at 10% 60%, white, transparent),
    radial-gradient(2px 2px at 50% 20%, white, transparent),
    radial-gradient(1px 1px at 70% 40%, white, transparent);
  background-size: 250px 250px;
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
  animation: starfield 60s linear infinite;
}

@keyframes starfield {
  to { background-position: 250px 250px; }
}

#app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.screen.active { display: flex; }

/* ============ HOME / LOBBY ============ */
.home {
  align-items: center;
  justify-content: flex-start;
  padding: 40px 20px 20px;
  overflow-y: auto;
  position: relative;
}

.logo-wrap {
  text-align: center;
  margin-bottom: 32px;
}

.logo {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(48px, 13vw, 80px);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  background: linear-gradient(180deg, #fff 0%, #ffe186 50%, #ffc94a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 12px rgba(255, 201, 74, 0.5));
  text-shadow: 0 4px 0 var(--gold-deep);
  margin-bottom: 8px;
}

.logo-sub {
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--text-muted);
  font-weight: 600;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 380px;
}

.menu-btn {
  position: relative;
  padding: 18px 24px;
  border: none;
  border-radius: 16px;
  font-family: 'Tajawal', sans-serif;
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-deep);
  overflow: hidden;
  transition: transform 0.15s;
}

.menu-btn:active { transform: scale(0.97); }

.menu-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.25) 0%, transparent 50%);
  pointer-events: none;
}

.menu-btn.primary {
  background: linear-gradient(180deg, var(--p1-glow) 0%, var(--p1-color) 60%, var(--p1-deep) 100%);
  border: 2px solid var(--p1-glow);
  box-shadow: var(--shadow-deep), inset 0 -4px 0 rgba(0,0,0,0.3), 0 0 24px rgba(43, 179, 255, 0.4);
}

.menu-btn.secondary {
  background: linear-gradient(180deg, #a78bfa 0%, var(--purple) 60%, #6d28d9 100%);
  border: 2px solid #c4b5fd;
  box-shadow: var(--shadow-deep), inset 0 -4px 0 rgba(0,0,0,0.3), 0 0 24px rgba(139, 92, 246, 0.4);
}

.menu-btn.accent {
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 60%, var(--gold-deep) 100%);
  color: #2d1b4e;
  border: 2px solid var(--gold-bright);
  box-shadow: var(--shadow-deep), inset 0 -4px 0 rgba(0,0,0,0.25), 0 0 24px rgba(255, 201, 74, 0.4);
}

.menu-btn.danger {
  background: linear-gradient(180deg, var(--p2-glow) 0%, var(--p2-color) 60%, var(--p2-deep) 100%);
  border: 2px solid var(--p2-glow);
  box-shadow: var(--shadow-deep), inset 0 -4px 0 rgba(0,0,0,0.3), 0 0 24px rgba(255, 61, 110, 0.4);
}

.menu-btn.ghost {
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.2);
  box-shadow: none;
}

.menu-btn .icon {
  font-size: 28px;
  flex-shrink: 0;
}

.menu-btn .menu-text {
  flex: 1;
  text-align: right;
}

.menu-btn .menu-title {
  font-size: 17px;
  font-weight: 800;
}

.menu-btn .menu-sub {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
  margin-top: 2px;
}

.coming-soon {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.4);
  color: var(--gold-bright);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 8px;
  letter-spacing: 0.05em;
}

/* ============ DIALOG ============ */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.dialog-overlay.show { display: flex; animation: fadeIn 0.2s; }

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

.dialog {
  background: linear-gradient(180deg, var(--bg-mid), var(--bg-deep));
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-deep);
  animation: slideUp 0.3s;
}

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

.dialog-title {
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 8px;
  color: var(--gold-bright);
}

.dialog-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.field { margin-bottom: 16px; }

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  color: var(--text);
  font-family: 'Tajawal', sans-serif;
  font-size: 16px;
  font-weight: 600;
  text-align: right;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus { border-color: var(--p1-color); }
.input.code-input {
  text-align: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 28px;
  letter-spacing: 0.3em;
  font-weight: 700;
  text-transform: uppercase;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.dialog-actions .menu-btn { padding: 14px; font-size: 15px; }
.dialog-actions .menu-btn .icon { font-size: 20px; }

/* Bot difficulty options */
.bot-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}

.bot-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  font-family: 'Tajawal', sans-serif;
  cursor: pointer;
  text-align: right;
  transition: all 0.15s;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.bot-option::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.bot-option.easy::before {
  background: linear-gradient(180deg, rgba(74, 222, 128, 0.15), transparent);
}
.bot-option.medium::before {
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.15), transparent);
}
.bot-option.hard::before {
  background: linear-gradient(180deg, rgba(255, 61, 110, 0.15), transparent);
}

.bot-option:hover::before { opacity: 1; }
.bot-option:active { transform: scale(0.98); }

.bot-option.easy:hover { border-color: #4ade80; }
.bot-option.medium:hover { border-color: var(--gold); }
.bot-option.hard:hover { border-color: var(--p2-color); }

.bot-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.bot-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bot-name {
  font-size: 16px;
  font-weight: 800;
}

.bot-desc {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ============ ROOM CREATED SCREEN ============ */
.room-info {
  text-align: center;
  padding: 16px;
  background: rgba(255,255,255,0.06);
  border-radius: 16px;
  margin-bottom: 16px;
  border: 2px dashed rgba(255, 201, 74, 0.4);
}

.room-code {
  font-family: 'Fredoka', sans-serif;
  font-size: 42px;
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: 0.2em;
  text-shadow: 0 2px 0 var(--gold-deep);
  margin: 8px 0;
}

.room-code-label {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.share-link {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  background: rgba(0,0,0,0.3);
  border-radius: 10px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  direction: ltr;
}

.share-link-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: monospace;
}

.copy-btn {
  background: var(--p1-color);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: 'Tajawal', sans-serif;
}

.waiting-line {
  text-align: center;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.dot-loader {
  display: inline-flex;
  gap: 4px;
}
.dot-loader span {
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  animation: dot-bounce 1.4s ease-in-out infinite;
}
.dot-loader span:nth-child(2) { animation-delay: 0.2s; }
.dot-loader span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* Searching for opponent screen */
.search-card {
  background: linear-gradient(180deg, var(--bg-card), var(--bg-warm));
  border: 2px solid rgba(255, 201, 74, 0.3);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow-deep);
  margin-bottom: 16px;
}

.search-spinner {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 24px;
}

.spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--gold);
  animation: spin 1.5s linear infinite;
}

.spinner-ring:nth-child(2) {
  inset: 8px;
  border-top-color: var(--p1-color);
  animation-duration: 2s;
  animation-direction: reverse;
}

.spinner-ring:nth-child(3) {
  inset: 16px;
  border-top-color: var(--p2-color);
  animation-duration: 1s;
}

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

.search-elapsed {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
}

.search-elapsed-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.search-elapsed-time {
  font-family: 'Fredoka', sans-serif;
  font-size: 36px;
  font-weight: 600;
  color: var(--gold-bright);
  letter-spacing: 0.05em;
}

.search-info {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Tutorial overlay */
.tutorial-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  z-index: 300;
  pointer-events: none;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tutorial-overlay.show {
  transform: translateY(0);
  pointer-events: auto;
}

.tutorial-card {
  background: linear-gradient(180deg, var(--bg-mid), var(--bg-deep));
  border: 2px solid var(--gold);
  border-radius: 20px;
  padding: 16px 18px;
  max-width: 480px;
  margin: 0 auto;
  box-shadow: var(--shadow-deep), var(--shadow-glow-gold);
}

.tutorial-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

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

.tutorial-progress {
  font-family: 'Fredoka', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--gold);
  background: rgba(255, 201, 74, 0.15);
  padding: 4px 10px;
  border-radius: 10px;
  letter-spacing: 0.05em;
}

.tutorial-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--gold-bright);
  margin-bottom: 6px;
}

.tutorial-instruction {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-cream);
  margin-bottom: 12px;
}

.tutorial-success {
  font-size: 14px;
  font-weight: 800;
  color: #4ade80;
  margin-bottom: 8px;
  padding: 8px;
  background: rgba(74, 222, 128, 0.1);
  border-radius: 8px;
  text-align: center;
}

.tutorial-actions {
  display: flex;
  gap: 8px;
}
.tutorial-actions .menu-btn { flex: 1; margin: 0; }

/* ===== Profile Button (top corner of home) ===== */
.profile-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold-deep));
  border: 2px solid var(--gold-bright);
  color: var(--bg-deep);
  font-family: 'Fredoka', sans-serif;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4), 0 0 16px rgba(255, 201, 74, 0.3);
  transition: transform 0.15s;
}
.profile-btn:active { transform: scale(0.92); }

.profile-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Profile Screen ===== */
.back-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.2);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 12px;
  font-family: 'Tajawal', sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  z-index: 5;
}
.back-btn:active { transform: scale(0.95); }

.profile-header {
  text-align: center;
  margin-top: 32px;
  margin-bottom: 24px;
}

.profile-big-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold-deep));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 48px;
  font-weight: 700;
  color: var(--bg-deep);
  margin: 0 auto 12px;
  border: 4px solid var(--gold-bright);
  box-shadow: var(--shadow-deep), var(--shadow-glow-gold);
}

.profile-name {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  font-family: 'Tajawal', sans-serif;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
}
.link-btn:active { opacity: 0.6; }

.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
  max-width: 420px;
  width: 100%;
}

.stat-tile {
  padding: 14px 8px;
  border-radius: 14px;
  text-align: center;
  border: 2px solid transparent;
  background: rgba(255,255,255,0.06);
}

.stat-tile.gold {
  background: linear-gradient(180deg, rgba(255, 201, 74, 0.2), rgba(184, 138, 31, 0.1));
  border-color: rgba(255, 201, 74, 0.4);
}
.stat-tile.green {
  background: linear-gradient(180deg, rgba(74, 222, 128, 0.2), rgba(22, 101, 52, 0.1));
  border-color: rgba(74, 222, 128, 0.4);
}
.stat-tile.blue {
  background: linear-gradient(180deg, rgba(43, 179, 255, 0.2), rgba(13, 109, 186, 0.1));
  border-color: rgba(43, 179, 255, 0.4);
}

.stat-tile .stat-value {
  font-family: 'Fredoka', sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-tile.gold .stat-value { color: var(--gold-bright); }
.stat-tile.green .stat-value { color: #4ade80; }
.stat-tile.blue .stat-value { color: var(--p1-glow); }

.stat-tile .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  font-weight: 600;
}

.stats-section {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(0,0,0,0.15));
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  max-width: 420px;
  width: 100%;
}

.stats-section-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--gold-bright);
  margin-bottom: 12px;
  text-align: right;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.stat-row:last-child { border-bottom: none; }

.stat-row-label {
  font-size: 13px;
  color: var(--text-cream);
  font-weight: 500;
}

.stat-row-value {
  font-family: 'Fredoka', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.stat-row-value.gold { color: var(--gold-bright); }

.profile-actions {
  max-width: 420px;
  width: 100%;
  margin: 20px 0;
}

.danger-text { color: #f4a890 !important; }
.danger-text:hover { border-color: var(--p2-color); }

/* ============ GAME SCREEN ============ */
.game {
  padding: 8px;
  gap: 8px;
  position: relative;
}

/* Header with players VS */
.header-vs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px;
  padding: 8px;
  position: relative;
}

.player-card {
  position: relative;
  padding: 10px 12px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));
  border: 2px solid rgba(255,255,255,0.15);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.3s;
  overflow: hidden;
}

.player-card.p1 {
  background: linear-gradient(180deg, var(--p1-bg), rgba(13, 109, 186, 0.4));
  border-color: var(--p1-color);
}

.player-card.p2 {
  background: linear-gradient(180deg, var(--p2-bg), rgba(176, 26, 71, 0.4));
  border-color: var(--p2-color);
}

.player-card.active {
  transform: scale(1.04);
  box-shadow: 0 0 24px currentColor;
}

.player-card.p1.active { box-shadow: var(--shadow-glow-blue); border-color: var(--p1-glow); }
.player-card.p2.active { box-shadow: var(--shadow-glow-red); border-color: var(--p2-glow); }

.player-card .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(255,255,255,0.3), rgba(255,255,255,0.1));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  border: 2px solid rgba(255,255,255,0.3);
  flex-shrink: 0;
}

.player-card.p1 .avatar { background: linear-gradient(135deg, var(--p1-glow), var(--p1-deep)); }
.player-card.p2 .avatar { background: linear-gradient(135deg, var(--p2-glow), var(--p2-deep)); }

.player-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-name-text {
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.you-badge {
  font-size: 9px;
  background: var(--gold);
  color: var(--bg-deep);
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

/* Score dots row (4/6, 0/6 style) */
.score-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.score-text {
  font-family: 'Fredoka', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.score-dots {
  display: flex;
  gap: 3px;
  flex: 1;
}

.score-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.2);
  transition: all 0.3s;
}

.score-dot.filled {
  background: var(--gold);
  border-color: var(--gold-bright);
  box-shadow: 0 0 6px var(--gold);
}

.vs-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold-deep));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  padding: 0 4px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

/* Turn banner */
.turn-banner {
  margin: 0 8px;
  padding: 10px 16px;
  text-align: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 18px;
  font-weight: 600;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--p1-glow), var(--p1-color), var(--p1-deep));
  border: 2px solid var(--p1-glow);
  box-shadow: 0 4px 0 var(--p1-deep), 0 0 20px rgba(43, 179, 255, 0.4);
  color: white;
  text-shadow: 0 2px 2px rgba(0,0,0,0.4);
  transition: all 0.3s;
  position: relative;
}

.turn-banner.opponent {
  background: linear-gradient(180deg, var(--p2-glow), var(--p2-color), var(--p2-deep));
  border-color: var(--p2-glow);
  box-shadow: 0 4px 0 var(--p2-deep), 0 0 20px rgba(255, 61, 110, 0.4);
}

.turn-banner.waiting {
  background: linear-gradient(180deg, #a78bfa, var(--purple), #6d28d9);
  border-color: #a78bfa;
  box-shadow: 0 4px 0 #5b21b6;
}

.turn-banner.winner-banner {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold), var(--gold-deep));
  border-color: var(--gold-bright);
  color: var(--bg-deep);
  text-shadow: none;
}

/* Timer bar inside banner */
.timer-bar {
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255,255,255,0.3);
  border-radius: 0 0 14px 14px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  background: white;
  width: 100%;
  transform-origin: right;
  transition: transform 0.1s linear;
}
.timer-fill.danger { background: #ffaa00; animation: timerPulse 0.5s infinite; }
@keyframes timerPulse {
  50% { opacity: 0.5; }
}

/* Board */
.board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.board {
  position: relative;
  /* قيد بالعرض وبالارتفاع المتاح */
  width: min(95vw, 480px, 95%);
  max-height: 100%;
  aspect-ratio: 1;
  /* fallback لو aspect-ratio مش supported */
  height: auto;
  border-radius: 32px;
  background:
    radial-gradient(ellipse at center, rgba(139, 92, 246, 0.25) 0%, transparent 70%),
    linear-gradient(180deg, #2d1b4e 0%, #1a0f2e 100%);
  border: 3px solid var(--gold);
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.6),
    0 8px 30px rgba(0,0,0,0.6),
    0 0 0 4px rgba(255, 201, 74, 0.2),
    0 0 40px rgba(255, 201, 74, 0.2);
  padding: 4%;
  flex-shrink: 0;
}

/* اضمن إن البورد يكون مربع حتى لو الـ height محدود */
@supports (aspect-ratio: 1) {
  .board { aspect-ratio: 1 / 1; }
}

.board-rotated {
  transform: rotate(180deg);
}

.board-inner {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Cells */
.cell {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, var(--cell-empty-light) 0%, var(--cell-empty) 100%);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.6), inset 0 -1px 1px rgba(255,255,255,0.1);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
}

.board-rotated .cell .marble,
.board-rotated .cell .target-indicator {
  /* counter-rotate marbles & indicators so they stay upright per viewer */
  transform: rotate(180deg);
}

.cell:active { transform: translate(-50%, -50%) scale(0.92); }

/* Marble */
.marble {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  position: relative;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.marble.p1 {
  background:
    radial-gradient(circle at 35% 30%, #ffffff 0%, var(--p1-glow) 30%, var(--p1-color) 60%, var(--p1-deep) 100%);
  box-shadow:
    inset -3px -4px 8px rgba(0,0,0,0.3),
    inset 2px 3px 6px rgba(255,255,255,0.4),
    0 3px 6px rgba(0,0,0,0.5),
    0 0 12px rgba(43, 179, 255, 0.4);
}

.marble.p2 {
  background:
    radial-gradient(circle at 35% 30%, #ffffff 0%, var(--p2-glow) 30%, var(--p2-color) 60%, var(--p2-deep) 100%);
  box-shadow:
    inset -3px -4px 8px rgba(0,0,0,0.3),
    inset 2px 3px 6px rgba(255,255,255,0.4),
    0 3px 6px rgba(0,0,0,0.5),
    0 0 12px rgba(255, 61, 110, 0.4);
}

/* Star shape for variety - subtle */
.marble::before {
  content: '';
  position: absolute;
  inset: 18%;
  background: radial-gradient(circle, rgba(255,255,255,0.4) 0%, transparent 60%);
  border-radius: 50%;
  pointer-events: none;
}

.marble.selected {
  transform: scale(1.12);
  animation: selectedPulse 1.2s ease-in-out infinite;
}

@keyframes selectedPulse {
  0%, 100% {
    box-shadow:
      inset -3px -4px 8px rgba(0,0,0,0.3),
      inset 2px 3px 6px rgba(255,255,255,0.4),
      0 0 0 3px var(--gold-bright),
      0 0 24px var(--gold);
  }
  50% {
    box-shadow:
      inset -3px -4px 8px rgba(0,0,0,0.3),
      inset 2px 3px 6px rgba(255,255,255,0.4),
      0 0 0 4px var(--gold-bright),
      0 0 36px var(--gold);
  }
}

/* Last move highlight */
.marble.last-moved {
  animation: lastMovePulse 1.8s ease-out;
}
@keyframes lastMovePulse {
  0% { box-shadow: 0 0 0 0 var(--gold), 0 3px 6px rgba(0,0,0,0.5); }
  100% { box-shadow: 0 0 0 20px transparent, 0 3px 6px rgba(0,0,0,0.5); }
}

/* Valid target indicator - golden dot */
.target-indicator {
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--gold-bright) 0%, var(--gold) 70%, transparent 100%);
  box-shadow: 0 0 16px var(--gold), 0 0 8px var(--gold-bright);
  animation: targetPulse 1.2s ease-in-out infinite;
  pointer-events: none;
}

.target-indicator.push {
  background: radial-gradient(circle, #fff 0%, var(--p2-color) 70%, transparent 100%);
  box-shadow: 0 0 20px var(--p2-color), 0 0 12px white;
}

@keyframes targetPulse {
  0%, 100% { transform: scale(0.7); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 1; }
}

/* Moving marble animation overlay */
.flying-marble {
  position: absolute;
  pointer-events: none;
  z-index: 50;
  transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1), top 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Marble pushed off the board */
.marble-pushed-off {
  position: absolute;
  pointer-events: none;
  z-index: 60;
  animation: pushedOff 0.9s ease-in forwards;
}

@keyframes pushedOff {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  60% { transform: translate(var(--push-x, 50px), var(--push-y, -100px)) scale(0.8) rotate(180deg); opacity: 1; }
  100% { transform: translate(calc(var(--push-x, 100px) * 2), calc(var(--push-y, -200px) * 2)) scale(0.3) rotate(540deg); opacity: 0; }
}

/* Impact flash at push point */
.impact-flash {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, white 0%, var(--gold) 30%, transparent 70%);
  transform: translate(-50%, -50%) scale(0);
  z-index: 40;
  animation: impactBurst 0.6s ease-out forwards;
}

@keyframes impactBurst {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
}

/* Particle burst for scoring */
.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 40;
  background: var(--gold-bright);
  box-shadow: 0 0 8px var(--gold);
}

@keyframes particleFly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--px), var(--py)) scale(0); opacity: 0; }
}

/* Footer area */
.footer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  gap: 8px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.2);
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.icon-btn:active { transform: scale(0.9); }

.action-clear {
  flex: 1;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.04));
  border: 2px solid rgba(255,255,255,0.18);
  color: white;
  font-family: 'Tajawal', sans-serif;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.action-clear:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.hint-text {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 0 12px;
}

/* Banner toast */
.banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: linear-gradient(180deg, var(--bg-mid), var(--bg-deep));
  border: 2px solid var(--gold);
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--gold-bright);
  z-index: 500;
  transition: transform 0.3s ease-out;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-deep);
}
.banner.show { transform: translateX(-50%) translateY(0); }
.banner.error { border-color: var(--p2-color); color: white; background: linear-gradient(180deg, var(--p2-deep), var(--p2-bg)); }
.banner.success { border-color: #4ade80; color: white; background: linear-gradient(180deg, #166534, #14532d); }

/* Winner modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.show { display: flex; animation: fadeIn 0.3s; }

.modal {
  background: linear-gradient(180deg, var(--bg-mid), var(--bg-deep));
  border: 3px solid var(--gold);
  border-radius: 24px;
  padding: 32px 24px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-deep), var(--shadow-glow-gold);
  animation: slideUp 0.4s;
}

.trophy {
  font-size: 80px;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 12px rgba(255, 201, 74, 0.6));
  animation: trophyBounce 0.8s ease-out;
}

@keyframes trophyBounce {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(0); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.modal h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 36px;
  color: var(--gold-bright);
  margin-bottom: 8px;
}

.modal-name {
  font-size: 24px;
  font-weight: 800;
  color: white;
  margin-bottom: 24px;
}

.modal .menu-btn { width: 100%; margin-bottom: 10px; }

/* Help screen */
.help-content {
  display: none;
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, var(--bg-mid), var(--bg-deep));
  z-index: 150;
  padding: 60px 20px 20px;
  overflow-y: auto;
  z-index: 250;
}
.help-content.show { display: block; }

.help-content h3 {
  font-family: 'Fredoka', sans-serif;
  color: var(--gold-bright);
  font-size: 28px;
  margin-bottom: 16px;
  text-align: center;
}

.help-content p, .help-content li {
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 8px;
}

.help-content ul {
  padding-right: 20px;
  margin-bottom: 16px;
  list-style: '✦ ';
}

.help-content strong { color: var(--gold-bright); }

.close-help {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--p2-color);
  color: white;
  border: 2px solid var(--p2-glow);
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow-deep);
}

.help-inner { max-width: 500px; margin: 0 auto; }

/* Mobile tweaks */
@media (max-height: 700px) {
  .home { padding: 24px 20px 16px; }
  .logo-wrap { margin-bottom: 20px; }
  .menu-btn { padding: 14px 18px; }
  .menu-btn .menu-sub { display: none; }
}

@media (max-width: 400px) {
  .player-card { padding: 8px 10px; }
  .player-card .avatar { width: 32px; height: 32px; font-size: 16px; }
  .player-name-text { font-size: 12px; }
  .score-text { font-size: 14px; }
  .vs-badge { font-size: 20px; }
  .turn-banner { font-size: 16px; padding: 8px 12px; }
}

/* Connection indicator */
.conn-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
  z-index: 30;
}
.conn-indicator.off { background: var(--p2-color); box-shadow: 0 0 8px var(--p2-color); }
