:root {
  --survival-field-width: 1600;
  --survival-field-height: 900;
  --survival-panel: rgba(255, 255, 255, 0.94);
  --survival-panel-strong: rgba(255, 255, 255, 0.98);
  --survival-line: rgba(220, 226, 240, 0.94);
  --survival-deep: rgba(27, 41, 92, 0.92);
  --survival-accent: #5b6cf0;
  --survival-accent-2: #7f9bff;
  --survival-good: #24b36b;
  --survival-warn: #f4b33c;
  --survival-danger: #ef6a6a;
}

body.math-survival-body {
  background: linear-gradient(180deg, #f7f9ff 0%, #eef3ff 100%);
}

body.math-survival-body .page-shell {
  width: min(1360px, calc(100vw - 20px));
  padding: 18px 0 28px;
}

body.math-survival-body .site-footer {
  display: none;
}

.math-survival-page {
  display: grid;
  gap: 16px;
}

.math-survival-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding: 14px 18px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.96) 0%, rgba(249,252,255,0.88) 52%, rgba(240,244,255,0.76) 100%),
    var(--survival-bg) center/cover no-repeat;
}

.math-survival-header-copy {
  max-width: 760px;
}

.math-survival-header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2.7vw, 2.8rem);
}

.math-survival-header p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.math-survival-header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.math-survival-board-shell {
  padding: 14px;
  background: rgba(255, 255, 255, 0.9);
}

.math-survival-topbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(96px, 1fr)) auto;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 14px;
}

.math-survival-mini-stat {
  border: 1px solid var(--survival-line);
  background: rgba(249, 251, 255, 0.96);
  border-radius: 18px;
  padding: 12px 14px;
  display: grid;
  gap: 5px;
  min-height: 68px;
}

.math-survival-mini-stat span {
  color: var(--muted);
  font-size: 0.92rem;
}

.math-survival-mini-stat strong {
  font-size: 1.3rem;
  line-height: 1.1;
}

.math-survival-toolbar-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

.math-survival-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 298px;
  gap: 16px;
  align-items: stretch;
}

.math-survival-stage {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid rgba(213, 220, 238, 0.96);
  background: linear-gradient(180deg, rgba(16,24,44,0.14), rgba(9,15,30,0.18));
  min-height: 560px;
}

.math-survival-world {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: min(64vh, 700px);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(10, 18, 40, 0.12), rgba(10, 18, 40, 0.22)),
    var(--survival-bg) center/cover no-repeat;
}

.math-survival-world::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 54%, rgba(132, 203, 255, 0.18), transparent 34%),
    radial-gradient(circle at 18% 78%, rgba(91, 108, 240, 0.1), transparent 18%),
    radial-gradient(circle at 81% 22%, rgba(255, 255, 255, 0.16), transparent 24%);
  pointer-events: none;
}

.survival-layer,
.survival-buddy,
.survival-player,
.survival-crosshair,
.survival-floating-message,
.survival-start-overlay,
.survival-end-overlay {
  position: absolute;
  inset: 0;
}

.survival-buddy {
  inset: auto;
  z-index: 4;
  width: 4.8%;
  height: 8.6%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.96;
}

.survival-buddy::after {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: -6%;
  height: 12%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(13, 27, 53, 0.16), rgba(13, 27, 53, 0));
  filter: blur(6px);
}

.survival-buddy-sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 16px rgba(18, 31, 80, 0.2));
}

.survival-player {
  inset: auto;
  z-index: 5;
  width: 5.5%;
  height: 9.4%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.survival-player img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 16px rgba(18, 31, 80, 0.28));
}

.survival-pickup-layer { z-index: 2; }
.survival-projectile-layer { z-index: 3; }
.survival-enemy-layer { z-index: 4; }
.survival-fx-layer { z-index: 6; pointer-events: none; }


/* MATH_SURVIVAL_BOSS_SHIELD_V4 */
.survival-enemy-bullet-layer {
  z-index: 5;
  pointer-events: none;
}

.survival-enemy-bullet {
  z-index: 5;
  border-radius: 999px;
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.98), rgba(255,216,122,0.96) 30%, rgba(250,127,91,0.98) 68%, rgba(190,50,61,0.92) 100%);
  box-shadow: 0 0 18px rgba(255, 118, 83, 0.66), 0 0 34px rgba(255, 190, 90, 0.28);
  animation: survival-boss-bullet-pulse 0.58s ease-in-out infinite;
}

