:root {
  --bg-0: #0b0620;
  --bg-1: #1d0f3d;
  --accent: #7c5cff;
  --accent-2: #ff5cc8;
  --gold: #ffd166;
  --text: #f4f0ff;
  --text-dim: #b9aee0;
  --panel: rgba(20, 12, 45, 0.82);
  --panel-border: rgba(160, 130, 255, 0.35);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: 'Baloo 2', 'Poppins', sans-serif; margin: 0 0 0.4em; }

a { color: var(--accent); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  max-width: 960px;
  margin: 0 auto;
}
.site-header .logo { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.site-header .logo img { width: 28px; height: 28px; border-radius: 8px; }
.site-header nav a { color: var(--text-dim); text-decoration: none; margin-left: 18px; font-size: 0.92rem; }
.site-header nav a:hover { color: var(--text); }

.game-wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 12px 20px;
}

.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 480 / 800;
  max-height: 82vh;
  margin: 0 auto;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.55), 0 0 0 1px var(--panel-border) inset;
  background: var(--bg-0);
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 20%, rgba(124,92,255,0.25), transparent 60%), rgba(11,6,32,0.72);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}
[hidden] { display: none !important; }

.title-lockup { font-size: 2.6rem; letter-spacing: 1px; background: linear-gradient(180deg, #fff, var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: 0 0 30px rgba(255,92,200,0.35); }
.subtitle { color: var(--text-dim); font-size: 0.95rem; margin-top: -8px; }

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 14px 30px;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: #1a0f33;
  background: linear-gradient(180deg, #ffe08a, var(--gold));
  box-shadow: 0 8px 0 #b8860b, 0 14px 24px rgba(255,209,102,0.35);
  transition: transform 0.08s ease;
  min-width: 200px;
}
.btn:active { transform: translateY(4px); box-shadow: 0 4px 0 #b8860b, 0 8px 16px rgba(255,209,102,0.3); }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.btn.secondary { background: linear-gradient(180deg, #8f7bff, var(--accent)); box-shadow: 0 8px 0 #4b32b0, 0 14px 24px rgba(124,92,255,0.35); color: #fff; }
.btn.secondary:active { box-shadow: 0 4px 0 #4b32b0; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--text-dim); border: 1px solid var(--panel-border); min-width: unset; padding: 10px 20px; font-size: 0.9rem; }
.btn.small { padding: 9px 18px; font-size: 0.85rem; min-width: unset; }

.best-pill { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 999px; padding: 6px 16px; font-weight: 600; color: var(--gold); }

.name-pill {
  appearance: none; display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px dashed var(--panel-border); border-radius: 999px;
  padding: 5px 14px; font-family: inherit; font-size: 0.82rem; color: var(--text-dim);
  cursor: pointer; margin-top: -4px;
}
.name-pill:hover, .name-pill:focus-visible { color: var(--text); border-color: var(--accent); }

.mini-leaderboard { width: 100%; max-width: 320px; margin-top: 4px; }
.mini-leaderboard h3 { font-size: 0.85rem; color: var(--text-dim); margin: 0 0 8px; letter-spacing: 0.4px; }
.mini-leaderboard-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.mini-leaderboard-list li {
  display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.03);
  border-radius: 8px; padding: 6px 12px; font-size: 0.85rem;
}
.mini-leaderboard-list li.is-you { background: rgba(124,92,255,0.25); border: 1px solid var(--accent); }
.mini-leaderboard-list li.loading, .mini-leaderboard-list li.empty { justify-content: center; color: var(--text-dim); }
.mini-leaderboard-list .rank { width: 20px; color: var(--gold); font-weight: 700; }
.mini-leaderboard-list .name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-leaderboard-list .score { font-weight: 700; }

.submit-row { display: flex; gap: 8px; width: 100%; max-width: 320px; }
.submit-row .nickname-field { margin: 0; flex: 1; }
.submit-row .btn { min-width: unset; flex: none; }

.icon-row { display: flex; gap: 10px; margin-top: 6px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--panel-border); background: var(--panel);
  color: var(--text); font-size: 1.2rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
}
.icon-btn.is-off { opacity: 0.45; }
.icon-btn:focus-visible { outline: 2px solid #fff; }

#hud {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; align-items: center;
  padding-top: calc(18px + var(--safe-top));
}
.hud-score { font-size: 2.6rem; font-weight: 800; font-family: 'Baloo 2', sans-serif; text-shadow: 0 0 18px rgba(255,255,255,0.35); }
.hud-combo { min-height: 1.4em; color: var(--gold); font-weight: 700; letter-spacing: 0.5px; text-shadow: 0 0 12px rgba(255,209,102,0.7); }
.hud-top-row { position: absolute; top: calc(14px + var(--safe-top)); left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; }
.hud-top-right { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.hud-height-pill, .hud-best-pill { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; padding: 6px 10px; font-size: 0.8rem; white-space: nowrap; }
#btn-pause { pointer-events: auto; width: 38px; height: 38px; flex: none; border-radius: 50%; border: 1px solid var(--panel-border); background: var(--panel); color: var(--text); font-size: 1rem; cursor: pointer; }

.banner {
  position: absolute; left: 50%; transform: translate(-50%, -50%) scale(0.7);
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.6rem;
  color: #fff; text-shadow: 0 0 20px rgba(255,92,200,0.8), 0 2px 4px rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none; white-space: nowrap;
}
/* Milestone and combo banners can fire in the same instant (a milestone
   height is very often reached via a Perfect drop) — stack them at
   different heights so the text never overlaps illegibly. */
#milestone-banner { top: 30%; font-size: 1.3rem; }
#combo-banner { top: 46%; }
.banner.show { animation: bannerPop 1.1s ease forwards; }
@keyframes bannerPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  30% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -55%) scale(1); }
}

