:root {
  color-scheme: dark;
  --ink: #11142b;
  --paper: #fff9ea;
  --pink: #ff3f83;
  --yellow: #ffd83d;
  --violet: #7062c8;
  --cyan: #6beaff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #080b1b;
  font-family: "Arial Black", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 18%, #4b1d5f 0, #16132f 34%, #080b1b 68%),
    #080b1b;
}

#game-shell {
  position: relative;
  display: grid;
  grid-template-rows: 7fr 3fr;
  width: min(100vw, calc(100svh / 2), 440px);
  height: min(100svh, calc(100vw * 2), 880px);
  aspect-ratio: 1 / 2;
  overflow: hidden;
  background: var(--ink);
  border-inline: 2px solid #4b4f7e;
  box-shadow: 0 0 0 2px #090b20, 0 0 42px #ff3f8340, 0 26px 90px #000c;
  user-select: none;
}

#game-viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #080b1b;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#bgm, #opening-bgm, #ending-bgm { display: none; }

#unlock-panel {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: start center;
  padding: 12px;
  background: #080b1bf2;
  overflow: auto;
  touch-action: pan-y;
}
html:has(#unlock-panel:not([hidden])), body:has(#unlock-panel:not([hidden])) { touch-action: pan-y; }
#unlock-form {
  width: 100%;
  max-width: 350px;
  padding: clamp(13px, 3vw, 21px);
  border: 2px solid var(--pink);
  background: #11142b;
  box-shadow: 0 0 0 3px #050712;
  font-size: 13px;
  line-height: 1.7;
}
.unlock-eyebrow { margin: 0; color: var(--yellow); font: 900 13px monospace; }
#unlock-form h1 { margin: 7px 0 10px; font-size: clamp(17px, 4.8vw, 22px); }
#unlock-form p { margin: 7px 0 12px; }
#unlock-form label { display: block; margin-top: 14px; color: var(--yellow); font-weight: 800; }
#unlock-password {
  display: block;
  width: 100%;
  min-height: 43px;
  margin-top: 5px;
  border: 2px solid #8a82c7;
  border-radius: 0;
  padding: 8px;
  background: #080b1b;
  color: #fff;
  font: 16px monospace;
  user-select: text;
  touch-action: auto;
}
#unlock-error { color: #ff9fbd; min-height: 20px; font-size: 12px; }
#unlock-submit, #unlock-back, #credits-back {
  appearance: none;
  cursor: pointer;
  width: 100%;
  min-height: 44px;
  padding: 9px;
  border: 2px solid var(--paper);
  background: var(--yellow);
  color: var(--ink);
  font: 900 14px "Yu Gothic", sans-serif;
  touch-action: manipulation;
}
#unlock-submit:disabled { opacity: .6; cursor: wait; }
#unlock-back { background: transparent; color: var(--paper); }
#unlock-form .unlock-note { color: #bcb5db; font-size: 10px; }
#credits-back { position: absolute; z-index: 12; bottom: 18px; left: 8%; width: 84%; }
#game-shell[data-state="credits"], #game-shell[data-state="creditsdone"], #game-shell[data-state="ending"] { background: #000; }
#game-shell[data-state="unlock"] #sound { visibility: hidden; }

#opening {
  position: absolute;
  inset: 0;
  z-index: 10;
  cursor: pointer;
}

#opening-skip, #opening-next {
  appearance: none;
  font-family: "Arial Black", "Yu Gothic", sans-serif;
  cursor: pointer;
  touch-action: manipulation;
  color: var(--paper);
}

#opening-skip {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 10px;
  padding: 10px 12px;
  border: 2px solid var(--violet);
  background: #11142bed;
  font: 900 12px monospace;
  min-height: 36px;
}

#opening-next {
  position: absolute;
  bottom: 4%;
  left: 4%;
  width: 92%;
  min-height: 25%;
  padding: 12px 14px 30px;
  display: block;
  text-align: left;
  border: 3px solid var(--paper);
  border-radius: 2px;
  background: #10142bf5;
  box-shadow: 0 0 0 3px #11142b, 0 5px 0 #0008;
}

#opening-next:focus-visible, #opening-skip:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
#opening-speaker { display: block; margin-bottom: 8px; color: var(--yellow); font-size: clamp(13px, 3.8vw, 17px); }
#opening-line { display: block; font-size: clamp(15px, 4.2vw, 19px); line-height: 1.65; font-weight: 700; }
.opening-prompt { position: absolute; bottom: 9px; right: 12px; color: #bcb5db; font: 700 9px monospace; letter-spacing: .05em; }
.opening-prompt b { color: var(--pink); margin-left: 7px; }

#stage-start {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: #10142b66;
  pointer-events: none;
}
#stage-start strong {
  width: 100%;
  padding: 22px 5px;
  text-align: center;
  color: var(--yellow);
  background: #10142be8;
  border-block: 3px solid var(--pink);
  font: 900 clamp(18px, 5.2vw, 25px) monospace;
}

#touch-controls {
  position: relative;
  z-index: 8;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-top: 3px solid var(--pink);
  background:
    linear-gradient(90deg, var(--yellow) 0 18%, var(--pink) 42%, var(--violet) 72%, var(--cyan) 100%) top / 100% 2px no-repeat,
    repeating-linear-gradient(135deg, #181a36 0 12px, #11142b 12px 24px);
  box-shadow: inset 0 8px 24px #050715bb;
  transition: filter .18s, opacity .18s;
  pointer-events: none;
}

