/* 学霸乐园 math arena — shared frame for the ten math games. */
.g-stage:has(> [data-game-stage] > .ma-root) { max-width: none; padding: 0; }
.ma-root {
  --ma-ink: #23304a; --ma-cream: #fffaf0; --ma-go: #ff8a1f; --ma-go-dark: #d9620a; --ma-green: #22b573;
  position: relative; display: flex; flex-direction: column; height: calc(100vh - 74px); min-height: 560px;
  overflow: hidden; color: var(--ma-ink); font-family: inherit; user-select: none; -webkit-user-select: none;
  isolation: isolate; background: #9fd8ff;
}
.ma-root:fullscreen { height: 100vh; }
.ma-bg { position: absolute; inset: 0; z-index: -1; background: center / cover no-repeat; transition: filter .4s; }
.ma-root[data-theme="dusk"] .ma-bg { filter: sepia(.35) saturate(1.35) hue-rotate(-18deg) brightness(.95); }
.ma-root[data-theme="night"] .ma-bg { filter: brightness(.55) saturate(1.2) hue-rotate(195deg); }
.ma-root[data-theme="candy"] .ma-bg { filter: hue-rotate(290deg) saturate(1.25) brightness(1.05); }
.ma-root[data-theme="mint"] .ma-bg { filter: hue-rotate(60deg) saturate(.95) brightness(1.05); }

