:root {
  --night: #070b1d;
  --night-soft: #0d1430;
  --panel: rgba(19, 28, 60, 0.72);
  --panel-strong: rgba(21, 31, 69, 0.92);
  --line: rgba(184, 207, 255, 0.14);
  --text: #eef2ff;
  --muted: #9ca9ce;
  --soft: #6e7b9f;
  --cyan: #62e6ff;
  --blue: #7c8cff;
  --violet: #c58cff;
  --gold: #ffd77c;
  --coral: #ff7b8b;
  font-family: "Avenir Next", Avenir, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  background: var(--night);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--night); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 15% 8%, rgba(85, 117, 255, 0.16), transparent 28rem),
    radial-gradient(circle at 88% 76%, rgba(184, 91, 255, 0.12), transparent 27rem),
    var(--night);
}

button { font: inherit; }

.gravity-page {
  width: min(1260px, calc(100% - 42px));
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(24px, 4.5vw, 58px) 0 26px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-decoration: none;
  transition: color 160ms ease, transform 160ms ease;
}

.back-link span { color: var(--cyan); font-size: 1rem; }
.back-link:hover { color: var(--text); transform: translateX(-3px); }

.game-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: clamp(32px, 6vw, 72px) 0 25px;
}

.eyebrow, .hud-kicker, .page-footer, .cover-kicker {
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--cyan);
  font-size: 0.66rem;
  font-weight: 850;
}

.eyebrow-dot, .danger-orb {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 5px rgba(98, 230, 255, 0.12), 0 0 16px rgba(98, 230, 255, 0.8);
}

h1, h2, p { margin: 0; }

h1 {
  margin-top: 15px;
  color: var(--text);
  font-size: clamp(3.1rem, 7vw, 6.6rem);
  font-weight: 850;
  letter-spacing: -0.1em;
  line-height: 0.86;
}

h1 span { color: var(--cyan); }

.game-tagline {
  margin-top: 17px;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: 650;
}

.header-actions { display: flex; flex-wrap: wrap; gap: 10px; padding-bottom: 4px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 850;
  letter-spacing: 0.02em;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  -webkit-tap-highlight-color: transparent;
}

.button:hover { transform: translateY(-2px); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: 0.42; transform: none; }
.button:focus-visible, .dpad button:focus-visible { outline: 3px solid rgba(98, 230, 255, 0.36); outline-offset: 3px; }

.button-primary {
  color: #061020;
  background: linear-gradient(135deg, var(--cyan), #9ceeff);
  box-shadow: 0 11px 25px rgba(98, 230, 255, 0.19);
}

.button-primary:hover { background: linear-gradient(135deg, #8cecff, #d2f8ff); box-shadow: 0 14px 30px rgba(98, 230, 255, 0.28); }
.button-primary span { margin-left: 9px; font-size: 1rem; }

.button-quiet {
  color: var(--muted);
  border-color: var(--line);
  background: rgba(17, 27, 57, 0.68);
}

.button-quiet:hover { color: var(--text); border-color: rgba(184, 207, 255, 0.28); background: rgba(30, 43, 86, 0.8); }
#codex-button span { margin-left: 7px; color: var(--cyan); font-size: 0.62rem; }

.game-shell { position: relative; }

.control-card {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.035);
  backdrop-filter: blur(14px);
}

.hud-kicker { color: var(--soft); font-size: 0.54rem; font-weight: 850; }

.canvas-frame {
  position: relative;
  min-height: clamp(580px, 68vw, 720px);
  overflow: hidden;
  border: 1px solid rgba(163, 189, 255, 0.2);
  border-radius: 25px;
  background: #06091b;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.38), 0 0 0 7px rgba(125, 151, 255, 0.03);
  isolation: isolate;
}

#scene-container, #scene-container canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#scene-container canvas { display: block; touch-action: none; }
.scene-vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at center, transparent 32%, rgba(3, 5, 18, 0.16) 68%, rgba(3, 5, 18, 0.77) 100%); }

.mass-progress {
  position: absolute;
  z-index: 8;
  right: 0;
  bottom: 0;
  left: 0;
  height: 7px;
  overflow: hidden;
  pointer-events: none;
  background: rgba(6, 13, 37, 0.82);
  box-shadow: inset 0 1px 0 rgba(198, 238, 255, 0.16);
}

