/* ============================================================
   Dark-glass DOM popup layer
   Replaces the Cocos sprite-frame panel visuals entirely.
   Native popup logic / button callbacks keep running underneath.
   ============================================================ */

#mj-glass-popup {
  position: fixed;
  inset: 0;
  z-index: 2147482000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  box-sizing: border-box;
  background: radial-gradient(ellipse at 50% 42%, rgba(4, 22, 15, .52), rgba(2, 10, 7, .84));
  backdrop-filter: blur(7px) saturate(1.15);
  -webkit-backdrop-filter: blur(7px) saturate(1.15);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#mj-glass-popup.open { display: flex; }

.mgp-card {
  position: relative;
  width: min(440px, 100%);
  max-height: 94vh;
  overflow: hidden auto;
  box-sizing: border-box;
  padding: 30px 28px 26px;
  border-radius: 22px;
  border: 1px solid rgba(232, 197, 99, .42);
  background: linear-gradient(158deg, rgba(19, 62, 45, .84), rgba(6, 28, 20, .92));
  backdrop-filter: blur(22px) saturate(1.3);
  -webkit-backdrop-filter: blur(22px) saturate(1.3);
  box-shadow:
    0 26px 74px rgba(0, 0, 0, .58),
    0 0 0 1px rgba(0, 0, 0, .28),
    inset 0 1px 0 rgba(255, 255, 255, .14),
    inset 0 0 44px rgba(232, 197, 99, .05);
  animation: mgp-in .3s cubic-bezier(.2, .85, .3, 1) both;
  scrollbar-width: thin;
  scrollbar-color: rgba(232, 197, 99, .4) transparent;
}

/* gold hairlines top & bottom */
.mgp-card::before,
.mgp-card::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(232, 197, 99, .58), transparent);
}
.mgp-card::before { top: 0; }
.mgp-card::after { bottom: 0; opacity: .5; }

