:root {
  --bg-color: #cbd5e1; /* Darker slate gray-blue */
  --panel-bg: rgba(255, 255, 255, 0.65); /* Less opaque white */
  --cell-bg: #e2e8f0; /* Stays same or slightly darker? Let's keep existing ratio but shift down */
  /* Actually let's shift everything down a notch */
  /* New palette: */
  --bg-color: #c4cbd6;
  --panel-bg: rgba(245, 247, 250, 0.75);
  --cell-bg: #b9c2ce; /* Darker unrevealed cell */
  --cell-hover: #aab5c2;
  --cell-revealed: #f1f4f8; /* Revealed stays light */
  --shadow-color: rgba(0, 0, 0, 0.15);
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --text-main: #1e293b;
  --text-muted: #475569;
  --mine-bg: #ef4444;
  --flag-bg: #fbbf24;
  --font-family: 'Outfit', system-ui, -apple-system, sans-serif;
}

body.dark {
  --bg-color: #0f172a;
  --panel-bg: rgba(30, 41, 59, 0.7);
  --cell-bg: #334155;
  --cell-hover: #475569;
  --cell-revealed: #1e293b;
  --shadow-color: rgba(0, 0, 0, 0.4);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

body {
  margin: 0;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Glassmorphism Panel */
/* Layout */
.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: 100vh;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 12px var(--shadow-color);
}

body.dark .top-bar {
  background: rgba(30, 41, 59, 0.7);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--primary);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.game-container {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 20px;
  border-radius: 20px;
  box-shadow: 0 20px 40px var(--shadow-color);
  max-width: 95vw;
  width: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  margin: auto; /* Vertically center in remaining space */
  margin-top: 20px; /* Ensure some spacing from top if screen is small */
  margin-bottom: 20px;
}

.controls-bar {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  background: rgba(0,0,0,0.03);
  padding: 8px 16px;
  border-radius: 12px;
  width: 100%;
}

.control-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.status-group {
  margin: 0 8px;
}

.pill-select {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid rgba(0,0,0,0.1);
  background: rgba(255,255,255,0.8);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.stat-pill {
  background: rgba(0,0,0,0.05);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.footer-controls {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

/* Dark Mode Overrides */
body.dark .pill-select {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.1);
  color: var(--text-main);
}
body.dark .pill-select option {
  background: #222;
  color: white;
}
body.dark .controls-bar {
  background: rgba(255,255,255,0.02);
}
body.dark .stat-pill {
  background: rgba(255,255,255,0.05);
}

/* Grid */
.grid {
  display: grid;
  gap: 2px;
  padding: 8px;
  background: rgba(0,0,0,0.03);
  border-radius: 12px;
  user-select: none;
  touch-action: manipulation;
  overflow: auto;
  max-width: 100%;
  max-height: 70vh;
}

.stat-box {
  background: var(--cell-bg);
  padding: 8px 12px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 90px;
  justify-content: center;
}

.controls {
  display: flex;
  gap: 8px;
}

/* Buttons & Select */
button, select {
  font-family: inherit;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
  outline: none;
}

input, textarea {
  user-select: text;
  -webkit-user-select: text;
}

select {
  background: var(--cell-bg);
  color: var(--text-main);
  padding-right: 24px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

button.primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

button.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(99, 102, 241, 0.4);
}

button.primary.small {
  padding: 8px 16px;
  font-size: 0.9rem;
}

button.primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

button.secondary {
  background: var(--bg-color);
  color: var(--text-main);
  border: 1px solid var(--text-muted);
}
button.secondary:hover {
  background: var(--cell-hover);
}

.icon-btn.sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
}

button.icon-btn {
  background: var(--cell-bg);
  color: var(--text-main);
  padding: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

button.icon-btn:hover {
  background: var(--cell-hover);
}

button.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.icon-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.pill-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid rgba(0,0,0,0.1);
  background: rgba(255,255,255,0.8);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-main);
}

.pill-btn:hover {
  background: rgba(255,255,255,1);
  transform: translateY(-1px);
}

body.dark .pill-btn {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.1);
  color: white;
}
body.dark .pill-btn:hover {
  background: rgba(255,255,255,0.1);
}

/* Grid */
.grid {
  display: grid;
  gap: 2px;
  padding: 8px;
  background: rgba(0,0,0,0.03);
  border-radius: 12px;
  user-select: none;
  touch-action: manipulation;
}

.cell {
  width: 36px;
  height: 36px;
  background: var(--cell-bg);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.1s, background-color 0.2s;
  position: relative;
  overflow: hidden;
}

