.magawa-main {
  max-width: 760px;
}

.magawa-main .header {
  margin-bottom: 0.25rem;
}

/* The rat in the title gives a friendly wave. */
.title-rat {
  width: 50px;
  height: 50px;
  display: inline-block;
  flex-shrink: 0;
  animation: wiggle 2.4s ease-in-out infinite;
}

.title-rat svg,
/* the painted rat is an <img> now; same box, same rules as the drawn one */
.title-rat img { width: 100%; height: 100%; object-fit: contain; display: block; }

.face-btn svg { width: 40px; height: 40px; display: block; }

/* ---------- Difficulty picker ---------- */

.levels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.05rem;
  padding: 0.45rem 0.95rem;
  border-radius: 14px;
  line-height: 1.15;
}

.level-btn small {
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--muted);
}

.level-btn.picked {
  background: var(--pick-bg);
  border-color: var(--pick-border);
  color: var(--primary-dark);
}

.level-btn.picked small { color: var(--primary-dark); }

/* ---------- Scoreboard ---------- */

.scoreboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 18px 18px 0 0;
  border-bottom: none;
  padding: 0.7rem 1rem;
  box-shadow: var(--shadow);
}

.readout {
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
  font-size: 1.45rem;
  letter-spacing: 1px;
  color: #ff5c5c;
  background: #1a0e0e;
  padding: 0.2rem 0.55rem;
  border-radius: 8px;
  min-width: 3.4ch;
  text-align: center;
  text-shadow: 0 0 6px rgba(255, 92, 92, 0.7);
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.85);
}

.readout-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.readout-wrap .readout-icon { font-size: 1.1rem; }

.face-btn {
  font-size: 1.7rem;
  line-height: 1;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: #fff;            /* cells stay light so the classic number colours read */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.face-btn:hover { transform: translateY(-1px) scale(1.05); }
.face-btn:active { transform: scale(0.95); }

/* The same painted mine and flag used on the board, reused in the scoreboard readout
   and the flag-mode button so the chrome matches the field it describes. Sized in em
   so each one tracks the text it sits beside. */
.chrome-art {
  height: 1.15em;
  width: auto;
  vertical-align: -0.18em;
  margin-right: 0.15em;   /* matches .inline-art elsewhere on the site */
}
.chrome-emoji { font-style: normal; }
.chrome-art + .chrome-emoji { display: none; }

/* Painted mine and flag. The cell is already flex-centred, so the image only needs a
   size; the emoji behind it is hidden while the image is there and comes back if the
   file 404s. pointer-events keeps taps and long-presses landing on the button. */
.cell-art {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
}
.cell-emoji { font-style: normal; }
.cell-art + .cell-emoji { display: none; }

/* ---------- Board ---------- */

/* The scoreboard and the board share one panel, so they must share one width. The
   frame is fit-content, which resolves to its widest child — the board — instead of
   the page, so a 9x9 Trainee grid no longer floats in a full-width card. Sizing each
   card separately would not work: the scoreboard is space-between and would bunch its
   readouts, and the two could end up different widths and break the joint. */
.game-frame {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}
.game-frame > .scoreboard,
.game-frame > .board-scroll { width: 100%; box-sizing: border-box; }


.board-scroll {
  overflow-x: auto;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 0 0 18px 18px;
  box-shadow: var(--shadow);
  padding: 0.6rem;
  -webkit-overflow-scrolling: touch;
}

.board {
  /* Cells shrink to fit the screen: the whole field stays visible on a phone
     instead of forcing a sideways scroll. 3.2rem = body (2rem) + board-scroll
     (1.2rem) horizontal padding; the gap term reserves the inter-cell gaps. */
  --cell: clamp(16px, calc((100vw - 3.2rem - (var(--cols) - 1) * 3px) / var(--cols)), 38px);
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  gap: 3px;
  margin: 0 auto;
  width: max-content;
  max-width: 100%;
  touch-action: manipulation;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  margin: 0;
  border-radius: 7px;
  border: none;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.55);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background 0.1s ease, transform 0.08s ease;
}

/* A clear, high-contrast focus ring for keyboard players — reads on both the
   dirt tiles and the cleared cells, light or dark theme. */
.cell:focus-visible {
  outline: 3px solid #15233a;
  outline-offset: -3px;
  position: relative;
  z-index: 2;
}