.mgp-x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(232, 197, 99, .3);
  background: rgba(0, 0, 0, .22);
  color: rgba(246, 236, 205, .86);
  font-size: 21px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.mgp-x:hover { background: rgba(232, 197, 99, .16); color: #fff3d0; transform: rotate(90deg); }
/* higher specificity than `.mgp-ico svg` so the close glyph stays small */
.mgp-x.mgp-x .mgp-ico,
.mgp-x svg { width: 15px; height: 15px; }

.mgp-kicker {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: rgba(232, 197, 99, .7);
  text-align: center;
}

.mgp-title {
  margin: 0 0 6px;
  text-align: center;
  font-size: clamp(25px, 6vw, 33px);
  font-weight: 800;
  letter-spacing: .02em;
  line-height: 1.1;
  background: linear-gradient(180deg, #f7e7b4 0%, #e0bd67 55%, #c9a44e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 12px rgba(0, 0, 0, .42));
}

.mgp-body {
  margin: 20px 0 24px;
  text-align: center;
  color: #eaf3ee;
}

.mgp-desc {
  margin: 0 auto 16px;
  max-width: 340px;
  font-size: 14px;
  line-height: 1.6;
  color: rgba(234, 243, 238, .82);
}

/* win screen (level complete — no item rewards) */
.mgp-win .mgp-ico {
  display: inline-block;
  width: 52px;
  height: 52px;
  margin: 2px 0 12px;
  color: #f2d98a;
  filter: drop-shadow(0 3px 10px rgba(232, 197, 99, .35));
}
.mgp-win .mgp-desc { margin-bottom: 8px; font-size: 16px; font-weight: 700; color: #f4ead0; }
.mgp-hint {
  margin: 0 auto;
  max-width: 320px;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(234, 243, 238, .55);
}

.mgp-level {
  display: inline-block;
  margin-top: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(232, 197, 99, .3);
  background: rgba(0, 0, 0, .24);
  font-size: 13px;
  font-weight: 700;
  color: #f0dfae;
}

/* reward / item grid */
.mgp-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.mgp-item {
  min-width: 78px;
  padding: 12px 10px 10px;
  border-radius: 14px;
  border: 1px solid rgba(232, 197, 99, .22);
  background: rgba(255, 255, 255, .05);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
}

.mgp-item .mgp-ico {
  width: 30px;
  height: 30px;
  margin: 0 auto 7px;
  color: #f0d68a;
}

.mgp-item .mgp-num {
  font-size: 13px;
  font-weight: 700;
  color: #f4ead0;
  font-variant-numeric: tabular-nums;
}

/* toggles */
.mgp-toggles {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.mgp-toggle {
  flex: 1 1 0;
  max-width: 160px;
  min-height: 62px;
  padding: 10px 8px;
  border-radius: 14px;
  border: 1px solid rgba(232, 197, 99, .25);
  background: rgba(255, 255, 255, .04);
  color: rgba(234, 243, 238, .72);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .12s ease;
}
.mgp-toggle .mgp-ico { width: 22px; height: 22px; }
.mgp-toggle:hover { border-color: rgba(232, 197, 99, .5); }
.mgp-toggle:active { transform: scale(.97); }
.mgp-toggle.on {
  border-color: rgba(232, 197, 99, .6);
  background: rgba(232, 197, 99, .14);
  color: #f6e6b6;
  box-shadow: inset 0 0 18px rgba(232, 197, 99, .08);
}
.mgp-toggle:not(.on) { opacity: .68; }

/* single stat banner */
.mgp-stat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(232, 197, 99, .22);
  background: rgba(0, 0, 0, .24);
}
.mgp-stat .mgp-ico { width: 34px; height: 34px; color: #f0d68a; }
.mgp-stat-text { text-align: left; }
.mgp-stat-label { font-size: 12px; color: rgba(234, 243, 238, .62); }
.mgp-stat-value { font-size: 19px; font-weight: 800; color: #f4ead0; font-variant-numeric: tabular-nums; }

/* actions */
.mgp-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.mgp-btn {
  flex: 1 1 120px;
  max-width: 210px;
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 13px;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform .14s ease, filter .14s ease, box-shadow .14s ease;
}
.mgp-btn .mgp-ico { width: 18px; height: 18px; }
.mgp-btn:hover { filter: brightness(1.08); }
.mgp-btn:active { transform: translateY(1px) scale(.98); }

.mgp-btn.primary {
  border: 1px solid rgba(255, 242, 198, .55);
  background: linear-gradient(180deg, #f2d98f 0%, #d4ad52 100%);
  color: #10301f;
  box-shadow: 0 8px 20px rgba(212, 173, 82, .28), inset 0 1px 0 rgba(255, 255, 255, .52);
}
.mgp-btn.ghost {
  border: 1px solid rgba(232, 197, 99, .46);
  background: rgba(255, 255, 255, .05);
  color: #f2e6bd;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07);
}
.mgp-btn.ghost:hover { background: rgba(232, 197, 99, .12); }

/* levels grid — all levels in a scrollable square-ish block */
.mgp-levels-scroll {
  width: min(370px, 100%);
  max-height: min(56vh, 372px);
  margin: 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 6px 4px 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(232,197,99,.5) transparent;
}
.mgp-levels-scroll::-webkit-scrollbar { width: 7px; }
.mgp-levels-scroll::-webkit-scrollbar-thumb { background: rgba(232,197,99,.45); border-radius: 4px; }
.mgp-levels-scroll::-webkit-scrollbar-track { background: transparent; }
.mgp-levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 9px;
  width: 100%;
  margin: 0 auto;
}
.mgp-level-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 0;
  border-radius: 13px;
  border: 1px solid rgba(232, 197, 99, .34);
  background: linear-gradient(158deg, rgba(19, 62, 45, .78), rgba(6, 28, 20, .9));
  color: #f4ead0;
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
  transition: transform .14s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease;
}
.mgp-level-cell:hover:not(:disabled) {
  border-color: rgba(232, 197, 99, .72);
  background: rgba(232, 197, 99, .16);
  transform: translateY(-2px);
}
.mgp-level-cell:active:not(:disabled) { transform: translateY(0) scale(.96); }
.mgp-level-cell.current {
  border-color: rgba(255, 242, 198, .85);
  background: linear-gradient(180deg, #f2d98f, #d4ad52);
  color: #10301f;
  box-shadow: 0 6px 18px rgba(212, 173, 82, .32), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.mgp-level-cell.locked {
  cursor: default;
  opacity: .5;
  border-style: dashed;
  border-color: rgba(232, 197, 99, .2);
  background: rgba(0, 0, 0, .24);
}
.mgp-level-cell .mgp-lvl-lock {
  display: inline-flex; width: 22px; height: 22px; color: rgba(232, 197, 99, .75);
}
.mgp-level-cell .mgp-lvl-lock svg { width: 100%; height: 100%; }
.mgp-level-cell .mgp-lvl-star {
  position: absolute; top: 4px; right: 5px; width: 11px; height: 11px; color: #f0d68a;
}
.mgp-level-cell .mgp-lvl-star svg { width: 100%; height: 100%; fill: currentColor; stroke: none; }

/* shared icon stroke */
.mgp-ico {
  display: inline-block;
  flex: 0 0 auto;
}
.mgp-ico svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes mgp-in {
  from { opacity: 0; transform: translateY(14px) scale(.95); }
  to   { opacity: 1; transform: none; }
}

@media (max-width: 480px) {
  #mj-glass-popup { padding: 14px; }
  .mgp-card { padding: 26px 20px 22px; border-radius: 18px; max-height: 92vh; }
  .mgp-title { font-size: 25px; }
  .mgp-actions { flex-direction: column; }
  .mgp-btn { max-width: none; flex: 1 1 auto; }
  .mgp-grid { gap: 8px; }
  .mgp-item { min-width: 66px; padding: 10px 8px 8px; }
  .mgp-toggles { gap: 8px; }
}
