/* Quần Đảo Rồng — Sân chơi nhỏ: Đồng bộ phong cách Cuộn Giấy Da (ui.css) */
.mg-overlay {
  --mg-border: var(--ui-scroll-border, #7d4016);
  --mg-ink: var(--ui-ink, #4c240d);
  --mg-ink-soft: var(--ui-ink-soft, #703914);
  --mg-cream: var(--ui-card-top, #fffbe0);
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  box-sizing: border-box;
  overflow: auto;
  overscroll-behavior: contain;
  padding: max(18px, env(safe-area-inset-top, 0px))
           max(14px, env(safe-area-inset-right, 0px))
           max(14px, env(safe-area-inset-bottom, 0px))
           max(14px, env(safe-area-inset-left, 0px));
  background: radial-gradient(ellipse at 50% 24%, rgba(56, 30, 12, 0.56), rgba(24, 12, 5, 0.78) 76%);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  color: var(--mg-ink);
  font: 700 var(--ui-fs-base, clamp(13px, calc(1.45vw / var(--ui-zoom, 1)), 15px))/1.35 var(--ui-font, "Quicksand", ui-rounded, system-ui, sans-serif);
  text-shadow: var(--ui-text-shadow, 0 1px 0 rgba(255, 248, 212, 0.55));
  color-scheme: light;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.mg-overlay[open] {
  display: flex;
  animation: mg-backdrop-in 0.2s ease-out;
}

.mg-overlay::backdrop {
  background: rgba(24, 12, 5, 0.6);
}

.mg-overlay *,
.mg-overlay *::before,
.mg-overlay *::after {
  box-sizing: border-box;
}

.mg-overlay [hidden] {
  display: none !important;
}

/* Cuộn giấy da đồng bộ .pr-modal-sheet trong ui.css */
.mg-sheet {
  position: relative;
  width: min(100%, 840px);
  min-width: 0;
  max-height: calc(calc(100dvh / var(--ui-zoom, 1)) - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  margin: auto;
  padding: clamp(6px, calc(1.4vw / var(--ui-zoom, 1)), 14px) clamp(6px, calc(1.4vw / var(--ui-zoom, 1)), 14px) clamp(8px, calc(1.6vw / var(--ui-zoom, 1)), 16px);
  background-color: var(--ui-scroll-mid, #f6d977);
  background-clip: padding-box;
  border-style: solid;
  border-color: transparent;
  border-width: 28px 18px;
  border-image: url('../assets/ui/panel-scroll.png') 98 62 98 62 fill / 28px 18px / 0 stretch;
  filter: drop-shadow(0 18px 34px rgba(34, 14, 4, 0.58));
  display: flex;
  flex-direction: column;
  gap: clamp(8px, calc(1.4vw / var(--ui-zoom, 1)), 14px);
  overflow: visible;
  animation: mg-sheet-in 0.26s cubic-bezier(0.22, 1.25, 0.36, 1);
}

.mg-sheet::before {
  content: "";
  position: absolute;
  inset: -6px 0;
  border-radius: 14px;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255, 252, 224, 0.45), transparent 54%),
    radial-gradient(ellipse at 86% 88%, rgba(164, 92, 24, 0.16), transparent 55%),
    repeating-linear-gradient(12deg, rgba(140, 76, 27, 0.03) 0 2px, transparent 2px 8px);
  pointer-events: none;
  z-index: 0;
}

.mg-sheet > * {
  position: relative;
  z-index: 1;
}

/* Tiêu đề ruy băng hồng & thanh điều khiển luôn thấy */
.mg-head {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.mg-menu .mg-head,
.mg-result .mg-head {
  margin-top: -40px;
  padding-inline: 2px;
}

.mg-heading {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.mg-menu .mg-heading,
.mg-result .mg-heading {
  align-items: center;
}

.mg-head h2 {
  margin: 0;
  font-size: var(--ui-fs-title, clamp(15px, calc(2vw / var(--ui-zoom, 1)), 19px));
  font-weight: 900;
  line-height: 1.18;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.mg-menu .mg-head h2,
.mg-result .mg-head h2 {
  padding: 2px 14px 4px;
  min-height: 40px;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background-color: var(--ui-ribbon-mid, #e8607c);
  background-clip: padding-box;
  border-style: solid;
  border-color: transparent;
  border-width: 7px 34px 10px 34px;
  border-image: url('../assets/ui/ribbon.png') 16 68 24 68 fill / 10px 36px 12px 36px / 0 stretch;
  filter: drop-shadow(0 4px 6px rgba(68, 18, 28, 0.36));
  color: #fffaf0;
  text-shadow: var(--ui-outline-brown, -1.2px -1.2px 0 #6b2514, 1.2px -1.2px 0 #6b2514, -1.2px 1.2px 0 #6b2514, 1.2px 1.2px 0 #6b2514, 0 2px 0 #4d170b);
  text-transform: uppercase;
  text-wrap: balance;
}

.mg-game .mg-head h2 {
  color: var(--mg-ink);
  font-size: clamp(16px, calc(2.2vw / var(--ui-zoom, 1)), 22px);
  text-shadow: 0 1px 0 rgba(255, 252, 224, 0.8);
}

/* Nút bấm đồng bộ .pr-btn (btn-blue / btn-orange / btn-grey) */
.mg-overlay button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.mg-overlay :focus-visible {
  outline: 3px solid #ffe66d;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(76, 36, 13, 0.55);
}

.mg-btn {
  position: relative;
  min-width: 44px;
  min-height: 44px;
  padding: 7px clamp(12px, calc(1.8vw / var(--ui-zoom, 1)), 18px);
  border-radius: 999px;
  border: 2px solid transparent;
  background-color: #2e98eb;
  border-image: url('../assets/ui/btn-blue.png') 20 44 24 44 fill / 12px 22px / 0 stretch;
  color: var(--ui-ink-white, #fffdf5);
  text-shadow: var(--ui-outline-blue, -1px -1px 0 #104178, 1px -1px 0 #104178, -1px 1px 0 #104178, 1px 1px 0 #104178, 0 2px 0 #0c305a);
  font: 800 var(--ui-fs-sm, clamp(12px, calc(1.25vw / var(--ui-zoom, 1)), 14px))/1.18 var(--ui-font, "Quicksand", ui-rounded, system-ui, sans-serif);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  filter: drop-shadow(0 3px 4px rgba(16, 44, 78, 0.34));
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.14s ease;
}

.mg-btn:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.02);
  filter: drop-shadow(0 4px 7px rgba(16, 44, 78, 0.42)) brightness(1.07);
}

.mg-btn:active:not(:disabled) {
  transform: translateY(2px) scale(0.96);
  filter: drop-shadow(0 1px 2px rgba(16, 44, 78, 0.32)) brightness(0.96);
}

.mg-btn:disabled {
  background-color: #867565;
  border-image: url('../assets/ui/btn-grey.png') 20 44 24 44 fill / 12px 22px / 0 stretch;
  color: #f3ece3;
  text-shadow: 0 1px 1px #3b2f25;
  opacity: 0.9;
  cursor: not-allowed;
  transform: none;
}

.mg-btn.mg-primary {
  background-color: var(--ui-primary, #ff942e);
  border-image: url('../assets/ui/btn-orange.png') 20 44 24 44 fill / 12px 22px / 0 stretch;
  color: var(--ui-primary-ink, #ffffff);
  text-shadow: var(--ui-outline-orange, -1px -1px 0 #7a2c06, 1px -1px 0 #7a2c06, -1px 1px 0 #7a2c06, 1px 1px 0 #7a2c06, 0 2px 0 #591e03);
  filter: drop-shadow(0 3px 6px rgba(118, 46, 8, 0.4));
  overflow: hidden;
  isolation: isolate;
}

.mg-btn.mg-primary::before {
  content: "";
  position: absolute;
  inset: -4px auto -4px -55%;
  width: 44%;
  background: linear-gradient(108deg, transparent 15%, rgba(255, 255, 255, 0.52) 50%, transparent 85%);
  transform: skewX(-20deg);
  pointer-events: none;
  animation: mg-sheen 3.4s ease-in-out infinite;
}

.mg-btn.mg-primary:hover:not(:disabled) {
  filter: drop-shadow(0 5px 9px rgba(168, 72, 10, 0.48)) brightness(1.08);
}

.mg-btn.mg-small {
  padding: 5px 13px;
  border-image-width: 10px 18px;
  font-size: var(--ui-fs-xs, clamp(11px, calc(1.15vw / var(--ui-zoom, 1)), 13px));
}

.mg-menu .mg-head [data-action="exit"],
.mg-result .mg-head [data-action="exit"] {
  flex-shrink: 0;
}

/* Màn chọn trò chơi: khay gỗ ruột cam nâu + 3 thẻ bưu thiếp giấy da */
.mg-note {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background-color: #fff3c4;
  border: 2px solid transparent;
  border-image: url('../assets/ui/flat/card.png') 30 30 30 30 fill / 12px / 0 stretch;
  color: var(--mg-ink-soft);
  font-weight: 800;
  text-align: center;
}

.mg-choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(8px, calc(1.4vw / var(--ui-zoom, 1)), 13px);
  padding: clamp(8px, calc(1.4vw / var(--ui-zoom, 1)), 12px);
  border-radius: 16px;
  background-color: #d99a4e;
  border: 2px solid transparent;
  border-image: url('../assets/ui/flat/panel-inner.png') 36 36 36 36 fill / 16px / 0 stretch;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #e69d35 rgba(76, 36, 13, 0.28);
  min-height: 0;
}

.mg-overlay .mg-choice {
  min-width: 0;
  min-height: 44px;
  display: grid;
  grid-template-rows: auto 1fr;
  text-align: left;
  padding: 7px;
  border-radius: 15px;
  background-color: #fff3c4;
  border: 2px solid transparent;
  border-image: url('../assets/ui/flat/card.png') 30 30 30 30 fill / 14px / 0 stretch;
  filter: drop-shadow(0 4px 6px rgba(76, 36, 13, 0.28));
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.14s ease;
}

.mg-overlay .mg-choice:hover {
  transform: translateY(-2px) scale(1.015);
  background-color: #fffbe0;
  border-image: url('../assets/ui/flat/slot-selected.png') 32 32 32 32 fill / 14px / 0 stretch;
  filter: drop-shadow(0 6px 12px rgba(34, 138, 224, 0.4));
}

.mg-overlay .mg-choice:active {
  transform: translateY(2px) scale(0.97);
}

.mg-postcard {
  display: block;
  width: 100%;
  aspect-ratio: 1.65;
  height: auto;
  min-width: 0;
  border-radius: 9px;
  border: 2px solid var(--ui-card-border, #8c4c1b);
  box-shadow: inset 0 1px 4px rgba(34, 14, 4, 0.35);
}

.mg-choice-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 9px 6px 4px;
}

.mg-choice-copy strong {
  font-size: clamp(16px, calc(2vw / var(--ui-zoom, 1)), 20px);
  font-weight: 900;
  line-height: 1.18;
  color: var(--mg-ink);
}

.mg-choice-copy > span {
  font-size: var(--ui-fs-sm, clamp(12px, calc(1.25vw / var(--ui-zoom, 1)), 14px));
  font-weight: 700;
  color: var(--mg-ink-soft);
}

.mg-choice-copy small {
  margin-top: auto;
  padding: 2px 9px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffdf73, #f0a828);
  border: 1.5px solid #8c4c1b;
  color: var(--mg-ink);
  font-size: 11.5px;
  font-weight: 800;
}

/* Sân chơi trực tiếp: thanh điểm/thời gian chip xanh, khung sân viền gỗ */
.mg-game {
  height: min(670px, calc(calc(100dvh / var(--ui-zoom, 1)) - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(6px, calc(1.2vw / var(--ui-zoom, 1)), 11px);
}

.mg-game .mg-head {
  padding: 5px 8px;
  border-radius: 15px;
  background-color: #d99a4e;
  border: 2px solid transparent;
  border-image: url('../assets/ui/flat/panel-inner.png') 36 36 36 36 fill / 12px / 0 stretch;
}

.mg-game .mg-head h2 {
  color: #fffaf0;
  text-shadow: var(--ui-outline-brown, -1.2px -1.2px 0 #6b2514, 1.2px -1.2px 0 #6b2514, -1.2px 1.2px 0 #6b2514, 1.2px 1.2px 0 #6b2514, 0 2px 0 #4d170b);
  font-size: clamp(15px, calc(2vw / var(--ui-zoom, 1)), 20px);
}

.mg-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.mg-stats span {
  display: inline-flex;
  align-items: center;
  padding: 2px 11px;
  border-radius: 999px;
  background-color: #1c65b8;
  border: 1.5px solid transparent;
  border-image: url('../assets/ui/flat/chip.png') 20 44 24 44 fill / 8px 14px / 0 stretch;
  color: var(--ui-ink-white, #fffdf5);
  text-shadow: var(--ui-outline-blue, -1px -1px 0 #104178, 1px -1px 0 #104178, -1px 1px 0 #104178, 1px 1px 0 #104178, 0 2px 0 #0c305a);
  font-size: var(--ui-fs-sm, clamp(12px, calc(1.25vw / var(--ui-zoom, 1)), 14px));
  font-weight: 800;
}

.mg-arena {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
  border: 3px solid var(--mg-border);
  border-radius: 15px;
  background: radial-gradient(ellipse at 50% 26%, #39656a, #1d3942 82%);
  box-shadow: inset 0 0 0 2px rgba(255, 248, 200, 0.3), 0 4px 12px rgba(42, 18, 5, 0.36);
}

.mg-field {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.mg-field:focus-visible {
  outline-offset: -4px;
  outline-color: #ffe66d;
}

.mg-rule {
  margin: 0;
  padding: 5px 12px;
  border-radius: 12px;
  background-color: #fff3c4;
  border: 2px solid transparent;
  border-image: url('../assets/ui/flat/card.png') 30 30 30 30 fill / 10px / 0 stretch;
  text-align: center;
  color: var(--mg-ink);
  font-size: var(--ui-fs-xs, clamp(11.5px, calc(1.35vw / var(--ui-zoom, 1)), 13.5px));
  font-weight: 800;
}

/* Màn che đếm ngược & tạm dừng */
.mg-veil {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  /* Cột co theo khung, không nở theo chữ: trên Safari thẻ dài từng đẩy cột rộng hơn sân chơi và bị lệch sang phải. */
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 12px;
  background: rgba(24, 14, 7, 0.56);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.mg-prompt {
  width: auto;
  min-width: 0;
  max-width: min(100%, 380px);
  overflow-wrap: anywhere;
  padding: clamp(14px, calc(3vw / var(--ui-zoom, 1)), 24px) clamp(16px, calc(3.6vw / var(--ui-zoom, 1)), 28px);
  text-align: center;
  border-radius: 18px;
  background-color: #fffbe0;
  border: 2px solid transparent;
  border-image: url('../assets/ui/flat/card.png') 30 30 30 30 fill / 14px / 0 stretch;
  filter: drop-shadow(0 10px 22px rgba(20, 9, 3, 0.52));
  animation: mg-pop-in 0.24s cubic-bezier(0.22, 1.32, 0.36, 1);
}

.mg-prompt-title {
  display: block;
  font-size: clamp(28px, calc(5vw / var(--ui-zoom, 1)), 48px);
  font-weight: 900;
  line-height: 1.08;
  color: var(--ui-primary, #ff942e);
  text-shadow: var(--ui-outline-brown, -1.2px -1.2px 0 #6b2514, 1.2px -1.2px 0 #6b2514, -1.2px 1.2px 0 #6b2514, 1.2px 1.2px 0 #6b2514, 0 2px 0 #4d170b);
}

.mg-prompt p {
  margin: 7px 0 0;
  font-weight: 800;
  color: var(--mg-ink-soft);
}

.mg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.mg-prompt .mg-actions {
  justify-content: center;
}

/* Trò chơi Lật thẻ rồng */
.mg-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(5px, calc(1.2vmin / var(--ui-zoom, 1)), 11px);
  width: 100%;
  max-width: 700px;
  height: 100%;
  margin: auto;
  padding: clamp(7px, calc(1.8vmin / var(--ui-zoom, 1)), 15px);
}

.mg-overlay .mg-tile {
  position: relative;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2.5px solid #e6bd75;
  border-radius: 12px;
  color: #ffe28c;
  background: #224d69;
  box-shadow: 0 3px 0 #122c42, 0 5px 10px rgba(10, 22, 34, 0.36);
  user-select: none;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.14s ease, border-color 0.2s ease;
}

.mg-overlay .mg-tile:not([aria-disabled]):hover {
  transform: translateY(-2px) scale(1.02);
  border-color: #ffe66d;
  filter: brightness(1.08);
}

.mg-overlay .mg-tile:not([aria-disabled]):active {
  transform: translateY(1px) scale(0.96);
}

.mg-back,
.mg-face {
  position: absolute;
  inset: 3px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: opacity 0.22s ease, transform 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mg-back {
  border: 1.5px solid #e6c684;
  font: normal clamp(24px, calc(6.4vmin / var(--ui-zoom, 1)), 46px)/1 Georgia, serif;
  background:
    repeating-linear-gradient(45deg, transparent 0 8px, rgba(255, 232, 163, 0.08) 8px 9px),
    repeating-linear-gradient(-45deg, transparent 0 8px, rgba(255, 232, 163, 0.08) 8px 9px),
    radial-gradient(circle at 50% 35%, #37799e, #1d425c 85%);
}

.mg-back::before {
  content: "";
  position: absolute;
  width: 0.94em;
  height: 0.94em;
  border: 1.5px solid rgba(255, 224, 140, 0.72);
  transform: rotate(45deg);
}

.mg-face {
  opacity: 0;
  transform: scale(0.86);
  background: linear-gradient(180deg, #fffbe0 0%, #f5de92 100%);
  border: 1.5px solid #c98c3a;
  color: var(--mg-ink);
}

.mg-up .mg-face,
.mg-paired .mg-face {
  opacity: 1;
  transform: scale(1);
}

.mg-up .mg-back,
.mg-paired .mg-back {
  visibility: hidden;
}

.mg-portrait {
  position: absolute;
  top: 0;
  width: 100%;
  height: calc(100% - 19px);
}

.mg-card-name {
  position: absolute;
  bottom: 2px;
  font-size: clamp(10px, calc(1.65vmin / var(--ui-zoom, 1)), 13.5px);
  font-weight: 800;
  line-height: 1.15;
}

.mg-seal {
  position: absolute;
  top: 2px;
  left: 5px;
  font: 800 clamp(12px, calc(2.4vmin / var(--ui-zoom, 1)), 19px)/1 Georgia, serif;
  color: #8c4c1b;
}

.mg-overlay .mg-paired {
  border-color: #6ce06b;
  box-shadow: 0 2px 0 #166120, 0 0 12px rgba(66, 201, 71, 0.55);
}

.mg-paired::after {
  content: "";
  position: absolute;
  right: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: url('../assets/ui/ico-check.png') center / contain no-repeat;
  filter: drop-shadow(0 1px 2px rgba(18, 86, 26, 0.45));
}

.mg-plus {
  position: absolute;
  top: 32%;
  left: 50%;
  transform: translateX(-50%);
  color: #ffe866;
  text-shadow: var(--ui-outline-green, -1px -1px 0 #14571c, 1px -1px 0 #14571c, -1px 1px 0 #14571c, 1px 1px 0 #14571c, 0 2px 0 #0d3e12);
  font-size: 24px;
  font-weight: 900;
  animation: mg-rise 0.65s ease-out forwards;
  pointer-events: none;
}

/* Màn kết quả: bảng thành tích sao bật lên & huy hiệu phần thưởng */
.mg-result {
  max-width: 680px;
}

.mg-result-body {
  display: flex;
  gap: clamp(12px, calc(2.8vw / var(--ui-zoom, 1)), 24px);
  align-items: center;
  padding: clamp(10px, calc(2vw / var(--ui-zoom, 1)), 16px);
  border-radius: 16px;
  background-color: #d99a4e;
  border: 2px solid transparent;
  border-image: url('../assets/ui/flat/panel-inner.png') 36 36 36 36 fill / 16px / 0 stretch;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #e69d35 rgba(76, 36, 13, 0.28);
  min-height: 0;
}

.mg-trophy {
  position: relative;
  flex: 0 0 38%;
  border: 3px solid var(--mg-border);
  border-radius: 44% 44% 16px 16px;
  overflow: hidden;
  background: #2f5a75;
  box-shadow: inset 0 0 0 2px rgba(255, 248, 200, 0.45), 0 6px 14px rgba(56, 22, 6, 0.36);
}

.mg-prize-art {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}

.mg-rank {
  text-align: center;
  padding: 5px 4px;
  background: linear-gradient(180deg, #7d4016, #4c240d);
  border-top: 2px solid #fae38f;
  color: #ffd44d;
  text-shadow: 0 2px 4px rgba(28, 10, 2, 0.8), 0 0 10px rgba(255, 212, 77, 0.65);
  font-size: clamp(24px, calc(4vw / var(--ui-zoom, 1)), 34px);
  line-height: 1.1;
  letter-spacing: 0.14em;
  animation: mg-star-pop 0.52s cubic-bezier(0.22, 1.5, 0.36, 1) both;
}

.mg-result-info {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 15px;
  background-color: #fff3c4;
  border: 2px solid transparent;
  border-image: url('../assets/ui/flat/card.png') 30 30 30 30 fill / 14px / 0 stretch;
  filter: drop-shadow(0 3px 6px rgba(76, 36, 13, 0.24));
}

.mg-score {
  margin: 0;
  font-size: clamp(32px, calc(5.6vw / var(--ui-zoom, 1)), 50px);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: var(--ui-primary, #ff942e);
  text-shadow: var(--ui-outline-brown, -1.2px -1.2px 0 #6b2514, 1.2px -1.2px 0 #6b2514, -1.2px 1.2px 0 #6b2514, 1.2px 1.2px 0 #6b2514, 0 2px 0 #4d170b);
  font-variant-numeric: tabular-nums;
  animation: mg-pop-in 0.38s cubic-bezier(0.22, 1.35, 0.36, 1);
}

.mg-score small {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: normal;
  color: var(--mg-ink-soft);
  text-shadow: none;
}

.mg-summary {
  margin: 6px 0 0;
  color: var(--mg-ink-soft);
  font-weight: 800;
  font-size: var(--ui-fs-sm, clamp(12px, calc(1.3vw / var(--ui-zoom, 1)), 14px));
}

.mg-result h4 {
  margin: 12px 0 6px;
  font-size: var(--ui-fs-xs, 12px);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mg-ink-soft);
}

.mg-rewards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mg-rewards span {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffdf73, #f0a828);
  border: 1.5px solid #8c4c1b;
  color: var(--mg-ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  animation: mg-pop-in 0.36s cubic-bezier(0.22, 1.32, 0.36, 1) both;
}

.mg-result .mg-note {
  margin-top: 8px;
  text-align: left;
  padding: 8px 10px;
  font-size: var(--ui-fs-xs, 12px);
}

/* ---------- Đáp ứng màn hình (360–430px dọc, 360px ngang, tablet, laptop, siêu rộng) ---------- */
@media (max-width: 550px) and (min-height: 451px) {
  .mg-overlay {
    padding: max(16px, env(safe-area-inset-top, 0px))
             max(8px, env(safe-area-inset-right, 0px))
             max(12px, env(safe-area-inset-bottom, 0px))
             max(8px, env(safe-area-inset-left, 0px));
  }
  .mg-sheet {
    border-width: 24px 14px;
    border-image-width: 24px 14px;
  }
  .mg-menu .mg-head,
  .mg-result .mg-head {
    margin-top: -34px;
  }
  .mg-menu .mg-head h2,
  .mg-result .mg-head h2 {
    padding: 2px 8px 3px;
    border-width: 6px 22px 9px 22px;
    border-image-width: 9px 24px 11px 24px;
    font-size: clamp(13px, calc(3.6vw / var(--ui-zoom, 1)), 16px);
  }
  .mg-choices { grid-template-columns: 1fr; }
  .mg-overlay .mg-choice { grid-template: 1fr / 36% minmax(0, 1fr); align-items: stretch; }
  .mg-postcard { height: 100%; min-height: 86px; aspect-ratio: auto; }
  .mg-choice-copy { padding: 6px 8px; gap: 3px; }
  .mg-board { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); }
  .mg-result-body { flex-direction: column; text-align: center; }
  .mg-trophy { width: min(50%, 172px); flex: auto; }
  .mg-result-info { width: 100%; }
  .mg-actions, .mg-rewards { justify-content: center; }
  .mg-result .mg-note { text-align: center; }
}

@media (max-height: 460px) and (min-width: 500px) {
  .mg-overlay {
    padding: max(8px, env(safe-area-inset-top, 0px))
             max(12px, env(safe-area-inset-right, 0px))
             max(8px, env(safe-area-inset-bottom, 0px))
             max(12px, env(safe-area-inset-left, 0px));
  }
  .mg-sheet {
    max-height: calc(calc(100dvh / var(--ui-zoom, 1)) - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    border-width: 18px 12px;
    border-image-width: 18px 12px;
    padding: 4px 8px 6px;
    gap: 5px;
  }
  .mg-menu .mg-head,
  .mg-result .mg-head { margin-top: -26px; }
  .mg-menu .mg-head h2,
  .mg-result .mg-head h2 {
    min-height: 32px;
    padding: 1px 10px 3px;
    border-width: 5px 24px 8px 24px;
    border-image-width: 8px 26px 10px 26px;
    font-size: 14px;
  }
  .mg-postcard { height: clamp(56px, calc(23vh / var(--ui-zoom, 1)), 94px); aspect-ratio: auto; }
  .mg-choice-copy { gap: 2px; padding: 5px; }
  .mg-game { height: calc(calc(100dvh / var(--ui-zoom, 1)) - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); gap: 5px; }
  .mg-game .mg-head { padding: 3px 6px; }
  .mg-game .mg-heading { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
  .mg-board { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); padding: 6px; }
  .mg-prompt { padding: 10px 16px; }
  .mg-prompt-title { font-size: 26px; }
  .mg-trophy { flex-basis: 28%; }
  .mg-result-info { padding: 8px 11px; }
  .mg-score { font-size: 30px; }
}

@media (min-width: 2000px) {
  .mg-sheet { width: min(100%, 920px); }
  .mg-result { max-width: 740px; }
}

/* ---------- Vi chuyển động & tôn trọng prefers-reduced-motion ---------- */
@keyframes mg-backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes mg-sheet-in { from { opacity: 0; transform: translateY(14px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes mg-pop-in { 0% { opacity: 0; transform: scale(0.86); } 70% { opacity: 1; transform: scale(1.04); } 100% { opacity: 1; transform: scale(1); } }
@keyframes mg-star-pop { 0% { opacity: 0; transform: scale(0.55); } 65% { opacity: 1; transform: scale(1.12); } 100% { opacity: 1; transform: scale(1); } }
@keyframes mg-rise { to { transform: translate(-50%, -22px); opacity: 0; } }
@keyframes mg-sheen {
  0%, 66% { transform: translateX(-120%) skewX(-20deg); opacity: 0; }
  74% { opacity: 1; }
  94% { transform: translateX(360%) skewX(-20deg); opacity: 1; }
  100% { transform: translateX(380%) skewX(-20deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mg-overlay, .mg-overlay *, .mg-overlay *::before, .mg-overlay *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .mg-plus, .mg-btn.mg-primary::before { display: none !important; }
  .mg-btn:hover, .mg-btn:active, .mg-choice:hover, .mg-choice:active, .mg-tile:hover, .mg-tile:active { transform: none !important; }
}
