# Style — Better Minesweeper

/* Theme variables */
:root {
  color-scheme: light dark;
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-raised: #f7f6f3;
  --border: #d4d0c8;
  --text: #2d2a26;
  --muted: #6e6a64;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --shadow: rgba(0, 0, 0, 0.12);
  --shadow-dark: rgba(0, 0, 0, 0.22);
  --cell: clamp(28px, 4.2vmin, 38px);

  --color-1: #1e40af;
  --color-2: #166534;
  --color-3: #b91c1c;
  --color-4: #1e3a8a;
  --color-5: #7f1d1d;
  --color-6: #0f766e;
  --color-7: #111827;
  --color-8: #4b5563;
}

body[data-theme="dark"] {
  --bg: #1c1917;
  --surface: #292524;
  --surface-raised: #44403c;
  --border: #57534e;
  --text: #f5f5f4;
  --muted: #a8a29e;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --shadow: rgba(0, 0, 0, 0.35);
  --shadow-dark: rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

.game-header {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.game-header h1 {
  margin: 0;
  font-size: 1.75rem;
  text-align: center;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.control-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.control-group.custom {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
}

.control-group.hidden {
  display: none;
}

select,
input[type="number"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.35rem 0.5rem;
  font: inherit;
}

input[type="number"] {
  width: 4.5rem;
}

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--shadow);
  transition: transform 80ms ease, background 120ms ease, box-shadow 120ms ease;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.theme-btn {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.45rem 0.6rem;
}

.theme-btn:hover {
  background: var(--border);
}

.game-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: 100%;
}

.hud {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 2px 8px var(--shadow);
}

.counter {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  min-width: 3.5ch;
  text-align: center;
  background: var(--bg);
  color: var(--text);
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
}

.status-btn {
  font-size: 1.6rem;
  width: 3rem;
  height: 3rem;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--surface-raised);
  cursor: pointer;
  transition: transform 120ms cubic-bezier(0.34, 1.56, 0.64, 1), background 120ms ease;
}

.status-btn:hover {
  transform: scale(1.08);
  background: var(--border);
}

.board-scroll {
  width: 100%;
  max-width: 100vw;
  overflow: auto;
  padding: 0.5rem;
  display: flex;
  justify-content: center;
}

.board {
  display: inline-grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  gap: 1px;
  background: var(--border);
  border: 3px solid var(--border);
  border-radius: 0.5rem;
  padding: 2px;
  box-shadow: 0 6px 18px var(--shadow);
  user-select: none;
  touch-action: manipulation;
}

.row {
  display: contents;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.65);
  font-weight: 800;
  line-height: 1;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: var(--surface-raised);
  color: var(--text);
  box-shadow:
    inset 2px 2px 2px rgba(255, 255, 255, 0.45),
    inset -2px -2px 2px var(--shadow),
    1px 1px 0 var(--shadow);
  transform: translateY(0);
  transition: transform 60ms ease, background 120ms ease, box-shadow 120ms ease, color 120ms ease;
}

.cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}

.cell.covered:active,
.cell.covered.active {
  transform: translateY(1px);
  box-shadow:
    inset 2px 2px 2px var(--shadow),
    inset -1px -1px 1px rgba(255, 255, 255, 0.3);
}

.cell.revealed {
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
  animation: pop 160ms ease;
}

@keyframes pop {
  0% { transform: scale(0.85); opacity: 0.7; }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); opacity: 1; }
}

.cell.flagged {
  animation: plant 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes plant {
  0% { transform: scale(1.5) rotate(-20deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.cell.mine {
  background: #fee2e2;
  color: #7f1d1d;
}

body[data-theme="dark"] .cell.mine {
  background: #450a0a;
  color: #fca5a5;
}

.cell.detonated {
  background: #ef4444;
  color: #fff;
  animation: flash 500ms ease infinite alternate;
}

@keyframes flash {
  from { background: #ef4444; }
  to { background: #b91c1c; }
}

.cell.number-0 { color: transparent; }

.instructions {
  max-width: 640px;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.instructions kbd {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: 0.05rem 0.3rem;
  font-family: inherit;
}

/* Result dialog */
#result-dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 16px 40px var(--shadow);
  text-align: center;
  min-width: 280px;
}

#result-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
}

#result-dialog h2 {
  margin: 0 0 0.5rem;
}

#result-dialog p {
  color: var(--muted);
  margin: 0 0 1.25rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 520px) {
  .controls {
    gap: 0.5rem;
  }

  .control-group.custom {
    flex-wrap: wrap;
    justify-content: center;
  }

  .hud {
    padding: 0.5rem 0.75rem;
    gap: 0.75rem;
  }

  .counter {
    font-size: 1.25rem;
  }
}
