/* assets/games/matching.css — v1.0 (Beta)
 * Match Game — Maryland MHIC beta launch (2026-06-15).
 * Mirrors the dark games aesthetic of wordfinder.css + crossword.css.
 * Per-state color tokens come from state-themes.css (`body.state-md`, etc.).
 * --xword-primary / --xword-accent are reused for visual parity with the
 * other games — when a canonical state-brand palette lands (see state-
 * themes.css comment), these reference the same vars. */

@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700;900&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --mg-bg:        #0c1117;
  --mg-panel:     #141b24;
  --mg-panel-2:   #1b2530;
  --mg-border:    #6b7a8e;   /* WCAG 1.4.11 UI 3:1 — was #243040 (1.30:1) → #6b7a8e (3.96:1) passes vs panel #141b24. Verified by contrast-ratio sweep 2026-06-16. */
  --mg-border-2:  #8b9ab0;   /* hover border — 6.06:1 vs panel. Reuses the --mg-muted value for token economy. */
  --mg-ink:       #e8eaed;
  --mg-muted:     #8b9ab0;
  --mg-good:      #2ecc71;
  --mg-bad:       #e74c3c;
}
body[class*="state-"] {
  /* Map the shared xword-* vars (set per state in state-themes.css)
     to local mg-* aliases for readability. */
  --mg-primary: var(--xword-primary);
  --mg-accent:  var(--xword-accent);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #15202d 0%, var(--mg-bg) 60%);
  color: var(--mg-ink); min-height: 100vh; padding: 20px 14px 60px;
}

/* Header */
.mg-header { max-width: 880px; margin: 0 auto 16px; display: flex; align-items: center; gap: 14px; }
.mg-back {
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--mg-panel); border: 1px solid var(--mg-border);
  color: var(--mg-ink); text-decoration: none; font-size: 1.1rem; flex-shrink: 0;
}
.mg-back:hover { background: var(--mg-panel-2); }
.mg-title {
  font-family: 'Barlow Condensed', sans-serif; font-weight: 900; font-size: 1.7rem;
  letter-spacing: 0.4px; line-height: 1; display: flex; align-items: center; gap: 8px;
}
.mg-accent { color: var(--mg-accent); }
.mg-beta {
  font-family: 'Barlow Condensed', sans-serif; font-weight: 900; font-size: 0.62rem;
  letter-spacing: 1.5px; text-transform: uppercase; color: #0c1117;
  background: var(--mg-accent); padding: 2px 8px; border-radius: 4px; margin-left: 4px;
}
.mg-sub { color: var(--mg-muted); font-size: 0.85rem; margin-top: 4px; line-height: 1.4; }
.mg-sub b { color: var(--mg-accent); font-weight: 700; }