.cell:hover:not(.revealed) {
  background: var(--cell-hover);
  transform: scale(1.05);
  z-index: 1;
}

.cell:active:not(.revealed) {
  transform: scale(0.95);
}

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

.cell.mine {
  background: var(--mine-bg);
  color: white;
  animation: shake 0.4s ease-in-out;
}

.cell.mine-trigger {
  background: #7f1d1d !important;
  box-shadow: 0 0 0 3px #fca5a5, 0 0 12px rgba(239, 68, 68, 0.6);
  z-index: 2;
  transform: scale(1.1);
}

.cell.flagged {
  color: var(--flag-bg);
}

.cell.wrong-flag {
  background: #fecaca;
  color: #ef4444;
  position: relative;
}
.cell.wrong-flag::after {
  content: '❌';
  font-size: 1rem;
  position: absolute;
}

/* Number Colors */
.n1 { color: #3b82f6; }
.n2 { color: #10b981; }
.n3 { color: #ef4444; }
.n4 { color: #8b5cf6; }
.n5 { color: #f59e0b; }
.n6 { color: #06b6d4; }
.n7 { color: #111827; }
.n8 { color: #6b7280; }

/* Overlay / Modal */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(1px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.overlay.visible {
  opacity: 1;
}

.modal {
  background: var(--panel-bg);
  backdrop-filter: blur(1px);
  padding: 32px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90%;
  width: 320px;
  border: 1px solid rgba(255,255,255,0.4);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  font-size: 1.2rem;
  opacity: 0.6;
}

.modal-close:hover {
  background: rgba(0,0,0,0.05); /* Subtle hover */
  opacity: 1;
}

body.dark .modal-close:hover {
  background: rgba(255,255,255,0.1);
}

.overlay.visible .modal {
  transform: scale(1);
}

.modal h2 {
  margin: 0 0 8px 0;
  font-size: 2rem;
}

.modal p {
  margin: 8px 0 24px 0;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.modal-actions button {
  width: 100%;
  max-width: 200px;
}

.modal.win { 
  border: 1px solid #10b981; 
}
.modal.win h2 { color: #10b981; }

.modal.lose { 
  border: 1px solid #ef4444; 
}
.modal.lose h2 { color: #ef4444; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes pop {
  0% { transform: scale(0); opacity: 0; }
  80% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.cell.pop {
  animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@media (max-width: 600px) {
  .cell { width: 30px; height: 30px; }
  .game-container { padding: 16px; border-radius: 16px; }
  .modal { padding: 24px; }
}

/* Custom Inputs */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
  text-align: left;
}

.input-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--text-main);
}

.input-group input {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.1);
  background: var(--cell-bg);
  color: var(--text-main);
  width: 80px;
  text-align: center;
  font-weight: bold;
}

/* Leaderboard */
.leaderboard-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  justify-content: center;
}

.tab-btn {
  background: var(--cell-bg);
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--primary);
  color: white;
}

.leaderboard-list {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.leaderboard-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--cell-bg);
  border-radius: 8px;
  margin-bottom: 8px;
  font-weight: 600;
}

.leaderboard-item .rank {
  color: var(--primary);
  min-width: 30px;
}

.leaderboard-item .name {
  flex: 1;
  text-align: left;
  margin-left: 8px;
}

.leaderboard-item .time {
  color: var(--text-muted);
}

/* Keybinds */
.keybinds {
  display: flex;
  gap: 16px;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.mouse-binds {
  margin-top: 8px;
  font-size: 0.8rem;
  opacity: 0.8;
}

.keybinds span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.keybinds kbd {
  background: var(--cell-bg);
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.75rem;
  font-family: inherit;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

/* GitHub Link */
.github-link {
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  opacity: 0.7;
}

.github-link:hover {
  color: var(--text-main);
  opacity: 1;
  transform: scale(1.1);
}

.github-link svg {
  width: 24px;
  height: 24px;
}

/* Help Modal */
.help-section {
  margin-bottom: 24px;
}

.help-section h3 {
  color: var(--primary);
  margin: 0 0 12px 0;
  font-size: 1.1rem;
}

.control-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.control-row:last-child {
  border-bottom: none;
}

.control-row .action {
  font-weight: 700;
  color: var(--text-main);
}

.control-row .desc {
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .controls-bar {
    flex-direction: column;
    gap: 12px;
  }
  
  .status-group {
    width: 100%;
    justify-content: center;
  }
  
  .game-container {
    padding: 16px;
    width: 95vw;
  }
}

.desktop-only { display: flex; }
.mobile-only { display: none; }

@media (pointer: coarse) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }
}
