:root {
  color-scheme: dark;
  --phone-width: 430px;
  --phone-height: 932px;
  --bg: #020817;
  --ink: #f4fcff;
  --cyan: #25dbff;
  --pink: #ff3f86;
  --gold: #fff25a;
  --line: rgba(117, 230, 255, .42);
  --safe-top: env(safe-area-inset-top);
  --safe-right: env(safe-area-inset-right);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --play-width: min(var(--phone-width), calc(100vw - var(--safe-left) - var(--safe-right)));
  --game-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 0%, rgba(37, 219, 255, .2), transparent 32%),
    radial-gradient(circle at 50% 100%, rgba(255, 63, 134, .16), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

body.nomonori-shell-ready {
  --game-height: calc(100dvh - 64px - var(--safe-top) - var(--safe-bottom));
}

.app {
  width: var(--play-width);
  height: min(var(--phone-height), var(--game-height));
  display: grid;
  grid-template-columns: 0 var(--play-width) 0;
  padding: 0;
  margin: 0 auto;
  overflow: hidden;
}

.left,
.right {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

.game-wrap {
  display: grid;
  place-items: center;
  width: var(--play-width);
  height: min(var(--phone-height), var(--game-height));
  min-width: 0;
  min-height: 0;
}

.stage {
  position: relative;
  width: var(--play-width);
  height: min(var(--phone-height), var(--game-height));
  overflow: hidden;
  background: #061b4a;
  border: 1px solid rgba(37, 219, 255, .5);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .16),
    inset 0 0 90px rgba(37, 219, 255, .16),
    0 0 42px rgba(37, 219, 255, .18);
}

#phaser-game {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  touch-action: none;
}

#phaser-game canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

.sound-button {
  position: absolute;
  z-index: 4;
  top: auto;
  bottom: 16px;
  right: 14px;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 14px;
  animation: hudBreath 1.8s ease-in-out infinite;
}

body.nomonori-shell-ready .sound-button {
  display: none;
}

button,
.help-link {
  appearance: none;
  border: 1px solid rgba(117, 230, 255, .58);
  border-radius: 8px;
  background: linear-gradient(180deg, #147be8, #083579);
  color: var(--ink);
  min-height: 40px;
  padding: 0 12px;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 0 20px rgba(37, 219, 255, .18);
}

button:hover,
.help-link:hover { border-color: rgba(255, 255, 255, .86); }

button:active { transform: translateY(1px); }

button.primary {
  background: linear-gradient(180deg, #ffcf4b, #ff7a1a 55%, #ff3f86);
  color: #07143a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .4);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .18), 0 14px 34px rgba(255, 63, 134, .36);
  animation: startPulse 1.16s ease-in-out infinite;
}

.help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 38%, rgba(37, 219, 255, .24), rgba(5, 13, 41, .86) 62%),
    rgba(5, 12, 36, .78);
  padding: 22px;
}

.overlay[hidden] { display: none; }

.modal {
  width: min(360px, calc(100vw - 42px));
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 242, 90, .22), transparent 42%),
    linear-gradient(180deg, rgba(17, 78, 172, .96), rgba(5, 18, 58, .98));
  border: 1px solid rgba(117, 230, 255, .58);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 0 34px rgba(37, 219, 255, .28), 0 24px 90px rgba(0, 0, 0, .42);
  animation: modalRise .42s cubic-bezier(.2, .9, .18, 1.1), modalGlow 2.4s ease-in-out infinite;
}

.modal h1 {
  color: #ffffff;
  font-size: 30px;
  margin: 0 0 8px;
  text-shadow: 0 0 18px rgba(37, 219, 255, .7);
}

.modal p {
  color: #d5f3ff;
  line-height: 1.5;
  margin: 0 0 16px;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.modal-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.hud-mirror {
  display: none;
}

@keyframes modalRise {
  from {
    opacity: 0;
    transform: translateY(18px) scale(.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modalGlow {
  0%, 100% { box-shadow: 0 0 34px rgba(37, 219, 255, .28), 0 24px 90px rgba(0, 0, 0, .42); }
  50% { box-shadow: 0 0 48px rgba(255, 242, 90, .24), 0 24px 90px rgba(0, 0, 0, .42); }
}

@keyframes startPulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 255, 255, .18), 0 14px 34px rgba(255, 63, 134, .36); }
  50% { box-shadow: 0 0 0 1px rgba(255, 255, 255, .28), 0 14px 42px rgba(255, 242, 90, .38); }
}

@keyframes hudBreath {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 0 20px rgba(37, 219, 255, .18); }
  50% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), 0 0 26px rgba(255, 242, 90, .2); }
}

@media (max-width: 700px) {
  body.nomonori-shell-ready {
    --game-height: calc(100dvh - 58px - var(--safe-top) - var(--safe-bottom));
  }
}
