:root {
  --bg: #0f1020;
  --bg2: #1a1b35;
  --accent: #ff8a3d;   /* MAME orange */
  --accent2: #ffd23d;
  --text: #f4f4fb;
  --muted: #9aa0c0;
  --card: rgba(255, 255, 255, 0.06);
  --good: #45d483;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
}

#app { position: fixed; inset: 0; }

#game-root { position: absolute; inset: 0; z-index: 1; }
#game-root canvas { display: block; width: 100% !important; height: 100% !important; }

/* Screens */
.screen {
  position: absolute; inset: 0; z-index: 5;
  display: none; flex-direction: column; align-items: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg));
  overflow-y: auto;
}
.screen.active { display: flex; }

#logo { width: 92px; height: 92px; object-fit: contain; margin-top: 12px; filter: drop-shadow(0 6px 16px rgba(0,0,0,.5)); }
h1 { font-size: 34px; letter-spacing: 2px; margin-top: 8px; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--muted); margin: 6px 0 18px; text-align: center; }

.me-card { width: 100%; max-width: 360px; background: var(--card); border-radius: 16px; padding: 14px 16px; margin-bottom: 18px; }
.me-row { display: flex; justify-content: space-between; padding: 5px 0; color: var(--muted); }
.me-row b { color: var(--text); }

/* Current character chip on home */
.char-current { width: 100%; max-width: 360px; display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 16px; padding: 10px 14px; margin-bottom: 14px; }
.char-current img { width: 46px; height: 46px; object-fit: contain; border-radius: 10px; background: rgba(0,0,0,.25); }
.cc-name { font-weight: 700; }
.cc-skill { color: var(--accent2); font-size: 13px; }
.cc-change { margin-left: auto; padding: 8px 14px; font-size: 14px; }

/* Character select grid */
.char-grid { width: 100%; max-width: 380px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.char-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 10px; border-radius: 16px; cursor: pointer; background: var(--card); border: 2px solid transparent; color: var(--text); transition: transform .08s; }
.char-card:active { transform: scale(.97); }
.char-card.selected { border-color: var(--accent); background: rgba(255,138,61,.12); }
.char-card img { width: 64px; height: 64px; object-fit: contain; }
.char-name { font-weight: 700; }
.char-skill { color: var(--accent2); font-size: 14px; }
.char-desc { color: var(--muted); font-size: 12px; text-align: center; }

/* How to play */
.howto { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.howto-row { display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: 14px; padding: 12px; }
.howto-row > img { width: 48px; height: 48px; object-fit: contain; flex: 0 0 48px; }
.howto-row b { color: var(--accent2); }
.howto-row p { color: var(--muted); font-size: 13px; margin-top: 2px; line-height: 1.35; }
.howto-skill { width: 48px; height: 48px; flex: 0 0 48px; display: flex; align-items: center; justify-content: center; font-size: 30px; }

.menu { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.btn {
  appearance: none; border: none; cursor: pointer;
  padding: 15px; border-radius: 14px; font-size: 17px; font-weight: 600;
  background: var(--card); color: var(--text); transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(90deg, var(--accent), var(--accent2)); color: #1a1300; }
.btn.big { padding: 18px; font-size: 20px; letter-spacing: 1px; }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.15); }
.btn.back { margin-top: 16px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 16px; text-align: center; max-width: 320px; }

/* Leaderboard */
h2 { font-size: 24px; margin: 8px 0 14px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab { padding: 8px 16px; border-radius: 999px; border: 1px solid rgba(255,255,255,.15); background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; }
.tab.active { background: var(--accent); color: #1a1300; border-color: transparent; font-weight: 700; }
.lb-list { list-style: none; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 6px; }
.lb-list li { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--card); border-radius: 12px; }
.lb-list li.me { outline: 2px solid var(--accent); }
.lb-rank { width: 28px; font-weight: 700; color: var(--accent2); text-align: center; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; }
.lb-empty { color: var(--muted); margin: 30px 0; text-align: center; }
.lb-me { width: 100%; max-width: 380px; margin-top: 10px; padding: 10px 14px; background: rgba(255,138,61,.15); border-radius: 12px; display: flex; gap: 10px; }
.hidden { display: none !important; }

/* Result */
#screen-result { justify-content: center; }
.result-score { font-size: 64px; font-weight: 800; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-stats { display: flex; gap: 28px; margin: 10px 0 18px; }
.result-stats div { display: flex; flex-direction: column; align-items: center; }
.result-stats span { font-size: 28px; font-weight: 700; }
.result-stats small { color: var(--muted); }
.result-rivals { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 14px; max-width: 360px; }
.rival-chip { background: var(--card); padding: 6px 12px; border-radius: 999px; font-size: 14px; }
.rival-chip.beaten { background: rgba(69,212,131,.18); color: var(--good); }
.result-standing { color: var(--muted); margin-bottom: 20px; text-align: center; }
.result-standing b { color: var(--accent2); }

/* Loading */
.loading { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: var(--bg); color: var(--muted); }
.loading.hidden { display: none; }

/* In-game SKILL button (overlay above the Phaser canvas) */
.skill-btn {
  position: absolute; z-index: 12;
  right: 18px; bottom: calc(24px + env(safe-area-inset-bottom));
  width: 76px; height: 76px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.2); cursor: pointer;
  background: rgba(255,255,255,.08); color: #fff;
  font-size: 15px; font-weight: 800; line-height: 1.1;
  display: flex; align-items: center; justify-content: center; text-align: center;
  transition: transform .1s, box-shadow .2s, background .2s;
}
.skill-btn:disabled { opacity: .55; pointer-events: none; }
.skill-btn.ready {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #1a1300; border-color: var(--accent2); opacity: 1;
  box-shadow: 0 0 0 0 rgba(255,210,61,.7); animation: pulse 1.1s infinite;
}
.skill-btn.ready:active { transform: scale(.92); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,210,61,.6); }
  70% { box-shadow: 0 0 0 16px rgba(255,210,61,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,210,61,0); }
}