.mass-progress-fill {
  width: 100%;
  height: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, #557cff 0%, #64dcff 62%, #e9fcff 100%);
  box-shadow: 0 0 12px rgba(100, 220, 255, 0.9), 0 0 24px rgba(85, 124, 255, 0.5);
  transition: transform 180ms ease-out;
}

.danger-alert {
  position: absolute;
  z-index: 4;
  top: 111px;
  left: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 123, 139, 0.35);
  border-radius: 12px;
  color: var(--coral);
  background: rgba(65, 17, 48, 0.68);
  box-shadow: 0 0 25px rgba(255, 70, 123, 0.16);
  backdrop-filter: blur(12px);
  animation: danger-pulse 900ms ease-in-out infinite alternate;
  pointer-events: none;
}

.danger-orb { flex: 0 0 auto; width: 7px; height: 7px; background: var(--coral); box-shadow: 0 0 0 4px rgba(255, 123, 139, 0.13), 0 0 16px rgba(255, 123, 139, 0.9); }
.danger-alert strong, .danger-alert small { display: block; }
.danger-alert strong { font-size: 0.75rem; }
.danger-alert small { margin-top: 2px; color: #d99cac; font-size: 0.61rem; }

.cosmic-event {
  --event-color: var(--cyan);
  position: absolute;
  z-index: 4;
  top: 20px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: min(310px, calc(100% - 32px));
  padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--event-color) 45%, transparent);
  border-radius: 13px;
  color: var(--event-color);
  background: rgba(13, 20, 48, 0.72);
  box-shadow: 0 0 28px color-mix(in srgb, var(--event-color) 18%, transparent);
  backdrop-filter: blur(12px);
  transform: translateX(-50%);
  pointer-events: none;
  animation: event-pulse 1100ms ease-in-out infinite alternate;
}
.event-orb { display: grid; flex: 0 0 auto; width: 24px; height: 24px; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: 0.8rem; }
.cosmic-event strong, .cosmic-event small { display: block; }
.cosmic-event strong { font-size: 0.72rem; }
.cosmic-event small { max-width: 230px; margin-top: 3px; color: var(--muted); font-size: 0.58rem; line-height: 1.35; }
.magnetic-polarity { margin-left: auto; padding: 4px 7px; border: 1px solid currentColor; border-radius: 999px; color: var(--cyan); font-size: 0.52rem; letter-spacing: 0.06em; white-space: nowrap; }
.magnetic-polarity.repelling { color: var(--coral); animation: danger-pulse 520ms ease-in-out infinite alternate; }
.cosmic-event em { margin-left: auto; color: var(--text); font-size: 0.7rem; font-style: normal; font-weight: 850; }
.magnetic-polarity:not([hidden]) + em { margin-left: 0; }

