:root {
  --bg: #07060c;
  --panel: #12101a;
  --panel2: #1a1424;
  --accent: #f0c45a;
  --accent2: #6ec8cf;
  --neon-pink: #ff3d8a;
  --neon-cyan: #3de8ff;
  --neon-amber: #ffb020;
  --danger: #ff4a5a;
  --text: #f2eef8;
  --muted: #9a8eb0;
  --p1: #e8eef6;
  --p2: #ff8a3a;
  --enemy: #2a2030;
  --radius: 12px;
  --font: "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background:
    radial-gradient(ellipse 90% 50% at 50% -10%, rgba(255,60,120,.18), transparent 55%),
    radial-gradient(ellipse 70% 40% at 85% 20%, rgba(60,200,255,.12), transparent 50%),
    radial-gradient(ellipse at top, #1a1228 0%, var(--bg) 62%);
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#app { min-height: 100%; display: flex; flex-direction: column; align-items: center; padding: 8px 12px 24px; }

.topbar {
  width: min(960px, 100%);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 4px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(145deg, #ff4a7a, #c4892a 55%, #3de8ff);
  color: #140810; font-weight: 900; font-size: 22px;
  display: grid; place-items: center;
  box-shadow: 0 0 16px rgba(255,60,120,.45), 0 4px 0 #5a2030, 0 6px 16px rgba(0,0,0,.45);
}
.brand h1 {
  font-size: 1.2rem; letter-spacing: .12em; line-height: 1.1;
  color: #ffe8b0;
  text-shadow: 0 0 12px rgba(255,80,120,.35), 2px 2px 0 #3a1020;
}
.sub { color: var(--muted); font-size: .75rem; letter-spacing: .06em; }

.hud { display: flex; flex-wrap: wrap; gap: 8px; font-size: .8rem; }
.hud span {
  background: linear-gradient(180deg, #1e1628, #120e18);
  border: 1px solid #4a3058;
  padding: 4px 10px; border-radius: 999px; color: var(--accent2);
  box-shadow: 0 0 10px rgba(255,60,120,.12), inset 0 1px 0 rgba(255,255,255,.06);
}
.hud span#hud-lives {
  color: #ff8a9a;
  border-color: #6a3040;
  letter-spacing: .02em;
  text-shadow: 0 0 8px rgba(255,80,100,.35);
}

main { width: min(960px, 100%); position: relative; }
.screen { display: flex; justify-content: center; }
.hidden { display: none !important; }

.panel {
  background:
    linear-gradient(180deg, rgba(255,50,100,.06), transparent 28%),
    linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid #5a3050;
  border-radius: var(--radius);
  padding: 22px 20px;
  box-shadow:
    0 0 0 1px rgba(255,180,60,.12),
    0 12px 40px rgba(0,0,0,.55),
    inset 0 1px 0 rgba(255,255,255,.06),
    0 0 28px rgba(255,40,100,.12);
  width: min(420px, 100%);
  text-align: center;
  position: relative;
  overflow: hidden;
}
.title-panel::before {
  content: "";
  position: absolute; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,.04) 2px, rgba(0,0,0,.04) 3px);
  opacity: .55;
}
.title-panel h2 {
  font-size: 1.85rem; margin: 8px 0 4px; color: #ffe8a0;
  letter-spacing: .18em;
  text-shadow:
    0 0 18px rgba(255,60,120,.55),
    3px 3px 0 #4a1028,
    -1px -1px 0 #1a3048;
  position: relative;
}
.title-panel h2::after {
  content: "NIGHT STREET BRAWL";
  display: block;
  margin-top: 4px;
  font-size: .62rem;
  letter-spacing: .28em;
  color: var(--neon-cyan);
  text-shadow: 0 0 10px rgba(61,232,255,.55);
  font-weight: 700;
}
.tagline { color: var(--muted); margin-bottom: 18px; font-size: .9rem; position: relative; }
.poster-stamp {
  display: inline-block;
  margin: 0 0 10px;
  padding: 3px 10px;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .14em;
  color: #1a0808;
  background: linear-gradient(90deg, #ff4a6a, #ffb020);
  border-radius: 3px;
  transform: rotate(-2deg);
  box-shadow: 0 0 12px rgba(255,60,80,.4);
}
.about-panel { text-align: left; max-width: 520px; width: min(520px, 100%); }
.about-panel h2, .about-panel h3 { text-align: center; margin: 8px 0; }
.about-panel p, .about-panel li { color: #c8d4c4; font-size: .92rem; line-height: 1.55; margin: 8px 0; }
.disclaimer {
  background: #2a2010; border-left: 3px solid var(--accent);
  padding: 10px 12px; border-radius: 6px; font-size: .85rem !important;
}
.about-panel ul { padding-left: 1.2rem; margin-bottom: 14px; }

.btn-col { display: flex; flex-direction: column; gap: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.btn {
  appearance: none; border: 1px solid #4a5c4c; background: #2c3a30;
  color: var(--text); font: inherit; font-weight: 600; padding: 12px 16px;
  border-radius: 10px; cursor: pointer; transition: transform .08s, background .15s;
}
.btn:hover { background: #354840; }
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(180deg, #ff6a8a, #e8a030 55%, #c99228);
  color: #1a0808; border-color: #a84840;
  box-shadow: 0 4px 0 #6a2830, 0 0 16px rgba(255,60,100,.3);
}
.btn.ghost { background: transparent; color: var(--muted); }
.btn.tiny { padding: 8px 10px; font-size: .8rem; }
.hint { margin-top: 14px; color: var(--muted); font-size: .75rem; line-height: 1.4; }

#screen-stages .panel { width: min(480px, 100%); }
.stage-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 18px;
}
.stage-grid button {
  aspect-ratio: auto; min-height: 56px; border-radius: 10px; border: 1px solid #4a5c4c;
  background: #2a3830; color: var(--text); font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 8px 4px; font-size: .82rem;
}
.stage-grid small { font-size: .65rem; color: var(--muted); font-weight: 600; }
.stage-grid button:hover { border-color: var(--accent); color: var(--accent); }
.stage-grid button.locked,
.stage-grid button:disabled {
  opacity: .45; cursor: not-allowed; filter: grayscale(.4);
  border-color: #3a4450; color: var(--muted);
}
.stage-grid button.locked:hover { border-color: #3a4450; color: var(--muted); }
.stage-grid .soon {
  display: block; font-size: .6rem; color: #a09060; font-weight: 600; margin-top: 2px;
}
.teaser { color: var(--accent); font-size: .85rem; }

.game-wrap {
  display: flex; gap: 12px; justify-content: center; align-items: flex-start; flex-wrap: wrap;
}
#screen-game { width: 100%; position: relative; }
body.playing { overscroll-behavior: none; }
body.playing #screen-game,
body.playing #screen-game * { touch-action: none; }
#game {
  background: #06080e;
  border-radius: 8px;
  border: 3px solid #5a3050;
  box-shadow:
    0 0 0 1px rgba(255,180,60,.2),
    0 0 24px rgba(255,40,100,.22),
    0 10px 30px rgba(0,0,0,.55),
    inset 0 0 40px rgba(0,0,0,.4);
  max-width: min(100%, 624px);
  width: 100%;
  height: auto;
  display: block;
  image-rendering: auto;
}
.side {
  width: 140px; background: var(--panel); border: 1px solid #334033;
  border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px;
}
.stat label { display: block; font-size: .7rem; color: var(--muted); }
.stat b { font-size: 1.2rem; color: var(--accent2); }
.legend { display: flex; flex-wrap: wrap; gap: 4px; }
.lg { font-size: .65rem; padding: 2px 6px; border-radius: 4px; }
.lg.brick { background: #8b4518; }
.lg.steel { background: #6a7380; }
.lg.water { background: #2a5a9a; }
.lg.grass { background: #2d6a2d; }
.lg.base { background: #c9a227; color: #1a1208; }

.overlay {
  position: absolute; inset: 0; background: rgba(6,10,8,.72);
  display: flex; align-items: center; justify-content: center; z-index: 20;
  backdrop-filter: blur(2px); border-radius: 8px;
}
.overlay-panel { width: min(360px, 92%); }

.game-pause { display: none; }

.touch {
  display: none;
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: env(safe-area-inset-bottom, 0px);
  width: auto;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 0;
  z-index: 30;
  pointer-events: none;
}
.dpad {
  display: grid; grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(3, 72px);
  gap: 8px; width: 232px;
}
.dpad button {
  border: 2px solid #526752; border-radius: 16px;
  background: linear-gradient(145deg, #435846, #29382d 72%);
  color: var(--text); font-size: 1.35rem; line-height: 1;
  text-shadow: 0 2px 3px rgba(0,0,0,.55); opacity: .95; pointer-events: auto;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.14), 0 4px 0 #182319;
}
.dpad button:active {
  transform: translateY(3px) scale(.97);
  background: linear-gradient(145deg, #526b55, #304632);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 1px 0 #182319;
}
.dpad button[data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad button[data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad button[data-dir="down"] { grid-column: 2; grid-row: 3; }
.dpad button[data-dir="right"] { grid-column: 3; grid-row: 2; }
.fire-btn {
  position: relative; isolation: isolate; overflow: hidden;
  width: 104px; height: 104px; flex: 0 0 auto; border-radius: 50%;
  border: 3px solid #d9a63d;
  background:
    radial-gradient(circle at 32% 20%, rgba(255,246,181,.9) 0 4%, transparent 19%),
    linear-gradient(145deg, #f5d16d 0%, #d99b2d 48%, #915e18 100%);
  color: #241707; font-weight: 900;
  box-shadow:
    0 0 0 4px #392b16,
    inset 0 2px 0 rgba(255,255,255,.62),
    inset 0 -7px 10px rgba(62,35,4,.42),
    0 7px 0 #704815, 0 10px 18px rgba(0,0,0,.4);
  opacity: .96; pointer-events: auto; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
}
.fire-btn::before {
  content: ""; position: absolute; z-index: -1; inset: 8px;
  border: 1px solid rgba(255,244,174,.62); border-radius: 50%;
  box-shadow: inset 0 -2px 0 rgba(86,48,7,.3);
}
.fire-btn:active {
  transform: translateY(3px) scale(.97);
  box-shadow:
    0 0 0 4px #392b16,
    inset 0 2px 0 rgba(255,255,255,.48),
    inset 0 -5px 8px rgba(62,35,4,.46),
    0 3px 0 #704815, 0 6px 12px rgba(0,0,0,.35);
}
.fire-mark { font-size: 1.35rem; line-height: 1; color: #fff1ae; text-shadow: 0 1px 2px #754d13; }
.fire-copy { display: flex; flex-direction: column; align-items: center; line-height: 1.05; }
.fire-copy b { font-size: .95rem; letter-spacing: .08em; }
.fire-copy small { font-size: .62rem; letter-spacing: .2em; margin-left: .2em; }

@media (max-width: 720px) {
  body.playing {
    overscroll-behavior: none;
    --hud-height: 36px;
    --touch-height: max(240px, calc(232px + env(safe-area-inset-bottom, 0px) + 8px));
    --game-size: min(calc(100vw - 12px), calc(100dvh - var(--hud-height) - var(--touch-height) - 4px));
  }
  body.playing #app { padding: 0 6px 0; }
  body.playing .topbar {
    width: 100%; height: var(--hud-height); min-height: var(--hud-height); padding: 2px 0 3px;
  }
  body.playing .brand { display: none; }
  body.playing .hud {
    width: 100%; justify-content: center; flex-wrap: nowrap; gap: 4px;
    font-size: .7rem;
  }
  body.playing .hud span { padding: 3px 7px; white-space: nowrap; }
  body.playing #hud-mode { display: none; }

  #screen-game {
    width: 100%; display: flex; flex-direction: column; align-items: center;
    touch-action: none;
  }
  #screen-game * { touch-action: none; }
  .game-wrap {
    width: 100%; gap: 0; flex-direction: column; align-items: center; flex-wrap: nowrap;
  }
  #game {
    width: var(--game-size); max-width: 624px; height: var(--game-size);
    aspect-ratio: 1; flex: 0 0 auto;
  }
  .side { display: none; }
  .game-pause {
    display: block; position: absolute; z-index: 31;
    top: 4px;
    right: max(4px, calc((100% - var(--game-size)) / 2 + 4px));
    padding: 5px 7px; font-size: .7rem; opacity: .9;
  }
  .touch {
    display: flex; position: relative; inset: auto; width: min(100%, 624px);
    height: var(--touch-height); min-height: var(--touch-height); margin: 4px auto 0;
    padding: 0 6px max(8px, env(safe-area-inset-bottom, 0px));
    justify-content: space-between; align-items: flex-end; gap: 12px;
  }

  /* Keep the non-game screens compact without making them feel cramped. */
  .panel { padding: 18px 14px; }
  .title-panel h2 { font-size: 1.4rem; }
  #title-canvas { max-width: 100%; height: auto; }
  .stage-grid { gap: 6px; margin: 12px 0 16px; }
}
@media (pointer: coarse) {
  .touch { display: flex; }
}

@media (pointer: coarse) and (min-width: 721px) and (max-height: 600px) {
  body.playing #app { padding-top: 0; }
  body.playing .brand { display: none; }
  body.playing .topbar { min-height: 38px; padding: 3px 4px; }
  body.playing .hud { justify-content: center; }
  .side { display: none; }
  #screen-game { touch-action: none; }
  #screen-game * { touch-action: none; }
  .game-wrap { width: 100%; }
  #game { width: min(calc(100vw - 16px), calc(100dvh - 50px)); height: min(calc(100vw - 16px), calc(100dvh - 50px)); aspect-ratio: 1; }
}

/* --- Online room UI --- */
.room-code {
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 0.28em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  background: #101810;
  border: 2px solid #4a5c28;
  border-radius: 14px;
  padding: 14px 8px 14px 18px;
  margin: 8px 0 12px;
  line-height: 1.1;
  text-shadow: 0 0 18px rgba(232,184,74,.35);
}
.join-display { min-height: 1.3em; }
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 8px 0 12px;
}
.keypad button {
  appearance: none;
  min-height: 64px;
  border-radius: 14px;
  border: 2px solid #4a5c4c;
  background: linear-gradient(180deg, #354840, #2a3830);
  color: var(--text);
  font: inherit;
  font-size: 1.55rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 #182319;
}
.keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #182319; }
.keypad .pad-fn { font-size: 1.25rem; color: var(--muted); }
.keypad .pad-go {
  font-size: 1.05rem;
  background: linear-gradient(180deg, #f0c45a, #c99228);
  color: #1a1208;
  border-color: #a87820;
  box-shadow: 0 4px 0 #7a5a18;
}
.err-hint { color: var(--danger) !important; min-height: 1.2em; }
@media (max-width: 720px) {
  .keypad button { min-height: 70px; }
  .room-code { font-size: clamp(2.8rem, 14vw, 3.8rem); }
}

.goal-stat b { color: var(--accent); font-size: .95rem; }
.hud span#hud-goal {
  background: #2a2410; border-color: #6a5a20; color: var(--accent);
}
.lg.brick { background: #6a3a30; }
.lg.steel { background: #5a6570; }
.lg.water { background: #3a2818; color: #e87820; }
.lg.grass { background: #3a6a3a; }


/* 怒氣／大技 HUD */
#hud-rage {
  color: #e8a060;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
#hud-rage.ready {
  color: #ffe08a;
  text-shadow: 0 0 8px rgba(255, 180, 60, 0.7);
  animation: ragePulse 0.7s ease-in-out infinite alternate;
}
@keyframes ragePulse {
  from { opacity: 0.85; }
  to { opacity: 1; }
}
.fire-btn.musou-ready {
  background: linear-gradient(160deg, #ffb040, #e05030) !important;
  box-shadow: 0 0 18px rgba(255, 140, 40, 0.55), inset 0 1px 0 rgba(255,255,200,.35);
  border-color: #ffd080;
}
.fire-btn.musou-ready .fire-copy small { color: rgba(40,20,0,.75); }


/* --- 90s HK action poster polish --- */
.title-art {
  position: relative;
  margin: 0 auto 6px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(255,40,100,.25), inset 0 0 0 1px rgba(255,200,120,.2);
}
#title-canvas { display: block; width: 100%; max-width: 320px; margin: 0 auto; background: #08060e; border-radius: 6px; }
.side {
  border-color: #4a3058 !important;
  background: linear-gradient(180deg, #1a1424, #100e16) !important;
  box-shadow: 0 0 14px rgba(255,40,100,.1);
}
.side .stat b { text-shadow: 0 0 8px rgba(61,232,255,.25); }
.hud span#hud-stage {
  color: #ffe8a0;
  border-color: #8a6040;
  text-shadow: 0 0 8px rgba(255,180,60,.35);
}
.hud span#hud-enemies {
  color: #ff9ab0;
  border-color: #6a3048;
}
.overlay {
  background: rgba(8,4,14,.78) !important;
}
.overlay-panel h2 {
  letter-spacing: .14em;
  text-shadow: 0 0 14px rgba(255,60,120,.45);
}
