:root {
  --navy: #141634;
  --win: #1a1d48;
  --gold: #f5c94a;
  --gold-dark: #b97a12;
  --brown: #2a1300;
  --mint: #6fe3c8;
  --text: #f4f1ff;
  --ink: #1b1d3f;
  --px: 4px; /* ドットのふちの太さ */
  --font: "DotGothic16", "Hiragino Sans", monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0e24; }
body { font-family: var(--font); color: var(--text); -webkit-user-select: none; user-select: none; }
img { image-rendering: pixelated; }

#stage { position: fixed; inset: 0; overflow: hidden; overflow: clip; }
#bg {
  position: absolute; inset: 0; transform: scale(1.08); image-rendering: pixelated;
  background:
    linear-gradient(180deg, rgba(10,10,35,.25), rgba(10,10,35,0) 40%, rgba(10,10,35,.35)),
    url("../assets/bg_pixel.png") center / cover no-repeat,
    #1a1b40;
}
#ambient { position: absolute; inset: 0; pointer-events: none; }
#ambient i {
  position: absolute; width: 4px; height: 4px;
  background: #ffe9a0; box-shadow: 0 0 0 2px rgba(255,200,90,.35);
  animation: floatUp steps(24) infinite; opacity: 0;
}
@keyframes floatUp {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-50vh); opacity: 0; }
}