.region-badge {
  --region-color: var(--cyan);
  position: absolute;
  z-index: 4;
  top: 20px;
  right: 20px;
  padding: 7px 10px;
  border: 1px solid color-mix(in srgb, var(--region-color) 35%, transparent);
  border-radius: 999px;
  color: var(--region-color);
  background: rgba(8, 14, 38, 0.48);
  font-size: 0.59rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.mission-tracker {
  position: absolute;
  z-index: 4;
  top: 20px;
  left: 20px;
  width: min(205px, calc(100% - 40px));
  padding: 10px 12px;
  border: 1px solid rgba(184, 207, 255, 0.16);
  border-radius: 12px;
  background: rgba(8, 14, 38, 0.54);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(9px);
  pointer-events: none;
}
.mission-kicker { display: block; color: var(--soft); font-size: 0.48rem; font-weight: 850; letter-spacing: 0.14em; }
.mission-tracker strong, .mission-tracker small { display: block; }
.mission-tracker strong { margin-top: 5px; color: var(--text); font-size: 0.7rem; }
.mission-tracker small { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 0.56rem; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }

.stage-hud {
  position: absolute;
  z-index: 4;
  bottom: 19px;
  left: 20px;
  width: min(270px, calc(100% - 40px));
  padding: 10px 12px 11px;
  border: 1px solid rgba(98, 230, 255, 0.2);
  border-radius: 13px;
  background: rgba(8, 14, 38, 0.66);
  box-shadow: 0 13px 30px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
  pointer-events: none;
}
.stage-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.stage-heading span { color: var(--cyan); font-size: 0.48rem; font-weight: 850; letter-spacing: 0.13em; }
.stage-heading strong { overflow: hidden; color: var(--text); font-size: 0.7rem; text-overflow: ellipsis; white-space: nowrap; }
.stage-hud > small { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 0.57rem; text-overflow: ellipsis; white-space: nowrap; }
.stage-progress { height: 4px; margin-top: 8px; overflow: hidden; border-radius: 99px; background: rgba(184, 207, 255, 0.12); }
.stage-progress div { width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #557cff, var(--cyan)); box-shadow: 0 0 10px rgba(98, 230, 255, 0.6); transform: scaleX(0); transform-origin: left center; transition: transform 180ms ease-out; }

.combo-pill {
  position: absolute;
  z-index: 4;
  right: 22px;
  bottom: 20px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 215, 124, 0.3);
  border-radius: 20px;
  color: var(--gold);
  background: rgba(53, 40, 31, 0.62);
  font-size: 0.65rem;
  font-weight: 850;
  letter-spacing: 0.14em;
  backdrop-filter: blur(10px);
}

.combo-pill strong { margin-left: 5px; font-size: 0.94rem; }
.scene-toast { position: absolute; z-index: 4; top: 128px; left: 50%; color: #eafbff; font-size: 0.82rem; font-weight: 800; text-shadow: 0 0 20px rgba(98, 230, 255, 0.85); transform: translateX(-50%); pointer-events: none; }
.toast-item { margin-top: 5px; animation: toast-rise 900ms ease-out forwards; white-space: nowrap; }
.evolution-banner { position: absolute; z-index: 6; top: 46%; left: 50%; min-width: 210px; padding: 12px 22px; border: 1px solid rgba(98, 230, 255, 0.38); border-radius: 999px; color: var(--text); background: linear-gradient(90deg, rgba(18, 35, 77, 0.18), rgba(20, 46, 91, 0.9), rgba(18, 35, 77, 0.18)); box-shadow: 0 0 42px rgba(98, 230, 255, 0.18); pointer-events: none; text-align: center; transform: translate(-50%, -50%); animation: quick-evolution 650ms ease-out both; }
.evolution-banner span, .evolution-banner strong { display: block; }
.evolution-banner span { color: var(--cyan); font-size: 0.5rem; font-weight: 900; letter-spacing: 0.18em; }
.evolution-banner strong { margin-top: 4px; font-size: 1.08rem; letter-spacing: -0.035em; text-shadow: 0 0 18px rgba(98, 230, 255, 0.6); }

.evolution-popup {
  position: absolute;
  z-index: 9;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 8, 29, 0.54);
  backdrop-filter: blur(10px);
}

.evolution-card {
  width: min(410px, 100%);
  max-height: calc(100% - 16px);
  padding: 30px 30px 27px;
  overflow-y: auto;
  border: 1px solid rgba(98, 230, 255, 0.34);
  border-radius: 21px;
  background: linear-gradient(145deg, rgba(20, 39, 81, 0.96), rgba(16, 22, 59, 0.96));
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.45), 0 0 42px rgba(98, 230, 255, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.09);
  text-align: center;
  animation: evolution-pop 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.evolution-kicker {
  color: var(--cyan);
  font-size: 0.58rem;
  font-weight: 850;
  letter-spacing: 0.17em;
}

.evolution-spark { display: inline-block; margin-right: 5px; color: var(--gold); animation: spark-pulse 800ms ease-in-out infinite alternate; }
.evolution-card h2 { margin-top: 12px; color: var(--text); font-size: clamp(2rem, 5vw, 2.8rem); letter-spacing: -0.08em; }
.evolution-card p { margin: 13px auto 0; max-width: 330px; color: var(--muted); font-size: 0.84rem; line-height: 1.75; }
.evolution-note { margin: 19px 0 23px; padding: 10px 12px; border: 1px solid rgba(184, 207, 255, 0.13); border-radius: 10px; color: #b8c8ee; background: rgba(255, 255, 255, 0.035); font-size: 0.65rem; line-height: 1.55; }
.evolution-choices { display: grid; gap: 7px; margin-top: 17px; text-align: left; }
.evolution-choice { display: block; width: 100%; padding: 9px 11px; border: 1px solid color-mix(in srgb, var(--choice-color) 34%, rgba(184, 207, 255, 0.12)); border-radius: 10px; color: var(--text); background: rgba(255, 255, 255, 0.035); cursor: pointer; text-align: left; transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, opacity 140ms ease; }
.evolution-choice:hover { border-color: var(--choice-color); background: color-mix(in srgb, var(--choice-color) 12%, rgba(255, 255, 255, 0.04)); transform: translateX(3px); }
.evolution-choice.selected { border-color: var(--choice-color); background: color-mix(in srgb, var(--choice-color) 16%, rgba(255, 255, 255, 0.06)); box-shadow: 0 0 18px color-mix(in srgb, var(--choice-color) 15%, transparent); }
.evolution-choice:disabled:not(.selected) { cursor: default; opacity: 0.35; }
.evolution-choice strong, .evolution-choice span { display: block; }
.evolution-choice strong { color: var(--choice-color); font-size: 0.7rem; }
.evolution-choice span { margin-top: 3px; color: var(--muted); font-size: 0.59rem; line-height: 1.4; }
.evolution-card .button { width: 100%; }

.stage-clear-popup { position: absolute; z-index: 10; inset: 0; display: grid; place-items: center; padding: 20px; overflow-y: auto; background: rgba(5, 8, 29, 0.62); backdrop-filter: blur(12px); }
.stage-clear-card { width: min(520px, 100%); padding: 26px; border: 1px solid rgba(98, 230, 255, 0.34); border-radius: 21px; background: linear-gradient(145deg, rgba(20, 39, 81, 0.97), rgba(16, 22, 59, 0.97)); box-shadow: 0 25px 70px rgba(0, 0, 0, 0.48), 0 0 42px rgba(98, 230, 255, 0.13); text-align: center; animation: evolution-pop 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.stage-clear-card h2 { margin-top: 10px; font-size: clamp(1.9rem, 5vw, 2.65rem); letter-spacing: -0.07em; }
.stage-clear-card > p { margin: 8px auto 0; max-width: 390px; color: var(--muted); font-size: 0.76rem; line-height: 1.6; }
.stage-results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 15px; }
.stage-results div { padding: 9px 6px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.03); }
.stage-results span, .stage-results strong { display: block; }
.stage-results span { color: var(--soft); font-size: 0.52rem; }
.stage-results strong { margin-top: 4px; color: var(--text); font-size: 0.66rem; }
.stage-reward-copy { margin-top: 10px; color: var(--gold); font-size: 0.68rem; font-weight: 850; }
.stage-choice-group { margin-top: 13px; text-align: left; }
.stage-choice-group > span { display: block; margin-bottom: 6px; color: var(--soft); font-size: 0.52rem; font-weight: 850; letter-spacing: 0.1em; }
.stage-reward-choices, .stage-route-choices { display: grid; gap: 6px; }
.stage-reward-choices { grid-template-columns: repeat(3, 1fr); }
.stage-route-choices { grid-template-columns: repeat(2, 1fr); }
.stage-reward-choice, .stage-route-choice { min-width: 0; padding: 9px; border: 1px solid rgba(184, 207, 255, 0.14); border-radius: 10px; color: var(--text); background: rgba(255, 255, 255, 0.035); cursor: pointer; text-align: left; transition: border-color 140ms ease, background 140ms ease, transform 140ms ease; }
.stage-reward-choice:hover, .stage-route-choice:hover { border-color: var(--cyan); background: rgba(98, 230, 255, 0.08); transform: translateY(-1px); }
.stage-reward-choice.selected, .stage-route-choice.selected { border-color: var(--cyan); background: rgba(98, 230, 255, 0.13); box-shadow: 0 0 16px rgba(98, 230, 255, 0.1); }
.stage-route-choice.risk.selected { border-color: var(--coral); background: rgba(255, 123, 139, 0.11); }
.stage-reward-choice strong, .stage-reward-choice small, .stage-route-choice strong, .stage-route-choice small { display: block; }
.stage-reward-choice strong, .stage-route-choice strong { overflow: hidden; font-size: 0.65rem; text-overflow: ellipsis; white-space: nowrap; }
.stage-reward-choice small, .stage-route-choice small { margin-top: 3px; color: var(--muted); font-size: 0.53rem; line-height: 1.35; }
.stage-clear-card .evolution-note { margin: 13px 0; }
.stage-clear-card > .button { width: 100%; }

.codex-popup { position: absolute; z-index: 11; inset: 0; display: grid; place-items: center; padding: 20px; overflow-y: auto; background: rgba(4, 7, 25, 0.7); backdrop-filter: blur(13px); }
.codex-card { width: min(720px, 100%); max-height: 100%; padding: 24px; overflow-y: auto; border: 1px solid rgba(184, 207, 255, 0.22); border-radius: 21px; background: linear-gradient(145deg, rgba(18, 31, 69, 0.98), rgba(12, 18, 48, 0.98)); box-shadow: 0 25px 70px rgba(0, 0, 0, 0.5); }
.codex-heading { display: flex; align-items: start; justify-content: space-between; gap: 18px; }
.codex-heading h2 { margin-top: 7px; font-size: 2rem; letter-spacing: -0.06em; }
.codex-heading p { margin-top: 7px; color: var(--muted); font-size: 0.72rem; line-height: 1.55; }
.codex-close { display: grid; flex: 0 0 auto; width: 34px; height: 34px; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: rgba(255, 255, 255, 0.035); cursor: pointer; font-size: 1.25rem; }
.codex-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.codex-item { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-width: 0; padding: 10px; border: 1px solid rgba(184, 207, 255, 0.13); border-radius: 12px; color: var(--text); background: rgba(255, 255, 255, 0.03); text-align: left; }
button.codex-item { cursor: pointer; transition: border-color 140ms ease, background 140ms ease, transform 140ms ease; }
button.codex-item:hover { border-color: var(--cosmetic-color); background: color-mix(in srgb, var(--cosmetic-color) 9%, rgba(255, 255, 255, 0.03)); transform: translateY(-1px); }
.codex-item.selected { border-color: var(--cosmetic-color); background: color-mix(in srgb, var(--cosmetic-color) 13%, rgba(255, 255, 255, 0.03)); }
.codex-item.locked { opacity: 0.52; filter: saturate(0.25); }
.codex-swatch { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid color-mix(in srgb, var(--cosmetic-color) 55%, transparent); border-radius: 50%; color: var(--cosmetic-color); background: radial-gradient(circle, color-mix(in srgb, var(--cosmetic-color) 28%, transparent), transparent 68%); box-shadow: 0 0 18px color-mix(in srgb, var(--cosmetic-color) 14%, transparent); }
.codex-copy { min-width: 0; }
.codex-copy strong, .codex-copy small { display: block; }
.codex-copy strong { overflow: hidden; font-size: 0.67rem; text-overflow: ellipsis; white-space: nowrap; }
.codex-copy small { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 0.54rem; text-overflow: ellipsis; white-space: nowrap; }
.codex-status { color: var(--soft); font-size: 0.5rem; font-weight: 850; letter-spacing: 0.07em; white-space: nowrap; }
.codex-item.selected .codex-status { color: var(--cosmetic-color); }
.codex-card .evolution-note { margin-bottom: 0; }

.evolving-flash::after {
  position: absolute;
  z-index: 7;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 90px rgba(98, 230, 255, 0.55);
  content: "";
  pointer-events: none;
  animation: evolution-flash 500ms ease-out both;
}

.pause-cover, .gameover-cover { position: absolute; z-index: 8; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(4, 7, 25, 0.46); backdrop-filter: blur(9px); }
.cover-card { width: min(390px, 100%); padding: 29px; border: 1px solid rgba(184, 207, 255, 0.2); border-radius: 19px; background: rgba(15, 24, 54, 0.9); box-shadow: 0 22px 60px rgba(0, 0, 0, 0.38); text-align: center; }
.cover-kicker { color: var(--cyan); font-size: 0.57rem; font-weight: 850; }
.cover-card h2 { margin-top: 11px; font-size: 2rem; letter-spacing: -0.06em; }
.cover-card p { margin: 12px auto 21px; color: var(--muted); font-size: 0.83rem; line-height: 1.7; }
.gameover-card .cover-kicker { color: var(--coral); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 22px; }
.result-grid div { padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.03); }
.result-grid span, .result-grid strong { display: block; }
.result-grid span { color: var(--soft); font-size: 0.56rem; letter-spacing: 0.08em; }
.result-grid strong { margin-top: 5px; color: var(--text); font-size: 1.15rem; }

