:root {
  color-scheme: dark;
  --bg: #030712;
  --bg-soft: #0b1329;
  --panel: rgba(15, 23, 42, 0.65);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #f8fafc;
  --muted: #94a3b8;
  
  --accent: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.2);
  --accent-strong: #06b6d4;
  --accent-strong-glow: rgba(6, 182, 212, 0.25);
  --danger: #f43f5e;
  --danger-glow: rgba(244, 63, 94, 0.25);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.25);

  --tile: #1e293b;
  --tile-open: #090d16;
  --tile-open-border: rgba(255, 255, 255, 0.03);
  --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100vh;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: 
    radial-gradient(circle at 10% 20%, rgba(6, 182, 212, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.08) 0%, transparent 40%),
    linear-gradient(135deg, #020617 0%, #090d16 100%);
  background-attachment: fixed;
  transition: background 0.5s ease;
}

/* Dynamic Ambient Glows based on Game State */
body.game-won {
  background: 
    radial-gradient(circle at 50% 30%, rgba(16, 185, 129, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.08) 0%, transparent 40%),
    linear-gradient(135deg, #020617 0%, #051410 100%);
}

body.game-lost {
  background: 
    radial-gradient(circle at 50% 30%, rgba(244, 63, 94, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 90% 80%, rgba(244, 63, 94, 0.08) 0%, transparent 40%),
    linear-gradient(135deg, #020617 0%, #1c080d 100%);
}

.shell {
  width: min(900px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 40px 0 60px;
}

.hero,
.status-bar,
.board-wrap,
.tips {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 32px;
  border-radius: 24px;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.3em;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent-strong);
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  background: linear-gradient(135deg, #ffffff 50%, var(--muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.lede {
  max-width: 52ch;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 0.95rem;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
  min-width: 240px;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.select-wrapper {
  position: relative;
  width: 100%;
}

select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: 12px 16px;
  padding-right: 40px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

select:hover,
select:focus {
  outline: none;
  border-color: var(--accent-strong);
  background: rgba(30, 41, 59, 0.8);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.15);
}

.select-wrapper::after {
  content: "↓";
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

button#restart {
  width: 100%;
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-strong) 0%, var(--accent) 100%);
  color: #020617;
  font-weight: 700;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.25);
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

button#restart:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
  filter: brightness(1.1);
}

button#restart:active {
  transform: translateY(0);
}

/* Status Bar & Cards */
.status-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 16px;
  margin-top: 18px;
  border-radius: 20px;
}

.status-card {
  padding: 18px 20px;
  border-radius: 14px;
  background: rgba(9, 13, 22, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.04);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.status-card::before {
  content: "";
  position: absolute;
  top: 15%;
  bottom: 15%;
  left: 0;
  width: 3px;
  border-radius: 2px;
  background: var(--muted);
}

#card-mines::before {
  background: var(--danger);
  box-shadow: 0 0 10px rgba(244, 63, 94, 0.6);
}

#card-timer::before {
  background: var(--accent-strong);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.6);
}

#card-status::before {
  background: var(--warning);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.6);
}

body.game-won #card-status::before {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
}

body.game-lost #card-status::before {
  background: var(--danger);
  box-shadow: 0 0 10px rgba(244, 63, 94, 0.6);
}

.status-card .label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.status-card strong {
  font-family: 'Share Tech Mono', monospace;
  font-size: 2.2rem;
  font-weight: 400;
  color: #ffffff;
  line-height: 1;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.1);
}

#minesLeft {
  color: #fda4af;
  text-shadow: 0 0 12px rgba(244, 63, 94, 0.35);
}

#timer {
  color: #99f6e4;
  text-shadow: 0 0 12px rgba(6, 182, 212, 0.35);
}

.status-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

#message {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

/* Pulsing Indicator Dot */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--warning);
  box-shadow: 0 0 8px var(--warning-glow);
  display: inline-block;
  flex-shrink: 0;
  animation: pulse 1.8s infinite ease-in-out;
}

body.game-playing .status-dot {
  background-color: var(--accent-strong);
  box-shadow: 0 0 10px var(--accent-strong);
}

