/*
 * games-common.css — wspólne style gier logicznych.
 * Mobile-first, plansze w CSS Grid z aspect-ratio, obsługa dotyku, dark mode.
 * Prefiks klas: gl- (izolacja od motywu i innych wtyczek).
 */

.gl-game {
  --gl-bg: #ffffff;
  --gl-fg: #1a1a2e;
  --gl-muted: #6b7280;
  --gl-line: #d1d5db;
  --gl-cell: #f3f4f6;
  --gl-cell-hover: #e5e7eb;
  --gl-accent: #4f46e5;
  --gl-accent-fg: #ffffff;
  --gl-win: #34d399;
  --gl-x: #ef4444;
  --gl-o: #3b82f6;
  --gl-radius: 12px;
  --gl-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);

  position: relative; /* zabezpieczenie: modal nigdy nie ucieka poza komponent gry */
  max-width: 560px;
  margin: 0 auto;
  padding: 12px;
  color: var(--gl-fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  box-sizing: border-box;
}

.gl-game *,
.gl-game *::before,
.gl-game *::after {
  box-sizing: border-box;
}

/* ------------------------------ Dark mode ------------------------------ */
@media (prefers-color-scheme: dark) {
  .gl-game {
    --gl-bg: #0f172a;
    --gl-fg: #e2e8f0;
    --gl-muted: #94a3b8;
    --gl-line: #334155;
    --gl-cell: #1e293b;
    --gl-cell-hover: #334155;
    --gl-accent: #6366f1;
    --gl-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  }
}

/* --------------------------- Ekran wyboru poziomu --------------------- */
.gl-level-select { text-align: center; padding: 8px 0; }
.gl-title { font-size: 1.4rem; margin: 4px 0 2px; }
.gl-subtitle { color: var(--gl-muted); margin: 0 0 14px; }

.gl-level-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 360px;
  margin: 0 auto;
}

