:root {
  --mg-bg: #0b0c10;
  --mg-panel: #171923;
  --mg-line: #2a2f3d;
  --mg-line-soft: #202532;
  --mg-text: #f5f7fb;
  --mg-muted: #98a2b3;
  --mg-soft: #cdd5e1;
  --mg-purple: #9f7aea;
  --mg-cyan: #22d3ee;
  --mg-gold: #ffdd00;
  --mg-safe-top: env(safe-area-inset-top, 0px);
  --mg-safe-right: env(safe-area-inset-right, 0px);
  --mg-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mg-safe-left: env(safe-area-inset-left, 0px);
  --mg-z-game: 6000;
  --mg-z-header: 7000;
  --mg-z-banner: 8000;
  --mg-z-menu-backdrop: 9000;
  --mg-z-menu: 9010;
  --mg-z-skip: 9020;
}

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

.mg-shell-mount {
  color: var(--mg-text);
  font-family: 'Courier New', Courier, monospace;
  line-height: 1.4;
  position: relative;
  z-index: var(--mg-z-header);
}

.mg-shell-mount a,
.mg-shell-mount button {
  -webkit-tap-highlight-color: transparent;
}

.mg-nojs-link {
  align-items: center;
  background: var(--mg-panel);
  border: 1px solid var(--mg-line);
  color: var(--mg-text);
  display: inline-flex;
  font-size: 0.9rem;
  min-height: 44px;
  padding: 0.5rem 0.85rem;
  text-decoration: none;
}

html.mg-js .mg-nojs-link {
  display: none;
}

.mg-shell--site {
  background: rgba(11, 12, 16, 0.94);
  border-bottom: 1px solid transparent;
  position: sticky;
  top: 0;
  z-index: var(--mg-z-header);
}

.mg-shell--site.mg-shell--scrolled {
  border-bottom-color: var(--mg-line-soft);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

.mg-shell--game {
  inset: 0 0 auto;
  pointer-events: none;
  position: fixed;
  z-index: var(--mg-z-game);
}

.mg-appbar {
  align-items: center;
  display: flex;
  gap: 0.75rem;
  margin: 0 auto;
  max-width: 1120px;
  min-height: 64px;
  padding: var(--mg-safe-top) max(1rem, var(--mg-safe-right)) 0 max(1rem, var(--mg-safe-left));
  position: relative;
  width: 100%;
}

.mg-shell--site .mg-appbar {
  padding-bottom: 0;
}

.mg-shell--game .mg-appbar {
  padding-left: max(0.75rem, var(--mg-safe-left));
  padding-right: max(0.75rem, var(--mg-safe-right));
  pointer-events: none;
}

.mg-brand {
  align-items: center;
  color: var(--mg-text);
  display: inline-flex;
  flex: 0 1 auto;
  gap: 0.55rem;
  min-height: 44px;
  min-width: 0;
  padding: 0.15rem 0;
  text-decoration: none;
  text-transform: uppercase;
}

.mg-brand:focus-visible,
.mg-menu-toggle:focus-visible,
.mg-game-exit:focus-visible,
.mg-menu-close:focus-visible,
.mg-menu-link:focus-visible,
.mg-skip-link:focus-visible {
  outline: 2px solid var(--mg-gold);
  outline-offset: 3px;
}

.mg-brand img {
  filter: drop-shadow(0 0 8px rgba(159, 122, 234, 0.55));
  flex: 0 0 auto;
  height: 40px;
  object-fit: contain;
  width: 40px;
}

.mg-brand span {
  display: block;
  font-size: clamp(0.76rem, 2vw, 0.94rem);
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1.15;
  max-width: 12rem;
}

.mg-brand b {
  color: var(--mg-cyan);
}

.mg-shell--game .mg-brand {
  display: none;
}

.mg-game-exit {
  align-items: center;
  background: rgba(11, 12, 16, 0.82);
  border: 1px solid rgba(205, 213, 225, 0.35);
  border-radius: 999px;
  color: var(--mg-text);
  display: inline-flex;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  margin-right: auto;
  min-height: 44px;
  padding: 0.5rem 0.85rem;
  pointer-events: auto;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
}

.mg-game-exit:hover,
.mg-game-exit:active {
  border-color: var(--mg-cyan);
  color: var(--mg-cyan);
}

.mg-menu-toggle {
  align-items: center;
  background: rgba(23, 25, 35, 0.95);
  border: 1px solid var(--mg-line);
  border-radius: 999px;
  color: var(--mg-text);
  cursor: pointer;
  display: inline-flex;
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  gap: 0.5rem;
  justify-content: center;
  letter-spacing: 0.08em;
  min-height: 44px;
  min-width: 78px;
  padding: 0.5rem 0.85rem;
  pointer-events: auto;
  text-transform: uppercase;
}

.mg-menu-toggle:hover,
.mg-menu-toggle[aria-expanded="true"] {
  background: rgba(34, 211, 238, 0.12);
  border-color: var(--mg-cyan);
  color: var(--mg-cyan);
}

.mg-menu-icon {
  display: inline-grid;
  gap: 3px;
  width: 16px;
}

.mg-menu-icon::before,
.mg-menu-icon::after,
.mg-menu-icon span {
  background: currentColor;
  content: '';
  display: block;
  height: 2px;
  width: 16px;
}

.mg-menu-shell {
  min-width: 0;
}

.mg-menu-shell[hidden] {
  display: none;
}

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

.mg-menu-panel {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  min-width: 0;
}

.mg-menu-heading,
.mg-menu-close {
  display: none;
}

.mg-primary-nav {
  align-items: center;
  display: flex;
  gap: 0.35rem;
}

.mg-menu-link {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--mg-muted);
  display: inline-flex;
  font-size: 0.78rem;
  justify-content: center;
  letter-spacing: 0.08em;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
}