.survival-shield-ring {
  position: absolute;
  inset: auto;
  z-index: 6;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  pointer-events: none;
  border: 3px solid rgba(119, 215, 255, 0.86);
  background: radial-gradient(circle, rgba(142, 220, 255, 0.16), rgba(91, 108, 240, 0.05) 58%, rgba(91, 108, 240, 0));
  box-shadow: 0 0 22px rgba(98, 190, 255, 0.62), inset 0 0 20px rgba(255,255,255,0.38);
  animation: survival-shield-flare 0.56s ease-out infinite alternate;
}

.survival-player.shield-active img {
  filter: drop-shadow(0 0 18px rgba(98, 190, 255, 0.86)) drop-shadow(0 10px 16px rgba(18, 31, 80, 0.28));
}

.survival-boss {
  z-index: 4;
}

.survival-boss .survival-enemy-sprite {
  filter: drop-shadow(0 18px 26px rgba(46, 33, 95, 0.34)) drop-shadow(0 0 18px rgba(255, 180, 78, 0.34));
}

.survival-boss-label {
  position: absolute;
  left: 50%;
  top: -22%;
  transform: translateX(-50%);
  z-index: 2;
  padding: 4px 9px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 114, 96, 0.96), rgba(255, 187, 69, 0.96));
  color: #fff;
  font-size: clamp(0.68rem, 1vw, 0.82rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 8px 16px rgba(160, 61, 48, 0.22);
}

.survival-shield-button.is-ready {
  border-color: rgba(44, 163, 112, 0.42);
  background: linear-gradient(180deg, rgba(239,255,249,0.98), rgba(216,248,235,0.94));
}

.survival-shield-button.is-active {
  color: #fff;
  background: linear-gradient(135deg, #4aa9ff, #5b6cf0);
}

.survival-shield-button.is-cooling {
  opacity: 0.72;
}

.survival-entity {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.survival-enemy {
  z-index: 4;
}

.survival-enemy-sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 14px 18px rgba(16, 24, 55, 0.26));
  animation: survival-enemy-float 1.75s ease-in-out infinite;
}

.survival-enemy::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -4%;
  height: 14%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(13, 27, 53, 0.22), rgba(13, 27, 53, 0));
  filter: blur(6px);
}

.survival-enemy-hp {
  position: absolute;
  left: 14%;
  right: 14%;
  top: -10%;
  height: 10%;
  border-radius: 999px;
  background: rgba(17, 30, 60, 0.18);
  overflow: hidden;
}

.survival-enemy-hp > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #4ed07e, #71ef9e);
}

.survival-projectile {
  z-index: 3;
  border-radius: 999px;
  background: radial-gradient(circle at 32% 32%, rgba(255,255,255,0.94), rgba(124, 165, 255, 0.98) 45%, rgba(74, 104, 240, 1) 72%, rgba(49, 73, 188, 0.9) 100%);
  box-shadow: 0 0 18px rgba(91, 108, 240, 0.55);
}

.survival-projectile::after {
  content: "";
  position: absolute;
  inset: -24%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(158, 185, 255, 0.6), transparent 66%);
  animation: survival-orb-pulse 0.72s ease-out infinite;
}

.survival-pickup {
  z-index: 2;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.98), rgba(113, 213, 255, 0.95) 38%, rgba(70, 126, 255, 0.98) 60%, rgba(53, 86, 217, 0.98) 100%);
  box-shadow: 0 0 22px rgba(98, 139, 255, 0.58);
}

.survival-pickup::before,
.survival-pickup::after {
  content: "";
  position: absolute;
  inset: -22%;
  border-radius: 999px;
  border: 2px solid rgba(154, 223, 255, 0.58);
  animation: survival-pickup-ring 1.4s ease-out infinite;
}

.survival-pickup::after {
  inset: -42%;
  animation-delay: 0.42s;
}

.survival-pickup-core {
  position: absolute;
  inset: 24%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255,255,255,0.94), rgba(255,239,162,0.92) 60%, rgba(255,196,83,0.82) 100%);
}

.survival-crosshair {
  inset: auto;
  width: 38px;
  height: 38px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.72);
  box-shadow: 0 0 0 8px rgba(255,255,255,0.06);
  pointer-events: none;
  z-index: 2;
}

.survival-crosshair::before,
.survival-crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255,255,255,0.72);
}

.survival-crosshair::before {
  left: 50%;
  top: 2px;
  bottom: 2px;
  width: 2px;
  transform: translateX(-50%);
}

.survival-crosshair::after {
  top: 50%;
  left: 2px;
  right: 2px;
  height: 2px;
  transform: translateY(-50%);
}

.survival-floating-message {
  inset: auto 20px 18px 20px;
  z-index: 7;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: calc(100% - 40px);
  padding: 11px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(16, 31, 76, 0.76);
  box-shadow: 0 10px 30px rgba(15, 29, 68, 0.16);
  backdrop-filter: blur(12px);
  font-weight: 700;
  line-height: 1.4;
}


