/* ========================================
   Lights Out - 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;
  --light-on: #f5c542;
  --light-on-glow: rgba(245, 197, 66, 0.6);
  --light-off: rgba(30, 30, 45, 0.8);
  --light-off-border: rgba(60, 60, 80, 0.5);
  --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;
  --radius-md: 10px;
}

* { 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: 600px;
  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(--light-on), var(--primary-neon));
  -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: 12px;
}

.diff-btn {
  padding: 8px 18px;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.85rem;
  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);
}

/* ========== Level Bar ========== */
.level-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.level-nav-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-glass);
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.level-nav-btn:hover {
  border-color: var(--primary-neon);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.level-selector {
  padding: 6px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  color: var(--text-main);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
}

.level-selector:hover {
  border-color: var(--primary-neon);
}

.level-stars {
  font-size: 0.75rem;
  letter-spacing: 1px;
}

.level-random-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--accent-cyan);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}

.level-random-btn:hover {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.3);
}

/* ========== Game Panel ========== */
.game-panel {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 20px;
  backdrop-filter: blur(12px);
}

/* ========== HUD ========== */
.hud {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 20px;
}

.hud-item {
  text-align: center;
}

.hud-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

/* ========== Board ========== */
.board-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.board {
  display: grid;
  gap: 6px;
  padding: 8px;
}

.board[data-size="3"] {
  grid-template-columns: repeat(3, 1fr);
}
.board[data-size="5"] {
  grid-template-columns: repeat(5, 1fr);
}
.board[data-size="7"] {
  grid-template-columns: repeat(7, 1fr);
}

/* ========== Light Cells ========== */
.light-cell {
  width: var(--cell-size, 56px);
  height: var(--cell-size, 56px);
  border: 2px solid var(--light-off-border);
  border-radius: var(--radius-md);
  background: var(--light-off);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.light-cell:hover {
  border-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.04);
}

.light-cell:active {
  transform: scale(0.95);
}

.light-cell.on {
  background: radial-gradient(circle at center, var(--light-on), #d4a017);
  border-color: var(--light-on);
  box-shadow:
    0 0 12px var(--light-on-glow),
    0 0 30px rgba(245, 197, 66, 0.3),
    inset 0 0 8px rgba(255, 255, 255, 0.3);
}

.light-cell.on.pulse {
  animation: lightPulse 0.4s ease-out;
}

.light-cell.off-pulse {
  animation: lightOff 0.3s ease-out;
}

.light-cell.hint-highlight {
  border-color: var(--accent-cyan) !important;
  box-shadow: 0 0 16px rgba(6, 182, 212, 0.6), 0 0 32px rgba(6, 182, 212, 0.3) !important;
  animation: hintPulse 1s ease-in-out infinite;
}

@keyframes lightPulse {
  0% { transform: scale(1); box-shadow: 0 0 12px var(--light-on-glow); }
  50% { transform: scale(1.08); box-shadow: 0 0 24px var(--light-on-glow), 0 0 48px rgba(245, 197, 66, 0.4); }
  100% { transform: scale(1); box-shadow: 0 0 12px var(--light-on-glow), 0 0 30px rgba(245, 197, 66, 0.3); }
}

@keyframes lightOff {
  0% { transform: scale(1.05); background: rgba(245, 197, 66, 0.3); }
  100% { transform: scale(1); background: var(--light-off); }
}

@keyframes hintPulse {
  0%, 100% { box-shadow: 0 0 16px rgba(6, 182, 212, 0.6); }
  50% { box-shadow: 0 0 24px rgba(6, 182, 212, 0.9), 0 0 40px rgba(6, 182, 212, 0.4); }
}

/* ========== Controls ========== */
.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
}

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

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

.ctrl-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.hint-btn {
  color: var(--accent-cyan);
  border-color: rgba(6, 182, 212, 0.3);
}

.hint-btn:hover {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.3);
}

/* ========== Level Grid ========== */
.level-grid-container {
  width: 100%;
  margin-top: 20px;
  text-align: center;
}

.level-grid-container h3 {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 12px;
  font-weight: 500;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
  max-width: 400px;
  margin: 0 auto;
}

.level-item {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.2s ease;
}

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

.level-item.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);
}

.level-item.cleared {
  border-color: rgba(34, 197, 94, 0.4);
}

.level-item .level-num {
  font-weight: 600;
  font-size: 0.85rem;
}

.level-item .level-mini-stars {
  font-size: 0.5rem;
  letter-spacing: 0px;
  line-height: 1;
}

/* ========== 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: 24px;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: rgba(20, 20, 35, 0.95);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 32px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  animation: modalIn 0.4s ease-out;
}

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

.modal-stars {
  font-size: 2.5rem;
  margin-bottom: 12px;
  letter-spacing: 4px;
}

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

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

.modal-record {
  color: var(--accent-cyan);
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-btn {
  padding: 12px 24px;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.25s ease;
}

.modal-btn:hover {
  border-color: var(--primary-neon);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
}

.modal-btn.primary {
  background: linear-gradient(135deg, rgba(99,102,241,0.4), rgba(6,182,212,0.3));
  border-color: var(--primary-neon);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.2);
}

.modal-btn.primary:hover {
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

/* ========== Win Celebration ========== */
.celebration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: confettiFall 1.5s ease-out forwards;
}

@keyframes confettiFall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg) scale(0.5); }
}

/* ========== Ad Container ========== */
.g4f-ad-container {
  width: 100%;
  max-width: 600px;
  margin: 20px auto;
  padding: 20px;
  border: 1px dashed var(--border-glass);
  border-radius: var(--radius-lg);
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
}

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

/* ========== Responsive ========== */
@media (max-width: 480px) {
  .game-container { padding: 12px; }
  .game-panel { padding: 14px; }
  .difficulty-bar { gap: 4px; }
  .diff-btn { padding: 6px 12px; font-size: 0.8rem; }
  .controls { gap: 6px; }
  .ctrl-btn { padding: 8px 14px; font-size: 0.8rem; }
  .level-grid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
}

@media (max-width: 360px) {
  .board { gap: 4px; padding: 4px; }
}