.mg-menu-link:hover,
.mg-menu-link:focus-visible,
.mg-menu-link[aria-current="page"],
.mg-menu-link[aria-current="location"] {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--mg-line);
  color: var(--mg-text);
  outline: none;
}

.mg-menu-link[aria-current="page"],
.mg-menu-link[aria-current="location"] {
  box-shadow: inset 0 -2px 0 var(--mg-cyan);
}

.mg-skip-link {
  background: var(--mg-gold);
  border-radius: 999px;
  color: #11131a;
  font-size: 0.8rem;
  font-weight: 700;
  left: 0.75rem;
  padding: 0.65rem 0.9rem;
  position: fixed;
  text-decoration: none;
  text-transform: uppercase;
  top: 0.75rem;
  transform: translateY(-150%);
  z-index: var(--mg-z-skip);
}

.mg-skip-link:focus-visible {
  transform: translateY(0);
}

body.mg-menu-open {
  overflow: hidden;
}

/* Lift the shell's stacking context above install prompts and game overlays while open. */
body.mg-menu-open .mg-shell--site,
body.mg-menu-open .mg-shell--game {
  z-index: var(--mg-z-menu-backdrop);
}

body.mg-has-site-shell .wrap {
  max-width: 760px;
  overflow-wrap: anywhere;
  padding-left: max(1rem, var(--mg-safe-left));
  padding-right: max(1rem, var(--mg-safe-right));
  width: 100%;
}

body.mg-has-site-shell .wrap > h1,
body.mg-has-site-shell .wrap > h2,
body.mg-has-site-shell .wrap p,
body.mg-has-site-shell .wrap li {
  overflow-wrap: anywhere;
}

body.mg-has-site-shell footer a {
  align-items: center;
  display: inline-flex;
  min-height: 44px;
  padding: 0.45rem 0.2rem;
}

body.mg-has-site-shell .btn {
  min-height: 44px;
}

body.mg-has-site-shell .modal-back {
  padding: max(1rem, var(--mg-safe-top)) max(1rem, var(--mg-safe-right)) max(1rem, var(--mg-safe-bottom)) max(1rem, var(--mg-safe-left));
}

