@font-face {
  font-family: Bangers;
  src: url("fonts/Bangers-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Lilita One";
  src: url("fonts/LilitaOne-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --gold: #ffd23a;
  --ink: #140c10;
  --cream: #fff6e0;
  --red: #e23a18;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #07060c;
  color: var(--cream);
  font-family: "Noto Sans", "Segoe UI", "Helvetica Neue", sans-serif;
}
[hidden] { display: none !important; }
button, input { font: inherit; }

.test-banner {
  position: absolute;
  z-index: 40;
  top: 0;
  left: 0;
  right: 0;
  margin: 0;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: #ffd23a;
  color: #1a0902;
  text-align: center;
  font-weight: 900;
  letter-spacing: 0.01em;
  font-size: 15px;
  line-height: 1.25;
}
.test-banner[hidden] { display: none !important; }
body.test-mode #overlay { padding-top: calc(52px + env(safe-area-inset-top)); }

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  flex: 1;
  min-height: 0;
  position: relative;
  z-index: 1;
}
canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#audio-gate {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  border: 0;
  background: rgba(8, 4, 12, 0.94);
  color: #fff6e0;
  text-align: center;
}
#audio-gate[hidden] { display: none !important; }
#audio-gate .speaker { font-size: 64px; line-height: 1; }
#audio-gate strong {
  font-family: Bangers, Impact, sans-serif;
  font-size: clamp(36px, 10vw, 56px);
  font-weight: 400;
  letter-spacing: 1px;
  color: #ffe56a;
}
#audio-gate span:last-child { font-weight: 800; color: #ffe9c4; }
#audio-gate .speaker.playing,
#mute.playing,
#audio-hint.playing {
  animation: speaker-pop 0.22s ease-out;
}
@keyframes speaker-pop {
  40% { transform: scale(1.22); filter: brightness(1.4); }
}
#audio-hint {
  position: absolute;
  z-index: 20;
  top: calc(48px + env(safe-area-inset-top));
  left: 8px;
  right: auto;
  max-width: calc(100% - 88px);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 8px 4px 12px;
  border-radius: 999px;
  border: 2px solid #ffe56a;
  background: #3a1208;
  color: #ffe56a;
  font-family: "Lilita One", Impact, sans-serif;
  letter-spacing: 0.03em;
  font-size: 14px;
  pointer-events: auto;
}
#audio-hint .x {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffe56a;
  color: #1a0902;
  font-size: 20px;
  line-height: 28px;
  text-align: center;
}
#audio-hint[hidden] { display: none !important; }
#audio-debug {
  position: absolute;
  z-index: 21;
  top: calc(92px + env(safe-area-inset-top));
  left: 8px;
  right: 72px;
  margin: 0;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.82);
  color: #d7ffd0;
  font: 10px/1.35 ui-monospace, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}
#audio-debug[hidden] { display: none !important; }
audio.sfx-slot {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
#bgm-btn, #mute {
  position: absolute;
  z-index: 6;
  top: calc(8px + env(safe-area-inset-top));
  min-width: 64px;
  height: 36px;
  border-radius: 999px;
  border: 2px solid var(--gold);
  background: rgba(10, 6, 12, 0.72);
  color: var(--gold);
  font-family: "Lilita One", Impact, sans-serif;
  letter-spacing: 0.06em;
  font-size: 14px;
}
#bgm-btn { right: 80px; }
#mute { right: 8px; }

#controls {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 136px 1fr;
  gap: 8px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(#120a14, #07060c 40%);
}
.move, .acts { display: grid; gap: 8px; }
.move { grid-template-columns: 1fr 1fr; }
.acts { grid-template-columns: 1fr 1fr; }

