:root {
  color-scheme: dark;
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #08090f;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font);
  color: #fff;
}
#stage {
  position: fixed;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  overflow: hidden;
  --u: 4px;
}
#screen {
  position: absolute;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}
.screen[hidden], #touch[hidden], #pause-btn[hidden], #toast[hidden] { display: none !important; }

button {
  font: inherit;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(#3a4060, #23273a);
  border: 2px solid #0d0e15;
  border-radius: 10px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .25), 0 3px 0 #0d0e15;
  padding: .45em 1em;
  min-height: 40px;
  cursor: pointer;
  font-size: clamp(12px, calc(var(--u) * 3.6), 20px);
  touch-action: manipulation;
}
button:hover { filter: brightness(1.15); }
button:active { transform: translateY(2px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .25), 0 1px 0 #0d0e15; }
button:focus-visible { outline: 3px solid #ffe04a; outline-offset: 2px; }
button.big {
  background: linear-gradient(#ff5a6a, #d01e36);
  font-size: clamp(16px, calc(var(--u) * 6), 30px);
  padding: .35em 1.6em;
  border-radius: 14px;
}
button.sub { background: linear-gradient(#4a5070, #2a2e44); }
button[aria-pressed="false"] { color: #b8bccb; background: linear-gradient(#2a2e3e, #1a1d28); }

/* ---------- タイトル ---------- */
#title {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, calc(var(--u) * 2), 14px);
  padding: calc(var(--u) * 3) max(16px, env(safe-area-inset-right)) calc(var(--u) * 3) max(16px, env(safe-area-inset-left));
  text-align: center;
}
.logo {
  margin: 0;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: rotate(-3deg);
  filter: drop-shadow(0 calc(var(--u) * .8) 0 rgba(0, 0, 0, .35));
}
.logo .super {
  font-size: clamp(14px, calc(var(--u) * 5.5), 34px);
  background: #ff2e44;
  color: #fff;
  padding: .1em .6em;
  border: 3px solid #0d0e15;
  border-radius: 999px;
  margin-bottom: -.2em;
  z-index: 1;
  letter-spacing: .1em;
}
.logo .name {
  font-size: clamp(34px, calc(var(--u) * 17), 110px);
  font-weight: 900;
  color: #fff;
  letter-spacing: .02em;
  -webkit-text-stroke: calc(clamp(34px, calc(var(--u) * 17), 110px) * .09) #0d0e15;
  paint-order: stroke fill;
  text-shadow: 0 .06em 0 #ff2e44, 0 .1em 0 #0d0e15;
}
.guide {
  margin: 0;
  max-width: min(92%, 760px);
  font-size: clamp(11px, calc(var(--u) * 3.5), 18px);
  line-height: 1.5;
  font-weight: 700;
  background: rgba(13, 14, 21, .72);
  border: 2px solid rgba(255, 255, 255, .2);
  border-radius: 12px;
  padding: .5em .9em;
}
.guide.is-speaking { border-color: #ffe04a; box-shadow: 0 0 0 2px rgba(255, 224, 74, .35); }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.row.small button { font-size: clamp(11px, calc(var(--u) * 3), 16px); min-height: 36px; padding: .3em .8em; }
.keys {
  margin: 0;
  font-size: clamp(9px, calc(var(--u) * 2.7), 14px);
  font-weight: 700;
  text-shadow: 0 1px 0 #000, 0 0 4px #000;
}
.keys.touch { display: none; }
body.touch .keys.touch { display: block; }
body.touch .keys.pc { display: none; }
.back {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  top: 8px;
  color: #fff;
  font-size: clamp(11px, calc(var(--u) * 2.8), 14px);
  font-weight: 800;
  text-decoration: none;
  background: rgba(13, 14, 21, .6);
  border-radius: 999px;
  padding: .35em .9em;
}

/* ---------- マップ ---------- */
#map-ui {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
#map-ui > * { pointer-events: auto; }
.stage-name {
  display: flex;
  flex-direction: column;
  background: rgba(13, 14, 21, .78);
  border: 2px solid rgba(255, 255, 255, .25);
  border-radius: 12px;
  padding: .3em .9em;
  font-weight: 900;
}
.stage-name small { color: #ffe04a; font-size: clamp(10px, calc(var(--u) * 3), 14px); letter-spacing: .1em; }
.stage-name strong { font-size: clamp(16px, calc(var(--u) * 6), 30px); }
.stage-name em { font-style: normal; color: #8cf59c; font-size: clamp(10px, calc(var(--u) * 2.8), 14px); }
.map-buttons { display: flex; gap: 8px; align-items: center; }
body.touch .map-buttons { margin-right: calc(var(--h) * .02); }

/* ---------- ステージ紹介 ---------- */
#intro {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  pointer-events: none;
  text-shadow: 0 3px 0 #000;
}
#intro p { margin: .1em; }
.intro-num { color: #ffe04a; font-size: clamp(14px, calc(var(--u) * 5), 30px); letter-spacing: .2em; }
.intro-name { font-size: clamp(26px, calc(var(--u) * 11), 70px); }
.intro-lives { font-size: clamp(14px, calc(var(--u) * 5), 30px); margin-top: calc(var(--u) * 16) !important; }

/* ---------- メニュー ---------- */
#pause, #gameover, #ending {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--u) * 2);
  background: rgba(8, 9, 15, .66);
  text-align: center;
  padding: 12px;
}
#ending { background: rgba(8, 9, 15, .35); }
.screen h2 {
  margin: 0;
  font-size: clamp(26px, calc(var(--u) * 11), 64px);
  font-weight: 900;
  -webkit-text-stroke: 6px #0d0e15;
  paint-order: stroke fill;
  letter-spacing: .04em;
}
#gameover h2 { color: #ff5a6a; }
#ending h2 { color: #ffe04a; }
.screen p { margin: 0; font-weight: 800; font-size: clamp(13px, calc(var(--u) * 4), 22px); text-shadow: 0 2px 0 #000; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: center; }

/* ---------- 声の字幕 ---------- */
#callout {
  position: absolute;
  left: 50%;
  top: calc(var(--h) * .17);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
  z-index: 3;
}
#callout b {
  font-size: clamp(20px, calc(var(--u) * 8), 48px);
  font-weight: 900;
  font-style: italic;
  color: #ffe04a;
  -webkit-text-stroke: 5px #0d0e15;
  paint-order: stroke fill;
  letter-spacing: .03em;
}
#callout span { font-size: clamp(11px, calc(var(--u) * 3.4), 18px); font-weight: 800; text-shadow: 0 2px 0 #000, 0 0 4px #000; }
#callout.show { animation: callout 1.5s ease-out forwards; }
@keyframes callout {
  0% { opacity: 0; transform: translateX(-50%) scale(.6); }
  12% { opacity: 1; transform: translateX(-50%) scale(1.12); }
  22% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

/* ---------- タッチ操作 ---------- */
#touch {
  position: absolute;
  inset: 0;
  z-index: 2;
  touch-action: none;
}
#dpad, #btn-jump, #btn-dash {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
#dpad {
  --s: clamp(96px, calc(var(--h) * .34), 150px);
  width: var(--s);
  height: var(--s);
  left: max(14px, calc(env(safe-area-inset-left) + 6px));
  bottom: max(8px, calc(var(--h) * .03));
  background: radial-gradient(circle, rgba(255, 255, 255, .1) 0 30%, rgba(255, 255, 255, .16) 31% 64%, rgba(255, 255, 255, .07) 65%);
  border: 2px solid rgba(255, 255, 255, .35);
}
#dpad i {
  position: absolute;
  font-style: normal;
  font-size: calc(var(--s) * .2);
  color: rgba(255, 255, 255, .7);
  text-shadow: 0 1px 2px #000;
}
#dpad .l { left: 8%; top: 50%; transform: translateY(-50%); }
#dpad .r { right: 8%; top: 50%; transform: translateY(-50%); }
#dpad .d { bottom: 6%; left: 50%; transform: translateX(-50%); }
#dpad.l-on .l, #dpad.r-on .r, #dpad.d-on .d { color: #ffe04a; transform: translate(0, -50%) scale(1.25); }
#dpad.d-on .d { transform: translateX(-50%) scale(1.25); }
#btn-jump, #btn-dash {
  --s: clamp(64px, calc(var(--h) * .23), 104px);
  width: var(--s);
  height: var(--s);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: calc(var(--s) * .2);
  color: #fff;
  text-shadow: 0 1px 2px #000;
  border: 3px solid rgba(13, 14, 21, .7);
}
#btn-jump {
  right: max(14px, calc(env(safe-area-inset-right) + 6px));
  bottom: calc(max(12px, calc(var(--h) * .05)) + var(--s) * .62);
  background: radial-gradient(circle at 35% 30%, rgba(255, 140, 150, .85), rgba(208, 30, 54, .7));
}
#btn-dash {
  right: calc(max(14px, calc(env(safe-area-inset-right) + 6px)) + var(--s) * 1.12);
  bottom: max(12px, calc(var(--h) * .05));
  background: radial-gradient(circle at 35% 30%, rgba(160, 200, 255, .85), rgba(40, 80, 200, .7));
}
#btn-jump.on, #btn-dash.on { filter: brightness(1.5); transform: scale(.94); }
#pause-btn {
  position: absolute;
  z-index: 4;
  top: 6px;
  right: max(10px, calc(env(safe-area-inset-right) + 4px));
  width: 44px;
  height: 40px;
  min-height: 0;
  padding: 0;
  font-size: 18px;
  border-radius: 10px;
  background: rgba(13, 14, 21, .55);
  opacity: .85;
}
#stage:not([data-screen="play"]) #pause-btn { display: none; }
body:not(.touch) #pause-btn { top: auto; bottom: 8px; }
body.touch #pause-btn { top: auto; bottom: 8px; right: auto; left: 50%; transform: translateX(-50%); }

#toast {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  background: rgba(13, 14, 21, .9);
  border: 2px solid rgba(255, 255, 255, .3);
  border-radius: 12px;
  padding: .5em 1em;
  font-weight: 800;
  font-size: clamp(12px, calc(var(--u) * 3.6), 18px);
  z-index: 5;
  max-width: 90%;
  text-align: center;
}
.noscript { position: absolute; inset: 0; display: grid; place-items: center; }
