:root {
  --game-design-width: 1920;
  --game-design-height: 1080;
  --game-scale: 1;
  --game-grid-size: 80px;
  --game-grid-screen-size: 80px;
  --game-render-width: 100vw;
  --game-render-height: 56.25vw;
  --game-offset-x: 0px;
  --game-offset-y: 0px;
  --game-safe-left: 0px;
  --game-safe-right: 0px;
  --game-safe-top: 0px;
  --game-safe-bottom: 0px;
}

html.game-viewport-managed,
html.game-viewport-managed body {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #020609;
}

html.game-viewport-managed body {
  position: relative;
}

#game-shell {
  position: fixed;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #020609;
  isolation: isolate;
}

#game-background {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 45%, rgba(17, 35, 42, .24), transparent 56%),
    #020609;
}

#game-stage {
  position: absolute;
  z-index: 1;
  container-type: size;
  container-name: game-stage;
  top: 50%;
  left: 50%;
  width: calc(var(--game-design-width) * 1px);
  height: calc(var(--game-design-height) * 1px);
  overflow: hidden;
  transform: translate(-50%, -50%) scale(var(--game-scale));
  transform-origin: 50% 50%;
  background: #050a0d;
  isolation: isolate;
  backface-visibility: hidden;
}

html.game-viewport-managed,
html.game-viewport-managed body,
#game-shell,
#game-background,
#game-stage,
#game-modal-layer {
  min-width: 0;
}

#game-modal-layer {
  position: absolute;
  z-index: 2147483000;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

#game-modal-layer > * {
  pointer-events: auto;
}

html[data-game-viewport-debug="true"] #game-stage {
  outline: max(1px, calc(2px / var(--game-scale))) solid rgba(86, 225, 255, .88);
  outline-offset: max(-2px, calc(-2px / var(--game-scale)));
}

html[data-game-viewport-debug="true"] #game-stage::after {
  position: absolute;
  z-index: 2147483647;
  top: 12px;
  left: 12px;
  padding: 6px 9px;
  border: 1px solid rgba(86, 225, 255, .65);
  color: #c9f8ff;
  background: rgba(0, 17, 23, .82);
  content: "GAME VIEWPORT · 1920 × 1080";
  font: 14px/1.2 Consolas, monospace;
  letter-spacing: .04em;
  pointer-events: none;
}

.game-viewport-fullscreen {
  position: fixed;
  z-index: 2147483646;
  top: 50%;
  right: -12px;
  bottom: auto;
  display: grid;
  width: 38px;
  height: 64px;
  padding: 0 8px 0 0;
  place-items: center;
  border: 1px solid rgba(112, 226, 242, .34);
  border-radius: 8px 0 0 8px;
  color: rgba(218, 249, 255, .82);
  background: rgba(3, 14, 20, .62);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .26), inset 0 0 18px rgba(63, 204, 224, .04);
  font: 20px/1 system-ui, sans-serif;
  cursor: pointer;
  opacity: .48;
  backdrop-filter: blur(8px);
  transform: translateY(-50%);
  transition: right .18s ease, opacity .18s ease, border-color .18s ease, background .18s ease;
}

.game-viewport-fullscreen:hover,
.game-viewport-fullscreen:focus-visible {
  right: 0;
  opacity: 1;
  outline: none;
  border-color: rgba(112, 226, 242, .78);
  background: rgba(5, 25, 34, .9);
}

.game-viewport-fullscreen svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: square;
  stroke-width: 1.6;
}

.game-viewport-size-warning {
  position: fixed;
  z-index: 2147483645;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: none;
  max-width: min(520px, calc(100vw - 88px));
  padding: 10px 14px;
  border: 1px solid rgba(239, 195, 94, .52);
  color: #f7e5b3;
  background: rgba(18, 14, 7, .92);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .34);
  font: 13px/1.45 "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: .02em;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

html[data-game-viewport-too-small="true"] .game-viewport-size-warning {
  display: block;
}

html[data-game-fullscreen="true"] .game-viewport-fullscreen {
  opacity: .28;
}

@media (max-width: 720px), (max-height: 540px) {
  .game-viewport-fullscreen {
    top: 50%;
    right: -12px;
    bottom: auto;
    width: 34px;
    height: 56px;
  }

  .game-viewport-size-warning {
    bottom: 8px;
    max-width: calc(100vw - 64px);
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-viewport-fullscreen {
    transition: none;
  }
}
