/* ═══════════════════════════════════════
   TABLA WORLD — MANCALA / מנקלה
   RTL · Hebrew · Arabic · Theme Support
   ═══════════════════════════════════════ */

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

:root {
  --bg:         var(--world-bg, #0d0d0f);
  --bg2:        var(--world-bg-2, #17171a);
  --wood-dark:  #6b3a1f;
  --wood-mid:   #8b4513;
  --wood-light: #a0522d;
  --wood-grain: #7a3e18;
  --cell-dark:  #3d1a00;
  --cell-light: #e8c99a;
  --gold:       var(--world-accent, #b9f36b);
  --gold2:      var(--world-accent-2, #d7ff9b);
  --text:       var(--world-text, #f5f5f5);
  --text-dim:   var(--world-muted, #a6a6ad);
  --shadow:     rgba(0,0,0,0.7);
  --radius:     12px;
  --font-main:  'Heebo', 'Segoe UI', 'Arial', sans-serif;
  
  --board-bg: linear-gradient(160deg, var(--world-panel-strong, #20262a), var(--world-bg-2, #17171a) 55%, var(--world-bg, #0d0d0f));
  --pit-bg: rgba(0,0,0,0.4);
  --pit-shadow: inset 0 8px 16px rgba(0,0,0,0.7);
  --board-border: var(--world-accent, #b9f36b);
}

[data-theme="light"] {
  --bg: var(--world-light-bg, #f7f7f4);
  --bg2: var(--world-light-bg-2, #eceee8);
  --text: #182019;
  --text-dim: #526057;
  --wood-dark: #d7ccc8;
  --board-bg: linear-gradient(160deg, #ffffff, #e8eee5 55%, #dce5d8);
  --pit-bg: rgba(90, 60, 20, 0.15);
  --pit-shadow: inset 0 6px 12px rgba(90, 60, 20, 0.4);
  --board-border: #8d6e63;
  --gold: #477a11;
}

[data-theme="navy-gold"] {
  --bg: #0f172a;
  --bg2: #1e293b;
  --text: #f8fafc;
  --text-dim: #cbd5e1;
  --board-bg: linear-gradient(160deg, #1e293b 0%, #0f172a 30%, #334155 60%, #020617 100%);
  --pit-bg: rgba(0,0,0,0.5);
  --pit-shadow: inset 0 6px 12px rgba(0,0,0,0.8);
  --board-border: #d9a441;
  --gold: #d9a441;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  /* No `direction: rtl` here: an author rule on html/body outranks the [dir]
     attribute the language switcher sets, so English stayed RTL no matter what
     the player picked. Direction now follows <html dir>, which the game sets. */
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer; border: none; font-family: inherit; font-size: inherit;
  transition: transform .12s, filter .12s; touch-action: manipulation;
}
button:active { transform: scale(0.94); }

/* HEADER */
.mancala-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--world-panel, rgba(18,20,24,.82));
  border-bottom: 1px solid var(--world-line, rgba(185,243,107,.18));
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
}
.back-btn {
  color: var(--gold); text-decoration: none; font-size: 0.9rem; font-weight: 600;
  padding: 6px 12px; border: 1px solid var(--world-line, rgba(185,243,107,.28)); border-radius: 8px;
  transition: background 0.2s;
}
.back-btn:hover { background: rgba(185,243,107,0.15); }
.mancala-brand { font-size: 1.1rem; font-weight: 900; color: var(--gold); text-shadow: 0 0 15px rgba(185,243,107,0.5); }

/* SCREENS */
.screen {
  display: none; position: fixed; top: 44px; bottom: 0; left: 0; right: 0;
  align-items: center; justify-content: center; flex-direction: column;
  background: radial-gradient(ellipse at 50% 30%, var(--bg2) 0%, var(--bg) 65%);
  overflow: auto; padding: 16px;
}
.screen.active { display: flex; }

/* MENU */
.menu-logo { font-size: clamp(2rem,8vw,3.5rem); font-weight: 900; color: var(--gold); margin-bottom: 4px; }
.menu-sub { font-size: .9rem; color: var(--text-dim); letter-spacing: .15em; text-transform: uppercase; margin-bottom: 40px; }

.menu-preview {
  display: flex; gap: 8px; margin-bottom: 36px; padding: 12px;
  background: var(--board-bg); border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow);
}
.mp-store { width: 24px; border-radius: 12px; background: var(--pit-bg); }
.mp-pits { display: flex; flex-direction: column; gap: 6px; }
.mp-row { display: flex; gap: 6px; }
.mp-pit { width: 24px; height: 24px; border-radius: 50%; background: var(--pit-bg); }

.menu-btns { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 320px; }
.btn-primary {
  padding: 16px 24px; border-radius: var(--radius); font-size: clamp(.95rem,3.5vw,1.1rem); font-weight: 700;
  background: linear-gradient(135deg, var(--gold), var(--gold2)); color: #0d0d0f;
  box-shadow: 0 4px 16px rgba(0,0,0,.5), 0 1px 0 rgba(255,255,255,.15) inset;
}
.btn-secondary {
  padding: 14px 24px; border-radius: var(--radius); font-size: clamp(.88rem,3vw,1rem); font-weight: 600;
  background: rgba(128,128,128,.1); color: var(--text); border: 1px solid rgba(128,128,128,.3);
}
.menu-footer { margin-top: 28px; display: flex; gap: 12px; }
.btn-icon {
  padding: 8px 14px; border-radius: 8px; background: rgba(128,128,128,.1);
  color: var(--text); font-size: 1rem; border: 1px solid rgba(128,128,128,.2);
}

/* DIFFICULTY */
.diff-title { font-size: clamp(1.2rem,5vw,1.8rem); font-weight: 800; color: var(--gold); margin-bottom: 28px; }
.diff-btns { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 300px; }

/* GAME TOPBAR */
#screen-game { justify-content: flex-start; padding: 8px 8px 16px; overflow: hidden; }
.game-topbar {
  width: 100%; max-width: 800px; display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px; margin-bottom: 20px;
}
.score-panel {
  display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.15);
  padding: 6px 12px; border-radius: 8px;
}
.score-panel.mine { box-shadow: 0 0 0 2px var(--gold); }
.score-dot { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.score-dot.red { background: radial-gradient(circle at 35% 30%, #ff8080, #dc2626); }
.score-dot.white { background: radial-gradient(circle at 35% 30%, #fff, #ddd); }
.you-tag { font-size: .62rem; font-weight: 700; color: var(--gold); letter-spacing: .04em; }
.score-num { font-size: 1.1rem; font-weight: 700; color: var(--text); min-width: 18px; text-align: center; }
#status-text { flex: 1; text-align: center; font-size: clamp(.85rem,2.5vw,1rem); font-weight: 700; color: var(--text); }
.btn-topbar { padding: 5px 10px; border-radius: 6px; background: rgba(128,128,128,.1); color: var(--text-dim); border: 1px solid rgba(128,128,128,.2); }

/* BOARD */
.board-wrap { display: flex; justify-content: center; align-items: center; flex: 1; width: 100%; }
.board-frame {
  background: var(--board-bg);
  padding: clamp(10px, 2.5vw, 24px);
  border-radius: 30px;
  box-shadow: 0 0 0 4px var(--board-border), 0 20px 60px rgba(0,0,0,.6);
  position: relative;
  max-width: 1000px;
  width: 95%;
}

#board { display: flex; gap: clamp(8px, 2vw, 16px); position: relative; }
.pits-container { display: flex; flex-direction: column; gap: clamp(8px, 2vw, 16px); flex: 1; }
.pits-row { display: flex; gap: clamp(8px, 2vw, 16px); justify-content: space-between; }

/* Pulse animation for active row */
@keyframes row-pulse {
  0% { box-shadow: 0 0 0 0 rgba(217, 164, 65, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(217, 164, 65, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 164, 65, 0); }
}
.pits-row.active-row {
  border-radius: 40px;
  animation: row-pulse 2s infinite;
  background: rgba(217, 164, 65, 0.05);
}

.pit, .store {
  background: var(--pit-bg);
  box-shadow: var(--pit-shadow);
  position: relative;
}
.pit {
  flex: 1; aspect-ratio: 1; border-radius: 50%;
  cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;
}
.pit.playable:hover { transform: scale(1.05); }
.pit.playable::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 0 15px var(--gold); opacity: 0; transition: opacity 0.2s;
}
.pit.playable:hover::after { opacity: 1; }

.store {
  width: clamp(50px, 12vw, 80px);
  border-radius: 40px;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
}

.pit-count, .store-count {
  position: absolute; font-size: clamp(0.8rem, 2.5vw, 1.1rem); font-weight: bold;
  color: var(--text-dim); width: 100%; text-align: center;
}
#row-a .pit-count { bottom: -28px; }
#row-b .pit-count { top: -28px; }
.store-count { bottom: -28px; }

/* STONES */
#stones-layer { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.stone {
  position: absolute;
  width: clamp(10px, 3vw, 16px);
  height: clamp(10px, 3vw, 16px);
  border-radius: 50%;
  box-shadow: inset -2px -2px 4px rgba(0,0,0,0.5), 2px 2px 4px rgba(0,0,0,0.4);
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  top: 0; left: 0; /* Base position, modified by JS transform */
}
.stone.c0 { background: radial-gradient(circle at 30% 30%, #ff6b81, #ff4757); }
.stone.c1 { background: radial-gradient(circle at 30% 30%, #7bed9f, #2ed573); }
.stone.c2 { background: radial-gradient(circle at 30% 30%, #70a1ff, #1e90ff); }
.stone.c3 { background: radial-gradient(circle at 30% 30%, #eccc68, #ffa502); }
.stone.c4 { background: radial-gradient(circle at 30% 30%, #a4b0be, #747d8c); }

/* TOAST */
#toast-msg {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: var(--gold); color: #0d0d0f;
  padding: 10px 24px; border-radius: 20px; font-weight: 800; font-size: 1.1rem;
  opacity: 0; transition: opacity .3s, transform .3s;
  pointer-events: none; z-index: 200;
  box-shadow: 0 6px 20px rgba(0,0,0,.6);
}
#toast-msg.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* WIN SCREEN */
#screen-win { text-align: center; z-index: 100; }
#win-emoji { font-size: clamp(4rem,15vw,7rem); margin-bottom: 16px; filter: drop-shadow(0 4px 16px rgba(0,0,0,.5)); }
#win-msg { font-size: clamp(1.6rem,7vw,2.8rem); font-weight: 900; color: var(--gold); margin-bottom: 40px; }
.win-btns { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 280px; margin: 0 auto; }

/* RESPONSIVE */
@media (max-width: 600px) {
  #board { flex-direction: row; gap: 6px; }
  .pits-container { gap: 6px; }
  .pits-row { gap: 6px; }
  .board-frame { padding: 16px 8px; width: 98%; border-radius: 20px; }
  .store { width: 12vw; border-radius: 20px; }
  .pit-count, .store-count { font-size: 0.8rem; }
  #row-a .pit-count, .store-count { bottom: -20px; }
  #row-b .pit-count { top: -20px; }
}
