/* ============================================================
   Mahjong Multiply — game-specific visuals only.
   Chrome (top bar, menu, celebration, stage frame) comes from
   shared/shell.css and the --g-* variables.
   Tiles are REAL mahjong faces from the shared renderer
   (games/shared/tiles.js -> window.SchoolTiles.makeTile): dots,
   bams and craks drawn as genuine pips/characters.
   Each tile keeps its small top-left index numeral, as a real
   tile does. The pips are the read the game teaches, but the
   index matters for anyone who does not know the Chinese
   numerals craks use — a 七萬 is the character for seven.
   The tile BODY is a neutral ivory slab; only the small pips
   inside carry suit color, so red and green never clash at the
   body level. Green is still never the dominant pairing color.
   ============================================================ */

.mm-wrap { width: 100%; max-width: 640px; margin: 0 auto; }

/* ---- top HUD: a console of full-width rows, no floating chips ----
   Every row spans the full column so no row can leave a dead half, and each
   group is a joined segmented control whose segments split the track equally.
   Loose chips floating in a space-between flex were leaving 85px and 400px
   holes at the player's width. */
.mm-hud { display: grid; gap: 10px; margin-bottom: 12px; }
.mm-hud-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.mm-hud-row.is-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.mm-seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  padding: 3px; border-radius: 13px; background: var(--g-bg2);
  border: 1px solid var(--g-line); box-shadow: inset 0 1px 3px rgba(58,46,32,.10); }
.mm-seg > .mm-pill { border: 0; background: transparent; box-shadow: none; border-radius: 10px;
  font: inherit; font-size: 12.5px; font-weight: 700; color: var(--g-muted);
  padding: 7px 6px; min-width: 0; cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s; }
.mm-seg > .mm-pill:hover { color: var(--g-fg); }
.mm-seg > .mm-pill.is-on { color: var(--g-on-accent, #fff);
  background: linear-gradient(180deg, var(--g-accent-lt), var(--g-accent));
  box-shadow: 0 1px 2px rgba(58,46,32,.28), inset 0 1px 0 rgba(255,255,255,.35); }
/* Do NOT set overflow:hidden or text-overflow on the segments: a truncated
   "Advanced" is worse than a visible overflow, and hidden overflow would also
   hide the problem from the layout check. */

.mm-ctrls { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.mm-ctrls .mj-btn { margin: 0; justify-content: center; padding: 7px 8px; font-size: 12.5px; }

/* ---- console: one instrument panel (target + stats) ----
   The target is no longer a box floating alone in a half-empty row. A tinted
   outer panel holds a raised target readout and the stat grid side by side. */
.mm-target-bar { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px;
  align-items: stretch; margin-bottom: 12px; padding: 10px; border-radius: 18px;
  background: linear-gradient(180deg, var(--g-bg2), var(--g-bg));
  border: 1px solid var(--g-line); box-shadow: var(--g-shadow-md); }
.mm-target-box { display: flex; align-items: center; gap: 10px; padding: 8px 18px;
  border-radius: 13px; background: var(--g-card); border: 1px solid var(--g-line);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), var(--g-shadow-sm);
  position: relative; overflow: hidden; }
/* keep the existing accent sweep, label and number styles */
.mm-target-box::before { content: ""; position: absolute; inset: 0;
  background: linear-gradient(120deg, var(--g-accent-soft), transparent 70%); pointer-events: none; }
.mm-target-label { font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--g-muted); font-weight: 700; }
.mm-target-num { font-family: var(--serif, Georgia, serif); font-weight: 800;
  font-size: clamp(34px, 9vw, 52px); line-height: 1; color: var(--g-heading);
  text-shadow: 0 1px 0 rgba(255,255,255,.35); }

.mm-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
/* Seven cells into eight slots: let the last cell take the spare column so the
   grid never shows an empty cell, which is exactly what the player flagged. */
.mm-stats > .mm-stat:last-child { grid-column: span 2; }
.mm-stat { display: flex; flex-direction: column; justify-content: center; min-width: 0;
  padding: 6px 10px; border-radius: 10px; background: var(--g-card);
  border: 1px solid var(--g-line); box-shadow: var(--g-shadow-sm); }