.ctrl {
  position: relative;
  min-height: 64px;
  border-radius: 16px;
  border: 3px solid #ffe08a;
  background: radial-gradient(circle at 50% 20%, #4a2c22, #140c10 72%);
  color: var(--cream);
  font-family: "Lilita One", Impact, sans-serif;
  font-size: clamp(15px, 4.2vw, 20px);
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 #000;
  box-shadow: 0 4px 0 #5a3010, inset 0 0 12px rgba(255, 122, 24, 0.25);
  touch-action: none;
}
.move-btn { font-size: 28px; }
.ctrl.held, .ctrl:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #5a3010, inset 0 0 12px rgba(255, 122, 24, 0.25);
}
.ctrl.block { border-color: #8be9ff; }
.ctrl.super { color: #ffe9a8; }
.ctrl.super.ready {
  border-color: #fff1a8;
  background: radial-gradient(circle at 50% 20%, #ffb000, #c2410c 62%, #3a0a00);
  animation: pulse 0.55s ease-in-out infinite;
}
.meter {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 6px;
  height: 5px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.meter b {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffb000, #ff4d00);
}
@keyframes pulse {
  50% { filter: brightness(1.18); }
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: linear-gradient(180deg, rgba(5, 3, 10, 0.05) 0%, rgba(5, 3, 10, 0.2) 38%, rgba(5, 3, 10, 0.88) 68%, rgba(5, 3, 10, 0.94) 100%);
  overflow: auto;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
}
.panel {
  width: min(520px, 100%);
  text-align: center;
}
.brand {
  margin: 0 0 4px;
  font-family: "Lilita One", Impact, sans-serif;
  letter-spacing: 0.16em;
  color: var(--gold);
  font-size: 14px;
}
h1 {
  margin: 0 0 8px;
  font-family: Bangers, Impact, sans-serif;
  font-weight: 400;
  font-size: clamp(40px, 12vw, 76px);
  line-height: 0.9;
  letter-spacing: 1px;
  color: #ffe56a;
  -webkit-text-stroke: 1px #1a0902;
  text-shadow: 0 4px 0 #c2410c, 0 0 18px rgba(255, 122, 24, 0.45);
}
.lead, .note, .howto, .keys {
  font-weight: 700;
}
.lead {
  margin: 0 0 12px;
  font-size: 17px;
  line-height: 1.35;
}
.note {
  margin: 10px 0;
  color: #ffe9c4;
  font-size: 15px;
  line-height: 1.4;
}
.howto {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  text-align: left;
  font-size: 14px;
  line-height: 1.45;
  color: #ffe9c4;
}
.howto li { margin: 4px 0 4px 0; }
.howto li::before { content: "▸ "; color: var(--gold); }
.keys {
  margin: 10px 0 0;
  font-size: 12px;
  color: #cbbda6;
}
.go, .ghost {
  display: block;
  width: 100%;
  margin-top: 12px;
  min-height: 58px;
  border-radius: 16px;
  border: 3px solid #fff1a8;
  font-family: Bangers, Impact, sans-serif;
  font-size: 32px;
  letter-spacing: 1px;
  cursor: pointer;
}
.go {
  background: linear-gradient(#ffd76a, #ff8a1e);
  color: #2a0c08;
  text-shadow: none;
  box-shadow: 0 5px 0 #8a3a08;
}
.go:active { transform: translateY(3px); box-shadow: 0 2px 0 #8a3a08; }
.ghost {
  background: transparent;
  color: var(--cream);
  font-size: 24px;
  border-color: #8be9ff;
}

.ticket {
  margin: 8px auto 0;
  padding: 10px 12px 12px;
  border-radius: 16px;
  background:
    radial-gradient(circle at 0 50%, transparent 10px, #fff8ea 11px) left / 18px 100% repeat-y,
    #fff8ea;
  color: #2a120c;
  box-shadow: 0 6px 0 #c2410c;
}
.ticket span, .ticket time {
  display: block;
  font-family: "Lilita One", Impact, sans-serif;
  letter-spacing: 0.08em;
  font-size: 13px;
  text-transform: uppercase;
}
.ticket strong {
  display: block;
  margin: 2px 0;
  font-family: Bangers, Impact, sans-serif;
  font-size: clamp(40px, 12vw, 64px);
  letter-spacing: 2px;
  color: var(--red);
  line-height: 1;
  user-select: text;
  -webkit-user-select: text;
}
.ticket time { letter-spacing: 0; text-transform: none; font-family: "Noto Sans", sans-serif; font-weight: 800; }

.scoreline, .rankline {
  margin: 6px 0;
  font-family: Bangers, Impact, sans-serif;
  font-weight: 400;
  letter-spacing: 1px;
  color: #ffe56a;
  font-size: clamp(26px, 7vw, 36px);
  line-height: 1;
}
.rankline { font-size: clamp(18px, 4.6vw, 24px); line-height: 1.25; }
.nick-label {
  display: block;
  margin-top: 8px;
  font-weight: 800;
  text-align: left;
}
.nick {
  display: block;
  width: 100%;
  margin-top: 6px;
  min-height: 52px;
  border-radius: 14px;
  border: 3px solid var(--gold);
  background: #1a1218;
  color: var(--cream);
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  touch-action: auto;
  user-select: text;
  -webkit-user-select: text;
}
.prizes, .board-list { text-align: left; }
.prizes { list-style: none; margin: 8px 0; padding: 0; font-weight: 800; }
.prizes li { margin: 4px 0; }
.board-list { margin-top: 8px; }
.board-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 2px 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 246, 224, 0.16);
  font-weight: 800;
}
.board-row span:last-child {
  grid-column: 2;
  font-weight: 700;
  color: #ffe9c4;
  font-size: 13px;
}
#screen-win h1, #screen-board h1, #screen-select h1 { font-size: clamp(34px, 9vw, 52px); }
#overlay.selecting {
  align-items: center;
  background: rgba(8, 4, 12, 0.78);
}
#screen-select {
  margin-top: 8px;
  padding: 14px 12px 8px;
  border-radius: 18px;
  background: #140c12;
  border: 2px solid rgba(255, 210, 58, 0.55);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}
#screen-select .lead { font-size: 15px; }
#screen-select .note { font-size: 13px; }
.roster {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 4px 0 2px;
}
.fighter-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-height: 0;
  padding: 10px 8px 12px;
  border-radius: 18px;
  border: 3px solid #5c4030;
  background: radial-gradient(circle at 50% 0%, #4a2a1c, #12080e 72%);
  color: var(--cream);
  cursor: pointer;
  text-align: center;
}
.fighter-card img {
  width: min(104px, 28vw);
  height: min(104px, 28vw);
  object-fit: cover;
  object-position: center 22%;
  border-radius: 50%;
  border: 3px solid #ffd23a;
  background: #1a0c10;
  margin-bottom: 4px;
}
.fighter-card[data-fighter="calu"] img { object-position: center 12%; }
.fighter-card[data-fighter="enoch"] img { object-position: center 28%; }
.fighter-card strong {
  font-family: Bangers, Impact, sans-serif;
  font-size: clamp(26px, 7vw, 34px);
  font-weight: 400;
  letter-spacing: 1px;
  line-height: 1;
  color: #ffe56a;
}
.fighter-card em {
  font-style: normal;
  font-family: "Lilita One", Impact, sans-serif;
  letter-spacing: 0.14em;
  font-size: 13px;
  text-transform: uppercase;
  color: #ff7a18;
}
.fighter-card span {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  color: #ffe9c4;
}
.fighter-card.picked {
  border-color: #ffe56a;
  box-shadow: 0 0 0 3px rgba(255, 122, 24, 0.4), 0 0 24px rgba(255, 80, 16, 0.45);
}
.fighter-card.picked img { border-color: #fff6c8; }
#screen-select .ghost { min-height: 48px; font-size: 24px; margin-top: 8px; }
#screen-win {
  margin-top: 12px;
  padding: 16px 14px 12px;
  border-radius: 18px;
  background: #140c12;
  border: 2px solid rgba(255, 210, 58, 0.5);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}
#screen-win .brand {
  display: inline-block;
  margin: 0 0 8px;
  padding: 5px 12px 4px;
  border-radius: 999px;
  background: #2a160c;
  border: 2px solid #ffd23a;
  color: #ffd23a;
}
#overlay.from-top { align-items: flex-start; }
#overlay.gate {
  align-items: center;
  background: rgba(5, 3, 10, 0.78);
}
#screen-closed {
  margin-top: 8px;
  padding: 16px 14px 12px;
  border-radius: 18px;
  background: rgba(10, 6, 12, 0.92);
  border: 2px solid rgba(255, 210, 58, 0.45);
}
#screen-closed h1 { font-size: clamp(34px, 9vw, 62px); }
#closed-board { text-align: left; margin-top: 8px; }
#screen-board {
  margin-top: 8px;
  padding: 12px 12px 4px;
  border-radius: 18px;
  background: rgba(10, 6, 12, 0.92);
}
#overlay input, #overlay .board-list { user-select: text; -webkit-user-select: text; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (orientation: landscape) {
  #controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    grid-template-columns: 150px 1fr;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.55) 28%);
    pointer-events: none;
  }
  #controls .ctrl { pointer-events: auto; min-height: 54px; }
  .move { grid-template-rows: none; grid-template-columns: 1fr 1fr; }
  .acts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #overlay { align-items: center; }
  .panel { width: min(640px, 92%); }
  h1 { font-size: clamp(36px, 8vh, 68px); }
}

@media (max-width: 360px) {
  #controls { grid-template-columns: 112px 1fr; gap: 6px; }
  .ctrl { min-height: 56px; border-width: 2px; }
}
@media (hover: hover) and (pointer: fine) {
  .keys { display: block; }
}
@media (hover: none) {
  .keys { display: none; }
}
