:root {
  --bg: #2b2f36;
  --bg-2: #21242a;
  --frame: #c9ccd1;
  --frame-dark: #8a8d92;
  --frame-light: #ffffff;
  --tile: #d4d7dc;
  --tile-hi: #ffffff;
  --tile-lo: #9a9da3;
  --tile-revealed: #e9ebee;
  --grid-line: #b9bcc2;
  --accent: #3a7afe;
  --text: #f3f4f6;

  /* classic minesweeper number colors */
  --n1: #1976d2;
  --n2: #388e3c;
  --n3: #d32f2f;
  --n4: #512da8;
  --n5: #8d3a1b;
  --n6: #0097a7;
  --n7: #212121;
  --n8: #757575;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  background: radial-gradient(ellipse at top, #343943, var(--bg-2));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(8px, 2vh, 20px);
  padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
}

.topbar {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.title {
  margin: 0;
  font-size: clamp(20px, 3.2vh, 30px);
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #ffffff, #b9c2cf);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 1px 0 rgba(0,0,0,0.15);
}

.difficulty {
  display: flex;
  gap: 6px;
  background: rgba(0,0,0,0.25);
  padding: 5px;
  border-radius: 12px;
}

.diff-btn {
  border: none;
  background: transparent;
  color: #c7ccd4;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.diff-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(58,122,254,0.4);
}

/* ----- Game frame ----- */
.frame {
  background: var(--frame);
  border-radius: 10px;
  padding: 10px;
  border-top: 3px solid var(--frame-light);
  border-left: 3px solid var(--frame-light);
  border-right: 3px solid var(--frame-dark);
  border-bottom: 3px solid var(--frame-dark);
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 96vw;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #bcbfc4;
  padding: 8px 10px;
  border-radius: 6px;
  border-top: 2px solid var(--frame-dark);
  border-left: 2px solid var(--frame-dark);
  border-right: 2px solid var(--frame-light);
  border-bottom: 2px solid var(--frame-light);
}

.counter {
  font-family: "DSEG7", "Courier New", monospace;
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 2px;
  color: #ff3b30;
  background: #1c0000;
  padding: 4px 8px;
  border-radius: 4px;
  min-width: 64px;
  text-align: center;
  text-shadow: 0 0 6px rgba(255,59,48,0.55);
  border: 1px solid #000;
}

.face {
  width: 50px;
  height: 50px;
  font-size: 28px;
  line-height: 1;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: var(--tile);
  border-top: 2px solid var(--tile-hi);
  border-left: 2px solid var(--tile-hi);
  border-right: 2px solid var(--tile-lo);
  border-bottom: 2px solid var(--tile-lo);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.05s;
}
.face:active { transform: scale(0.94); }

/* ----- Board ----- */
.board-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  max-width: 92vw;
}

.board {
  display: grid;
  gap: 0;
  background: var(--grid-line);
  border-top: 3px solid var(--frame-dark);
  border-left: 3px solid var(--frame-dark);
  border-right: 3px solid var(--frame-light);
  border-bottom: 3px solid var(--frame-light);
  touch-action: none;
}

.cell {
  width: var(--cell, 32px);
  height: var(--cell, 32px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: calc(var(--cell, 32px) * 0.55);
  line-height: 1;
  cursor: pointer;
  position: relative;
  background: var(--tile);
  border-top: calc(var(--cell, 32px) * 0.08) solid var(--tile-hi);
  border-left: calc(var(--cell, 32px) * 0.08) solid var(--tile-hi);
  border-right: calc(var(--cell, 32px) * 0.08) solid var(--tile-lo);
  border-bottom: calc(var(--cell, 32px) * 0.08) solid var(--tile-lo);
  overflow: hidden;
}

.cell.pressed {
  border-color: var(--tile-revealed);
  background: var(--tile-revealed);
}

.cell.revealed {
  background: var(--tile-revealed);
  border: 1px solid var(--grid-line);
  cursor: default;
}

.cell.n1 { color: var(--n1); }
.cell.n2 { color: var(--n2); }
.cell.n3 { color: var(--n3); }
.cell.n4 { color: var(--n4); }
.cell.n5 { color: var(--n5); }
.cell.n6 { color: var(--n6); }
.cell.n7 { color: var(--n7); }
.cell.n8 { color: var(--n8); }

.cell .glyph {
  width: 78%;
  height: 78%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell .glyph svg { width: 100%; height: 100%; display: block; }

.cell.mine-hit { background: #ff3b30; border: 1px solid #b71c1c; }
.cell.flag-wrong { background: var(--tile-revealed); border: 1px solid var(--grid-line); }

/* ----- Toolbar ----- */
.toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  margin-bottom: 4px;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  border-radius: 14px;
  padding: 12px 26px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(180deg, #4a4f59, #353a43);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: background 0.15s, transform 0.05s;
  min-width: 150px;
  justify-content: center;
}
.mode-toggle:active { transform: scale(0.97); }
.mode-toggle[aria-pressed="true"] {
  background: linear-gradient(180deg, #ff5b4a, #e23b2c);
  box-shadow: 0 4px 16px rgba(226,59,44,0.5), inset 0 1px 0 rgba(255,255,255,0.2);
}
.mode-icon { font-size: 20px; }

.hint {
  margin: 0;
  font-size: 12px;
  color: #99a0aa;
  text-align: center;
}

.win-flash { animation: pop 0.4s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15) rotate(8deg); }
  100% { transform: scale(1); }
}