body.game-won .status-dot {
  background-color: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

body.game-lost .status-dot {
  background-color: var(--danger);
  box-shadow: 0 0 10px var(--danger);
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

/* Board Styles */
.board-wrap {
  padding: 24px;
  margin-top: 18px;
  border-radius: 24px;
  background: rgba(10, 15, 30, 0.8);
  overflow: auto;
  display: flex;
  justify-content: center;
}

body.game-won .board-wrap {
  border-color: rgba(16, 185, 129, 0.2);
  box-shadow: 0 0 30px rgba(16, 185, 129, 0.1);
}

body.game-lost .board-wrap {
  border-color: rgba(244, 63, 94, 0.2);
  box-shadow: 0 0 30px rgba(244, 63, 94, 0.1);
}

.board {
  display: grid;
  gap: 6px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* Individual Cells */
.cell {
  width: clamp(30px, 4.5vw, 40px);
  height: clamp(30px, 4.5vw, 40px);
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  box-shadow: 
    inset 0 1.5px 0 rgba(255, 255, 255, 0.15),
    0 4px 6px -1px rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-weight: 800;
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: 
    transform 120ms cubic-bezier(0.4, 0, 0.2, 1),
    border-color 120ms ease,
    background-color 120ms ease,
    box-shadow 120ms ease;
}

.cell:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--accent-strong);
  background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
  box-shadow: 
    inset 0 1.5px 0 rgba(255, 255, 255, 0.2),
    0 0 12px rgba(6, 182, 212, 0.4),
    0 6px 12px -2px rgba(0, 0, 0, 0.3);
}

.cell:active:not(:disabled) {
  transform: scale(0.92);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}

/* Open/Revealed Cell */
.cell.open {
  background: var(--tile-open);
  border-color: var(--tile-open-border);
  box-shadow: 
    inset 0 3px 6px rgba(0, 0, 0, 0.7),
    0 1px 0 rgba(255, 255, 255, 0.02);
  cursor: default;
  transform: none !important;
}

/* Flagged Cell */
.cell.flagged {
  border-color: rgba(244, 63, 94, 0.4);
  box-shadow: 
    inset 0 1.5px 0 rgba(255, 255, 255, 0.15),
    0 0 10px rgba(244, 63, 94, 0.25),
    0 4px 6px -1px rgba(0, 0, 0, 0.4);
  animation: flag-pop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cell.flagged::after {
  content: "🚩";
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
  filter: drop-shadow(0 0 4px rgba(244, 63, 94, 0.6));
}

@keyframes flag-pop {
  0% { transform: scale(0.7); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Revealed Mine (Exploded) */
.cell.mine.revealed {
  background: radial-gradient(circle, #f43f5e 0%, #991b1b 100%) !important;
  border-color: #f43f5e;
  box-shadow: 
    0 0 20px rgba(244, 63, 94, 0.8),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  animation: explode 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.35);
  z-index: 2;
}

.cell.mine.revealed::after {
  content: "💥" !important;
  font-size: clamp(0.9rem, 2vw, 1.15rem);
}

@keyframes explode {
  0% { transform: scale(1); }
  45% { transform: scale(1.25); filter: brightness(1.4); }
  100% { transform: scale(1); }
}

/* Revealed Mine on Game Over (Safe/Unexploded) */
.cell.mine:not(.revealed)::after {
  content: "💣";
  font-size: clamp(0.8rem, 1.8vw, 1rem);
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.3));
}

.cell:disabled {
  cursor: default;
}

/* Tips & Instructions */
.tips {
  margin-top: 18px;
  padding: 20px 24px;
  border-radius: 18px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.tips p {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tips p::before {
  content: "💡";
  font-size: 1.1rem;
}

/* Responsive Scaling */
@media (max-width: 768px) {
  .shell {
    padding: 20px 0 40px;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
    padding: 24px;
  }

  .lede {
    margin-bottom: 8px;
  }

  .controls {
    width: 100%;
    min-width: 0;
  }

  .status-bar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .status-card {
    padding: 14px 16px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .status-card::before {
    top: 0;
    bottom: 0;
    left: 0;
    width: 4px;
    height: 100%;
    border-radius: 4px 0 0 4px;
  }

  .status-card .label {
    margin-bottom: 0;
  }

  .status-card strong {
    font-size: 1.8rem;
  }

  #message {
    text-align: right;
  }

  .board-wrap {
    padding: 12px;
    border-radius: 16px;
  }

  .cell {
    border-radius: 6px;
  }
}