.game-controls { display: grid; grid-template-columns: minmax(300px, 1.35fr) minmax(220px, 0.85fr); gap: 10px; margin-top: 11px; }
.control-card { display: flex; align-items: center; gap: 13px; min-height: 78px; padding: 12px 14px; border-radius: 14px; }
.control-copy { min-width: 0; flex: 1; }
.control-copy strong, .control-copy span { display: block; }
.control-copy strong { margin-top: 4px; color: var(--text); font-size: 0.8rem; }
.control-copy span { margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 0.61rem; text-overflow: ellipsis; white-space: nowrap; }
.how-card { gap: 15px; }
.dpad { display: grid; grid-template-columns: repeat(3, 27px); grid-template-rows: repeat(2, 27px); gap: 3px; flex: 0 0 auto; }
.dpad button { border: 1px solid rgba(184, 207, 255, 0.16); border-radius: 7px; color: var(--muted); background: rgba(255, 255, 255, 0.035); cursor: pointer; line-height: 1; transition: color 120ms ease, background 120ms ease; touch-action: none; }
.dpad button:first-child { grid-column: 2; }
.dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }
.dpad button.active, .dpad button:active { color: var(--cyan); background: rgba(98, 230, 255, 0.13); }
.mobile-joystick { display: none; }
.record-card { display: block; }
.record-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 7px; color: var(--muted); font-size: 0.65rem; }
.record-row strong { color: var(--text); font-size: 0.9rem; }