/* MATH_SURVIVAL_TOUCH_STICK_V1 */
.survival-touch-stick {
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: 126px;
  height: 126px;
  z-index: 8;
  display: none;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.survival-touch-stick-base,
.survival-touch-stick-knob {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

.survival-touch-stick-base {
  inset: 0;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,0.46), rgba(203, 214, 248, 0.22) 48%, rgba(122, 141, 207, 0.18) 100%),
    linear-gradient(180deg, rgba(17, 30, 71, 0.16), rgba(17, 30, 71, 0.08));
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow: inset 0 10px 22px rgba(255,255,255,0.16), 0 14px 26px rgba(15, 29, 68, 0.16);
  backdrop-filter: blur(12px);
}

.survival-touch-stick-base::before,
.survival-touch-stick-base::after {
  content: "";
  position: absolute;
  inset: 50%;
  background: rgba(255, 255, 255, 0.12);
  transform: translate(-50%, -50%);
}

.survival-touch-stick-base::before {
  width: 2px;
  height: 68%;
  border-radius: 999px;
}

.survival-touch-stick-base::after {
  width: 68%;
  height: 2px;
  border-radius: 999px;
}

.survival-touch-stick-knob {
  width: 54px;
  height: 54px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.98), rgba(201, 220, 255, 0.96) 34%, rgba(118, 149, 248, 0.98) 76%, rgba(73, 101, 212, 0.98) 100%);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 14px 22px rgba(16, 31, 76, 0.26), inset 0 3px 12px rgba(255,255,255,0.3);
  transition: transform 0.08s ease-out, box-shadow 0.12s ease-out;
}

.survival-touch-stick.is-active .survival-touch-stick-knob {
  box-shadow: 0 16px 28px rgba(16, 31, 76, 0.34), inset 0 3px 12px rgba(255,255,255,0.34);
}

.survival-touch-stick-caption {
  position: absolute;
  left: 50%;
  bottom: -28px;
  transform: translateX(-50%);
  min-width: max-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(14, 26, 62, 0.68);
  color: rgba(255,255,255,0.92);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 20px rgba(15, 29, 68, 0.16);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.survival-start-overlay,
.survival-end-overlay {
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 16, 36, 0.46);
  backdrop-filter: blur(10px);
}

/* MATH_SURVIVAL_START_DUAL_MODE_V1 */
.survival-start-overlay,
.survival-end-overlay {
  pointer-events: auto;
}

.survival-overlay-card {
  position: relative;
  z-index: 1;
}

.survival-start-overlay.hidden,
.survival-end-overlay.hidden,
.math-trace-modal.hidden {
  display: none;
  pointer-events: none;
}


.survival-overlay-card {
  width: min(620px, 92%);
  padding: 24px 24px 22px;
  text-align: center;
  background: rgba(255, 255, 255, 0.96);
}

.survival-overlay-card h2 {
  margin: 0 0 10px;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
}

.survival-overlay-card p {
  margin: 0;
  line-height: 1.7;
  color: var(--muted);
}

.survival-overlay-points,
.survival-end-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 18px;
}

.survival-overlay-points span,
.survival-end-stats div {
  padding: 10px 14px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary-2);
  font-weight: 700;
}

.survival-end-stats div {
  border-radius: 18px;
  min-width: 120px;
  display: grid;
  gap: 4px;
  background: #f7f9ff;
}

.survival-end-stats span {
  color: var(--muted);
  font-size: 0.9rem;
}

.survival-end-stats strong {
  font-size: 1.4rem;
}

.survival-overlay-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 22px;
}

.math-survival-sidebar {
  display: grid;
  gap: 14px;
  align-content: start;
}

.survival-side-card {
  border: 1px solid var(--survival-line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.96);
  padding: 18px 18px 16px;
}

.survival-side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.survival-side-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.survival-energy-meter {
  height: 16px;
  border-radius: 999px;
  background: rgba(91, 108, 240, 0.12);
  overflow: hidden;
}

.survival-energy-value {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #67d389, #56b6ff 58%, #5b6cf0 100%);
  transition: width 0.18s ease;
}

.survival-side-stats {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

.survival-side-stats div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding-bottom: 8px;
  border-bottom: 1px dashed rgba(220, 226, 240, 0.92);
}

.survival-side-stats div:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.survival-side-stats dt,
.survival-side-copy,
.survival-help-list,
.math-trace-hint {
  color: var(--muted);
}

