/* GraphChinese — 麻将 tab/page (assets/mahjong.js).
   Built entirely from the shared tokens in styles.css, so it inherits dark mode
   rather than declaring its own. The only place this file goes off-token is the
   tile itself: a mahjong tile is bone-white with a green back in every theme,
   because it is a physical object and objects do not repaint at night. Its ink
   still comes from the palette so the page reads as one system. */

.mj { display: block; }
.mj-loading { color: var(--ink-whisper); padding: 28px 2px; }

/* ── section nav ─────────────────────────────────────────────────────────── */
.mj-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; }
.mj-navbtn {
  display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: 13.5px;
  padding: 8px 14px; min-height: 40px; cursor: pointer; white-space: nowrap;
  background: var(--paper-raised); color: var(--ink-faded);
  border: 1px solid var(--hairline); border-radius: 999px;
}
.mj-navbtn:hover { color: var(--ink); border-color: var(--ink-whisper); }
.mj-navbtn.on { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent); }
.mj-navmark { font-family: var(--han); font-size: 15px; line-height: 1; }
.mj-navbtn.on .mj-navmark { color: var(--on-accent); }

.mj-lede { font-size: 15px; line-height: 1.65; color: var(--ink-faded); max-width: 62ch; margin: 0 0 18px; }
.mj-lede i { font-style: italic; color: var(--accent); }
.mj-foot { font-size: 13px; line-height: 1.6; color: var(--ink-whisper); max-width: 62ch; margin: 20px 0 0; }
.mj-foot i, .mj-win i { font-style: italic; }
.mj-h3 { font-family: var(--serif-display); font-size: 20px; margin: 28px 0 12px; }
.mj-h3 span { font-size: 15px; font-style: italic; color: var(--accent); }

