:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --play: #0b1222;
  --cell: #28334d;
  --cell-open: #1a2438;
  --mine-hit: #7f1d1d;
  --accent: #e879f9;
  --text: #e2e8f0;
  --muted: #94a3b8;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* Disable pull-to-refresh, scroll bounce, and double-tap zoom on iOS */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 100vh;  /* fallback */
  height: 100dvh; /* iOS Safari dynamic viewport */
  padding: max(12px, env(safe-area-inset-top))
           max(12px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom))
           max(12px, env(safe-area-inset-left));
}
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(90vmin, 520px);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
#hud .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; }
#hud a { color: var(--muted); text-decoration: none; font-size: 14px; }
#hud .value { font-weight: 700; font-size: 22px; }
#mid { display: flex; align-items: center; gap: 10px; }
#face {
  font-size: 22px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: min(90vmin, 520px);
}
#controls button {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#controls button.active { color: var(--text); border-color: var(--accent); }
#flag-mode { margin-left: auto; }
#board-wrap { position: relative; }
canvas {
  display: block;
  background: var(--play);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.82);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding: 24px;
}
#overlay.hidden { display: none; }
#overlay h1 { font-size: 34px; letter-spacing: 0.02em; }
#overlay p { color: var(--muted); font-size: 16px; line-height: 1.5; }
#overlay .big-score { font-size: 26px; font-weight: 700; color: var(--accent); }
#overlay button {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