/* ---- toolbar ---- */
.ma-bar {
  position: relative; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: rgba(255, 255, 255, .88); backdrop-filter: blur(8px); box-shadow: 0 3px 14px rgba(20, 40, 80, .12);
}
.ma-logo {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-weight: 800;
  color: #fff; text-decoration: none; background: linear-gradient(135deg, #22b573, #11906a); white-space: nowrap;
  box-shadow: 0 3px 0 #0d6e51;
}
.ma-title { font-family: 'ZCOOL KuaiLe', inherit; font-size: 20px; letter-spacing: 1px; white-space: nowrap; }
.ma-hud { flex: 1; display: flex; justify-content: center; gap: 10px; min-width: 0; }
.ma-hud-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: #fff;
  border: 2px solid #e3e9f3; font-weight: 800; white-space: nowrap;
}
.ma-hud-chip.is-low { color: #e03131; border-color: #ffc9c9; animation: ma-pulse .8s infinite; }
.ma-tools { display: flex; align-items: center; gap: 6px; }
.ma-tools button, .ma-home {
  display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 10px; border: 0; border-radius: 10px;
  background: #f1f5fb; color: var(--ma-ink); font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
}
.ma-tools button:hover, .ma-home:hover { background: #e2ebf8; }
.ma-tools button:disabled { opacity: .4; cursor: default; }
.ma-tools button span { font-size: 13px; }
.ma-select { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; }
.ma-select span { color: #6b7894; }
.ma-select select {
  height: 34px; padding: 0 8px; border: 2px solid #e1e8f3; border-radius: 10px; background: #fff; font: inherit;
  font-weight: 700; color: var(--ma-ink); max-width: 150px;
}
@media (max-width: 1100px) { .ma-tools button span, .ma-select span { display: none; } .ma-title { display: none; } }

/* ---- body & overlays ---- */
.ma-body { position: relative; flex: 1; min-height: 0; container-type: size; }
.ma-layer {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px;
  background: rgba(20, 30, 55, .45); backdrop-filter: blur(3px); animation: ma-fade .2s;
}
.ma-layer[hidden] { display: none; }
.ma-card {
  width: min(560px, 100%); max-height: 100%; overflow: auto; padding: 24px 26px; border-radius: 26px; background: var(--ma-cream);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .12), 0 20px 50px rgba(0, 0, 0, .25); border: 4px solid #fff; animation: ma-pop .35s cubic-bezier(.2, 1.6, .4, 1);
  user-select: text;
}
.ma-card h2 { margin: 0 0 10px; font-family: 'ZCOOL KuaiLe', inherit; font-size: 28px; }
.ma-card-emoji { font-size: 56px; text-align: center; }
.ma-card.is-pause { text-align: center; }
.ma-card.is-result { width: min(860px, 100%); }
.ma-card.is-units { width: min(820px, 100%); }
.ma-card.is-settings { width: min(720px, 100%); }
.ma-note { margin: 6px 0; color: #66718a; line-height: 1.6; }
.ma-note code { padding: 1px 6px; border-radius: 6px; background: #eef2f8; }
.ma-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; }
.ma-actions.is-left { justify-content: flex-start; margin-top: 8px; }
.ma-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 20px; border: 0; border-radius: 14px;
  background: #fff; color: var(--ma-ink); font: inherit; font-weight: 800; font-size: 16px; cursor: pointer;
  box-shadow: 0 4px 0 #d5dcea; transition: transform .1s, box-shadow .1s; text-decoration: none;
}
.ma-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d5dcea; }
.ma-btn-go { background: linear-gradient(180deg, #ffa53d, var(--ma-go)); color: #fff; box-shadow: 0 4px 0 var(--ma-go-dark); }
.ma-btn-go:active { box-shadow: 0 1px 0 var(--ma-go-dark); }
.ma-btn.is-danger { color: #d6336c; }
.ma-file { position: relative; }
.ma-rules { margin: 0; padding-left: 22px; line-height: 1.9; font-size: 16px; }

/* ---- cover ---- */
.ma-cover { position: absolute; inset: 0; display: grid; grid-template-columns: 1.1fr 1fr; align-items: center; gap: 2cqw; padding: 3cqh 4cqw; }
.ma-cover-art { position: relative; height: 100%; }
.ma-cover-art img { position: absolute; filter: drop-shadow(0 12px 14px rgba(0, 0, 0, .25)); animation: ma-bob 2.6s ease-in-out infinite; }
.ma-cover-art img:nth-child(2n) { animation-delay: -1.3s; }
.ma-cover-art img:nth-child(3n) { animation-duration: 3.2s; }
.ma-cover-panel {
  justify-self: end; width: min(520px, 100%); padding: 4cqh 34px; border-radius: 32px; background: rgba(255, 250, 240, .93);
  border: 5px solid #fff; box-shadow: 0 12px 0 rgba(0, 0, 0, .1), 0 24px 60px rgba(20, 40, 80, .25); animation: ma-pop .5s cubic-bezier(.2, 1.5, .4, 1);
}
.ma-cover-kicker { margin: 0; color: var(--ma-green); font-weight: 800; letter-spacing: 2px; }
.ma-cover-title {
  margin: 6px 0 4px; font-family: 'ZCOOL KuaiLe', inherit; font-size: clamp(36px, 7cqh, 64px); line-height: 1.1; color: #ff7a00;
  text-shadow: 3px 3px 0 #fff, 6px 6px 0 rgba(255, 122, 0, .18);
}
.ma-cover-sub { margin: 0 0 14px; font-size: 18px; color: #4a5672; }
.ma-cover-features { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }
.ma-cover-features li { padding: 6px 12px; border-radius: 999px; background: #fff; border: 2px solid #ffe0b8; font-weight: 700; font-size: 14px; }
.ma-cover-modes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.ma-mode {
  padding: 8px 14px; border: 3px solid #e2e8f2; border-radius: 14px; background: #fff; font: inherit; font-weight: 800; cursor: pointer;
}
.ma-mode.is-on { border-color: var(--ma-green); background: #e3f8ee; color: #0f7a4e; }
.ma-cover-actions { display: flex; gap: 12px; }
.ma-cover-actions .ma-btn-go { min-height: 58px; padding: 0 34px; font-size: 22px; animation: ma-pulse 1.6s infinite; }
.ma-cover-bank { margin: 14px 0 0; color: #6b7894; font-size: 14px; }
@media (max-width: 900px) { .ma-cover { grid-template-columns: 1fr; } .ma-cover-art { display: none; } .ma-cover-panel { justify-self: center; } }

/* ---- countdown, floats, toasts ---- */
.ma-countdown { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(20, 30, 55, .25); }
.ma-countdown b {
  font-family: 'ZCOOL KuaiLe', inherit; font-size: 28cqh; color: #fff; -webkit-text-stroke: 6px #ff7a00; paint-order: stroke fill;
  text-shadow: 0 10px 0 rgba(0, 0, 0, .15); animation: ma-zoom .7s ease-out;
}
.ma-float {
  position: absolute; z-index: 15; transform: translate(-50%, -50%); pointer-events: none; font-weight: 900; font-size: 30px; color: #fff;
  -webkit-text-stroke: 4px #22b573; paint-order: stroke fill; animation: ma-rise 1.1s ease-out forwards;
}
.ma-float.is-bad { -webkit-text-stroke-color: #e03131; }
.ma-float.is-gold { -webkit-text-stroke-color: #f08c00; font-size: 38px; }
.ma-burst { position: absolute; z-index: 14; width: 0; height: 0; pointer-events: none; }
.ma-burst i { position: absolute; width: 12px; height: 12px; margin: -6px; border-radius: 50%; animation: ma-burst .75s ease-out forwards; }
.ma-toast {
  position: absolute; left: 50%; top: 18%; z-index: 16; transform: translateX(-50%); padding: 10px 26px; border-radius: 999px;
  background: #fff; font-weight: 900; font-size: 24px; color: #ff7a00; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); pointer-events: none;
  animation: ma-toast 1.5s ease-out forwards; white-space: nowrap;
}
.ma-toast.is-bad { color: #e03131; }

/* ---- avatars ---- */
.ma-avatar {
  display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%; overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #fff, var(--pc) 160%); border: 3px solid var(--pc);
}
.ma-avatar img { width: 120%; height: 120%; object-fit: cover; object-position: 50% 8%; }
.ma-avatar.is-big { width: 84px; height: 84px; border-width: 4px; }

/* ---- option pad ---- */
.ma-pad {
  display: flex; flex-direction: column; gap: 8px; height: 100%; padding: 10px; border-radius: 20px; background: rgba(255, 255, 255, .94);
  border: 4px solid var(--pc); box-shadow: 0 6px 0 var(--pd);
}
.ma-pad-q {
  display: grid; place-items: center; min-height: 54px; border-radius: 14px; background: var(--ps); color: var(--pd);
  font-weight: 900; font-size: clamp(22px, 5cqh, 40px); letter-spacing: 1px; white-space: nowrap;
}
.ma-pad-q.is-new { animation: ma-pop .35s cubic-bezier(.2, 1.6, .4, 1); }
.ma-pad-timer { height: 8px; border-radius: 999px; background: #edf1f7; overflow: hidden; }
.ma-pad-timer i { display: block; height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, #40c057, #94d82d); }
.ma-pad-timer i.is-low { background: linear-gradient(90deg, #fa5252, #ff922b); }
.ma-pad-opts { flex: 1; display: grid; grid-template-columns: repeat(var(--cols, 2), 1fr); gap: 8px; min-height: 0; }
.ma-opt {
  position: relative; display: grid; place-items: center; min-height: 44px; border: 0; border-radius: 14px; background: #fff; color: var(--ma-ink);
  font: inherit; font-size: clamp(20px, 4.6cqh, 36px); font-weight: 900; cursor: pointer; box-shadow: inset 0 0 0 3px #e3e9f3, 0 4px 0 #d5dcea;
  transition: transform .08s;
}
.ma-opt:hover { box-shadow: inset 0 0 0 3px var(--pc), 0 4px 0 var(--pd); }
.ma-opt:active { transform: translateY(3px); }
.ma-opt kbd { position: absolute; left: 6px; top: 4px; font: 700 11px/1 inherit; color: #9aa5ba; }
.ma-opt.is-right { background: #2fbf71; color: #fff; box-shadow: 0 4px 0 #1b8a4e; animation: ma-pop .3s; }
.ma-opt.is-wrong { background: #ff6b6b; color: #fff; box-shadow: 0 4px 0 #c92a2a; }
.ma-pad.is-compact .ma-pad-q { min-height: 40px; font-size: clamp(18px, 3.8cqh, 30px); }
.ma-pad.is-compact .ma-opt { min-height: 36px; font-size: clamp(18px, 3.6cqh, 28px); }
.is-shake { animation: ma-shake .45s; }

/* ---- keypad ---- */
.ma-keypad {
  display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 22px; background: rgba(255, 255, 255, .95);
  border: 4px solid var(--pc); box-shadow: 0 6px 0 var(--pd);
}
.ma-keypad.is-disabled, .is-disabled > .ma-keypad { opacity: .5; pointer-events: none; }
.ma-keypad-label { font-weight: 900; color: var(--pd); text-align: center; }
.ma-keypad-out {
  display: grid; place-items: center; height: 56px; border-radius: 14px; background: var(--ps); font-size: 36px; font-weight: 900; color: var(--pd);
}
.ma-keypad-out.is-ok { background: #d3f9d8; color: #2b8a3e; }
.ma-keypad-out.is-bad { background: #ffe3e3; color: #e03131; animation: ma-shake .4s; }
.ma-keypad-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.ma-keypad-keys button {
  height: clamp(38px, 7cqh, 58px); border: 0; border-radius: 12px; background: #fff; font: inherit; font-size: 24px; font-weight: 900; color: var(--ma-ink);
  box-shadow: inset 0 0 0 2px #e3e9f3, 0 3px 0 #d5dcea; cursor: pointer;
}
.ma-keypad-keys button:active { transform: translateY(2px); background: var(--ps); }
.ma-keypad-keys .is-fn { font-size: 16px; color: #6b7894; }
.ma-keypad-ok {
  height: clamp(42px, 7.5cqh, 60px); border: 0; border-radius: 14px; background: var(--pc); color: #fff; font: inherit; font-size: 22px; font-weight: 900;
  box-shadow: 0 4px 0 var(--pd); cursor: pointer; letter-spacing: 4px;
}
.ma-keypad-ok:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--pd); }

/* ---- player chips ---- */
.ma-player {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; background: rgba(255, 255, 255, .95);
  border: 3px solid var(--pc); font-weight: 800; box-shadow: 0 3px 0 var(--pd, rgba(0, 0, 0, .15));
}
.ma-player .ma-avatar { width: 34px; height: 34px; border-width: 2px; }
.ma-player b { font-size: 20px; color: var(--pc); }
.ma-dots { display: inline-flex; gap: 4px; }
.ma-dots i { width: 12px; height: 12px; border-radius: 50%; background: #e3e9f3; transition: background .2s, transform .2s; }
.ma-dots i.is-on { background: #ffc107; transform: scale(1.15); box-shadow: 0 0 8px #ffd43b; }

/* ---- results ---- */
.ma-result-head { display: flex; align-items: center; gap: 18px; margin-bottom: 12px; }
.ma-champion { position: relative; }
.ma-crown { position: absolute; left: 50%; top: -24px; transform: translateX(-50%) rotate(-8deg); font-size: 34px; animation: ma-bob 1.6s infinite; }
.ma-rank { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.ma-rank li {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 16px; background: var(--ps); border: 3px solid var(--pc);
  animation: ma-slide .4s backwards;
}
.ma-rank li:nth-child(2) { animation-delay: .08s; } .ma-rank li:nth-child(3) { animation-delay: .16s; } .ma-rank li:nth-child(4) { animation-delay: .24s; }
.ma-rank-no { width: 34px; font-size: 26px; text-align: center; font-weight: 900; }
.ma-rank-name { min-width: 64px; font-size: 18px; }
.ma-rank-stats { flex: 1; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.ma-rank-stats span { display: grid; min-width: 58px; padding: 3px 8px; border-radius: 10px; background: #fff; text-align: center; }
.ma-rank-stats small { color: #8590a6; font-size: 11px; }
.ma-rank-stats b { font-size: 18px; }
.ma-review { margin-top: 14px; padding: 10px 14px; border-radius: 14px; background: #fff; }
.ma-review summary { cursor: pointer; font-weight: 800; color: #e8590c; }
.ma-review ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.ma-review li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; background: #fff5f5; }
.ma-review li i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ma-review li span { margin-left: auto; color: #e03131; font-size: 13px; }
.ma-perfect { text-align: center; font-weight: 800; color: #2b8a3e; }

/* ---- settings & units ---- */
.ma-form { display: grid; gap: 12px; }
.ma-chips, .ma-names { margin: 0; padding: 10px 12px; border: 0; border-radius: 16px; background: #fff; display: flex; flex-wrap: wrap; gap: 8px; }
.ma-chips legend, .ma-names legend { float: left; width: 100%; margin-bottom: 4px; font-weight: 800; }
.ma-chips label input { position: absolute; opacity: 0; pointer-events: none; }
.ma-chips label span {
  display: inline-block; padding: 7px 14px; border-radius: 12px; border: 2px solid #e2e8f2; font-weight: 700; cursor: pointer;
}
.ma-chips label input:checked + span { border-color: var(--ma-go); background: #fff1e0; color: var(--ma-go-dark); }
.ma-chips label input:focus-visible + span { outline: 3px solid #74c0fc; }
.ma-names label { display: flex; align-items: center; gap: 6px; }
.ma-names input { width: 96px; height: 36px; padding: 0 10px; border: 2px solid var(--pc); border-radius: 10px; font: inherit; font-weight: 700; }
.ma-units { display: grid; grid-template-columns: 210px 1fr; gap: 14px; }
.ma-unit-list { display: grid; align-content: start; gap: 6px; margin: 0; padding: 0; list-style: none; max-height: 330px; overflow: auto; }
.ma-unit-list button {
  width: 100%; display: flex; justify-content: space-between; gap: 6px; padding: 9px 12px; border: 2px solid #e2e8f2; border-radius: 12px; background: #fff;
  font: inherit; font-weight: 700; text-align: left; cursor: pointer;
}
.ma-unit-list button.is-on { border-color: var(--ma-green); background: #e3f8ee; }
.ma-unit-list small { color: #8590a6; }
.ma-unit-edit { display: grid; gap: 8px; }
.ma-unit-edit input, .ma-unit-edit textarea { width: 100%; box-sizing: border-box; padding: 9px 12px; border: 2px solid #e2e8f2; border-radius: 12px; font: inherit; }
.ma-unit-edit textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; }
@media (max-width: 700px) { .ma-units { grid-template-columns: 1fr; } }

/* ---- shared game furniture ---- */
.ma-split { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n, 1), 1fr); gap: 10px; padding: 10px; }
.ma-lane-tag {
  position: absolute; z-index: 3; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px;
  background: var(--pc); color: #fff; font-weight: 800; font-size: 14px; box-shadow: 0 3px 0 rgba(0, 0, 0, .15);
}
.ma-lane-tag .ma-avatar { width: 26px; height: 26px; border-width: 2px; border-color: #fff; }
.ma-root.is-paused .ma-body * { animation-play-state: paused !important; }

/* ---- keyframes ---- */
@keyframes ma-fade { from { opacity: 0; } }
@keyframes ma-pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes ma-zoom { 0% { transform: scale(2.4); opacity: 0; } 40% { transform: scale(.9); opacity: 1; } 100% { transform: scale(1); opacity: .9; } }
@keyframes ma-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes ma-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes ma-rise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 20% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -190%) scale(1); } }
@keyframes ma-burst { to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
@keyframes ma-toast { 0% { opacity: 0; transform: translate(-50%, 20px) scale(.7); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 80% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -20px); } }
@keyframes ma-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
@keyframes ma-slide { from { opacity: 0; transform: translateX(-30px); } }
@keyframes ma-run { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-8%) rotate(3deg); } }
@keyframes ma-hop { 0% { transform: translateY(0); } 40% { transform: translateY(-40%); } 100% { transform: translateY(0); } }
@keyframes ma-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ma-root *, .ma-root *::before, .ma-root *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