#touch-controls::before,
#touch-controls::after {
  content: "";
  position: absolute;
  top: 29px;
  bottom: 11px;
  width: 27%;
  border: 1px solid #575b88;
  background: linear-gradient(180deg, #292d55b8, #10132bb8);
  clip-path: polygon(8% 0, 100% 0, 92% 100%, 0 100%);
}

#touch-controls::before { left: -7px; }
#touch-controls::after { right: -7px; transform: scaleX(-1); }

.control-caption {
  position: absolute;
  z-index: 2;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 5px;
  color: #8f91b9;
  font: 800 clamp(8px, 2.3vw, 11px)/1 monospace;
  letter-spacing: .08em;
  white-space: nowrap;
}

.control-caption b { color: var(--pink); }

.move-pad,
.action-pad {
  position: absolute;
  z-index: 3;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: clamp(7px, 2vw, 11px);
  pointer-events: none;
}

.move-pad { left: max(12px, env(safe-area-inset-left)); }
.action-pad { right: max(12px, env(safe-area-inset-right)); }

.control,
#pause,
#sound,
#menu-action {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  touch-action: none;
  font-family: inherit;
}

.control {
  pointer-events: auto;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid #fff9;
  color: white;
  background: linear-gradient(145deg, #454b78, #1a1e40 66%);
  box-shadow: inset 0 0 0 3px #0b0d22cc, 0 5px 0 #080a1e, 0 8px 16px #0008;
  text-shadow: 0 2px #080a1e;
  transition: filter .08s, transform .08s, box-shadow .08s;
}

.control:active,
.control.active {
  transform: translateY(4px) scale(.97);
  filter: brightness(1.3);
  box-shadow: inset 0 0 0 3px #0b0d22cc, 0 1px 0 #080a1e, 0 3px 8px #0008;
}

.control.move {
  width: clamp(54px, 17vw, 72px);
  height: clamp(62px, 19vw, 80px);
  border-radius: 10px;
  font-size: clamp(22px, 7vw, 32px);
}

.control.action {
  width: clamp(64px, 20vw, 82px);
  height: clamp(70px, 22vw, 90px);
  grid-template-rows: 1fr auto;
  border-radius: 50%;
  padding: 12% 0 13%;
  line-height: 1;
}

.control.action small {
  font: 900 clamp(8px, 2.5vw, 11px)/1 monospace;
  letter-spacing: .04em;
}

.control.jump {
  border-color: #b7b2ff;
  background: linear-gradient(145deg, #514b91, #1b1c42 66%);
}

.control.jump .icon { font-size: clamp(23px, 7vw, 34px); }

.control.attack {
  border-color: #ff92b9;
  background: radial-gradient(circle at 34% 27%, #8d315c, #2b1734 63%, #120e21);
}

.tube-icon {
  width: 66%;
  height: 59%;
  background: url("./assets/weapon-tube.webp") center / contain no-repeat;
  transform: rotate(8deg);
  filter: drop-shadow(0 0 5px #fff) drop-shadow(0 2px 1px #080a18);
}

#system-controls {
  position: absolute;
  z-index: 11;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 7px;
  pointer-events: none;
}

#pause,
#sound {
  pointer-events: auto;
  width: clamp(32px, 9vw, 40px);
  height: clamp(32px, 9vw, 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  border: 2px solid #fff8;
  border-radius: 8px;
  color: white;
  background: #11142be6;
  box-shadow: 0 3px 0 #06081a, 0 0 10px #7062c866;
}

#sound { font: 900 20px/1 monospace; }
#pause span { display: block; width: 4px; height: 16px; background: white; }
#pause:active,
#sound:active { transform: translateY(2px); }

#menu-action {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  min-width: min(265px, 78vw);
  min-height: 50px;
  padding: 10px 22px;
  border: 3px solid #fff;
  border-radius: 6px;
  color: #17152d;
  background: var(--yellow);
  box-shadow: inset 0 -5px #e39b18, 0 5px 0 #090b20, 0 0 0 3px #17152d, 0 0 22px #ff3f8366;
  font: 900 clamp(17px, 5.3vw, 23px)/1 "Arial Black", "Yu Gothic", sans-serif;
  letter-spacing: .06em;
  text-shadow: 1px 1px #fff7;
}

#menu-action:active {
  transform: translate(-50%, 4px);
  box-shadow: inset 0 -2px #e39b18, 0 1px 0 #090b20, 0 0 0 3px #17152d;
}

#rotate-message {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 32px;
  color: var(--paper);
  text-align: center;
  background: radial-gradient(circle at 50% 40%, #3d1e50, #080b1b 70%);
}

.phone-icon { font-size: 60px; color: var(--yellow); }
#rotate-message strong { font-size: 17px; line-height: 1.6; }

@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
  #game-shell {
    width: 100vw;
    height: 100svh;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
  }
  #rotate-message { display: grid; }
}

@media (hover: hover) and (pointer: fine) {
  .control:hover,
  #pause:hover,
  #sound:hover,
  #menu-action:hover { filter: brightness(1.17); }
}

@media (max-height: 680px) {
  .move-pad,
  .action-pad { bottom: max(10px, env(safe-area-inset-bottom)); }
  .control.move { height: clamp(55px, 17vw, 68px); }
  .control.action { height: clamp(62px, 19vw, 76px); }
}
