/* Minesweeper — tokens come from /assets/base.css. Only game-specific
   overrides and extras live here. */
:root {
  --panel: #101426;
  --accent-strong: #b3a8ff;
  --border: #23263b;
  --danger: #ff5d7a;
  --good: #5cffb4;

  --cell-size: 40px; /* overridden at runtime by fitBoard() */
  --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.55);

  /* Bright crosshair cursor visible on dark backgrounds */
  --cursor-crosshair: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cline x1='12' y1='3' x2='12' y2='21' stroke='%23fff' stroke-width='1.5' stroke-linecap='round'/%3E%3Cline x1='3' y1='12' x2='21' y2='12' stroke='%23fff' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") 12 12, crosshair;
}

.cell {
  font-size: calc(var(--cell-size) * 0.45);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 0;
}

.app {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* HEADER — centered title, matches Hearts / Clock */

.top {
  width: 100%;
  max-width: 700px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.top-side {
  display: flex;
  align-items: center;
}
.top-side-right { justify-content: flex-end; }

.top-center {
  text-align: center;
}

.top h1 {
  font-size: clamp(1.6rem, 3.2vw, 2.1rem);
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

/* MAIN PANEL */

.panel {
  background: linear-gradient(145deg, rgba(16, 20, 38, 0.95), #090c18 40%, #05060f 100%);
  border-radius: 26px;
  padding: 22px 20px 16px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.06);
  width: min(100%, 700px);
  backdrop-filter: blur(18px);
}

.board-slot {
  /* Hard-locked square — same pixel size for every difficulty.
     Medium and Hard overflow and pan inside this window. */
  width: 520px;
  height: 520px;
  margin: 6px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: contain;
  border-radius: 14px;
}

.board-slot::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.board-slot::-webkit-scrollbar-track {
  background: transparent;
}
.board-slot::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}
.board-slot::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* When the board is bigger than the slot, start aligned top-left inside
   the scroll area — flex centering only applies when content fits. */
.board-slot > .board {
  margin: auto;
}

.board-wrap {
  position: relative;
}


.magnify-toggle {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(10, 12, 22, 0.85);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 2;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.magnify-toggle:hover {
  background: rgba(20, 24, 44, 0.9);
}
.magnify-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(138, 124, 255, 0.18);
}
.magnify-toggle .icon {
  width: 18px;
  height: 18px;
}

/* CSS-transform magnifier — a circular viewport with a scaled clone of the
   board inside. GPU-composited, zero canvas drawing per frame. */
.mag-lens {
  position: absolute;
  left: 0;
  top: 0;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
  z-index: 6;
  display: none;
  will-change: transform;
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.12),
              0 0 24px rgba(0, 0, 0, 0.6);
  background: #080a14;
}
.mag-lens.show { display: block; }
.mag-lens-board {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}
.board-wrap,
.panel,
.app {
  overflow: visible;
}

.magnify-toggle.hidden {
  display: none;
}

@media (max-height: 860px) {
  .board-slot { width: 460px; height: 460px; }
}
@media (max-height: 780px) {
  .board-slot { width: 400px; height: 400px; }
}
@media (max-height: 700px) {
  .board-slot { width: 340px; height: 340px; }
}
@media (max-width: 600px) {
  .board-slot {
    width: min(92vw, 92vh);
    height: min(92vw, 92vh);
  }
}

/* CONTROLS */

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.difficulty {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--muted);
}

.pill {
  border: none;
  outline: none;
  cursor: pointer;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 0.84rem;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.07);
  transition:
    background 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease,
    transform 0.06s ease;
}

.pill:hover {
  background: rgba(255, 255, 255, 0.07);
  transform: translateY(-1px);
}

.pill.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}

.info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.info-box {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 14px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  min-width: 80px;
}

.info-box .label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.info-box .value {
  font-family: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 1rem;
}

/* Ghost button — matches Hearts' pattern */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.45rem 0.95rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease,
    transform 0.08s ease, color 0.2s ease;
}

.btn.ghost {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(6, 11, 26, 0.9);
}

.btn.ghost:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.04);
}

.top-newgame {
  padding: 6px 16px;
}

.top-newgame.state-lose {
  color: var(--danger);
  border-color: rgba(255, 93, 122, 0.5);
}

