/* Minesweeper. Loads after base.css, which supplies the tokens, reset,
   background and card chrome. */

:root {
  /* --cell is written by the script once the board width is known; the value
     here is only what the very first paint uses. */
  --cell: 30px;
  --cell-gap: 3px;
  --cell-radius: 5px;

  /* Digit colours, roughly ordered cool -> hot so a busy corner reads as one. */
  --n1: #22d3ee;
  --n2: #4ade80;
  --n3: #f472b6;
  --n4: #818cf8;
  --n5: #fbbf24;
  --n6: #2dd4bf;
  --n7: #e879f9;
  --n8: #9ca3af;
}

/* Wider than 2048: the expert field is 22 columns across. */
.card {
  max-width: 620px;
}

.card__body {
  padding: 26px 26px 22px;
}

.card__foot {
  padding: 13px 26px;
}

/* Header: title + counters */
.head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.title {
  position: relative;
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 6.4vw, 2.4rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  background: linear-gradient(
    100deg,
    var(--accent-cyan) 0%,
    #818cf8 45%,
    var(--accent-violet) 100%
  );
  background-size: 200% auto;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation:
    rise 700ms var(--ease-smooth) 120ms both,
    shimmer 8s linear infinite;
}

.scores {
  display: flex;
  gap: 8px;
  animation: fade-in 700ms var(--ease-smooth) 240ms both;
}

.score {
  position: relative;
  min-width: 68px;
  padding: 6px 10px 7px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-chip);
  text-align: center;
}

.score__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1.4;
}

.score__value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* A record set this run gets a moment of green before settling back. */
.score__value--record {
  animation: record 1.4s var(--ease-smooth);
}

/* Difficulty picker */
.levels {
  display: flex;
  gap: 6px;
  margin-top: 18px;
  animation: fade-in 600ms var(--ease-smooth) 300ms both;
}

.level {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--bg-chip);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition:
    color var(--duration-short) var(--ease-smooth),
    border-color var(--duration-short) var(--ease-smooth),
    background var(--duration-short) var(--ease-smooth);
}

.level:hover,
.level:focus-visible {
  color: var(--text-secondary);
  border-color: var(--border-hover);
  outline: none;
}

.level[aria-pressed="true"] {
  color: var(--accent-cyan);
  border-color: rgba(34, 211, 238, 0.35);
  background: rgba(34, 211, 238, 0.1);
}

/* Hint line */
.hint {
  margin: 14px 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  animation: fade-in 600ms var(--ease-smooth) 340ms both;
}

.hint__sigil {
  color: var(--accent-lime);
  margin-right: 8px;
}

.hint__touch { display: none; }

/* Coarse pointers get the tap wording instead of the mouse one. */
@media (hover: none) and (pointer: coarse) {
  .hint__desktop { display: none; }
  .hint__touch { display: inline; }
}

/* Board */
.board {
  position: relative;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: calc(var(--cell-radius) + 7px);
  background: rgba(255, 255, 255, 0.025);
  animation: rise 700ms var(--ease-smooth) 400ms both;
}

/* The expert field can outgrow a phone; it scrolls inside the card rather than
   shrinking the cells below a tappable size. */
.board__scroll {
  overflow: auto;
  overscroll-behavior: contain;
}

.field {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  gap: var(--cell-gap);
  width: max-content;
  margin: 0 auto;
  -webkit-user-select: none;
  user-select: none;
  /* Long-press to flag must not pop the iOS callout or select text. */
  -webkit-touch-callout: none;
}

/* Rows exist for assistive tech only; they must not break the single grid. */
.row { display: contents; }

.cell {
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--cell-radius);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: calc(var(--cell) * 0.5);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition:
    background var(--duration-short) var(--ease-smooth),
    border-color var(--duration-short) var(--ease-smooth);
}

.cell:hover:not(.cell--open) {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-hover);
}

.cell:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 1px;
  z-index: 1;
}

.cell--open {
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.04);
  cursor: default;
}

.cell--flag {
  color: var(--accent-cyan);
  background: rgba(34, 211, 238, 0.12);
  border-color: rgba(34, 211, 238, 0.3);
}

/* Revealed after a loss: every mine the player had not found. */
.cell--mine {
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
}

/* The one that ended the run. */
.cell--boom {
  color: #fff1f2;
  background: rgba(244, 63, 94, 0.55);
  border-color: rgba(244, 63, 94, 0.7);
  box-shadow: 0 0 22px -4px rgba(244, 63, 94, 0.8);
}

/* A flag on a cell that turned out to be safe. */
.cell--wrong {
  color: #fda4af;
  background: rgba(244, 63, 94, 0.14);
  border-color: rgba(244, 63, 94, 0.35);
  text-decoration: line-through;
}

.cell[data-n="1"] { color: var(--n1); }
.cell[data-n="2"] { color: var(--n2); }
.cell[data-n="3"] { color: var(--n3); }
.cell[data-n="4"] { color: var(--n4); }
.cell[data-n="5"] { color: var(--n5); }
.cell[data-n="6"] { color: var(--n6); }
.cell[data-n="7"] { color: var(--n7); }
.cell[data-n="8"] { color: var(--n8); }

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: calc(var(--cell-radius) + 7px);
  background: rgba(5, 5, 7, 0.82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  text-align: center;
  animation: fade-in 320ms var(--ease-smooth) both;
}

.overlay[hidden] { display: none; }

.overlay__title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, var(--accent-cyan), var(--accent-violet));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.overlay__text {
  margin: 0 0 12px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.overlay__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* Buttons */
.controls {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-chip);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition:
    color var(--duration-short) var(--ease-smooth),
    border-color var(--duration-short) var(--ease-smooth),
    background var(--duration-short) var(--ease-smooth);
}

.btn:hover:not(:disabled),
.btn:focus-visible {
  color: var(--accent-cyan);
  border-color: var(--border-hover);
  outline: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn--primary {
  color: var(--text-primary);
  border-color: rgba(34, 211, 238, 0.25);
  background: rgba(34, 211, 238, 0.1);
}

.btn[aria-pressed="true"] {
  color: var(--accent-lime);
  border-color: rgba(74, 222, 128, 0.35);
  background: rgba(74, 222, 128, 0.1);
}

/* Square glyph-only button, so it does not eat the row on a narrow phone. */
.btn--icon {
  flex: none;
  min-width: 46px;
  padding: 9px 0;
  font-size: 0.95rem;
}

.btn--icon[aria-pressed="false"] {
  color: var(--text-dim);
  text-decoration: line-through;
}

.overlay .btn {
  flex: none;
  min-width: 116px;
}

/* Animation Keyframes */
@keyframes record {
  0%, 100% { color: var(--text-primary); }
  20%, 70% { color: var(--accent-lime); }
}

/* Responsive Design */
@media (max-width: 660px) {
  .stage { padding: 14px; }

  .card__body { padding: 20px 16px 18px; }

  .card__foot { padding: 12px 16px; }

  .head { gap: 12px; }

  .scores { width: 100%; }

  .score { flex: 1; min-width: 0; }
}

/* Accessibility - Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-delay: 0ms !important;
  }
}