/* -------------------------------- Przyciski --------------------------- */
.gl-btn {
  appearance: none;
  border: 1px solid var(--gl-line);
  background: var(--gl-cell);
  color: var(--gl-fg);
  padding: 12px 16px;
  border-radius: var(--gl-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
}
.gl-btn:hover { background: var(--gl-cell-hover); }
.gl-btn:active { transform: scale(0.97); }
.gl-btn-primary { background: var(--gl-accent); color: var(--gl-accent-fg); border-color: transparent; }
.gl-btn-small { padding: 6px 10px; font-size: 0.85rem; }

.gl-level-btn { padding: 16px; font-size: 1.05rem; }
.gl-level-latwy  { border-left: 4px solid #22c55e; }
.gl-level-sredni { border-left: 4px solid #eab308; }
.gl-level-trudny { border-left: 4px solid #f97316; }
.gl-level-ultra  { border-left: 4px solid #ef4444; }

/* --------------------------------- Topbar ----------------------------- */
.gl-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.gl-badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  background: var(--gl-accent);
}
.gl-badge-latwy  { background: #22c55e; }
.gl-badge-sredni { background: #eab308; }
.gl-badge-trudny { background: #f97316; }
.gl-badge-ultra  { background: #ef4444; }
.gl-session { font-variant-numeric: tabular-nums; color: var(--gl-muted); font-size: 0.9rem; }

/* --------------------------------- Status ----------------------------- */
.gl-status {
  text-align: center;
  font-weight: 600;
  min-height: 1.4em;
  margin-bottom: 10px;
  color: var(--gl-fg);
}

/* -------------------------------- Plansze ----------------------------- */
/* Obszar planszy = kontekst pozycjonowania dla modala (modal kryje tylko planszę). */
.gl-board-area { position: relative; }
.gl-board-wrap { position: relative; }
.gl-grid {
  display: grid;
  gap: 6px;
  width: 100%;
  margin: 0 auto;
}
.gl-board-locked { pointer-events: none; opacity: 0.85; }

.gl-cell {
  appearance: none;
  border: 1px solid var(--gl-line);
  background: var(--gl-cell);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s ease;
  touch-action: manipulation;
}
.gl-cell:hover { background: var(--gl-cell-hover); }

/* Kółko i krzyżyk */
.gl-grid-ttt { grid-template-columns: repeat(3, 1fr); max-width: 360px; aspect-ratio: 1 / 1; }
.gl-cell-ttt { font-size: clamp(2rem, 14vw, 4rem); font-weight: 700; line-height: 1; }
.gl-cell-ttt.gl-x { color: var(--gl-x); }
.gl-cell-ttt.gl-o { color: var(--gl-o); }
.gl-cell-ttt.gl-win { background: var(--gl-win); color: #06281d; }

/* Cztery w rzędzie */
.gl-grid-c4 {
  grid-template-columns: repeat(7, 1fr);
  aspect-ratio: 7 / 6;
  background: var(--gl-accent);
  padding: 6px;
  border-radius: var(--gl-radius);
}
.gl-cell-c4 { background: var(--gl-bg); border: none; border-radius: 50%; aspect-ratio: 1/1; }
.gl-disc {
  width: 82%;
  height: 82%;
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08);
}
.gl-disc.gl-c4-human { background: radial-gradient(circle at 35% 30%, #ff8a8a, #dc2626); }
.gl-disc.gl-c4-ai { background: radial-gradient(circle at 35% 30%, #ffe07a, #f59e0b); }
@keyframes gl-drop-anim {
  0% { transform: translateY(-320%); }
  70% { transform: translateY(6%); }
  100% { transform: translateY(0); }
}
.gl-disc.gl-drop { animation: gl-drop-anim 0.32s cubic-bezier(0.3, 0.8, 0.4, 1); }

/* Reversi */
.gl-grid-reversi {
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  background: #1f7a4d;
  padding: 5px;
  border-radius: var(--gl-radius);
  gap: 3px;
}
.gl-cell-reversi { background: #2e9e66; border: 1px solid #1f7a4d; border-radius: 4px; aspect-ratio: 1/1; }
.gl-cell-reversi.gl-legal { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.5); }
.gl-disc-r {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  transform: scale(0);
  transition: transform 0.18s ease, background 0.18s ease;
}
.gl-disc-r.gl-r-black { transform: scale(1); background: radial-gradient(circle at 35% 30%, #555, #111); }
.gl-disc-r.gl-r-white { transform: scale(1); background: radial-gradient(circle at 35% 30%, #fff, #cbd5e1); }

/* Kulki / Lines 98 */
.gl-kulki-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-weight: 600;
}
.gl-kulki-preview { display: inline-flex; align-items: center; gap: 4px; color: var(--gl-muted); }
.gl-grid-kulki { grid-template-columns: repeat(9, 1fr); aspect-ratio: 1 / 1; gap: 3px; }
.gl-cell-kulki { aspect-ratio: 1/1; }
.gl-cell-kulki.gl-selected { box-shadow: inset 0 0 0 3px var(--gl-accent); }
.gl-ball {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  transform: scale(0);
  transition: transform 0.15s ease;
}
.gl-ball.gl-ball-on { transform: scale(1); }
.gl-preview-dot { width: 16px; height: 16px; transform: scale(1); display: inline-block; }

/* Paleta kul (7 kolorów) */
.gl-ball-1 { background: radial-gradient(circle at 35% 30%, #ff9a9a, #e11d48); }
.gl-ball-2 { background: radial-gradient(circle at 35% 30%, #93c5fd, #2563eb); }
.gl-ball-3 { background: radial-gradient(circle at 35% 30%, #86efac, #16a34a); }
.gl-ball-4 { background: radial-gradient(circle at 35% 30%, #fde68a, #d97706); }
.gl-ball-5 { background: radial-gradient(circle at 35% 30%, #d8b4fe, #7c3aed); }
.gl-ball-6 { background: radial-gradient(circle at 35% 30%, #67e8f9, #0891b2); }
.gl-ball-7 { background: radial-gradient(circle at 35% 30%, #fda4af, #be123c); }

@keyframes gl-shake-anim {
  0%, 100% { transform: scale(1) translateX(0); }
  25% { transform: scale(1) translateX(-14%); }
  75% { transform: scale(1) translateX(14%); }
}
.gl-ball.gl-shake { animation: gl-shake-anim 0.28s ease; }

/* --------------------------------- Modal ------------------------------ */
.gl-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: var(--gl-radius);
  z-index: 5;
}
.gl-hidden { display: none; }
.gl-modal-card {
  background: var(--gl-bg);
  color: var(--gl-fg);
  padding: 20px;
  border-radius: var(--gl-radius);
  box-shadow: var(--gl-shadow);
  text-align: center;
  max-width: 300px;
  width: 86%;
  max-height: 100%;
  overflow: auto;
}
.gl-modal-icon { font-size: 2.4rem; margin-bottom: 6px; }
.gl-modal-title { margin: 0 0 16px; font-size: 1.15rem; }
.gl-modal-actions { display: flex; flex-direction: column; gap: 8px; }

/* --------------------------- Większe ekrany --------------------------- */
@media (min-width: 480px) {
  .gl-grid { gap: 8px; }
}