body.mg-has-site-shell .modal {
  max-height: calc(100dvh - 2rem - var(--mg-safe-top) - var(--mg-safe-bottom));
  overflow-y: auto;
}

body.mg-has-site-shell .toast {
  bottom: max(1rem, calc(1rem + var(--mg-safe-bottom)));
}

body.mg-has-game-shell .mg-menu-shell {
  pointer-events: auto;
}

@media (min-width: 768px) {
  /* Keep the desktop navigation in the app bar instead of creating a second row. */
  .mg-shell--site .mg-menu-shell,
  .mg-shell--game .mg-menu-shell {
    position: absolute;
    right: max(1rem, calc((100% - 1120px) / 2 + 1rem));
    top: 0;
  }

  .mg-shell--site .mg-menu-panel,
  .mg-shell--game .mg-menu-panel {
    min-height: 64px;
  }
}

@media (max-width: 767px) {
  .mg-shell--site .mg-appbar {
    min-height: calc(64px + var(--mg-safe-top));
  }

  .mg-shell--site .mg-brand span {
    max-width: 10rem;
  }

  .mg-shell--game .mg-appbar {
    min-height: calc(60px + var(--mg-safe-top));
  }

  .mg-shell--game .mg-menu-toggle {
    margin-left: auto;
  }

  .mg-menu-shell {
    background: rgba(3, 4, 7, 0.78);
    inset: 0;
    padding: var(--mg-safe-top) var(--mg-safe-right) var(--mg-safe-bottom) var(--mg-safe-left);
    position: fixed;
    z-index: var(--mg-z-menu-backdrop);
  }

  .mg-menu-panel {
    align-items: stretch;
    background: var(--mg-panel);
    border-left: 1px solid var(--mg-line);
    box-shadow: -18px 0 48px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 100%;
    margin-left: auto;
    max-width: 24rem;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
    width: min(100%, 24rem);
  }

  .mg-menu-heading {
    color: var(--mg-cyan);
    display: block;
    font-size: 0.78rem;
    letter-spacing: 0.16em;
    margin: 0;
    text-transform: uppercase;
  }

  .mg-menu-close {
    align-items: center;
    background: transparent;
    border: 1px solid var(--mg-line);
    border-radius: 999px;
    color: var(--mg-text);
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-size: 0.76rem;
    font-weight: 700;
    justify-content: center;
    letter-spacing: 0.08em;
    min-height: 44px;
    padding: 0.5rem 0.8rem;
    text-transform: uppercase;
  }

  .mg-menu-head {
    align-items: center;
    display: flex;
    gap: 0.8rem;
    justify-content: space-between;
  }

  .mg-primary-nav {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .mg-menu-link {
    border-radius: 10px;
    font-size: 0.92rem;
    justify-content: flex-start;
    min-height: 48px;
    padding: 0.75rem 0.9rem;
  }

  .mg-menu-link[aria-current="page"],
  .mg-menu-link[aria-current="location"] {
    box-shadow: inset 3px 0 0 var(--mg-cyan);
  }
}

@media (max-width: 359px) {
  .mg-brand span {
    font-size: 0.7rem;
    max-width: 8rem;
  }

  .mg-menu-toggle {
    min-width: 44px;
    padding-left: 0.6rem;
    padding-right: 0.6rem;
  }

  .mg-menu-toggle > span:last-child {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mg-menu-shell,
  .mg-menu-panel,
  .mg-shell--site {
    scroll-behavior: auto;
    transition: none !important;
  }
}

/* Hide replaced top-level escapes after the shared shell has initialized. */
body.mg-has-site-shell .mg-legacy-top-nav,
body.mg-has-site-shell .mg-legacy-back,
body.mg-has-game-shell .mg-legacy-back,
body.mg-has-game-shell .mg-legacy-game-masthead {
  display: none !important;
}

/* Keep page-owned action bars visible; only the marked escape link is removed. */
body.mg-has-game-shell .mg-legacy-game-nav .mg-legacy-back {
  display: none !important;
}