.mm-stat-k { font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--g-muted); font-weight: 700; }
.mm-stat-v { font-size: 17px; font-weight: 800; color: var(--g-fg); line-height: 1.15;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.mm-stat.is-hot .mm-stat-v { color: var(--g-accent-dk); }
.mm-stat.is-hot { border-color: var(--g-accent); background: var(--g-accent-soft); }

/* ---- the board (a calm felt table) ---- */
.mm-board-frame { padding: 14px; border-radius: 20px; width: fit-content;
  background: linear-gradient(150deg, var(--g-bg2), var(--g-card) 60%, var(--g-bg));
  border: 1px solid var(--g-line);
  box-shadow: 0 0 0 2px var(--g-accent), var(--g-shadow-lg);
  max-width: 100%; margin: 0 auto; }
.mm-board { display: grid; gap: 7px; justify-content: center;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, var(--mm-tile, 64px))); }
.mj-game[data-bg="ink"] .mm-board-frame,
.mj-game[data-bg="plum"] .mm-board-frame { box-shadow: 0 0 0 2px var(--g-accent), var(--g-shadow-lg); }

/* ---- a single tile: neutral ivory body holding a real mahjong face ---- */
.mm-tile { --mm-tile: 64px; position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0;
  width: var(--mm-tile); max-width: 100%;
  border-radius: 10px; cursor: pointer; font: inherit; color: inherit;
  background: linear-gradient(165deg, #fdfcf7, #ece4d2);
  border: 1px solid rgba(60,50,30,.22);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.85), 0 2px 5px rgba(0,0,0,.16);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  transition: transform .12s ease, box-shadow .18s ease, border-color .18s ease; }
/* the real mahjong face fills the tile body. The body look lives on .mm-tile,
   so strip any face-level chrome. Constrain BOTH the inline SVG and the PNG
   override: bams (and dot-7) use PNG art, and without an explicit size that
   image renders at its full pixel dimensions and blows out the board. */
.mm-tile .tl { position: relative; width: 92%; height: 95%; display: block; background: none; border: 0; box-shadow: none; }
.mm-tile .tl svg { width: 100%; height: 100%; display: block; }
.mm-tile .tl .tl-img { width: 100%; height: 100%; display: block; object-fit: contain; pointer-events: none; }
/* Corner numeral: the small index a real tile carries, kept in the top-left so
   anyone can name a tile at a glance. This matters most for craks, whose face
   is a Chinese numeral (the 七萬 is the character for seven, not a digit an
   English reader knows) and for bams, where nine thin sticks are hard to count
   at 60px. The pips stay the primary read; the digit is the label. Styled here
   because this page does not load site.css, and in warm ink rather than the
   site's red index — red would sit beside the green bams, which is out.
   Plain ink, no chip: a white badge with a drop shadow read as a sticker
   pasted on the tile. The body is always ivory, so the ink alone carries
   roughly 10:1 without any backing. */
.mm-tile .tl .cnr { position: absolute; top: 1px; left: 3px; z-index: 3;
  display: block !important;
  font-family: var(--sans, system-ui, -apple-system, "Segoe UI", sans-serif);
  font-size: 11px; font-weight: 800; line-height: 1.2; text-align: center;
  color: #3A2E20; background: none; box-shadow: none; }
.mm-tile:hover { transform: translateY(-2px); box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 4px 10px rgba(0,0,0,.2); }
.mm-tile:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 2px; }

/* An ivory separator ring plus a SOLID accent ring. The accent alone against
   ivory is only ~3.4:1, and the previous 20%-opacity ring was invisible. */
.mm-tile.is-sel { border-color: var(--g-accent); z-index: 3;
  background: linear-gradient(165deg, #fffaf0, #f4e6cb);
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 0 0 2px rgba(255,253,248,.98), 0 0 0 5px var(--g-accent),
              0 10px 22px rgba(58,46,32,.30); }

/* hint spotlight */
.mm-tile.is-hint { animation: mm-pulse 1s ease-in-out infinite; }
@keyframes mm-pulse {
  0%,100% { box-shadow: 0 0 0 0 var(--g-accent-soft), var(--g-shadow-md); }
  50% { box-shadow: 0 0 0 6px var(--g-accent-hi), var(--g-shadow-md); }
}

/* wrong: shake (neutral graphite — never red, to keep green off red) */
.mm-tile.is-wrong { animation: mm-shake .5s; border-color: #3A352E !important; }
@keyframes mm-shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}

/* correct: pop then fade */
.mm-tile.is-gone { animation: mm-pop .3s ease forwards; pointer-events: none; }
@keyframes mm-pop {
  0% { transform: scale(1); opacity: 1; }
  60% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(.2); opacity: 0; }
}

/* obstacle tiles */
.mm-tile.obs-locked { cursor: not-allowed; filter: grayscale(.5);
  background: linear-gradient(170deg, rgba(0,0,0,.12), var(--g-card)); }