.page-footer { display: flex; align-items: center; gap: 14px; margin-top: 21px; color: var(--soft); font-size: 0.59rem; font-weight: 800; }
.footer-rule { width: 56px; height: 1px; background: var(--line); }

[hidden] { display: none !important; }

@keyframes danger-pulse { from { transform: translateX(0); } to { transform: translateX(4px); } }
@keyframes event-pulse { from { box-shadow: 0 0 22px color-mix(in srgb, var(--event-color) 13%, transparent); } to { box-shadow: 0 0 34px color-mix(in srgb, var(--event-color) 27%, transparent); } }
@keyframes toast-rise { from { opacity: 0; transform: translateY(10px) scale(0.92); } 18% { opacity: 1; } to { opacity: 0; transform: translateY(-28px) scale(1.03); } }
@keyframes evolution-pop { from { opacity: 0; transform: translateY(16px) scale(0.92); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes evolution-flash { from { opacity: 0.9; } to { opacity: 0; } }
@keyframes quick-evolution { from { opacity: 0; transform: translate(-50%, -30%) scale(0.88); } 24% { opacity: 1; } 72% { opacity: 1; } to { opacity: 0; transform: translate(-50%, -68%) scale(1.04); } }
@keyframes spark-pulse { from { transform: scale(0.84) rotate(-12deg); } to { transform: scale(1.16) rotate(12deg); } }

@media (max-width: 920px) {
  .game-header { align-items: start; flex-direction: column; }
  .header-actions { align-self: stretch; }
  .header-actions .button { flex: 1; }
  .game-controls { grid-template-columns: 1fr 1fr; }
  .record-card { grid-column: 1 / -1; display: flex; align-items: center; gap: 22px; }
  .record-card .hud-kicker { margin-right: auto; }
  .record-row { margin-top: 0; gap: 8px; }
}

@media (max-width: 640px) {
  .gravity-page { width: min(100% - 22px, 560px); padding-top: 22px; }
  .game-header { margin-top: 31px; margin-bottom: 19px; gap: 19px; }
  h1 { font-size: clamp(2.8rem, 14vw, 4.7rem); }
  .game-tagline { font-size: 0.92rem; }
  .canvas-frame { min-height: min(690px, 142vw); border-radius: 19px; }
  .danger-alert { top: 153px; left: 12px; max-width: calc(100% - 24px); }
  .scene-toast { top: 174px; }
  .cosmic-event { top: 13px; min-width: 0; width: calc(100% - 116px); padding: 7px 9px; }
  .cosmic-event small { max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .magnetic-polarity { padding: 3px 5px; font-size: 0.46rem; }
  .region-badge { top: 13px; right: 12px; font-size: 0.52rem; }
  .mission-tracker { top: 67px; left: 12px; width: min(188px, calc(100% - 24px)); padding: 8px 10px; }
  .stage-hud { bottom: 19px; left: 12px; width: min(185px, calc(100% - 170px)); padding: 8px 9px; }
  .stage-heading { display: block; }
  .stage-heading strong { display: block; margin-top: 3px; }
  .stage-results { gap: 4px; }
  .stage-clear-popup { align-items: start; padding: 12px; }
  .stage-clear-card { margin: auto 0; padding: 20px 16px; }
  .evolution-popup { align-items: start; padding: 12px; }
  .evolution-card { margin: auto 0; padding: 22px 17px 19px; }
  .stage-reward-choices { grid-template-columns: 1fr; }
  .codex-popup { align-items: start; padding: 12px; }
  .codex-card { margin: auto 0; padding: 18px 14px; }
  .codex-grid { grid-template-columns: 1fr; }
  .game-controls { grid-template-columns: 1fr; }
  .record-card { grid-column: auto; }
  .control-card { min-height: 73px; }
  .how-card { display: flex; }
  .how-card > .dpad { display: none; }
  .page-footer { font-size: 0.52rem; }
}

@media (max-width: 640px), (any-pointer: coarse) {
  .mobile-joystick {
    position: absolute;
    z-index: 7;
    right: 13px;
    bottom: 19px;
    display: block;
    width: 136px;
    height: 136px;
    touch-action: none;
    user-select: none;
  }
  .joystick-base {
    position: absolute;
    inset: 0;
    border: 1px solid rgba(184, 207, 255, 0.24);
    border-radius: 50%;
    background:
      radial-gradient(circle at 50% 43%, rgba(98, 230, 255, 0.1), transparent 34%),
      radial-gradient(circle, rgba(8, 14, 38, 0.7) 0 55%, rgba(8, 14, 38, 0.36) 56% 72%, rgba(98, 230, 255, 0.08) 73% 74%, rgba(8, 14, 38, 0.2) 75%);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 0 24px rgba(98, 230, 255, 0.08);
    cursor: grab;
    touch-action: none;
  }
  .joystick-base:active { cursor: grabbing; }
  .joystick-base::after {
    position: absolute;
    inset: 17px;
    border: 1px dashed rgba(184, 207, 255, 0.12);
    border-radius: 50%;
    content: "";
    pointer-events: none;
  }
  .joystick-stick {
    --stick-x: 0px;
    --stick-y: 0px;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 58px;
    height: 58px;
    border: 1px solid rgba(190, 248, 255, 0.74);
    border-radius: 50%;
    background: radial-gradient(circle at 34% 28%, #d8fbff 0 5%, #75e8ff 28%, #3777d1 72%, #243a83 100%);
    box-shadow: 0 8px 17px rgba(0, 0, 0, 0.34), 0 0 22px rgba(98, 230, 255, 0.36), inset 0 2px 4px rgba(255, 255, 255, 0.52);
    pointer-events: none;
    transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
    transition: transform 100ms ease-out;
  }
}

.fullscreen-toolbar { display: none; }
body.game-fullscreen { overflow: hidden; }
.canvas-frame.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 20000;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.is-fullscreen .fullscreen-toolbar {
  display: flex;
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 20;
  gap: 8px;
}
.fullscreen-toolbar .button { min-height: 44px; background: rgba(10, 19, 43, 0.94); }
.is-fullscreen .region-badge { top: calc(65px + env(safe-area-inset-top, 0px)); }
.is-fullscreen .mobile-joystick { right: calc(13px + env(safe-area-inset-right, 0px)); bottom: calc(19px + env(safe-area-inset-bottom, 0px)); }
.is-fullscreen .stage-hud { left: calc(12px + env(safe-area-inset-left, 0px)); bottom: calc(19px + env(safe-area-inset-bottom, 0px)); }
.is-fullscreen .mass-progress { bottom: env(safe-area-inset-bottom, 0px); }
.is-fullscreen .evolution-popup, .is-fullscreen .stage-clear-popup, .is-fullscreen .codex-popup { padding-top: calc(68px + env(safe-area-inset-top, 0px)); padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
