/* ============================================================
   grammar-match.css — Match exercise, designer redesign.

   A self-contained "tap-to-match" card component. Built by the
   modular engine js/grammar/match.js into a #grammar-match-mount
   container. All selectors are scoped under .gm-stage and use a
   gm- prefix so the generic names (.gm-card, .gm-toggle, …) can't
   collide with the rest of the site. Colour tokens live on
   .gm-stage; the frame keeps its own warm palette regardless of
   the site light/dark theme (dark-mode adaptation is a follow-up).
   ============================================================ */

.gm-stage {
  --gm-acc: #20507e;
  --gm-accbg: rgba(32, 80, 126, 0.08);
  --gm-ink: #232026;
  --gm-muted: #5d5852;
  --gm-faint: #938b80;
  --gm-line: #e3dac8;
  --gm-line2: #d7cdb6;
  --gm-card: #faf6ee;
  --gm-inset: #fcfaf5;
  --gm-green: #2f8f5b;
  --gm-red: #b1322a;

  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(8px, 2vw, 22px) 0;
  font-family: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* The engine builds its frame inside this mount div; make the mount fill
   the stage and centre the frame, so every exercise reaches the same
   max-width instead of shrinking to its content. */
.gm-stage > div {
  width: 100%;
  display: flex;
  justify-content: center;
}

.gm-frame {
  width: 100%;
  /* Fill the site's content column so every exercise matches the width of
     the other content pages (.wrap caps at 1180px − 2×28px = 1124px). All
     exercises share this so widths are consistent; on phones the frame just
     shrinks to fit. The match family then splits each side into two columns
     on wide screens so the cards don't stack into a long scroll. */
  max-width: 1124px;
  background: var(--gm-card);
  border: 1px solid var(--gm-line);
  border-radius: 22px;
  box-shadow: 0 10px 40px rgba(40, 50, 70, 0.07);
  padding: clamp(16px, 4vw, 26px);
  color: var(--gm-ink);
}

/* ── Top bar ─────────────────────────────────────────── */
.gm-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.gm-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.gm-setlabel {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gm-faint);
  white-space: nowrap;
}
.gm-toggles {
  display: flex;
  align-items: center;
  gap: 7px;
}
.gm-ghostbtn {
  background: transparent;
  border: 1px solid var(--gm-line2);
  color: var(--gm-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}
.gm-toggle {
  border: 1px solid var(--gm-line2);
  background: var(--gm-inset);
  color: var(--gm-muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.gm-toggle.is-on {
  background: var(--gm-acc) !important;
  color: #fff !important;
  border-color: var(--gm-acc) !important;
}
@media (hover: hover) {
  .gm-ghostbtn:hover,
  .gm-toggle:not(.is-on):hover { border-color: var(--gm-acc); }
}

/* ── Title row + counter ─────────────────────────────── */
.gm-titlerow {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  margin-top: 16px;
}
.gm-titlewrap { min-width: 0; }
.gm-title {
  margin: 0;
  font-weight: 800;
  font-size: clamp(18px, 4.4vw, 23px);
  letter-spacing: -0.02em;
  color: var(--gm-ink);
  line-height: 1.1;
}
.gm-instruction {
  font-size: 13px;
  color: var(--gm-muted);
  margin-top: 5px;
  line-height: 1.4;
}
.gm-counter {
  text-align: right;
  flex: none;
}
.gm-counter-top {
  font-weight: 800;
  font-size: 17px;
  color: var(--gm-acc);
  line-height: 1;
}
.gm-counter-den { color: var(--gm-faint); font-weight: 600; }
.gm-counter-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gm-faint);
  margin-top: 3px;
}

/* ── Progress bar ────────────────────────────────────── */
.gm-progress {
  height: 5px;
  background: var(--gm-line);
  border-radius: 999px;
  margin-top: 13px;
  overflow: hidden;
}
.gm-progress-fill {
  height: 100%;
  width: 0;
  background: var(--gm-acc);
  border-radius: 999px;
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.3, 1);
}

/* ── Columns + cards ─────────────────────────────────── */
.gm-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(9px, 2.4vw, 18px);
  margin-top: 20px;
  align-items: start;
}
.gm-col { min-width: 0; }

/* On wider screens, split each side into two card columns so a set of 8
   becomes ~4 rows instead of a long vertical scroll. CSS multi-column keeps
   the cards in normal block flow, so the collapse-on-match + distractor
   refill still behave exactly as in the single-column phone layout. */
.gm-card { break-inside: avoid; }
@media (min-width: 700px) {
  .gm-grid [data-gm="left"],
  .gm-grid [data-gm="right"] {
    column-count: 2;
    column-gap: clamp(8px, 1.6vw, 14px);
  }
}

.gm-collabel {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gm-faint);
  margin-bottom: 9px;
  padding-left: 2px;
}