.survival-side-stats dd {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.survival-dpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(62px, 1fr));
  gap: 10px;
  justify-items: center;
}

.survival-dpad-button {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  border: 1px solid rgba(91, 108, 240, 0.26);
  background: linear-gradient(180deg, rgba(248,250,255,0.96), rgba(234,240,255,0.92));
  color: var(--primary-2);
  font-size: 1.6rem;
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(91, 108, 240, 0.08);
}

.survival-dpad-button[data-dir="up"] {
  grid-column: 2;
}

.survival-dpad-button[data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.survival-dpad-button[data-dir="down"] {
  grid-column: 2;
  grid-row: 2;
}

.survival-dpad-button[data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.survival-dpad-button:active,
.survival-dpad-button.is-active {
  transform: translateY(1px);
  background: linear-gradient(180deg, rgba(225,233,255,0.98), rgba(210,222,255,0.94));
}

.survival-side-copy {
  margin: 14px 0 0;
  line-height: 1.7;
}

.survival-help-list {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 10px;
  line-height: 1.65;
}

.survival-buddy-preview {
  min-height: 136px;
  border-radius: 22px;
  border: 1px dashed rgba(184, 196, 233, 0.92);
  background: linear-gradient(180deg, rgba(248,250,255,0.98), rgba(237,242,255,0.92));
  display: grid;
  place-items: center;
  overflow: hidden;
}

.survival-buddy-preview-media {
  width: min(78%, 180px);
  height: min(78%, 118px);
  object-fit: contain;
  filter: drop-shadow(0 10px 16px rgba(18, 31, 80, 0.16));
}

.survival-buddy-meta {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.survival-buddy-meta strong {
  font-size: 1.08rem;
  color: var(--survival-deep);
}

.math-trace-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 16, 36, 0.55);
  backdrop-filter: blur(12px);
}

.math-trace-card {
  width: min(860px, 96vw);
  padding: 24px 24px 20px;
  background: rgba(255, 255, 255, 0.98);
}

.math-trace-card h2 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.math-trace-problem-text {
  margin: 10px 0 0;
  color: var(--primary-2);
  font-size: clamp(1.4rem, 2vw, 2rem);
  font-weight: 900;
}

.math-trace-stage {
  position: relative;
  margin-top: 16px;
  min-height: 260px;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid rgba(211, 220, 242, 0.96);
  background: linear-gradient(180deg, rgba(248,250,255,0.98), rgba(239,244,255,0.95));
}

.math-trace-guide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(4rem, 9vw, 7rem);
  font-weight: 900;
  color: rgba(91, 108, 240, 0.18);
  letter-spacing: 0.08em;
  pointer-events: none;
  user-select: none;
  text-align: center;
  padding: 12px 16px;
}

#mathTraceCanvas {
  width: 100%;
  height: 260px;
  display: block;
  position: relative;
  z-index: 1;
  touch-action: none;
  cursor: crosshair;
}

.math-trace-progress {
  margin-top: 14px;
  height: 16px;
  border-radius: 999px;
  background: rgba(91, 108, 240, 0.12);
  overflow: hidden;
}

.math-trace-progress-value {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #77d590, #66bef4 56%, #5b6cf0 100%);
  transition: width 0.12s linear;
}

.math-trace-hint {
  margin: 12px 0 0;
  line-height: 1.65;
}

/* MATH_SURVIVAL_MOBILE_READY_START_V1 */
body.math-survival-body {
  overflow-x: hidden;
  overflow-y: auto;
  height: auto;
  min-height: 100dvh;
  -webkit-overflow-scrolling: touch;
}

body.math-survival-body .page-shell {
  min-height: auto;
  height: auto;
  overflow: visible;
}

.math-survival-board-shell {
  overflow: visible;
}

.math-survival-topbar,
.math-survival-mini-stat,
.math-survival-toolbar-actions {
  min-width: 0;
}

.math-survival-toolbar-actions .button {
  white-space: nowrap;
}

#survivalQuickStartButton.is-hidden {
  display: none;
}

/* MATH_SURVIVAL_TRACE_CONFIRM_V1 */
.math-trace-actions {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.math-trace-actions .button[disabled] {
  opacity: 0.42;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.math-trace-actions .button[disabled]:hover,
.math-trace-actions .button[disabled]:active {
  background: linear-gradient(135deg, var(--primary), #7d8fff);
  transform: none;
}

.survival-burst {
  position: absolute;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255,255,255,0.96), rgba(125, 174, 255, 0.6), rgba(91, 108, 240, 0));
  animation: survival-burst-pop 0.42s ease-out forwards;
}

.survival-pickup-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  color: #fff;
  font-weight: 900;
  font-size: 1.1rem;
  text-shadow: 0 4px 12px rgba(25, 38, 80, 0.34);
  animation: survival-pop-text 0.7s ease-out forwards;
  pointer-events: none;
}

