/* ── Reset & Base ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background:
    radial-gradient(circle at 20% 10%, rgba(74, 158, 255, 0.14), transparent 45%),
    radial-gradient(circle at 80% 90%, rgba(46, 213, 115, 0.1), transparent 45%),
    linear-gradient(160deg, #0d1324 0%, #0a0e1c 60%, #070a14 100%) fixed;
  color: #e0e0e0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
}

/* ── HUD ── */
#hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 14px;
  margin-bottom: 12px;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-display {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 14px;
  border-radius: 10px;
  font-family: 'SF Mono', 'Menlo', 'Courier New', monospace;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 2px;
  min-width: 100px;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}

.hud-icon {
  font-size: 1.1rem;
}

#mine-count {
  color: #ff5c6c;
  text-shadow: 0 0 10px rgba(255, 92, 108, 0.6);
}

#timer {
  color: #3ddc84;
  text-shadow: 0 0 10px rgba(61, 220, 132, 0.55);
}

#tool-buttons { display: flex; gap: 6px; }

.tool-btn {
  width: 42px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04));
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.tool-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(74, 158, 255, 0.25); }
.tool-btn.active { background: linear-gradient(180deg, #ff6b81, #e94560); border-color: #ff8fa0; box-shadow: 0 0 16px rgba(233, 69, 96, 0.5); }
.tool-flag { width: 20px; height: 20px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='6' y='3' width='2.2' height='18' rx='1' fill='%23cbd5e1'/%3E%3Cpath d='M8.2 3.5 L19 7.6 L8.2 11.8 Z' fill='%23ff4d6d'/%3E%3Crect x='3.5' y='19.5' width='8' height='2' rx='1' fill='%2394a3b8'/%3E%3C/svg%3E") center / contain no-repeat; }

#difficulty-selector {
  display: flex;
  gap: 6px;
}

.diff-btn {
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: #b8c0dc;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.diff-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.diff-btn.active {
  background: linear-gradient(135deg, #4a9eff, #6c5ce7);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(74, 158, 255, 0.35);
}

/* ── Board ── */
#board-wrapper {
  display: flex;
  justify-content: center;
  width: 100%;
  overflow: auto;
  padding: 4px;
}

#board-stage { position: relative; }

#board {
  display: grid;
  gap: 2px;
  padding: 8px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

#board.shake { animation: board-shake 0.5s ease-out; }

@keyframes board-shake {
  10%, 50% { transform: translate(-6px, 2px); }
  30%, 70% { transform: translate(6px, -2px); }
  90% { transform: translate(-2px, 0); }
}

#fx-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 5; }

.fx-flash { position: absolute; inset: 0; border-radius: 14px; background: rgba(255, 77, 109, 0.45); animation: fx-flash 0.5s ease-out forwards; }

@keyframes fx-flash {
  from { opacity: 1; }
  to { opacity: 0; }
}

.fx-confetti {
  position: absolute;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: confetti 1.8s cubic-bezier(.3, .6, .5, 1) both;
}

@keyframes confetti {
  from { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

/* ── Cells ── */
.cell {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 900;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  position: relative;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 66%;
}

.cell-unrevealed {
  background-color: #2a3352;
  background-image: linear-gradient(160deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.04) 55%, rgba(0, 0, 0, 0.08));
  background-size: 100%;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -2px 0 rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.35);
}

.cell-unrevealed:hover {
  background-color: #34406a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.3), 0 0 12px rgba(74, 158, 255, 0.45);
}

.cell-unrevealed:active {
  transform: scale(0.94);
}

.cell-revealed {
  background-color: rgba(8, 12, 26, 0.65);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.55);
  cursor: default;
  animation: cellReveal 0.22s cubic-bezier(.2, 1.4, .4, 1) both;
}

@keyframes cellReveal {
  0% {
    opacity: 0;
    transform: scale(0.6);
    background-color: rgba(120, 180, 255, 0.6);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.cell-flagged {
  background-color: #2a3352;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='6' y='3' width='2.2' height='18' rx='1' fill='%23cbd5e1'/%3E%3Cpath d='M8.2 3.5 L19 7.6 L8.2 11.8 Z' fill='%23ff4d6d'/%3E%3Crect x='3.5' y='19.5' width='8' height='2' rx='1' fill='%2394a3b8'/%3E%3C/svg%3E"), linear-gradient(160deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.04) 55%, rgba(0, 0, 0, 0.08));
  background-size: 62%, 100%;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -2px 0 rgba(0, 0, 0, 0.3), 0 0 10px rgba(255, 77, 109, 0.35);
  animation: flagPlant 0.3s ease-out;
}

@keyframes flagPlant {
  0% {
    background-size: 0%, 100%;
  }
  60% {
    background-size: 78%, 100%;
  }
  100% {
    background-size: 62%, 100%;
  }
}

.cell-mine {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg stroke='%23111827' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3M5.3 5.3l2.1 2.1M16.6 16.6l2.1 2.1M5.3 18.7l2.1-2.1M16.6 7.4l2.1-2.1'/%3E%3C/g%3E%3Ccircle cx='12' cy='12' r='6.4' fill='%23111827'/%3E%3Ccircle cx='9.8' cy='9.6' r='1.9' fill='%23ffffff' opacity='0.85'/%3E%3C/svg%3E");
  background-size: 70%;
  background-color: rgba(255, 200, 210, 0.85);
}

.cell-mine-chain { animation: mine-pop 0.35s ease-out both; }

.cell-mine-exploded {
  background-color: #ff4d6d !important;
  box-shadow: 0 0 22px rgba(255, 77, 109, 0.9) !important;
  animation: explode 0.5s ease-out;
  z-index: 2;
}

@keyframes mine-pop {
  0% { transform: scale(0.4); background-color: #fff; }
  50% { transform: scale(1.25); background-color: #ffb3c1; }
  100% { transform: scale(1); }
}

@keyframes explode {
  0% {
    transform: scale(1);
    background-color: #fff;
  }
  30% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}

.cell-wrong-flag {
  background-color: rgba(8, 12, 26, 0.65);
  box-shadow: inset 0 0 0 2px rgba(255, 92, 108, 0.7);
  color: #ff5c6c;
}

.cell-chord-flash {
  background-color: rgba(255, 240, 150, 0.55) !important;
  transform: scale(1.06);
}

.cell-hint { animation: hint-glow 0.45s ease-in-out infinite alternate; z-index: 2; }

@keyframes hint-glow {
  from { box-shadow: 0 0 0 2px #ffe066, 0 0 10px rgba(255, 224, 102, 0.6); }
  to { box-shadow: 0 0 0 3px #ffe066, 0 0 22px rgba(255, 224, 102, 0.95); }
}

#board.won .cell-revealed { animation: win-wave 0.6s ease-out both; }

@keyframes win-wave {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); background-color: rgba(61, 220, 132, 0.45); }
  100% { transform: scale(1); }
}

/* Number colors */
.num-1 { color: #5aa9ff; text-shadow: 0 0 8px rgba(90, 169, 255, 0.45); }
.num-2 { color: #3ddc84; text-shadow: 0 0 8px rgba(61, 220, 132, 0.4); }
.num-3 { color: #ff5c6c; text-shadow: 0 0 8px rgba(255, 92, 108, 0.45); }
.num-4 { color: #b388ff; text-shadow: 0 0 8px rgba(179, 136, 255, 0.45); }
.num-5 { color: #ffa94d; text-shadow: 0 0 8px rgba(255, 169, 77, 0.45); }
.num-6 { color: #22d3ee; text-shadow: 0 0 8px rgba(34, 211, 238, 0.45); }
.num-7 { color: #f8fafc; }
.num-8 { color: #94a3b8; }

/* ── Overlay ── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 26, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(6px);
  animation: overlayIn 0.3s ease;
}

@keyframes overlayIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

#overlay.hidden {
  display: none;
}

#overlay-content {
  background: linear-gradient(160deg, rgba(40, 52, 90, 0.95), rgba(16, 22, 44, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  padding: 32px 40px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  animation: slideUp 0.4s ease;
}

@keyframes slideUp {
  0% {
    transform: translateY(40px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

#overlay-title {
  font-size: 1.6rem;
  margin-bottom: 16px;
  letter-spacing: 1px;
}

#overlay-title.win {
  color: #2ed573;
}

#overlay-title.lose {
  color: #ff4757;
}

#overlay-stats {
  font-size: 0.95rem;
  color: #a0a0b8;
  line-height: 1.8;
  margin-bottom: 20px;
}

#overlay-stats span {
  color: #e0e0e0;
  font-weight: 700;
}

#high-scores-section {
  margin-bottom: 20px;
}

#high-scores-section.hidden {
  display: none;
}

#high-scores-section h3 {
  color: #ffa502;
  font-size: 1rem;
  margin-bottom: 8px;
}

#high-scores-list {
  list-style: none;
  padding: 0;
  counter-reset: rank;
}

#high-scores-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.9rem;
  color: #a0a0b8;
  font-family: 'Courier New', monospace;
}

#high-scores-list li::before {
  content: counter(rank) ".";
  color: #ffa502;
  font-weight: 700;
  min-width: 24px;
  text-align: right;
}

#high-scores-list li.new-score {
  color: #2ed573;
  font-weight: 700;
}

#play-again-btn {
  padding: 12px 32px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #4a9eff, #6c5ce7);
  box-shadow: 0 6px 20px rgba(74, 158, 255, 0.35);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
}

#play-again-btn:hover {
  transform: scale(1.05);
}

/* ── Mobile Responsive ── */
@media (max-width: 600px) {
  #app {
    padding: 8px;
  }

  #hud {
    padding: 8px 10px;
    gap: 6px;
    justify-content: center;
  }

  .hud-display {
    font-size: 1rem;
    padding: 6px 10px;
    min-width: 85px;
  }

  .diff-btn {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  #board {
    padding: 4px;
    gap: 1px;
  }

  .cell {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
    border-radius: 3px;
  }

  .cell-flagged::after {
    font-size: 1rem;
  }
}

@media (max-width: 380px) {
  .cell {
    width: 28px;
    height: 28px;
    font-size: 0.8rem;
  }
}

#overlay {
  top: var(--gp-header-h, 80px);
  overflow-y: auto;
  align-items: safe center;
}

@media (pointer: coarse) {
  .diff-btn { min-height: 36px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #app {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    max-width: none;
    gap: 12px;
    padding: 6px;
  }
  #hud {
    width: auto;
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 0;
    padding: 8px;
  }
  #difficulty-selector { flex-direction: column; }
  #board-wrapper { width: auto; padding: 0; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #start-overlay > div { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 24px; align-items: center; align-content: center; justify-items: center; width: min(780px, calc(100% - 24px)); max-width: none; }
  #start-overlay > div > * { grid-column: 2; }
  #start-overlay > div > div { grid-column: 1; grid-row: 1 / span 6; margin: 0; max-width: 340px; width: 100%; }
}

.start-box { text-align: center; padding: 30px; }
.start-title { font-size: 36px; margin-bottom: 8px; color: #fff; }
.start-sub { color: #888; margin-bottom: 16px; }
.how-to { max-width: 340px; text-align: left; margin: 0 auto 16px; padding: 14px 18px; background: rgba(255,255,255,0.04); border-radius: 8px; font-size: 13px; line-height: 1.7; color: #aaa; }
.how-to-title { font-size: 11px; font-weight: 700; letter-spacing: 2px; color: #666; margin-bottom: 8px; text-transform: uppercase; }
.start-btn { padding: 12px 36px; font-size: 16px; font-weight: 800; border: 0; border-radius: 999px; background: linear-gradient(135deg, #4a9eff, #6c5ce7); color: #fff; cursor: pointer; letter-spacing: 1px; box-shadow: 0 6px 20px rgba(74, 158, 255, 0.35); }

[data-theme="light"] html,
[data-theme="light"] body { background: var(--gp-page-grad) fixed; color: var(--gp-ink); }
[data-theme="light"] #hud { background: var(--gp-surface); color: var(--gp-ink); box-shadow: inset 0 0 0 1px var(--gp-line), var(--gp-shadow); }
[data-theme="light"] .diff-btn { background: var(--gp-surface-2); color: var(--gp-ink-2); }
[data-theme="light"] .diff-btn:hover { background: #e9e6f7; color: var(--gp-ink); }
[data-theme="light"] #overlay { background: var(--gp-overlay); }
[data-theme="light"] #overlay-content { background: var(--gp-surface); color: var(--gp-ink); box-shadow: var(--gp-shadow); }
[data-theme="light"] #overlay-title.win, [data-theme="light"] #high-scores-list li.new-score { color: #15803d; }
[data-theme="light"] #overlay-stats, [data-theme="light"] #high-scores-list li { color: var(--gp-ink-2); }
[data-theme="light"] #overlay-stats span { color: var(--gp-ink); }
[data-theme="light"] #high-scores-section h3, [data-theme="light"] #high-scores-list li::before { color: #c2410c; }
[data-theme="light"] #start-overlay { background: var(--gp-overlay); }
[data-theme="light"] .start-title { color: var(--gp-ink); }
[data-theme="light"] .start-sub { color: var(--gp-ink-2); }
[data-theme="light"] .how-to { background: rgba(31, 27, 69, 0.05); color: var(--gp-ink-2); }
[data-theme="light"] .how-to-title { color: var(--gp-ink-3); }
[data-theme="light"] #board { background: linear-gradient(160deg, #ffffff, #eef1fb); border-color: rgba(80, 90, 160, 0.16); box-shadow: 0 16px 40px rgba(60, 70, 150, 0.14); }
[data-theme="light"] .cell-unrevealed, [data-theme="light"] .cell-flagged { background-color: #c9d3f2; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 -2px 0 rgba(60, 70, 150, 0.18), 0 1px 2px rgba(60, 70, 150, 0.2); }
[data-theme="light"] .cell-unrevealed:hover { background-color: #b7c4ef; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 -2px 0 rgba(60, 70, 150, 0.18), 0 0 10px rgba(74, 120, 255, 0.35); }
[data-theme="light"] .cell-revealed, [data-theme="light"] .cell-wrong-flag { background-color: #f4f6fc; box-shadow: inset 0 1px 2px rgba(60, 70, 150, 0.18); }
[data-theme="light"] .num-1 { color: #1d6fe0; text-shadow: none; }
[data-theme="light"] .num-2 { color: #138a4e; text-shadow: none; }
[data-theme="light"] .num-3 { color: #d6263c; text-shadow: none; }
[data-theme="light"] .num-4 { color: #6d3fd1; text-shadow: none; }
[data-theme="light"] .num-5 { color: #c25e00; text-shadow: none; }
[data-theme="light"] .num-6 { color: #0e8ea3; text-shadow: none; }
[data-theme="light"] .num-7 { color: #1f2937; }
[data-theme="light"] .num-8 { color: #64748b; }
[data-theme="light"] .hud-display { background: #ffffff; border-color: var(--gp-line); box-shadow: inset 0 1px 3px rgba(60, 70, 150, 0.12); }
[data-theme="light"] #mine-count { color: #d6263c; text-shadow: none; }
[data-theme="light"] #timer { color: #138a4e; text-shadow: none; }
[data-theme="light"] .tool-btn { background: var(--gp-surface-2); border-color: var(--gp-line); }
[data-theme="light"] .tool-btn.active { background: linear-gradient(180deg, #ff6b81, #e94560); }
[data-theme="light"] #board.won .cell-revealed { animation-name: win-wave; }

.gp-btn-music.off { opacity: .4; }