.mm-tile.obs-locked::after { content: "\1F512"; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; font-size: 22px; opacity: .7; }
.mm-tile.obs-iced { cursor: not-allowed; }
.mm-tile.obs-iced::after { content: ""; position: absolute; inset: 0; border-radius: 10px;
  background: linear-gradient(160deg, rgba(180,220,240,.55), rgba(120,170,200,.35));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.5); }
.mm-tile.obs-iced::before { content: "\2744"; position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center; font-size: 24px; color: #6fa8c9; }
/* .tl is the shared renderer's face wrapper (pips + corner numeral), not a
   numeral, so hiding it hides the whole face until the player taps the cloud.
   Keep it hidden while fogged; the cloud and the "?" below are the only marks. */
.mm-tile.mm-fog .tl { visibility: hidden; }
/* Covered look: a soft warm haze over the ivory body (not flat white) plus a
   dashed warm border, so the tile reads as deliberately obscured, not broken. */
.mm-tile.mm-fog {
  background:
    linear-gradient(165deg, rgba(120,105,80,.12), rgba(120,105,80,.10)),
    linear-gradient(165deg, #fdfcf7, #ece4d2);
  border: 1px dashed rgba(120,105,80,.55);
}
/* Cloud: large enough to read as a cover, in a warm mid-gray that clears
   ~4:1 against the hazed ivory body (the prior white-on-ivory was ~1.65:1). */
.mm-tile.mm-fog::after { content: "\2601"; position: absolute; top: 3%; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 58px; line-height: 1; color: #695d4d; opacity: .95;
  text-shadow: 0 1px 1px rgba(255,255,255,.45); }
/* "?" below the cloud marks an unknown value, in the same warm dark ink as the
   corner digits (#3A2E20). No red: red is reserved for the tile faces. */
.mm-tile.mm-fog::before { content: "?"; position: absolute; bottom: 11%; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; line-height: 1; color: #3A2E20;
  font-family: var(--sans, system-ui, -apple-system, "Segoe UI", sans-serif); }

/* ---- feed line ---- */
.mm-feed { text-align: center; margin: 16px auto 0; max-width: 520px;
  font-size: 14px; color: var(--g-muted); min-height: 20px; line-height: 1.5; }
.mm-feed b { color: var(--g-heading); }

/* ---- result panel ---- */
.mm-result { text-align: center; margin-top: 18px;
  background: var(--g-card); border: 1px solid var(--g-line); border-radius: 18px;
  padding: 22px 18px; box-shadow: var(--g-shadow-lg); }
.mm-medal { font-size: 44px; line-height: 1; color: var(--g-accent);
  text-shadow: 0 0 18px var(--g-accent-soft); }
.mm-result h2 { margin: 8px 0 6px; font-family: var(--serif, Georgia, serif);
  font-size: 24px; color: var(--g-heading); }
.mm-result p { margin: 0; font-size: 14px; color: var(--g-muted); line-height: 1.5; }
.mm-lb { margin-top: 12px; text-align: left; font-size: 13px; color: var(--g-fg);
  background: var(--g-bg); border: 1px solid var(--g-line); border-radius: 12px; padding: 10px 12px; }
.mm-lb ol { margin: 6px 0 0; padding-left: 22px; }
.mm-lb li { margin: 2px 0; }
.mm-ctrl { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
/* Result-panel actions: every label stays on the theme. The shell's default
   .mj-btn label is --g-fg, a near-black brown that reads as plain black next to
   the brass "Next level"; here they take the accent's dark end instead, so the
   whole row looks of a piece. The primary keeps white on the accent gradient. */
.mm-ctrl .mj-btn { color: var(--g-heading); background: linear-gradient(180deg, rgba(255,255,255,.7), var(--g-card));
  border: 1px solid var(--g-accent-soft); }
.mm-ctrl .mj-btn:hover { border-color: var(--g-accent); }
.mm-ctrl .mj-btn.is-on { color: var(--g-on-accent, #fff); background: linear-gradient(180deg, var(--g-accent-lt), var(--g-accent));
  border-color: transparent; }

/* ---- how-to ---- */
/* ---- Help sheet (opened by the top-right "?") ----
   The how-to lives behind the "?" in the top bar now, the same affordance
   the other games use. Fixed and full-viewport so it reads as a page-level
   sheet rather than a panel inside the board column. */
.mm-help { position: fixed; inset: 0; z-index: 96; display: flex; align-items: center;
  justify-content: center; padding: 18px; background: rgba(24,18,10,.55);
  backdrop-filter: blur(3px); opacity: 0; transition: opacity .18s ease; }
.mm-help[hidden] { display: none; }
.mm-help.show { opacity: 1; }
.mm-help-card { position: relative; width: min(600px, 94vw); max-height: 86vh; overflow: auto;
  padding: 26px 26px 28px; border-radius: 18px;
  background: linear-gradient(180deg, var(--g-card), var(--g-panel));
  border: 1px solid var(--g-accent-edge);
  box-shadow: 0 0 0 4px var(--g-accent-soft), var(--g-shadow-lg), inset 0 1px 0 rgba(255,255,255,.28);
  transform: translateY(8px); transition: transform .18s ease; }
.mm-help.show .mm-help-card { transform: translateY(0); }
.mm-help-card h2 { margin: 0 0 12px; font-family: var(--serif, Georgia, serif); font-size: 24px; color: var(--g-heading); }
.mm-help-card h3 { margin: 18px 0 6px; font-family: var(--serif, Georgia, serif); font-size: 16px; color: var(--g-heading); }
.mm-help-lead { max-width: 62ch; margin: 0 0 4px; font-size: 14px; line-height: 1.66; color: var(--g-fg); }
.mm-help-card p { max-width: 64ch; margin: 8px 0 0; font-size: 13.5px; line-height: 1.72; color: var(--g-muted); }
.mm-help-card p b { color: var(--g-strong); font-weight: 700; }
.mm-help-note { margin-top: 16px !important; border-top: 1px solid var(--g-line); padding-top: 10px;
  font-size: 12px; font-style: italic; opacity: .85; }
.mm-help-x { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  font: inherit; font-size: 22px; line-height: 1; color: var(--g-strong);
  background: linear-gradient(180deg, var(--g-card), var(--g-panel));
  border: 1px solid var(--g-line); border-radius: 50%;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), var(--g-shadow-sm);
  transition: border-color .15s, color .15s, transform .12s; }
.mm-help-x:hover { border-color: var(--g-accent); color: var(--g-accent); transform: translateY(-1px); }
.mm-help-x:focus-visible { outline: 2px solid var(--g-accent); outline-offset: 2px; }

/* Countdown line on the result card (Classic auto-advance only). */
.mm-result p.mm-auto { margin: 12px 0 0; font-size: 12.5px; font-weight: 700; color: var(--g-strong); }
.mm-result p.mm-auto[hidden] { display: none; }

/* ---- array explainer overlay (the teaching payload) ---- */
.mm-array { position: fixed; inset: 0; z-index: 78; display: flex; align-items: center;
  justify-content: center; background: rgba(0,0,0,.5); backdrop-filter: blur(3px);
  animation: mm-fade .2s ease; }
.mm-array[hidden] { display: none; }
@keyframes mm-fade { from { opacity: 0; } to { opacity: 1; } }
.mm-array-card { width: min(420px, 92vw); text-align: center; padding: 22px 20px;
  background: var(--g-panel); color: var(--g-fg);
  border: 1px solid var(--g-line); border-top: 3px solid var(--g-accent); border-radius: 22px;
  box-shadow: var(--g-shadow-lg), 0 0 0 6px var(--g-accent-soft);
  transform: translateY(10px) scale(.96); animation: mm-rise .28s cubic-bezier(.2,.9,.3,1.3) forwards; }
@keyframes mm-rise { to { transform: none; } }
.mm-array-tiles { display: flex; gap: 14px; justify-content: center; margin-bottom: 14px; }
.mm-array-tiles .mm-tile { --mm-tile: 58px; cursor: default; box-shadow: inset 0 1px 0 rgba(255,255,255,.85), 0 2px 6px rgba(0,0,0,.18); }
.mm-array-tiles .mm-tile .tl { width: 92%; height: 95%; }
.mm-array-grid { display: grid; gap: 6px; grid-template-columns: repeat(6, 18px);
  justify-content: center; margin: 0 auto 14px; }
.mm-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--g-accent);
  box-shadow: inset 0 -2px 3px rgba(0,0,0,.25); }
.mm-array-eq { font-family: var(--serif, Georgia, serif); font-size: 26px; font-weight: 800;
  color: var(--g-heading); margin-bottom: 16px; }

/* ---- responsive ---- */
@media (max-width: 520px) {
  .mm-hud-row.is-split { grid-template-columns: minmax(0, 1fr); }
  .mm-seg > .mm-pill { font-size: 10.5px; padding: 6px 2px; }
  .mm-target-bar { grid-template-columns: minmax(0, 1fr); }
  .mm-target-box { justify-content: center; }
  .mm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mm-board-frame { padding: 10px; border-radius: 16px; }
  .mm-board { gap: 6px; --mm-tile: 56px; }
}