/* Control bar */
#mg-mount { max-width: 880px; margin: 0 auto; }
.mg-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--mg-panel); border: 1px solid var(--mg-border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 16px;
}
.mg-seg { display: inline-flex; background: var(--mg-panel-2); border: 1px solid var(--mg-border); border-radius: 9px; padding: 3px; }
.mg-seg button {
  font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 0.85rem;
  letter-spacing: 0.6px; text-transform: uppercase; color: var(--mg-muted);
  background: none; border: none; padding: 7px 16px; border-radius: 6px; cursor: pointer;
}
.mg-seg button.on { background: var(--mg-primary, #c8102e); color: #fff; }
.mg-seg button:disabled { opacity: 0.55; cursor: not-allowed; }
.mg-seg button .n { opacity: 0.7; font-weight: 600; }
.mg-check { color: var(--mg-good); font-weight: 900; }

.mg-spacer { flex: 1; }
.mg-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--mg-panel-2); border: 1px solid var(--mg-border); border-radius: 20px;
  padding: 6px 13px; font-family: 'Barlow Condensed', sans-serif; font-weight: 700;
  font-size: 0.9rem; letter-spacing: 0.5px; white-space: nowrap;
}
.mg-chip .num { color: var(--mg-accent, #ffd700); font-size: 1.05rem; }
.mg-btn {
  font-family: 'Barlow Condensed', sans-serif; font-weight: 900; font-size: 0.82rem;
  letter-spacing: 0.8px; text-transform: uppercase; cursor: pointer;
  border: none; border-radius: 8px; padding: 9px 15px;
}
.mg-btn-hint { background: var(--mg-accent, #ffd700); color: #0c1117; }
.mg-btn-hint:disabled { opacity: 0.4; cursor: not-allowed; }
.mg-btn-hint .cost { font-weight: 700; opacity: 0.8; font-size: 0.72rem; }
.mg-btn-ghost { background: none; border: 1px solid var(--mg-border); color: var(--mg-muted); }
.mg-btn-primary { background: var(--mg-primary, #c8102e); color: #fff; }

/* Board */
.mg-board { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; align-items: start; }
.mg-col-h {
  font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 0.68rem;
  letter-spacing: 2px; text-transform: uppercase; color: var(--mg-muted);
  padding: 0 4px 8px;
}
.mg-stack { display: flex; flex-direction: column; gap: 9px; }

.mg-tile {
  text-align: left; width: 100%; cursor: pointer;
  background: var(--mg-panel); border: 1.5px solid var(--mg-border); border-radius: 10px;
  padding: 11px 13px; color: var(--mg-ink); font-family: inherit;
  /* Transitions cover hover (border/transform/bg) AND the post-match fade+collapse
     orchestrated by the .matched class. Keep max-height/padding/margin/opacity in
     here so the matched-then-collapse choreography is purely CSS. */
  transition:
    border-color .12s,
    transform .08s,
    background .12s,
    opacity 1.2s ease-out,
    max-height .55s ease-in-out 1.2s,
    padding .55s ease-in-out 1.2s,
    margin .55s ease-in-out 1.2s,
    border-width .55s ease-in-out 1.2s;
  font-size: 0.9rem; line-height: 1.35;
  max-height: 220px;  /* generous ceiling; collapses to 0 on .matched (sans .show-all) */
  overflow: hidden;
}
.mg-tile:hover:not(.matched) { border-color: var(--mg-border-2); transform: translateY(-1px); }
.mg-term { font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 1.02rem; letter-spacing: 0.4px; }
.mg-term .mg-eqmark {
  font-size: 0.6rem; color: var(--mg-accent, #ffd700); margin-left: 6px;
  vertical-align: middle; letter-spacing: 1px; font-family: 'Barlow Condensed', sans-serif;
}
.mg-eq { font-family: 'Roboto Mono', ui-monospace, monospace; font-size: 0.84rem; color: #cfe3ff; }

/* Selection state — gold pulse ring for strong visibility against the dark
   panel. 3px ring (was 2px) + thicker border for parity with the accent
   chip styling elsewhere in the app. */
.mg-tile.sel {
  border-color: var(--mg-accent, #ffd700);
  background: #20283488;  /* opaque-er so the gold rim reads cleanly */
  box-shadow: 0 0 0 3px rgba(255,215,0,0.45);
}

/* Matched state — slow fade then collapse-and-slide-up of the remaining
   tiles. Two-phase:
     phase 1 (0 → 1.2s): opacity 1 → 0   (slow fade)
     phase 2 (1.2 → 1.75s): max-height/padding/margin → 0 (slide collapse)
   The flex parent (.mg-stack with gap:9px) reflows during phase 2 so the
   remaining tiles glide up to fill the gap. negative margin-bottom eats the
   gap once the tile has fully collapsed. */
.mg-tile.matched {
  border-color: var(--mg-good);
  background: rgba(46,204,113,0.10);
  color: var(--mg-muted);
  cursor: default;
  pointer-events: none;
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: -9px;  /* eats the .mg-stack gap so the column truly closes up */
  border-width: 0;
}
.mg-tile.matched.byhint { border-color: var(--mg-accent, #ffd700); background: rgba(255,215,0,0.10); }

/* End-of-game reveal — engine adds .show-all to ALL matched tiles when the
   board is complete so the player sees the full final board with every
   matched pair visible at ~55% opacity. Transition direction reverses the
   collapse choreography in a single smooth restore. */
.mg-tile.matched.show-all {
  opacity: 0.55;
  max-height: 220px;
  padding-top: 11px;
  padding-bottom: 11px;
  margin-bottom: 0;
  border-width: 1.5px;
}

.mg-tile.wrong { animation: mg-shake .35s; border-color: var(--mg-bad) !important; }
@keyframes mg-shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-5px); }
  40%,80% { transform: translateX(5px); }
}
.mg-check-sm { float: right; font-size: 0.78rem; color: var(--mg-good); }

/* Respect prefers-reduced-motion — replace the slow fade-and-collapse with
   an instant hide. Player still sees matched tiles disappear; the remaining
   tiles still reflow; just no glide. WCAG 2.1 §2.3.3 compliance. */
@media (prefers-reduced-motion: reduce) {
  .mg-tile { transition: border-color .12s, background .12s; }
  .mg-tile.matched { transition: none; }
  .mg-tile.matched.show-all { transition: none; }
}

/* Progress bar */
.mg-prog { height: 6px; background: var(--mg-panel-2); border-radius: 4px; overflow: hidden; margin: 14px 0 4px; }
.mg-prog > i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--mg-primary, #c8102e), var(--mg-accent, #ffd700));
  transition: width .3s;
}

/* Completion modal
   2026-06-17 (Matthew QA): on short vertical viewports the modal exceeded
   the screen height and the Play Hard / Share buttons sat below the fold
   with no way to scroll to them (display:flex + align-items:center clipped
   the bottom). Backdrop now scrolls vertically and the modal aligns to the
   top with viewport padding so the entire card — including the action row
   — is always reachable. .mg-modal also gets a max-height + internal scroll
   as belt-and-suspenders for extremely small landscape screens. */
.mg-modal-bg {
  position: fixed; inset: 0; background: rgba(8,12,18,0.82);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 28px 20px; z-index: 9999;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mg-modal {
  background: var(--mg-panel); border: 1px solid var(--mg-border);
  border-top: 4px solid var(--mg-accent, #ffd700);
  border-radius: 14px; padding: 26px 24px; max-width: 420px; width: 100%; text-align: center;
  margin: auto;  /* still vertically centered when content fits; pushed to top when it doesn't */
  max-height: none;
}
.mg-modal h2 { font-family: 'Barlow Condensed', sans-serif; font-weight: 900; font-size: 1.6rem; }
.mg-modal-total {
  font-family: 'Barlow Condensed', sans-serif; font-weight: 900; font-size: 3rem;
  color: var(--mg-accent, #ffd700); line-height: 1; margin: 6px 0;
}
.mg-modal-label {
  color: var(--mg-muted); font-size: 0.8rem; letter-spacing: 1px; text-transform: uppercase;
  font-family: 'Barlow Condensed', sans-serif; font-weight: 700;
}
.mg-breakdown {
  text-align: left; background: var(--mg-panel-2); border-radius: 10px;
  padding: 12px 14px; margin: 14px 0; font-size: 0.86rem;
}
.mg-breakdown .row { display: flex; justify-content: space-between; padding: 3px 0; color: var(--mg-muted); }
.mg-breakdown .row b { color: var(--mg-ink); }
.mg-breakdown .row.bonus b { color: var(--mg-good); }
.mg-breakdown .row.pen b { color: var(--mg-bad); }
.mg-breakdown .row.total { border-top: 1px solid var(--mg-border); margin-top: 6px; padding-top: 8px; }
.mg-breakdown .row .accent { color: var(--mg-accent, #ffd700); }
.mg-breakdown .row.accent-row { color: var(--mg-accent, #ffd700); }
.mg-modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.mg-modal-actions .mg-btn { flex: 1; }

/* Footnote */
.mg-footnote {
  max-width: 880px; margin: 30px auto 0; padding: 14px 16px;
  background: var(--mg-panel); border: 1px dashed #3a4a5e; border-radius: 10px;
  font-size: 0.76rem; color: var(--mg-muted); line-height: 1.5; text-align: center;
}

/* Mobile (2026-06-17 Matthew QA): keep the 2-column term↔match grid even
   on vertical phones — previously collapsed to a single stack of terms then
   defs, which made the matching mechanic feel like a scrolling list rather
   than a side-by-side game. Tighten gap + tile padding / font on narrow
   widths so two columns still fit cleanly at ~360px. The 1fr collapse only
   kicks in at the smallest landscape-phone widths (<340px) where two
   columns truly can't render. */
@media (max-width: 560px) {
  .mg-title { font-size: 1.4rem; }
  .mg-board { gap: 8px 8px; }
  .mg-stack { gap: 7px; }
  .mg-tile { padding: 9px 10px; font-size: 0.84rem; }
  .mg-term { font-size: 0.92rem; }
  .mg-eq { font-size: 0.76rem; }
  .mg-col-h { font-size: 0.62rem; letter-spacing: 1.5px; padding: 0 2px 6px; }
}
@media (max-width: 339px) {
  .mg-board { grid-template-columns: 1fr; }
  .mg-col-h.right { margin-top: 8px; }
}