.math-survival-board-shell:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  border: none;
  padding: 12px;
  background: rgba(247, 249, 255, 0.98);
}

.math-survival-board-shell:fullscreen .math-survival-layout {
  height: calc(100vh - 110px);
}

.math-survival-board-shell:fullscreen .math-survival-stage,
.math-survival-board-shell:fullscreen .math-survival-world {
  min-height: 0;
  height: 100%;
}

@keyframes survival-enemy-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes survival-pickup-ring {
  0% { transform: scale(0.72); opacity: 0.68; }
  100% { transform: scale(1.28); opacity: 0; }
}

@keyframes survival-orb-pulse {
  0%, 100% { transform: scale(0.84); opacity: 0.46; }
  50% { transform: scale(1.08); opacity: 0.14; }
}

@keyframes survival-burst-pop {
  0% { transform: translate(-50%, -50%) scale(0.28); opacity: 0.88; }
  100% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; }
}

@keyframes survival-pop-text {
  0% { transform: translate(-50%, -50%) translateY(8px); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(-50%, -50%) translateY(-38px); opacity: 0; }
}


@keyframes survival-boss-bullet-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(0.92); opacity: 0.9; }
  50% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; }
}

@keyframes survival-shield-flare {
  0% { opacity: 0.56; transform: translate(-50%, -50%) scale(0.96); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
}

@media (hover: none) and (pointer: coarse), (max-height: 620px) {
  body.math-survival-body .page-shell {
    width: min(100%, calc(100vw - 12px));
    padding: 10px 0 calc(18px + env(safe-area-inset-bottom));
  }

  .math-survival-page {
    gap: 10px;
  }

  .math-survival-header {
    padding: 12px 14px;
    gap: 12px;
    flex-direction: column;
  }

  .math-survival-header-copy {
    max-width: none;
  }

  .math-survival-header p {
    margin-top: 4px;
    font-size: 0.96rem;
    line-height: 1.5;
  }

  .math-survival-header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .math-survival-board-shell {
    padding: 10px;
  }

  .math-survival-topbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .math-survival-toolbar-actions {
    grid-column: 1 / -1;
    order: -1;
    justify-content: flex-start;
    position: sticky;
    top: calc(env(safe-area-inset-top) + 4px);
    z-index: 8;
    padding: 6px;
    border-radius: 16px;
    background: rgba(247, 249, 255, 0.92);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 20px rgba(16, 24, 55, 0.08);
  }

  .math-survival-mini-stat {
    min-height: 58px;
    padding: 10px 12px;
  }

  .math-survival-mini-stat strong {
    font-size: 1.16rem;
  }

  .math-survival-stage {
    min-height: 0;
  }

  .math-survival-world {
    min-height: min(48vh, 360px);
  }

  .survival-touch-stick {
    display: block;
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: 132px;
    height: 132px;
  }

  .survival-floating-message {
    inset: auto 12px calc(18px + env(safe-area-inset-bottom)) 158px;
    max-width: calc(100% - 170px);
    font-size: 0.9rem;
    padding: 10px 14px;
  }

  .survival-start-overlay,
  .survival-end-overlay {
    padding: 12px;
  }

  .survival-overlay-card {
    width: min(520px, 96%);
    padding: 18px 18px 16px;
  }

  .survival-overlay-card h2 {
    font-size: clamp(1.45rem, 4vw, 1.9rem);
  }

  .survival-overlay-card p {
    font-size: 0.94rem;
    line-height: 1.55;
  }

  .survival-overlay-points span {
    padding: 8px 10px;
    font-size: 0.86rem;
  }

  .math-survival-sidebar {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  .math-survival-world {
    min-height: min(44vh, 320px);
  }
}

@media (max-width: 1120px) {
  .math-survival-topbar {
    grid-template-columns: repeat(3, minmax(110px, 1fr));
  }

  .math-survival-layout {
    grid-template-columns: 1fr;
  }

  .math-survival-sidebar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  body.math-survival-body .page-shell {
    width: min(100vw - 14px, 100%);
    padding: 12px 0 18px;
  }

  .math-survival-header {
    padding: 16px;
  }

  .math-survival-topbar {
    grid-template-columns: repeat(2, minmax(110px, 1fr));
  }

  .math-survival-sidebar {
    grid-template-columns: 1fr;
  }

  .math-survival-world {
    min-height: min(72vh, 600px);
  }

  .survival-floating-message {
    font-size: 0.92rem;
  }
}

@media (max-width: 860px) and (hover: none) and (pointer: coarse) {
  .survival-touch-stick {
    width: 120px;
    height: 120px;
    left: max(12px, env(safe-area-inset-left));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .survival-touch-stick-knob {
    width: 50px;
    height: 50px;
  }

  .survival-touch-stick-caption {
    font-size: 0.72rem;
    bottom: -26px;
  }

  .survival-floating-message {
    inset: auto 10px calc(16px + env(safe-area-inset-bottom)) 144px;
    max-width: calc(100% - 154px);
    font-size: 0.84rem;
    padding: 9px 12px;
  }
}

@media (max-width: 640px) {
  .math-survival-header,
  .math-survival-board-shell,
  .survival-side-card,
  .math-trace-card {
    border-radius: 18px;
  }

  .survival-touch-stick {
    width: 108px;
    height: 108px;
  }

  .survival-touch-stick-knob {
    width: 46px;
    height: 46px;
  }

  .survival-touch-stick-caption {
    display: none;
  }

  .math-trace-card {
    padding: 18px;
  }

  .math-trace-stage,
  #mathTraceCanvas {
    height: 220px;
    min-height: 220px;
  }

  .math-trace-guide {
    font-size: clamp(3rem, 14vw, 5rem);
  }

  .math-survival-world {
    min-height: min(62vh, 500px);
  }
}

/* MATH_SURVIVAL_BUDDY_ATTACK_V7 */
.survival-projectile-buddy {
  background: radial-gradient(circle at 32% 30%, rgba(255,255,255,0.98), rgba(132, 235, 175, 0.96) 42%, rgba(39, 180, 116, 0.98) 72%, rgba(28, 120, 91, 0.92) 100%);
  box-shadow: 0 0 18px rgba(69, 214, 136, 0.58), 0 0 32px rgba(93, 240, 174, 0.22);
}
.survival-projectile-buddy::after {
  background: radial-gradient(circle, rgba(145, 255, 194, 0.62), transparent 66%);
}
.survival-projectile-buddy-spread {
  background: radial-gradient(circle at 32% 30%, rgba(255,255,255,0.98), rgba(255, 219, 102, 0.98) 40%, rgba(244, 151, 48, 0.96) 72%, rgba(168, 92, 28, 0.9) 100%);
  box-shadow: 0 0 18px rgba(255, 176, 64, 0.58), 0 0 32px rgba(255, 218, 122, 0.22);
}
.survival-projectile-buddy-homing {
  background: radial-gradient(circle at 34% 28%, rgba(255,255,255,0.98), rgba(174, 156, 255, 0.98) 42%, rgba(112, 87, 236, 0.98) 74%, rgba(65, 52, 160, 0.92) 100%);
  box-shadow: 0 0 19px rgba(135, 112, 255, 0.62), 0 0 36px rgba(171, 152, 255, 0.24);
}
.survival-projectile-buddy-pulse {
  background: radial-gradient(circle at 34% 28%, rgba(255,255,255,0.98), rgba(126, 231, 255, 0.98) 42%, rgba(38, 166, 225, 0.98) 74%, rgba(32, 101, 170, 0.92) 100%);
  box-shadow: 0 0 18px rgba(73, 208, 255, 0.6), 0 0 34px rgba(108, 232, 255, 0.24);
}

/* MATH_SURVIVAL_TABLET_SHIELD_SPEED_V8 */
.survival-dpad-wrap {
  display: grid;
  gap: 12px;
}

.survival-dpad-actions {
  display: flex;
  justify-content: stretch;
  align-items: center;
}

.survival-dpad-shield-button {
  width: 100%;
  min-height: 52px;
  border-radius: 18px;
  font-size: 1rem;
  font-weight: 900;
  box-shadow: 0 14px 26px rgba(91, 108, 240, 0.14);
  touch-action: manipulation;
}

.survival-dpad-shield-button.is-ready {
  transform: translateY(-1px);
}

@media (hover: none) and (pointer: coarse) {
  .survival-dpad-wrap {
    grid-template-columns: minmax(0, 1fr);
  }

  .survival-dpad-button {
    min-height: 58px;
  }

  .survival-dpad-shield-button {
    min-height: 60px;
    font-size: 1.08rem;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  .survival-side-card:has(.survival-dpad-wrap) {
    position: relative;
  }

  .survival-dpad-actions {
    margin-top: 2px;
  }

  .survival-dpad-shield-button {
    letter-spacing: 0.04em;
  }
}

.survival-touch-shield-button {
  display: none;
  position: absolute;
  z-index: 9;
  left: calc(max(14px, env(safe-area-inset-left)) + 150px);
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 24px));
  min-width: 112px;
  min-height: 58px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #5b6cf0, #7f9bff);
  box-shadow: 0 14px 28px rgba(57, 82, 204, 0.24), 0 0 0 6px rgba(255,255,255,0.32);
  font-weight: 900;
  letter-spacing: 0.02em;
  touch-action: manipulation;
}

.survival-touch-shield-button.is-ready {
  animation: survival-shield-ready-pulse 1.1s ease-in-out infinite;
}

.survival-touch-shield-button.is-active {
  background: linear-gradient(135deg, #4aa9ff, #5b6cf0);
}

.survival-touch-shield-button.is-cooling {
  color: rgba(255,255,255,0.86);
  background: linear-gradient(135deg, rgba(74, 91, 156, 0.9), rgba(91, 108, 240, 0.82));
}

@keyframes survival-shield-ready-pulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.03); }
}

