:root {
  --ink: #172033;
  --muted: #64748b;
  --line: #cbd5e1;
  --paper: #f8fafc;
  --tile: #d9e2ec;
  --tile-dark: #a8b6c7;
  --open: #fffdf5;
  --accent: #0f8b8d;
  --danger: #e63946;
  --gold: #f2b84b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 139, 141, 0.16), transparent 36%),
    linear-gradient(315deg, rgba(242, 184, 75, 0.18), transparent 38%),
    #edf2f7;
  font-family: Arial, Helvetica, sans-serif;
}

.game {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  min-height: 100vh;
  padding: 22px;
}

.topbar,
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  letter-spacing: 0;
}

#contextLabel {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

button {
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-actions button {
  min-width: 72px;
  padding: 10px 14px;
  color: white;
  background: var(--accent);
}

.header-actions button:disabled {
  background: #94a3b8;
}

.game .topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 38px;
}

.game .topbar > div:first-child {
  min-width: 0;
}

.game #contextLabel {
  display: block;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game .header-actions {
  width: auto;
  flex: 0 0 auto;
}

.game .header-actions button {
  width: auto;
  min-width: 76px;
  min-height: 32px;
  padding: 6px 12px;
}

.table {
  align-self: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

.board-wrap {
  justify-self: center;
  width: min(78vmin, 640px);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: clamp(3px, 0.75vmin, 6px);
  aspect-ratio: 1;
  padding: clamp(6px, 1.4vmin, 12px);
  border: 3px solid #314055;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.26), transparent 36%),
    #475569;
  box-shadow: 0 22px 48px rgba(15, 23, 42, 0.22);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid rgba(49, 64, 85, 0.2);
  border-radius: 6px;
  color: #1f2937;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.72), transparent 45%),
    var(--tile);
  box-shadow:
    inset 0 -4px 0 var(--tile-dark),
    0 1px 0 rgba(255, 255, 255, 0.7);
  font-size: clamp(13px, 2.4vmin, 20px);
  line-height: 1;
}

.cell:hover:not(:disabled),
.cell:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.cell.open {
  background: var(--open);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--owner, #cbd5e1) 56%, white);
}

.cell.mine {
  color: white;
  background:
    radial-gradient(circle at 34% 30%, #ff9aa1, var(--danger) 58%, #8f1d2b);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.65);
}

.cell.last::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 2px solid var(--gold);
  border-radius: 5px;
  pointer-events: none;
}

.cell[data-number="1"] {
  color: #0f766e;
}

.cell[data-number="2"] {
  color: #2563eb;
}

.cell[data-number="3"] {
  color: #b45309;
}

.cell[data-number="4"],
.cell[data-number="5"],
.cell[data-number="6"],
.cell[data-number="7"],
.cell[data-number="8"] {
  color: #7c2d12;
}

footer {
  flex-wrap: wrap;
}

.identity {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: #314055;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.result-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 10;
  min-width: min(78vw, 380px);
  padding: 26px 32px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.96);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.3);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.result-overlay.hidden {
  display: none;
}

.result-message {
  color: #0f766e;
  font-size: clamp(36px, 8vmin, 72px);
  font-weight: 900;
  line-height: 1;
}

@media (max-width: 760px) {
  .game {
    padding: 16px;
  }

  .topbar {
    align-items: center;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .header-actions {
    width: auto;
  }

  .header-actions button {
    flex: 0 0 auto;
    min-width: 76px;
    padding-inline: 10px;
  }

  .table {
    grid-template-columns: 1fr;
  }

  .board-wrap {
    width: min(94vw, 620px);
  }
}