/* ── the tile ────────────────────────────────────────────────────────────── */
.mj-tile {
  --tile-face: #FCFAF2;
  --tile-edge: #D9CFB4;
  --tile-ink: #2A241C;
  display: inline-flex; flex-direction: column; align-items: center; gap: 5px;
  font: inherit; padding: 0; background: none; border: 0; cursor: pointer;
}
.mj-tileface {
  display: flex; align-items: center; justify-content: center;
  width: 46px; height: 62px; border-radius: 7px;
  background: linear-gradient(#FFFDF6, var(--tile-face));
  border: 1px solid var(--tile-edge);
  box-shadow: 0 2px 0 var(--tile-edge), 0 4px 10px rgba(var(--shadow-rgb), 0.16);
  color: var(--tile-ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.mj-tile:hover .mj-tileface { transform: translateY(-2px); box-shadow: 0 4px 0 var(--tile-edge), 0 8px 16px rgba(var(--shadow-rgb), 0.2); }
.mj-tile:focus-visible .mj-tileface { outline: 2px solid var(--accent); outline-offset: 2px; }
.mj-tile.on .mj-tileface { border-color: var(--accent); box-shadow: 0 2px 0 var(--accent-dark), 0 6px 14px rgba(var(--accent-rgb), 0.3); }
.mj-tile-sm .mj-tileface { width: 34px; height: 46px; border-radius: 5px; }
.mj-tile-big .mj-tileface { width: 84px; height: 112px; border-radius: 10px; }

/* The stamped face: number over suit, the way a 萬 tile is actually laid out. */
.mj-face { display: flex; flex-direction: column; align-items: center; line-height: 1; font-family: var(--han); }
.mj-face b { font-size: 21px; font-weight: 600; }
.mj-face em { font-size: 19px; font-style: normal; color: var(--accent-dark); margin-top: 3px; }
.mj-face.is-solo { font-size: 30px; font-weight: 600; }
.mj-face.is-red { color: #A8322A; }
.mj-face.is-green { color: #1D7A5F; }
.mj-tile-sm .mj-face b { font-size: 15px; }
.mj-tile-sm .mj-face em { font-size: 13px; margin-top: 2px; }
.mj-tile-sm .mj-face.is-solo { font-size: 21px; }
.mj-tile-big .mj-face b { font-size: 38px; }
.mj-tile-big .mj-face em { font-size: 34px; margin-top: 6px; }
.mj-tile-big .mj-face.is-solo { font-size: 56px; }

/* Dots and bamboo: no characters at all — count them and say the number. */
.mj-pips { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 100%; }
.mj-piprow { display: flex; align-items: center; justify-content: center; gap: 3px; }
.mj-dot { width: 9px; height: 9px; border-radius: 50%; background: #1E5C99; box-shadow: inset 0 0 0 2px #FCFAF2, 0 0 0 1px #1E5C99; }
.mj-dot.is-mid { background: #A8322A; box-shadow: inset 0 0 0 2px #FCFAF2, 0 0 0 1px #A8322A; }
/* Bamboo stacks vertically as well as across, so the rows need clear air
   between them — 2索 stacked tight reads as one long stick, not two. */
.mj-pips-bamboo { gap: 5px; }
.mj-stick { width: 5px; height: 11px; border-radius: 2px; background: #1D7A5F; }
.mj-stick.is-mid { background: #A8322A; }
.mj-tile-sm .mj-dot { width: 6px; height: 6px; box-shadow: inset 0 0 0 1.5px #FCFAF2, 0 0 0 1px #1E5C99; }
.mj-tile-sm .mj-stick { width: 4px; height: 9px; }
.mj-tile-big .mj-dot { width: 15px; height: 15px; }
.mj-tile-big .mj-stick { width: 8px; height: 22px; }
.mj-tileface { position: relative; }
.mj-birdnote {
  position: absolute; bottom: 3px; right: 4px; font-family: var(--han); font-size: 9px;
  color: var(--ink-whisper); opacity: .8;
}
.mj-tilesay { font-family: var(--han); font-size: 12.5px; color: var(--ink-faded); }

/* ── 牌 · the wall ───────────────────────────────────────────────────────── */
/* styles.css gives a bare <section> 76px of landing-page padding; these are
   groups inside a component, not page sections. */
.mj-suit { margin: 0 0 26px; padding: 0; }
.mj-suit-h { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 10px; }
.mj-suit-zh { font-family: var(--han); font-size: 19px; font-weight: 600; }
.mj-suit-en { font-size: 13px; color: var(--accent); }
.mj-suit-gloss { flex: 1 1 260px; font-size: 13px; color: var(--ink-whisper); }
.mj-row { display: flex; flex-wrap: wrap; gap: 9px; }

/* The tile card — a popup, not a panel in the flow. Same shape and behaviour
   as the dictionary's tap-a-hanzi card (.char-card in styles.css): anchored to
   the tile on a wide screen, a bottom sheet on a phone. An inline panel meant
   every tap scrolled the wall out from under you. */
.mj-card {
  position: absolute; z-index: 260; width: 380px; max-width: calc(100vw - 24px);
  max-height: min(82vh, 680px); overflow-y: auto;
  background: var(--paper-raised); border: 1px solid var(--hairline); border-radius: 14px;
  box-shadow: 0 18px 50px -12px rgba(var(--shadow-rgb), 0.35);
  padding: 18px 20px 16px;
}
.mj-card[hidden] { display: none; }
.mj-card.sheet {
  position: fixed; left: 10px !important; right: 10px; bottom: 10px; top: auto !important;
  width: auto; max-width: none; max-height: 76vh;
}
.mj-card-x {
  position: absolute; top: 8px; right: 8px; background: none; border: 0; cursor: pointer;
  color: var(--ink-whisper); font-size: 15px; padding: 8px; line-height: 1;
}
.mj-card-x:hover { color: var(--ink); }
.mj-card-hero { display: flex; gap: 18px; align-items: flex-start; }
.mj-card-meta { min-width: 0; }
.mj-say { font-family: var(--han); font-size: 26px; line-height: 1.2; }
.mj-say-py { font-size: 15px; color: var(--accent); font-style: italic; margin-top: 2px; }
.mj-say-en { font-size: 14.5px; color: var(--ink); margin-top: 6px; }
.mj-stamped { font-size: 13px; color: var(--ink-faded); margin-top: 10px; }
.mj-stamped b { font-family: var(--han); font-size: 16px; }
.mj-stamped-note { color: var(--ink-whisper); }
.mj-note { font-size: 13.5px; line-height: 1.6; color: var(--ink-faded); margin: 12px 0 0; }
.mj-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.mj-card-actions .btn { font-size: 13px; padding: 8px 13px; min-height: 40px; }
.mj-glyphs { display: flex; gap: 10px; margin-top: 14px; }
.mj-glyphs[hidden] { display: none; }
.mj-glyph { width: 74px; height: 74px; border: 1px solid var(--hairline); border-radius: 8px; background: var(--paper); }
.mj-glyph svg { width: 100%; height: 100%; display: block; }

/* character → the topic that teaches it */
.mj-chars { display: grid; gap: 10px; margin-top: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.mj-card .mj-chars { grid-template-columns: 1fr; }
.mj-char { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px;
  background: var(--paper); border: 1px solid var(--hairline); border-radius: 10px; }
.mj-char-zh { font-family: var(--han); font-size: 30px; line-height: 1; background: none; border: 0;
  color: var(--ink); cursor: pointer; padding: 0; }
.mj-char-zh:hover { color: var(--accent); }
.mj-char-meta { font-size: 13px; color: var(--ink-faded); min-width: 0; }
.mj-char-meta b { color: var(--accent); font-style: italic; font-weight: 500; }
.mj-char-trad { display: block; font-size: 12px; color: var(--ink-whisper); margin-top: 2px; }
.mj-char-trad b { font-family: var(--han); font-size: 15px; color: var(--ink-faded); font-style: normal; }
.mj-topic { display: block; margin-top: 6px; font: inherit; font-size: 12.5px; text-align: left;
  background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.mj-topic:hover { text-decoration: underline; }
.mj-topic b { font-family: var(--han); color: inherit; font-style: normal; }

/* ── 手 · read a hand ────────────────────────────────────────────────────── */
.mj-hand { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 18px; }
.mj-hand-tight { gap: 5px; }
.mj-handtile { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mj-handsay { display: flex; flex-direction: column; align-items: center; font-size: 12px; line-height: 1.4; }
.mj-handsay b { font-family: var(--han); font-size: 13px; font-weight: 500; }
.mj-handsay i { color: var(--accent); font-style: italic; }
.mj-handsay.is-hidden { visibility: hidden; }
.mj-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ── 对 · match ──────────────────────────────────────────────────────────── */
.mj-matchbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px;
  font-size: 13px; color: var(--ink-faded); }
.mj-matchbar b { color: var(--ink); font-variant-numeric: tabular-nums; }
.mj-matchgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; max-width: 520px; }
.mj-matchcard {
  display: flex; align-items: center; justify-content: center; min-height: 78px;
  font: inherit; cursor: pointer; padding: 6px;
  background: var(--paper-raised); border: 1px solid var(--hairline); border-radius: 10px;
  transition: border-color .15s ease, opacity .2s ease, transform .12s ease;
}
.mj-matchcard:hover { border-color: var(--ink-whisper); }
.mj-matchcard.is-open { border-color: var(--accent); }
.mj-matchcard.is-wrong { border-color: var(--accent); animation: mj-shake .25s ease; }
.mj-matchcard.is-done { opacity: .28; cursor: default; }
.mj-matchpy { font-style: italic; font-size: 15px; color: var(--accent); }
@keyframes mj-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@media (prefers-reduced-motion: reduce) { .mj-matchcard.is-wrong { animation: none; } }
.mj-win { font-family: var(--han); font-size: 17px; color: var(--ink); margin: 14px 0 0; }
.mj-win i { font-family: var(--serif-display); font-size: 15px; color: var(--accent); }

/* ── 听 · which tile wins ────────────────────────────────────────────────── */
.mj-choices { display: flex; flex-wrap: wrap; gap: 12px; margin: 18px 0; }
.mj-choice { padding: 8px; background: var(--paper-raised); border: 1px solid var(--hairline);
  border-radius: 12px; cursor: pointer; font: inherit; }
.mj-choice:hover { border-color: var(--ink-whisper); }
.mj-choice.is-right { border-color: rgba(var(--correct-rgb), 0.9); background: rgba(var(--correct-rgb), 0.08); }
.mj-choice.is-wrong { border-color: var(--accent); background: rgba(var(--accent-rgb), 0.08); }
.mj-explain { padding: 16px 18px; background: var(--paper-raised); border: 1px solid var(--hairline);
  border-radius: 12px; }
.mj-explain.is-right { border-color: rgba(var(--correct-rgb), 0.55); }
.mj-explain-h { font-family: var(--han); font-size: 16px; margin: 0 0 12px; }
.mj-explain-h i { font-family: var(--serif-display); font-size: 14px; font-style: italic; color: var(--accent); }
.mj-explain-tile { margin-bottom: 14px; }
.mj-shape { display: flex; flex-wrap: wrap; gap: 16px; }
.mj-shapegrp { display: flex; flex-direction: column; gap: 5px; }
.mj-shaperow { display: flex; gap: 4px; }
.mj-shapename { font-size: 12px; color: var(--ink-faded); }
.mj-shapename b { font-family: var(--han); font-size: 13px; }
.mj-shapename i { color: var(--accent); font-style: italic; }

/* ── 说 · table talk ─────────────────────────────────────────────────────── */
.mj-talk { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.mj-phrase { position: relative; padding: 12px 14px; background: var(--paper-raised);
  border: 1px solid var(--hairline); border-radius: 10px; }
.mj-phrase-zh { font-family: var(--han); font-size: 21px; line-height: 1.5; }
.mj-phrase-py { font-size: 13px; font-style: italic; color: var(--accent); margin-top: 1px; }
.mj-phrase-en { font-size: 13.5px; color: var(--ink); margin-top: 5px; }
.mj-phrase-when { font-size: 12.5px; line-height: 1.55; color: var(--ink-whisper); margin: 6px 0 0; }
.mj-phrase-when b { font-family: var(--han); font-size: 14px; color: var(--ink-faded); }
.mj-phrase-play { position: absolute; top: 8px; right: 8px; background: none; border: 0; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 6px; opacity: .55; }
.mj-phrase-play:hover { opacity: 1; }

/* ── 数 · numbers ────────────────────────────────────────────────────────── */
.mj-ladder { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.mj-rung { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.mj-rung-py { font-size: 12.5px; font-style: italic; color: var(--accent); }
.mj-rung-n { font-size: 11.5px; color: var(--ink-whisper); font-variant-numeric: tabular-nums; }
.mj-wanbox { padding: 14px 16px; background: var(--paper-raised); border: 1px solid var(--hairline);
  border-radius: 12px; max-width: 62ch; }
.mj-wanbox h3 { margin-top: 0; }
.mj-wanbox p { font-size: 14px; line-height: 1.65; color: var(--ink-faded); margin: 0; }
.mj-counters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.mj-counter { padding: 12px 14px; background: var(--paper-raised); border: 1px solid var(--hairline); border-radius: 10px; }
.mj-counter-zh { font-family: var(--han); font-size: 26px; line-height: 1.2; }
.mj-counter-py { font-size: 13px; font-style: italic; color: var(--accent); }
.mj-counter-en { font-size: 13px; color: var(--ink-faded); margin-top: 4px; }
.mj-counter-eg { font-size: 13px; color: var(--ink); margin-top: 8px; }
.mj-counter-eg b { font-family: var(--han); font-size: 15px; font-weight: 500; }
.mj-counter-eg i { color: var(--accent); font-style: italic; }
.mj-chars-wide { margin-top: 18px; }

/* ── guide-mode CTA ──────────────────────────────────────────────────────── */
.mj-cta { margin-top: 34px; padding: 22px 24px; background: var(--paper-raised);
  border: 1px solid var(--hairline); border-radius: 16px; max-width: 66ch; }
.mj-cta-h { font-family: var(--serif-display); font-size: 21px; margin: 0 0 8px; }
.mj-cta p { font-size: 14.5px; line-height: 1.7; color: var(--ink-faded); margin: 0 0 16px; }

@media (max-width: 560px) {
  /* Keep the section NAMES on a phone — six unexplained hanzi is not a nav.
     Two rows of three is the right trade. */
  .mj-nav { gap: 5px; }
  .mj-navbtn { padding: 7px 10px; font-size: 12.5px; gap: 6px; flex: 1 1 auto; justify-content: center; }
  .mj-navmark { font-size: 14px; }
  .mj-tileface { width: 40px; height: 54px; }
  .mj-card-hero { gap: 14px; }
  .mj-matchgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