@media (hover: none) and (pointer: coarse) {
  .survival-touch-shield-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 640px) {
  .survival-touch-shield-button {
    left: calc(max(12px, env(safe-area-inset-left)) + 122px);
    bottom: max(18px, calc(env(safe-area-inset-bottom) + 18px));
    min-width: 98px;
    min-height: 52px;
    font-size: 0.92rem;
  }
}

/* MATH_SURVIVAL_MOBILE_TRACE_SHIELD_DAMAGE_V9 */
.math-trace-modal {
  overflow: auto;
  align-items: start;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.math-trace-card {
  max-height: calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom)));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.math-trace-actions {
  position: sticky;
  bottom: 0;
  z-index: 4;
  padding-top: 10px;
  padding-bottom: max(2px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,0.98) 28%, rgba(255,255,255,0.98));
}

@media (hover: none) and (pointer: coarse), (max-width: 720px) {
  .math-trace-modal {
    display: block;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .math-trace-card {
    width: min(100%, 760px);
    min-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .math-trace-card .eyebrow {
    margin-bottom: 0;
    font-size: 0.76rem;
  }

  .math-trace-card h2 {
    font-size: clamp(1.35rem, 6vw, 1.8rem);
  }

  .math-trace-problem-text {
    margin-top: 4px;
    font-size: clamp(1.25rem, 7vw, 1.8rem);
  }

  .math-trace-stage {
    flex: 1 1 auto;
    min-height: 210px;
    max-height: 46dvh;
    margin-top: 6px;
    border-radius: 18px;
  }

  #mathTraceCanvas {
    height: 100%;
    min-height: 210px;
  }

  .math-trace-guide {
    font-size: clamp(3.2rem, 18vw, 6rem);
    line-height: 1.05;
    letter-spacing: 0.04em;
  }

  .math-trace-progress {
    margin-top: 6px;
    height: 12px;
    flex: 0 0 auto;
  }

  .math-trace-hint {
    margin-top: 0;
    font-size: 0.92rem;
    line-height: 1.45;
    flex: 0 0 auto;
  }

  .math-trace-actions {
    margin-top: auto;
    gap: 8px;
    flex: 0 0 auto;
  }

  .math-trace-actions .button {
    flex: 1 1 140px;
    min-height: 48px;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  .math-trace-card {
    padding: 10px 12px;
    gap: 6px;
  }

  .math-trace-stage {
    min-height: 148px;
    max-height: 42dvh;
  }

  #mathTraceCanvas {
    min-height: 148px;
  }

  .math-trace-guide {
    font-size: clamp(2.7rem, 12vw, 5.2rem);
  }

  .math-trace-actions .button {
    min-height: 42px;
  }
}

/* MATH_SURVIVAL_BUDDY_SPECIAL_HP_SHIELD_V11 */
.survival-player-hp-panel {
  position: absolute;
  z-index: 8;
  left: max(16px, env(safe-area-inset-left));
  top: max(14px, env(safe-area-inset-top));
  width: min(260px, 42%);
  padding: 10px 12px 11px;
  border: 1px solid rgba(221, 228, 246, 0.9);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 26px rgba(28, 41, 90, 0.12);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.survival-player-hp-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: var(--survival-deep);
  font-weight: 900;
  font-size: clamp(0.78rem, 1.4vw, 0.94rem);
}

.survival-player-hp-panel-head strong {
  color: var(--survival-good);
  font-size: 1.04em;
}

.survival-player-hp-meter {
  height: 12px;
  border-radius: 999px;
  background: rgba(28, 41, 90, 0.12);
  overflow: hidden;
}

.survival-player-hp-meter > span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #35c977, #76e99b);
  transition: width 0.16s ease, background 0.16s ease;
}

