body,
html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #3e2723;
  font-family: Arial, sans-serif;
  touch-action: none; /* Prevent browser handling of gestures like pinch zoom on the body */
}

.board {
  display: grid;
  gap: 1px;
  background-color: #261410;
  width: max-content;
  height: max-content;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0; /* Explicit z-index so stacking order is unambiguous in Firefox */
  will-change: transform;
  -ms-touch-action: none; /* Samsung Internet / legacy Edge */
  touch-action: none; /* Prevent browser from intercepting touch for scroll/zoom */
  -webkit-touch-callout: none; /* Prevent callout on long-press (iOS/Samsung) */
  -webkit-user-select: none; /* Safari */
  -moz-user-select: none; /* Firefox */
  -ms-user-select: none; /* IE10+/Edge */
  user-select: none; /* Standard */
}

.cell {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #d88c9a;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.05),
    rgba(0, 0, 0, 0.05) 2px,
    transparent 2px,
    transparent 4px
  );
  cursor: pointer;
  font-size: 2rem;
  font-weight: bold;
}

.cell.revealed {
  background-color: #6d4c41;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.1),
    rgba(0, 0, 0, 0.1) 2px,
    transparent 2px,
    transparent 4px
  );
  cursor: default;
  color: #fbe9e7;
}

.cell.mine {
  background-color: #f44336;
  font-size: 2.2rem;
}

.cell.flagged {
  background-color: #d88c9a;
  color: #3e2723;
  font-size: 2.2rem;
}

.score-overlay {
  background-color: rgba(62, 39, 35, 0.8);
  color: #fbe9e7;
  font-size: 18px;
  padding: 10px;
  position: fixed;
  right: 10px;
  top: 10px;
  border-radius: 5px;
  z-index: 1000;
}

.toast {
  background-color: rgba(62, 39, 35, 0.8);
  border-radius: 5px;
  color: #fbe9e7;
  display: none;
  font-size: 18px;
  padding: 20px;
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 1000;
}

.restart-btn,
.leaderboard-btn {
  background-color: #e28a93;
  color: #3e2723;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  padding: 10px;
  position: fixed;
  top: 10px;
  z-index: 1000;
}

.restart-btn {
  left: 10px;
}

.leaderboard-btn {
  left: 90px;
}

.leaderboard-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}

.leaderboard {
  border-collapse: collapse;
  margin-bottom: 20px;
  width: 100%;
  max-width: 600px;
}

.leaderboard th,
.leaderboard td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.leaderboard th {
  background-color: #f2f2f2;
}

.submit-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: rgba(62, 39, 35, 0.8);
  color: #fbe9e7;
  font-size: 18px;
  padding: 20px;
  border-radius: 5px;
  position: fixed;
  bottom: 10%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.submit-score input {
  font-size: 16px;
  margin-bottom: 10px;
  padding: 5px;
}

.submit-score button, .export-png-btn {
  cursor: pointer;
  font-size: 16px;
  padding: 10px;
  margin-top: 5px;
  background-color: #5d4037;
  color: #fff;
  border: none;
  border-radius: 5px;
}

.submit-score button:hover, .export-png-btn:hover {
  background-color: #4e342e;
}

.notification {
  display: none; /* Hidden by default */
  position: fixed;
  bottom: 20px;
  left: 20px;
  padding: 15px;
  background-color: rgba(62, 39, 35, 0.8);
  color: #fbe9e7;
  border-radius: 5px;
  z-index: 1000;
  font-size: 16px;
}

.notification.show {
  display: block;
}

.ad-container {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  justify-content: center;
  align-items: center;
}

.info-area {
  position: fixed;
  bottom: 10px;
  left: 10px;
  z-index: 9998;
}

.info-icon {
  background-color: rgba(62, 39, 35, 0.8);
  color: #fbe9e7;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  font-weight: bold;
}

.keybinds-tooltip {
  display: none;
  position: fixed;
  bottom: 50px;
  left: 10px;
  z-index: 9999;
  background-color: rgba(62, 39, 35, 0.8);
  color: #fbe9e7;
  padding: 10px;
  border-radius: 5px;
  width: 250px;
}

.info-area:hover .keybinds-tooltip {
  display: block;
}

.hackatoa-banner {
  position: fixed;
  bottom: 10px;
  right: 10px;
  background-color: rgba(62, 39, 35, 0.8);
  color: #fbe9e7;
  padding: 5px 10px;
  text-decoration: none;
  border-radius: 5px;
  font-weight: bold;
  z-index: 1000;
}

.games-hub-badge {
  position: fixed;
  bottom: 10px;
  right: 120px;
  background-color: rgba(62, 39, 35, 0.8);
  color: #ff69b4;
  padding: 5px 10px;
  text-decoration: none;
  border-radius: 5px;
  font-weight: bold;
  z-index: 1000;
  border: 1px solid rgba(255, 105, 180, 0.3);
  transition: background-color 0.2s, color 0.2s;
}
.games-hub-badge:hover {
  background-color: rgba(62, 39, 35, 0.95);
  color: #ffb6c1;
}

/* Screen reader only utility class for SEO headings */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}


.zoom-controls {
  position: fixed;
  bottom: 80px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 10;
}

.zoom-controls button {
  width: 40px;
  height: 40px;
  font-size: 24px;
  border-radius: 5px;
  border: none;
  background-color: rgba(62, 39, 35, 0.8);
  color: #fbe9e7;
  cursor: pointer;
}

.mobile-mode-toggle {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  /* z-index 9999: ensures toggle paints and receives touch above .board's
     will-change:transform stacking context in Firefox and Samsung Internet */
  z-index: 9999;
  isolation: isolate; /* Force own stacking context so nothing bleeds through */
  background-color: rgba(62, 39, 35, 0.8);
  padding: 5px;
  border-radius: 20px;
  /* Ensure the toggle container itself doesn't swallow touch events that should
     reach the board if the touch misses a button */
  touch-action: auto;
  pointer-events: auto;
}

.mobile-mode-toggle button {
  width: 50px;
  height: 50px;
  font-size: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  background-color: transparent;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  pointer-events: auto; /* Explicit — overrides any inherited suppression */
}

.mobile-mode-toggle button.active {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: #fbe9e7;
}

@media (min-width: 768px) {
  .mobile-mode-toggle {
    display: none;
  }
}

.flag-x {
  position: relative;
  display: inline-block;
}
.flag-x::after {
  content: '❌';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.8em;
  opacity: 0.8;
}

.region-border-right {
  border-right: 2px solid #ffeb3b !important;
}
.region-border-bottom {
  border-bottom: 2px solid #ffeb3b !important;
}
.region-border-left {
  border-left: 2px solid #ffeb3b !important;
}
.region-border-top {
  border-top: 2px solid #ffeb3b !important;
}

