/* ========================================
   Minesweeper - game4.fun UI System
   Dark glassmorphism, neon accents
======================================== */

:root {
  --bg-dark: #0a0a0f;
  --bg-card: rgba(20, 20, 30, 0.75);
  --primary-neon: #6366f1;
  --secondary-neon: #ec4899;
  --accent-cyan: #06b6d4;
  --text-main: #f1f5f9;
  --text-dim: rgba(148, 163, 184, 0.7);
  --border-glass: rgba(255, 255, 255, 0.1);
  --radius-xl: 24px;
  --radius-lg: 16px;

  --cell-size: 36px;
  --cell-gap: 2px;
  --cell-radius: 6px;
  --cell-bg: rgba(30, 30, 45, 0.8);
  --cell-bg-hover: rgba(50, 50, 70, 0.9);
  --cell-revealed: rgba(15, 15, 25, 0.9);
  --cell-mine: rgba(220, 38, 38, 0.35);
  --cell-flagged: rgba(99, 102, 241, 0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ========== Game Container ========== */
.game-container {
  width: 100%;
  max-width: 700px;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-header {
  text-align: center;
  margin-bottom: 16px;
}

.game-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ========== Difficulty Bar ========== */
.difficulty-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.diff-btn {
  padding: 8px 20px;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.25s ease;
  backdrop-filter: blur(8px);
}

.diff-btn:hover {
  border-color: var(--primary-neon);
  color: var(--text-main);
}

.diff-btn.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.3), rgba(6,182,212,0.2));
  border-color: var(--primary-neon);
  color: var(--text-main);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.25);
}

/* ========== Game Panel ========== */
.game-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 16px;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ========== HUD ========== */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 360px;
  margin-bottom: 16px;
  padding: 8px 16px;
  background: rgba(10, 10, 20, 0.6);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-icon {
  font-size: 1.1rem;
}

.hud-value {
  font-family: 'Courier New', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-cyan);
  min-width: 40px;
  text-align: center;
}

.smiley-btn {
  font-size: 1.8rem;
  background: none;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease;
  line-height: 1;
  padding: 4px;
  border-radius: 50%;
}

.smiley-btn:hover {
  transform: scale(1.2);
}

.smiley-btn:active {
  transform: scale(0.95);
}

/* ========== Board ========== */
.board-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}

.board {
  display: grid;
  gap: var(--cell-gap);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  border: 1px solid var(--border-glass);
  border-radius: var(--cell-radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
  transition: background 0.12s ease, transform 0.1s ease, box-shadow 0.12s ease;
}

.cell:hover:not(.revealed):not(.game-over) {
  background: var(--cell-bg-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.cell:active:not(.revealed):not(.game-over) {
  transform: scale(0.92);
}

.cell.revealed {
  background: var(--cell-revealed);
  border-color: rgba(255, 255, 255, 0.05);
  cursor: default;
}

.cell.revealed.mine-cell {
  background: var(--cell-mine);
}

.cell.revealed.mine-cell.triggered {
  background: rgba(220, 38, 38, 0.6);
  box-shadow: 0 0 12px rgba(220, 38, 38, 0.4);
}

.cell.flagged {
  background: var(--cell-flagged);
}

.cell.game-over {
  cursor: default;
}

/* Number colors */
.cell.n1 { color: var(--accent-cyan); }
.cell.n2 { color: #22c55e; }
.cell.n3 { color: #ef4444; }
.cell.n4 { color: #a855f7; }
.cell.n5 { color: #f97316; }
.cell.n6 { color: #14b8a6; }
.cell.n7 { color: #f472b6; }
.cell.n8 { color: #94a3b8; }

/* ========== Mobile Controls ========== */
.mobile-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.flag-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border: 2px solid var(--border-glass);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.25s ease;
}

.flag-toggle-btn.active {
  border-color: var(--secondary-neon);
  color: var(--secondary-neon);
  background: rgba(236, 72, 153, 0.15);
  box-shadow: 0 0 16px rgba(236, 72, 153, 0.2);
}

.flag-icon {
  font-size: 1.1rem;
}

.mobile-hint {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ========== Best Time ========== */
.best-time-display {
  margin-top: 12px;
  padding: 8px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  color: var(--text-dim);
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
}

/* ========== Modal ========== */
.modal-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: 1000;
  padding: 16px;
}

.modal-overlay.visible {
  display: flex;
  animation: fadeIn 0.3s ease;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 32px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  backdrop-filter: blur(20px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  animation: modalIn 0.35s ease;
}

.modal-emoji {
  font-size: 3.5rem;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-message {
  color: var(--text-dim);
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.modal-record {
  color: var(--secondary-neon);
  font-weight: 700;
  margin-bottom: 20px;
  font-size: 0.95rem;
  min-height: 1.3em;
}

.modal-btn {
  padding: 12px 36px;
  border: none;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary-neon), var(--accent-cyan));
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.modal-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

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

/* ========== Ad Container ========== */
.g4f-ad-container {
  width: 100%;
  max-width: 700px;
  margin: 20px auto;
  padding: 24px;
  background: var(--bg-card);
  border: 1px dashed var(--border-glass);
  border-radius: var(--radius-lg);
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
}

/* ========== Footer ========== */
.footer {
  width: 100%;
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ========== Animations ========== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes cellReveal {
  from { transform: scale(0.8); opacity: 0.5; }
  to { transform: scale(1); opacity: 1; }
}

.cell.revealed {
  animation: cellReveal 0.15s ease;
}

/* ========== Responsive ========== */
@media (max-width: 600px) {
  .game-container {
    padding: 12px 8px;
  }

  .game-title {
    font-size: 1.5rem;
  }

  .mobile-controls {
    display: flex;
  }

  :root {
    --cell-size: 30px;
    --cell-gap: 1.5px;
    --cell-radius: 4px;
  }

  .cell {
    font-size: 0.78rem;
  }

  .hud {
    padding: 6px 12px;
  }

  .hud-value {
    font-size: 1.1rem;
  }

  .diff-btn {
    padding: 6px 14px;
    font-size: 0.8rem;
  }
}

@media (max-width: 400px) {
  :root {
    --cell-size: 26px;
    --cell-gap: 1px;
  }

  .cell {
    font-size: 0.7rem;
  }
}

/* Hard mode on small screens - allow horizontal scroll */
@media (max-width: 700px) {
  .board-wrapper {
    max-width: calc(100vw - 48px);
  }
}
