:root {
  color-scheme: dark;
  --black: #07070d;
  --panel: #10101d;
  --steel: #292b3b;
  --red: #f12b36;
  --pink: #ff2c89;
  --purple: #8f43ff;
  --blue: #31cfff;
  --cyan: #b9fbff;
}

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

[hidden] { display: none !important; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #030309;
  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%, #2a123f 0, #090714 38%, #030309 72%),
    #030309;
}

#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(--black);
  border-inline: 2px solid #34354d;
  box-shadow: 0 0 0 2px #090911, 0 0 50px #d61d6040, 0 28px 100px #000;
  user-select: none;
}

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

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

#touch-controls {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-top: 3px solid #e52e65;
  background:
    linear-gradient(90deg, #ff244f 0 18%, #7d2b8d 42%, #243c8f 70%, #21bce8 100%) top / 100% 2px no-repeat,
    linear-gradient(180deg, #191827 0, #0a0a13 100%);
  box-shadow: inset 0 8px 24px #000b;
  transition: filter .18s, opacity .18s;
}

#touch-controls::before,
#touch-controls::after {
  content: "";
  position: absolute;
  top: 27px;
  bottom: 10px;
  width: 26%;
  border: 1px solid #45465b;
  background: repeating-linear-gradient(135deg, #171724 0 8px, #11111b 8px 16px);
  clip-path: polygon(8% 0, 100% 0, 92% 100%, 0 100%);
  opacity: .68;
}

#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: #777a96;
  font: 800 clamp(8px, 2.3vw, 11px)/1 monospace;
  letter-spacing: .08em;
  white-space: nowrap;
}

.control-caption b { color: #ff3d70; }

.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);
}

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

.control,
.system-button,
#menu-action {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  touch-action: none;
  color: #fff;
  font-family: inherit;
}

.control {
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid #77798f;
  background: linear-gradient(145deg, #38394b, #141520 64%);
  box-shadow: inset 0 0 0 3px #080810, 0 5px 0 #030307, 0 8px 18px #0009;
  text-shadow: 0 2px #000;
  transition: filter .08s, transform .08s, box-shadow .08s;
}

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

.control.move {
  width: clamp(54px, 17vw, 72px);
  height: clamp(62px, 19vw, 80px);
  border-radius: 9px;
  color: #d9d9e6;
  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%;
}

.control.action > span { font-size: clamp(23px, 7vw, 34px); line-height: 1; }
.control.action small,
.control.plasma small {
  font: 900 clamp(8px, 2.5vw, 11px)/1 monospace;
  letter-spacing: .04em;
}

.control.jump {
  border-color: #7458bc;
  background: linear-gradient(145deg, #4b3975, #191525 66%);
}

.control.attack {
  border-color: #f0445f;
  background: radial-gradient(circle at 34% 27%, #8d2639, #28121b 62%, #100b10);
}

.chain-mark {
  color: #d9dbe1;
  font-family: Georgia, serif;
  font-weight: 900;
  transform: rotate(-18deg);
}

.control.plasma {
  position: absolute;
  z-index: 6;
  top: 35px;
  left: 50%;
  transform: translateX(-50%);
  width: clamp(67px, 21vw, 88px);
  height: clamp(67px, 21vw, 88px);
  grid-template-rows: 1fr auto;
  border: 2px solid #bffaff;
  border-radius: 50%;
  padding: 12% 0 12%;
  background: radial-gradient(circle, #e5ffff 0 7%, #3ee9ff 9% 20%, #1765ed 35%, #101842 67%, #070b18 100%);
  box-shadow: inset 0 0 0 3px #0b1740, 0 0 9px #49efff, 0 0 22px #2476ffcc, 0 5px 0 #02040d;
  animation: plasmaPulse .72s steps(2, end) infinite;
}

.control.plasma:active,
.control.plasma.active { transform: translate(-50%, 4px) scale(.97); }

.plasma-core {
  width: 26px;
  height: 26px;
  border: 4px double white;
  border-radius: 50%;
  box-shadow: 0 0 9px white;
}

@keyframes plasmaPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.48); box-shadow: inset 0 0 0 3px #0b1740, 0 0 15px #c4ffff, 0 0 32px #2476ff, 0 5px 0 #02040d; }
}

.system-button {
  position: absolute;
  z-index: 9;
  top: max(8px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(32px, 9vw, 40px);
  height: clamp(32px, 9vw, 40px);
  padding: 0;
  border: 2px solid #ffffff78;
  border-radius: 7px;
  background: #0b0b18d9;
  box-shadow: 0 3px 0 #030306, 0 0 10px #5d64ff44;
}

#pause { right: max(8px, env(safe-area-inset-right)); gap: 4px; }
#sound { right: calc(max(8px, env(safe-area-inset-right)) + clamp(38px, 11vw, 48px)); font: 900 20px/1 monospace; }
#pause span { display: block; width: 4px; height: 16px; background: #fff; }
.system-button: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: 4px;
  color: #fff;
  background: linear-gradient(180deg, #ee314a, #a60f29);
  box-shadow: inset 0 -5px #650617, 0 5px 0 #020207, 0 0 0 3px #17121f, 0 0 20px #ff285877;
  font: 900 clamp(17px, 5.3vw, 23px)/1 "Arial Black", "Yu Gothic", sans-serif;
  letter-spacing: .06em;
  text-shadow: 2px 2px #5d0717;
}

#menu-action:active {
  transform: translate(-50%, 4px);
  box-shadow: inset 0 -2px #650617, 0 1px 0 #020207, 0 0 0 3px #17121f;
}

#die-games-link {
  position: absolute;
  z-index: 13;
  left: 50%;
  bottom: 3px;
  transform: translateX(-50%);
  color: #c9cad8;
  font: 700 clamp(8px, 2.4vw, 10px)/1.4 "Yu Gothic", sans-serif;
  letter-spacing: .04em;
  text-decoration: none;
  white-space: nowrap;
  text-shadow: 1px 1px #000;
}

#die-games-link:focus-visible {
  outline: 2px solid #72edff;
  outline-offset: 2px;
}

#rotate-message {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 30px;
  color: #f6f0ff;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, #28143d, #080711 70%);
}

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

@media (orientation: landscape) and (max-height: 600px) {
  #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,
  .system-button:hover,
  #menu-action:hover,
  #die-games-link:hover { filter: brightness(1.22); }
}

@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); }
  .control.plasma { top: 29px; }
}
