* { box-sizing: border-box; margin: 0; }

:root {
  --bg: #10131a;
  --panel: #1a1f2b;
  --border: #2b3245;
  --text: #e7ecf5;
  --muted: #8a94a8;
  --cell: #232a3a;
  --cell-hover: #2e3750;
  --cell-open: #171c27;
  --accent: #3b82f6;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand { font-size: 18px; font-weight: 700; }

.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

#mines-left {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 6px 10px;
  background: var(--cell);
  border-radius: 8px;
}

button, select, input {
  font: inherit;
  color: var(--text);
  background: var(--cell);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
}

button { cursor: pointer; }
button:hover { background: var(--cell-hover); }
#invite.copied { background: #1d4a2c; border-color: #2f7a47; }
#flag-mode.active { background: #7a2b2b; border-color: #e6494f; box-shadow: 0 0 0 1px #e6494f55; }

#players {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 18px 0;
}

.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 13px;
}

.player-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.player-chip .score { color: var(--muted); font-variant-numeric: tabular-nums; }
.player-chip.me { border-color: #4a5570; box-shadow: 0 0 0 1px var(--border); }

#status {
  padding: 8px 18px;
  min-height: 34px;
  font-weight: 600;
}
#status.won { color: #4ade80; }
#status.lost { color: #f87171; }

main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 10px 18px 30px;
  overflow: auto;
}

#board-wrap { position: relative; }

#board {
  --cols: 16;
  --size: clamp(19px, calc((100vw - 44px) / var(--cols)), 30px);
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--size));
  gap: 2px;
  background: var(--border);
  padding: 2px;
  border-radius: 8px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.cell {
  width: var(--size);
  height: var(--size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell);
  border-radius: 3px;
  font-weight: 700;
  font-size: calc(var(--size) * 0.52);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.cell:not(.open):hover { background: var(--cell-hover); }
.cell.open { background: var(--cell-open); cursor: default; }
.cell.open.tinted { box-shadow: inset 0 0 0 30px var(--tint); }
.cell.mine { background: #3d1d22; }
.cell.exploded { background: #b91c1c; }
.cell.flag { font-size: calc(var(--size) * 0.48); }

.n1 { color: #60a5fa; }
.n2 { color: #4ade80; }
.n3 { color: #f87171; }
.n4 { color: #c084fc; }
.n5 { color: #fbbf24; }
.n6 { color: #2dd4bf; }
.n7 { color: #f472b6; }
.n8 { color: #cbd5e1; }

#cursors { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.cursor-tag {
  position: absolute;
  transform: translate(6px, 6px);
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  transition: left 80ms linear, top 80ms linear;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 11, 16, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay.hidden { display: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px 34px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(92vw, 360px);
  text-align: center;
}

.panel h1 { font-size: 22px; }
.panel p { color: var(--muted); font-size: 14px; }
.panel button { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.panel button:hover { filter: brightness(1.1); }
.panel input { font-size: 16px; } /* ≥16px stops iOS zooming the page on focus */

.help-panel {
  width: min(92vw, 460px);
  text-align: left;
  max-height: 85vh;
  overflow-y: auto;
}
.help-panel h1 { text-align: center; }
.help-body { display: flex; flex-direction: column; gap: 10px; }
.help-body h2 { font-size: 15px; margin-top: 4px; }
.help-body p, .help-body li { color: var(--muted); font-size: 14px; line-height: 1.5; }
.help-body strong { color: var(--text); }
.help-body ul { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

@media (max-width: 600px) {
  header { padding: 8px 10px; gap: 6px; }
  .brand { font-size: 15px; }
  .controls { gap: 5px; }
  button, select { padding: 6px 9px; font-size: 13px; }
  #players { padding: 8px 10px 0; }
  #status { padding: 6px 10px; font-size: 14px; }
  main { padding: 8px 6px 24px; }
}