.gm-card {
  position: relative;
  display: flex;
  text-align: left;
  width: 100%;
  margin-bottom: clamp(8px, 2vw, 11px);
  background: var(--gm-inset);
  border: 1.5px solid var(--gm-line2);
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
  color: var(--gm-ink);
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s, transform 0.12s,
    box-shadow 0.15s, max-height 0.35s ease, opacity 0.3s, padding 0.35s,
    margin 0.35s;
}
.gm-jpcard {
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
  padding: clamp(10px, 2.6vw, 15px) clamp(11px, 2.8vw, 17px);
  max-height: 280px;
}
.gm-encard {
  align-items: center;
  min-height: 48px;
  padding: clamp(10px, 2.6vw, 14px) clamp(12px, 3vw, 18px);
  max-height: 200px;
}
.gm-jptext {
  font-family: 'Noto Sans JP', sans-serif;
  font-weight: 500;
  font-size: clamp(18px, 4.7vw, 26px);
  line-height: 1.65;
  color: var(--gm-ink);
}
.gm-romaji {
  font-size: clamp(11px, 2.7vw, 13px);
  color: var(--gm-faint);
  letter-spacing: 0.02em;
}
.gm-entext {
  font-size: clamp(14px, 3.5vw, 17px);
  font-weight: 500;
  color: var(--gm-ink);
  line-height: 1.4;
}
.gm-checkbadge {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gm-green);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
}

/* Romaji visibility is driven by a frame-level class so toggling it
   never rebuilds the cards (which would kill the collapse animation). */
.gm-frame:not(.gm-show-romaji) .gm-romaji { display: none; }

/* Kanji mode (kanji_match): the left card is a single large glyph,
   centred; the right card is its reading. */
.gm-mode-kanji .gm-jpcard {
  align-items: center;
  justify-content: center;
}
.gm-mode-kanji .gm-jptext {
  font-size: clamp(34px, 9vw, 54px);
  line-height: 1.15;
}

.gm-card:focus-visible {
  outline: 2px solid var(--gm-acc);
  outline-offset: 2px;
}
@media (hover: hover) {
  .gm-card:not(.is-matched):not(.is-correct):not(.is-wrong):hover {
    border-color: var(--gm-acc);
  }
}
.gm-card.is-selected {
  border-color: var(--gm-acc) !important;
  background: var(--gm-accbg) !important;
  box-shadow: 0 0 0 1.5px var(--gm-acc) inset;
  transform: translateY(-1px);
}
.gm-card.is-correct {
  border-color: var(--gm-green) !important;
  background: rgba(47, 143, 91, 0.1) !important;
}
.gm-card.is-correct .gm-checkbadge { animation: gmPop 0.3s ease forwards; }
.gm-card.is-wrong {
  border-color: var(--gm-red) !important;
  background: rgba(177, 50, 42, 0.07) !important;
  animation: gmShake 0.42s ease;
}
.gm-card.is-matched {
  max-height: 0 !important;
  /* min-height must also be cleared — .gm-encard sets min-height:48px,
     which otherwise wins over max-height:0 and leaves a collapsed-but-
     still-48px-tall gap where the matched answer was. */
  min-height: 0 !important;
  opacity: 0;
  margin: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-width: 0 !important;
  pointer-events: none;
}

/* Incoming distractor cards fade in. A keyframe (not an rAF opacity
   toggle) so it can't get stuck partway. */
.gm-card.gm-enter { animation: gmFadeIn 0.3s ease; }

/* ── Furigana ruby ───────────────────────────────────── */
.gm-jptext ruby { ruby-position: over; }
.gm-jptext ruby rt {
  font-size: 0.42em;
  color: var(--gm-faint);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.02em;
  margin-bottom: 1px;
}

/* ── Footer feedback row ─────────────────────────────── */
.gm-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  min-height: 34px;
}
.gm-feedback {
  font-size: 13px;
  font-weight: 600;
  color: var(--gm-muted);
}
.gm-feedback.fb-good { color: var(--gm-green) !important; }
.gm-feedback.fb-bad { color: var(--gm-red) !important; }

/* ── Completion ──────────────────────────────────────── */
.gm-complete {
  text-align: center;
  padding: clamp(28px, 7vw, 46px) 16px clamp(20px, 5vw, 32px);
}
.gm-complete-check {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--gm-acc);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin: 0 auto 16px;
  box-shadow: 0 8px 22px rgba(32, 80, 126, 0.28);
}
.gm-complete-title {
  font-weight: 800;
  font-size: clamp(20px, 5vw, 25px);
  color: var(--gm-ink);
  letter-spacing: -0.02em;
}
.gm-complete-stats {
  color: var(--gm-muted);
  margin-top: 7px;
  font-size: 15px;
}
.gm-complete-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 24px;
  flex-wrap: wrap;
}
.gm-btn-secondary {
  background: transparent;
  border: 1.5px solid var(--gm-line2);
  color: var(--gm-acc);
  font-family: inherit;
  font-weight: 600;
  font-size: 14.5px;
  padding: 11px 22px;
  border-radius: 10px;
  cursor: pointer;
}
.gm-btn-primary {
  background: var(--gm-acc);
  border: 1.5px solid var(--gm-acc);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 14.5px;
  padding: 11px 24px;
  border-radius: 10px;
  cursor: pointer;
}

.gm-hidden { display: none !important; }

@keyframes gmShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
@keyframes gmPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes gmFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