.survival-player-hp-panel.is-low .survival-player-hp-panel-head strong {
  color: var(--survival-warn);
}

.survival-player-hp-panel.is-low .survival-player-hp-meter > span {
  background: linear-gradient(90deg, #f3b43b, #ffd067);
}

.survival-player-hp-panel.is-danger .survival-player-hp-panel-head strong {
  color: var(--survival-danger);
}

.survival-player-hp-panel.is-danger .survival-player-hp-meter > span {
  background: linear-gradient(90deg, #ef6a6a, #ff9a90);
}

.survival-shield-ring.is-buddy-shield {
  border-color: rgba(255, 222, 115, 0.9);
  background: radial-gradient(circle, rgba(255, 236, 148, 0.22), rgba(255, 188, 76, 0.08) 58%, rgba(255, 188, 76, 0));
  box-shadow: 0 0 22px rgba(255, 204, 83, 0.62), inset 0 0 20px rgba(255,255,255,0.4);
}

.survival-player.buddy-shield-active img {
  filter: drop-shadow(0 0 18px rgba(255, 211, 83, 0.86)) drop-shadow(0 10px 16px rgba(18, 31, 80, 0.28));
}

.survival-projectile-buddy-angel {
  background: radial-gradient(circle at 34% 28%, rgba(255,255,255,0.98), rgba(255, 241, 168, 0.98) 40%, rgba(255, 180, 71, 0.94) 72%, rgba(204, 122, 43, 0.9) 100%);
  box-shadow: 0 0 20px rgba(255, 225, 111, 0.66), 0 0 36px rgba(255, 238, 178, 0.28);
  border-radius: 70% 45% 70% 45%;
}

.survival-projectile-buddy-two_way {
  background: radial-gradient(circle at 30% 28%, rgba(255,255,255,0.98), rgba(177, 218, 255, 0.98) 40%, rgba(77, 128, 241, 0.98) 72%, rgba(37, 64, 156, 0.94) 100%);
  box-shadow: 0 0 19px rgba(91, 142, 255, 0.62), 0 0 36px rgba(119, 181, 255, 0.24);
}

.survival-projectile-buddy-ninja {
  background: radial-gradient(circle at 34% 28%, rgba(255,255,255,0.95), rgba(103, 218, 151, 0.98) 38%, rgba(25, 138, 93, 0.98) 72%, rgba(18, 75, 61, 0.94) 100%);
  box-shadow: 0 0 18px rgba(64, 217, 132, 0.58), 0 0 32px rgba(111, 245, 180, 0.22);
}

.survival-projectile-buddy-knight {
  background: radial-gradient(circle at 34% 28%, rgba(255,255,255,0.98), rgba(218, 227, 255, 0.98) 42%, rgba(123, 147, 244, 0.98) 74%, rgba(65, 77, 175, 0.92) 100%);
  box-shadow: 0 0 18px rgba(126, 151, 255, 0.6), 0 0 34px rgba(164, 181, 255, 0.24);
}

.survival-caltrop {
  z-index: 2;
  width: 22px;
  height: 22px;
  background:
    linear-gradient(45deg, transparent 42%, rgba(36, 47, 84, 0.96) 43%, rgba(36, 47, 84, 0.96) 57%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, rgba(36, 47, 84, 0.96) 43%, rgba(36, 47, 84, 0.96) 57%, transparent 58%),
    radial-gradient(circle, rgba(122, 239, 169, 0.96) 0 18%, rgba(46, 162, 106, 0.96) 19% 32%, transparent 33%);
  filter: drop-shadow(0 4px 8px rgba(9, 20, 48, 0.26));
}

.survival-caltrop::after {
  content: "";
  position: absolute;
  inset: -18%;
  border-radius: 999px;
  border: 1px dashed rgba(91, 238, 157, 0.5);
  animation: survival-caltrop-pulse 1.1s ease-in-out infinite;
}

@keyframes survival-caltrop-pulse {
  0%, 100% { transform: scale(0.86); opacity: 0.38; }
  50% { transform: scale(1.18); opacity: 0.86; }
}

@media (hover: none) and (pointer: coarse) {
  .survival-player-hp-panel {
    width: min(232px, 54%);
    padding: 9px 10px 10px;
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 640px) {
  .survival-player-hp-panel {
    left: max(10px, env(safe-area-inset-left));
    top: max(8px, env(safe-area-inset-top));
    width: min(210px, 60%);
    border-radius: 14px;
  }
  .survival-player-hp-panel-head {
    font-size: 0.74rem;
  }
  .survival-player-hp-meter {
    height: 10px;
  }
}