/* Unrevealed dirt — the ground Magawa hasn't sniffed yet. */
.cell.hidden-cell {
  background: linear-gradient(145deg, #f7c89a 0%, #e9a86d 100%);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.1), inset 0 2px 0 rgba(255, 255, 255, 0.35);
}

.cell.hidden-cell:hover {
  background: linear-gradient(145deg, #fad3aa 0%, #efb47e 100%);
  transform: translateY(-1px);
}

.cell.hidden-cell:active { transform: translateY(0) scale(0.96); }

/* Flash shown when you chord a number that isn't satisfied yet — points out
   which hidden tiles it's counting. */
.cell.hidden-cell.peek {
  background: #fff6ec;
  box-shadow: inset 0 0 0 2px var(--pick-border);
  transform: none;
}

.cell.flag {
  background: linear-gradient(145deg, #f7c89a 0%, #e9a86d 100%);
}

/* Cleared, safe ground. */
.cell.open {
  background: #fff6ec;
  box-shadow: inset 0 0 0 1px var(--border);
  cursor: default;
}

.cell.mine {
  background: #ffe0e0;
  box-shadow: inset 0 0 0 1px #f3b6b6;
}

.cell.mine.detonated {
  background: #ff6b6b;
  animation: boom 0.4s ease;
}

@keyframes boom {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Classic Minesweeper number colours, darkened where needed so every digit
   clears WCAG AA contrast on the cleared-cell background (#fff6ec). */
.cell[data-n="1"] { color: #1f5fb0; }
.cell[data-n="2"] { color: #1d7a43; }
.cell[data-n="3"] { color: #c62f2f; }
.cell[data-n="4"] { color: #6a3fb0; }
.cell[data-n="5"] { color: #a8521f; }
.cell[data-n="6"] { color: #137676; }
.cell[data-n="7"] { color: #444; }
.cell[data-n="8"] { color: #6b6b6b; }

/* ---------- Status line ---------- */

.status {
  margin-top: 1rem;
  text-align: center;
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--primary-dark);
  min-height: 1.4em;
  animation: cardPop 0.35s cubic-bezier(0.17, 0.89, 0.32, 1.275);
}

/* ---------- Controls row ---------- */

.controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1rem 0 0;
  flex-wrap: wrap;
}

#flag-toggle { cursor: pointer; }

.best-pill {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.best-pill b { font-variant-numeric: tabular-nums; }

/* ---------- How to play ---------- */

.how-to {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 1.25rem 1.4rem 1.1rem;
  margin-top: 1.5rem;
  box-shadow: var(--shadow);
}

.how-to h2 {
  margin: 0 0 0.6rem;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 1.15rem;
  font-weight: 500;
}

.how-to ul {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
}

.how-to li { margin-bottom: 0.35rem; }
.how-to b { color: var(--ink); }

/* ---------- Banana reward shower ---------- */

.banana-pop {
  position: fixed;
  bottom: -2.5rem;
  z-index: 60;
  pointer-events: none;
  will-change: transform, opacity;
  animation-name: banana-rise;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

.banana-pop svg {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2));
}

@keyframes banana-rise {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translateY(-112vh) rotate(380deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .banana-pop { display: none; }
  .title-rat { animation: none; }
  .cell.mine.detonated { animation: none; }
  .status { animation: none; }
  .cell.hidden-cell.peek { transition: none; }
  .cell { transition: none; }
}

/* Screen-reader-only helper text (visually hidden, still announced). */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- About Magawa ---------- */

.about {
  background: var(--card);
  border: 2px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: 20px;
  padding: 1.25rem 1.4rem 1.3rem;
  margin-top: 1.25rem;
  box-shadow: var(--shadow);
}

.about h2 {
  margin: 0 0 0.6rem;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 1.15rem;
  font-weight: 500;
}

.about p {
  margin: 0 0 0.8rem;
  color: var(--muted);
}

.about p:last-child { margin-bottom: 0; }
.about b { color: var(--ink); }

.donate-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem 0.9rem;
  margin-top: 0.4rem !important;
}

.donate-btn {
  display: inline-block;
  padding: 0.55rem 1.3rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: background 0.15s ease, transform 0.15s ease;
}

.donate-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.donate-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.donate-link:hover { text-decoration: underline; }

@media (max-width: 500px) {
  .readout { font-size: 1.2rem; }
  .face-btn { width: 46px; height: 46px; }
  .face-btn svg { width: 34px; height: 34px; }
}
