:root{
  --mg-good-bg: rgba(0, 255, 140, .14);
  --mg-good-br: rgba(0, 255, 140, .45);

  --mg-warn-bg: rgba(255, 200, 0, .14);
  --mg-warn-br: rgba(255, 200, 0, .45);

  --mg-tile-bg: rgba(255,255,255,.03);
  --mg-tile-br: rgba(255,255,255,.16);
  --mg-tile-hover: rgba(255,255,255,.06);

  --mg-ring: rgba(120,160,255,.55);

  --mgHelpBorder: rgba(255,255,255,.07);
  --mgHelpBg: rgba(255,255,255,.02);
}

:root[data-theme="light"]{
  --mg-good-bg: rgba(0, 160, 90, .22);
  --mg-good-br: rgba(0, 160, 90, .46);

  --mg-warn-bg: rgba(200, 150, 0, .16);
  --mg-warn-br: rgba(200, 150, 0, .40);

  --mg-tile-bg: rgba(11,15,20,.03);
  --mg-tile-br: rgba(11,15,20,.16);
  --mg-tile-hover: rgba(11,15,20,.06);

  --mg-ring: rgba(60,120,255,.45);

  --mgHelpBorder: rgba(11,15,20,.12);
  --mgHelpBg: rgba(11,15,20,.02);
}

/* tighter wrapping like OpGlyph */
header.wrap { padding-bottom: 6px; }
main.wrap { padding-top: 6px; }

.card.mgCard { padding: 10px 10px 12px; }
@media (max-width:520px){
  .wrap { padding-left: 10px; padding-right: 10px; }
  .card.mgCard { padding: 8px 8px 10px; }
}

.mgTopRow{
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  gap:10px;
  margin-bottom: 8px;
}

.mgMeta{ display:flex; flex-direction:column; gap:8px; }

.mgKicker{
  font-size: 12px;
  opacity:.8;
  letter-spacing:.08em;
  text-transform:uppercase;
}
.mgSubMeta{ font-size: 13px; opacity:.92; }

/* ✅ Mode + Cap rows */
.mgRow{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:nowrap;
}
.mgRow .mgKicker,
.mgRow .mgSubMeta{
  white-space:nowrap;
  margin:0;
}
/* buttons can wrap within the group if needed (prevents horizontal scroll) */
.mgRow .modeSeg{
  margin:0;
  flex-wrap:wrap;
}

/* Right panel */
.mgRight{
  text-align:right;
  display:flex;
  flex-direction:column;
  gap:6px;
  align-items:flex-end;
  min-width: 0; /* ✅ no forced overflow */
}
.mgTimer{
  font-size: 28px;
  line-height: 1;
  letter-spacing: .02em;
}
.mgS{ font-size: 14px; opacity:.7; margin-left: 2px; }
.mgMiniMeta{
  display:flex;
  gap:10px;
  font-size: 12px;
  opacity:.9;
  flex-wrap:wrap;
  justify-content:flex-end;
}

/* ✅ Mobile: stack header meta + timer to avoid right-shift */
@media (max-width:520px){
  .mgTopRow{
    flex-direction:column;
    align-items:stretch;
  }
  .mgRight{
    align-items:flex-start;
    text-align:left;
  }
  .mgMiniMeta{
    justify-content:flex-start;
  }
  .mgTimer{
    font-size: 24px;
  }
}

/* HUD pills */
.mgHUD{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin-top: 2px;
}
.mgHudPill{
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.02);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
}
:root[data-theme="light"] .mgHudPill{
  border: 1px solid rgba(11,15,20,.12);
  background: rgba(11,15,20,.02);
}

/* Body */
.mgBody{
  margin-top: 10px;
  display:flex;
  flex-direction:column;
  gap:10px;
  align-items:center;
}

.mgQ{
  font-weight: 950;
  letter-spacing: .01em;
  font-size: clamp(34px, 6.2vw, 46px);
  line-height: 1.05;
  text-align:center;
  margin-top: 2px;
}

.mgMsg{
  min-height: 18px;
  font-size: 13px;
  opacity:.9;
  text-align:center;
}