.result-score { font-size: 3rem; font-weight: 800; font-family: 'Baloo 2', sans-serif; }
.result-stats { display: flex; gap: 18px; color: var(--text-dim); font-size: 0.9rem; }
.new-best-badge { background: linear-gradient(90deg, var(--gold), #fff3c4); color: #1a0f33; font-weight: 800; padding: 6px 14px; border-radius: 999px; font-size: 0.85rem; letter-spacing: 0.4px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,2,15,0.72); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 24px; max-width: 380px; width: 100%; max-height: 80vh; overflow-y: auto;
}
.modal h2 { display: flex; align-items: center; justify-content: space-between; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 1.3rem; cursor: pointer; }
.modal p, .modal li { color: var(--text-dim); font-size: 0.92rem; line-height: 1.5; }

.leaderboard-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.leaderboard-list li { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.03); border-radius: 10px; padding: 8px 12px; }
.leaderboard-list li.is-you { background: rgba(124,92,255,0.25); border: 1px solid var(--accent); }
.leaderboard-list .rank { width: 32px; color: var(--gold); font-weight: 700; }
.leaderboard-list .name { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-list .score { color: var(--text); font-weight: 700; }
.leaderboard-list .empty { justify-content: center; color: var(--text-dim); }

.nickname-field { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--panel-border); background: rgba(255,255,255,0.06); color: var(--text); font-size: 1rem; margin: 10px 0; }
.nickname-field:focus-visible { outline: 2px solid var(--accent); }

.toast {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 999px; padding: 10px 20px;
  opacity: 0; transition: opacity 0.25s ease, transform 0.25s ease; z-index: 60; font-size: 0.9rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.ad-slot { max-width: 480px; margin: 10px auto; min-height: 90px; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 0.75rem; border: 1px dashed var(--panel-border); border-radius: 10px; }

.seo-content { max-width: 720px; margin: 40px auto; padding: 0 20px 60px; color: var(--text-dim); line-height: 1.7; }
.seo-content h2 { color: var(--text); margin-top: 1.6em; }
.seo-content details { background: rgba(255,255,255,0.03); border-radius: 10px; padding: 10px 16px; margin-bottom: 8px; }
.seo-content summary { cursor: pointer; font-weight: 600; color: var(--text); }
.related-games { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.related-games a { color: var(--accent-2); text-decoration: none; font-size: 0.9rem; }

.site-footer { text-align: center; color: var(--text-dim); font-size: 0.8rem; padding: 20px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 480px) {
  .title-lockup { font-size: 2.1rem; }
  .result-score { font-size: 2.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  .banner.show { animation: none; opacity: 1; }
  * { scroll-behavior: auto !important; }
}