.top-newgame.state-win {
  color: var(--good);
  border-color: rgba(92, 255, 180, 0.5);
}

@media (max-width: 480px) {
  .top-newgame .icon + span { display: none; }
}

.reset-btn:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.6);
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.4));
}

/* BOARD */

.board {
  margin: 6px auto 0;
  display: grid;
  gap: 4px;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 1rem;
  cursor: var(--cursor-crosshair);
  user-select: none;
  -webkit-tap-highlight-color: transparent;

  background: linear-gradient(145deg, #2a2f52 0%, #171a30 100%);
  border: 1px solid rgba(120, 128, 170, 0.12);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.14),
    inset 2px 2px 0 rgba(255, 255, 255, 0.05),
    inset -1px -1px 0 rgba(0, 0, 0, 0.55),
    inset -2px -2px 0 rgba(0, 0, 0, 0.35),
    0 2px 6px rgba(0, 0, 0, 0.55);
  transition:
    background 0.08s ease,
    transform 0.06s ease,
    box-shadow 0.08s ease;
}

.cell:hover {
  background: linear-gradient(145deg, #343a60 0%, #1d2038 100%);
}

.cell:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.8),
    0 2px 4px rgba(0, 0, 0, 0.7);
}

/* States */

.cell.revealed {
  background: #0a0c16;
  border-color: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.9);
  cursor: var(--cursor-crosshair);
}

.cell.empty {
  color: var(--muted);
}

.cell.mine {
  color: var(--danger);
}

.cell.flag {
  color: #ef4d5e;
}
.cell.flag .cell-icon {
  fill: currentColor;
  stroke: currentColor;
  width: 62%;
  height: 62%;
}

.cell.wrong-flag {
  color: var(--danger);
  background: linear-gradient(145deg, #2a1420, #1a0d16);
}

/* Number colors */
.cell.n1 { color: #9ad0ff; }
.cell.n2 { color: #7dffcf; }
.cell.n3 { color: #ffcf7d; }
.cell.n4 { color: #ff9fb4; }
.cell.n5 { color: #ff6b6b; }
.cell.n6 { color: #cfa2ff; }
.cell.n7 { color: #f4f5ff; }
.cell.n8 { color: #b3b6d1; }

/* STATUS + HIGHSCORES */

.status {
  margin-top: 10px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.2em;
}

.status.win {
  color: var(--good);
}

.status.lose {
  color: var(--danger);
}

.highscores {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.hs-item {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  gap: 6px;
}

/* FOOTER */

.foot {
  text-align: center;
  font-size: 0.8rem;
}

.tagwhy {
  color: var(--accent-strong);
}

/* OVERLAY (win / lose screen) */

.overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.92));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: linear-gradient(145deg, #15192b, #05060f);
  border-radius: 24px;
  padding: 22px 24px 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  min-width: 260px;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(20px);
}

.result-icon {
  font-size: 2.3rem;
  margin-bottom: 6px;
}

.overlay-card h2 {
  margin: 4px 0 6px;
  font-size: 1.3rem;
}

.overlay-card p {
  margin: 2px 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.result-highscore {
  margin-top: 6px;
  font-size: 0.9rem;
}

.result-highscore.new {
  color: var(--good);
}

.primary-btn {
  margin-top: 10px;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #0b0b18;
  font-weight: 600;
  box-shadow: 0 10px 22px rgba(138, 124, 255, 0.4);
  transition:
    transform 0.08s ease,
    box-shadow 0.08s ease,
    filter 0.12s ease;
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(138, 124, 255, 0.55);
  filter: brightness(1.05);
}

.primary-btn:active {
  transform: translateY(0);
  box-shadow: 0 6px 14px rgba(138, 124, 255, 0.35);
}

/* Prevent iOS text selection / callout on long-press */
.cell {
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.cell-icon {
  width: 55%;
  height: 55%;
  stroke: currentColor;
  fill: none;
  pointer-events: none;
}
.cell.mine .cell-icon {
  fill: currentColor;
  stroke: none;
}

/* RESPONSIVE */

@media (max-width: 600px) {
  .panel {
    padding: 18px 12px 12px;
  }

  .controls {
    gap: 10px;
  }

  .highscores {
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }
}