.mgAnsGrid{
  width: min(620px, 100%);
  display:grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(8px, 2vw, 12px);
  margin-top: 2px;
  user-select:none;
  -webkit-user-select:none;
  touch-action: manipulation;
}

.mgAns{
  border-radius: 18px;
  border: 1px solid var(--mg-tile-br);
  background: var(--mg-tile-bg);
  padding: 14px 12px;
  min-height: 76px;

  display:flex;
  align-items:center;
  justify-content:center;

  font-size: clamp(24px, 5vw, 34px);
  font-weight: 950;
  letter-spacing:.01em;
  cursor:pointer;

  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, filter 120ms ease;
}
.mgAns:hover{ background: var(--mg-tile-hover); transform: translateY(-1px); }
.mgAns:active{ transform: translateY(0px) scale(.99); }
.mgAns[disabled]{ cursor: default; opacity:.78; transform:none; }

.mgAns.correct{
  background: var(--mg-good-bg);
  border-color: var(--mg-good-br);
  filter: saturate(1.05);
}
.mgAns.wrong{
  background: var(--mg-warn-bg);
  border-color: var(--mg-warn-br);
}
.mgAns.reveal{
  outline: 3px solid var(--mg-ring);
  outline-offset: 2px;
}

.mgActions{
  display:flex;
  justify-content:center;
  gap:10px;
  flex-wrap:wrap;
  margin-top: 10px;
}

/* Shake */
@keyframes mgShake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}
.mgAnsGrid.shake{
  animation: mgShake 240ms ease;
}

/* dialogs */
.mgHelpDlg, .mgStatsDlg, .mgEndDlg{
  padding: 0;
  border: 0;
  background: transparent;

  width: fit-content;
  max-width: calc(100vw - 24px);
  margin: auto;
}
.mgHelpDlg::backdrop,
.mgStatsDlg::backdrop,
.mgEndDlg::backdrop{ background: rgba(0,0,0,.55); }
:root[data-theme="light"] .mgHelpDlg::backdrop,
:root[data-theme="light"] .mgStatsDlg::backdrop,
:root[data-theme="light"] .mgEndDlg::backdrop{ background: rgba(0,0,0,.35); }

.mgHelp, .mgStats, .mgEnd{
  padding: 10px 10px 12px;
  max-width: 560px;
}
.mgHelpScroll{ max-height: 70vh; overflow:auto; padding-right:2px; }

.mgHelpBox{
  border: 1px solid var(--mgHelpBorder);
  background: var(--mgHelpBg);
  border-radius: 12px;
  padding: 9px 10px;
  margin: 8px 0;
}
.mgHelpKicker{
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .78;
  margin-bottom: 6px;
}
.mgHelpList{ margin:0; padding-left:18px; }
.mgHelpList li{ margin: 5px 0; }

.mgHelpActions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  flex-wrap:wrap;
  margin-top:8px;
}

#helpX, #statsX, #endX{ color:#ff4d4d; }
#helpX:hover, #statsX:hover, #endX:hover{ color:#ff6b6b; }

.mgStatsGrid, .mgEndGrid{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}
@media (max-width:520px){
  .mgStatsGrid, .mgEndGrid{ grid-template-columns: 1fr; }
}

.mgStatBox{
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.02);
  border-radius: 14px;
  padding: 10px 12px;
}
:root[data-theme="light"] .mgStatBox{
  border: 1px solid rgba(11,15,20,.12);
  background: rgba(11,15,20,.02);
}

.mgStatVal{
  font-size: 18px;
  font-weight: 900;
  margin-top: 2px;
}

.mgLast10List{
  display:flex;
  flex-direction:column;
  gap:6px;
}
.mgLast10Row{
  display:flex;
  justify-content:space-between;
  gap:10px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
}
:root[data-theme="light"] .mgLast10Row{
  border: 1px solid rgba(11,15,20,.10);
  background: rgba(11,15,20,.02);
}
.mgLast10Row .muted{ opacity:.75; }

/* ✅ Support button smaller on narrow screens (prevents wrapping) */
@media (max-width:420px){
  header .pillbtn{
    font-size: 12px;
    padding: 8px 10px;
  }
}