.screen {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: max(16px, env(safe-area-inset-top)) 18px max(16px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; animation: fadeIn .4s steps(4); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* タイトルロゴ（画像） */
.logo-img { width: min(92vw, 460px); height: auto; margin-bottom: -10px; filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }

/* キャラクター */
.hero { width: min(60vw, 280px); aspect-ratio: 1; object-fit: contain; }
.hero.small { width: min(46vw, 210px); }
.bob { animation: bob 2.6s steps(2) infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* ドットの窓（四隅が1段欠けたふち） */
.px-border {
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--bc), 0 var(--px) 0 0 var(--bc),
    calc(var(--px) * -1) 0 0 0 var(--bc), var(--px) 0 0 0 var(--bc);
}
.win {
  --bc: var(--gold);
  position: relative; width: min(calc(100% - 8px), 520px); background: var(--win);
  padding: 16px 18px 14px;
}
.win-name {
  --bc: var(--gold);
  position: absolute; top: -18px; left: 14px; font-size: 15px;
  background: var(--gold); color: var(--ink); padding: 1px 10px;
}
.type-text { margin: 4px 0 0; font-size: 16px; line-height: 1.8; min-height: 3.6em; letter-spacing: .03em; }
.type-text.done::after { content: "▼"; display: inline-block; margin-left: 4px; color: var(--gold); animation: blink .8s steps(1) infinite; font-size: 12px; }
@keyframes blink { 50% { opacity: 0; } }

/* ボタン */
.gbtn {
  --bc: var(--brown);
  font-family: var(--font); font-size: 19px; color: var(--ink); cursor: pointer; border: none; border-radius: 0;
  background: var(--gold); padding: 11px 24px 13px 18px; letter-spacing: .04em;
  box-shadow:
    inset 0 -4px 0 0 var(--gold-dark), inset 0 4px 0 0 #fff0a8,
    0 -4px 0 0 var(--bc), 0 4px 0 0 var(--bc), -4px 0 0 0 var(--bc), 4px 0 0 0 var(--bc),
    0 10px 0 0 rgba(0,0,0,.35);
}
.gbtn:active { transform: translateY(3px); }
.gbtn .cur { display: inline-block; margin-right: 8px; animation: nudge .6s steps(2) infinite; }
@keyframes nudge { 50% { transform: translateX(4px); } }
.gbtn.small { font-size: 15px; padding: 7px 16px 9px 12px; }
.note { margin: 0; font-size: 11px; color: rgba(244,241,255,.8); text-align: center; text-shadow: 0 2px 0 #000; }

/* 入力 */
.win.form { padding: 14px 16px 6px; }
.field-label { display: block; font-size: 13px; color: var(--mint); margin-bottom: 10px; }
.name-in {
  --bc: var(--gold);
  width: calc(100% - 8px); margin: 0 4px; font-family: var(--font); font-size: 26px; color: var(--ink); text-align: center;
  padding: 8px 12px; border: none; border-radius: 0; background: #fffdf4; outline: none;
  -webkit-user-select: text; user-select: text;
}
.name-in:focus { --bc: var(--mint); }
.warn { margin: 8px 0 4px; min-height: 1.3em; color: #ff9db0; font-size: 13px; text-align: center; }

/* 演出と結果 */
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; display: none; image-rendering: pixelated; }
#fxui { position: absolute; inset: 0; display: none; pointer-events: none; }
#fxui.on, #fx.on { display: block; }
.px-canvas { display: block; image-rendering: pixelated; }

.res-logo {
  position: absolute; left: 50%; top: max(8px, env(safe-area-inset-top)); transform: translateX(-50%);
  width: min(58vw, 280px); opacity: 0; transition: opacity .6s steps(4);
}
.res-logo.on { opacity: 1; }

.fx-fairy {
  position: absolute; width: min(42vw, 200px); left: 50%; top: 3%; translate: -50% 0; opacity: 0;
  transition: opacity .3s steps(3);
}
.fx-fairy.in { opacity: 1; animation: fairyIn .8s steps(8) both; }
@keyframes fairyIn {
  0% { transform: translate(60vw, -40vh); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.fx-fairy.hop { opacity: 1; animation: fairyHop .4s steps(4) both; }
@keyframes fairyHop { 50% { transform: translateY(-20px); } }
.fx-fairy.gone { opacity: 0; }
.fx-fairy.side { opacity: 1; width: min(38vw, 180px); left: max(20%, calc(50% - 200px)); top: 57%; }

.fx-impact { position: absolute; z-index: 3; left: 50%; top: 9%; opacity: 0; transform: translate(-50%, 0) scale(0); }
.fx-impact.on { animation: impact 1.4s steps(14) forwards; }
@keyframes impact {
  0% { transform: translate(-50%, 0) scale(0); opacity: 0; }
  20% { transform: translate(-50%, 0) scale(1.25); opacity: 1; }
  35% { transform: translate(-50%, 0) scale(1); }
  80% { transform: translate(-50%, 0) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -20px) scale(1); opacity: 0; }
}

.res-win {
  --bc: transparent;
  position: absolute; left: max(6%, calc(50% - 286px)); right: max(6%, calc(50% - 286px)); top: 18%; height: 36%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.res-win.framed { --bc: var(--gold); background: rgba(26,29,72,.94); }
.fx-label { font-size: clamp(15px, 4.4vw, 20px); color: #fff; opacity: 0; transition: opacity .4s steps(4); text-shadow: 0 2px 0 #000; max-width: 92%; text-align: center; }
.fx-label b { color: var(--gold); font-weight: 400; }
.fx-label.on { opacity: 1; }
.fx-nick { width: 100%; height: 50%; display: flex; align-items: center; justify-content: center; }
.fx-nick canvas { opacity: 0; transform: scale(3); }
.fx-nick canvas.slam { animation: slam .45s steps(6) forwards; }
@keyframes slam {
  0% { opacity: 0; transform: scale(3); filter: brightness(3); }
  60% { opacity: 1; transform: scale(.9); filter: brightness(1.6); }
  100% { opacity: 1; transform: scale(1); filter: brightness(1); }
}
.fx-nick.dance canvas { animation: dance 1s steps(2) infinite; opacity: 1; transform: none; }
.fx-nick.dance canvas:nth-child(even) { animation-delay: -.5s; }
@keyframes dance { 0%,100% { translate: 0 0; } 50% { translate: 0 -4px; } }

.fx-type {
  --bc: var(--brown);
  font-size: clamp(14px, 4vw, 18px); color: var(--ink); background: var(--gold); padding: 4px 14px;
  opacity: 0; transform: translateY(12px); transition: opacity .4s steps(4), transform .4s steps(4); max-width: 90%; text-align: center;
}
.fx-type.on { opacity: 1; transform: none; }

.fx-line {
  --bc: var(--gold);
  position: absolute; right: max(6%, calc(50% - 286px)); top: 61%; width: min(58%, 320px);
  background: var(--win); color: #fff; padding: 10px 12px; font-size: 15px; line-height: 1.6;
  opacity: 0; transition: opacity .3s steps(3);
}
.fx-line.on { opacity: 1; }

.res-foot {
  position: absolute; left: 0; right: 0; bottom: max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  opacity: 0; transition: opacity .4s steps(4); pointer-events: none;
}
.res-foot.on { opacity: 1; pointer-events: auto; }
.shot-hint { margin: 0; font-size: 13px; color: #fff; background: rgba(10,10,30,.75); padding: 5px 12px; }

#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.on { animation: flash .9s steps(6) forwards; }
@keyframes flash { 0% { opacity: 1; } 15% { opacity: 1; } 100% { opacity: 0; } }

#mute {
  position: fixed; top: max(8px, env(safe-area-inset-top)); right: 8px; z-index: 10;
  width: 52px; height: 52px; padding: 0; border: none; background: none; cursor: pointer;
}
#mute img { width: 100%; height: 100%; display: block; }
#mute:active { transform: translateY(2px); }

@media (max-height: 680px) {
  .hero { width: 30vh; }
  .hero.small { width: 22vh; }
  .logo-img { width: min(80vw, 360px); }
  .type-text { font-size: 14px; }
}
