:root {
  --ink: #2e2740;
  --muted: #746d86;
  --panel: rgba(255, 255, 255, 0.92);
  --purple: #7d63c9;
  --purple-dark: #5b43a8;
  --mint: #86d8c4;
  --pink: #e4a6c7;
  --danger: #ee6c77;
  --shadow: 0 18px 60px rgba(75, 58, 120, 0.22);
  --radius: 28px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 15%, rgba(255,255,255,.9), transparent 28%),
    radial-gradient(circle at 85% 5%, rgba(213,201,255,.65), transparent 26%),
    linear-gradient(145deg, #f8f5ff 0%, #ece8fb 50%, #f7f3ff 100%);
  overflow-x: hidden;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.page-shell {
  width: min(100%, 1120px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 18px 12px;
  display: grid;
  place-items: center;
  gap: 12px;
}
.game-card { width: min(100%, 680px); }
.game-stage {
  position: relative;
  width: min(100%, calc((100vh - 88px) * 0.66614));
  aspect-ratio: 842 / 1264;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 32px;
  background: #e9e3f8;
  box-shadow: var(--shadow), 0 0 0 1px rgba(98, 78, 145, 0.08);
  touch-action: none;
  user-select: none;
}
#gameCanvas { width: 100%; height: 100%; display: block; background: #eee8fb; }

.hud {
  position: absolute;
  inset: max(14px, env(safe-area-inset-top)) 14px auto;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 9px;
  align-items: center;
  z-index: 15;
  pointer-events: none;
}
.hud-pill, .icon-button {
  min-height: 46px;
  border: 1px solid rgba(91, 67, 168, 0.12);
  border-radius: 16px;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(70, 55, 110, .13);
}
.hud-pill { display: flex; align-items: center; gap: 8px; padding: 7px 14px; }
.hud-score span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.hud-score strong { font-size: 22px; }
.hud-lives { gap: 7px; padding-inline: 12px; }
.life-dot { width: 17px; height: 17px; border-radius: 6px; transform: rotate(45deg); background: linear-gradient(145deg, #fff, #e7e2f1); box-shadow: inset -2px -2px 4px rgba(88,74,120,.16), 0 2px 5px rgba(79,60,120,.18); transition: .25s ease; }
.life-dot.lost { opacity: .2; transform: rotate(45deg) scale(.7); }
.icon-button { width: 46px; padding: 0; border: 0; cursor: pointer; pointer-events: auto; font-size: 19px; }

.effect-strip {
  position: absolute;
  z-index: 16;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 7px;
  pointer-events: none;
}
.effect-chip {
  padding: 7px 11px;
  border-radius: 999px;
  color: white;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(60,45,100,.2);
  animation: chipIn .22s ease;
}
.effect-chip.hazard { background: linear-gradient(135deg, #f06d75, #c94352); }
.effect-chip.slow { background: linear-gradient(135deg, #76b9dd, #5b8ec7); }
.effect-chip.double { background: linear-gradient(135deg, #8b6bd6, #5f3db8); }
@keyframes chipIn { from { opacity: 0; transform: translateY(-8px) scale(.94); } }

.tap-feedback {
  position: absolute;
  width: 58px;
  height: 58px;
  border: 3px solid rgba(255,255,255,.75);
  border-radius: 50%;
  pointer-events: none;
  z-index: 12;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.4);
}
.tap-feedback.show { animation: tapWave .35s ease-out; }
@keyframes tapWave { 0% { opacity: 1; transform: translate(-50%,-50%) scale(.35); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(1.25); } }

.screen-overlay, .modal-layer {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(18px, 5vw, 34px);
}
.screen-overlay { background: linear-gradient(180deg, rgba(243,239,254,.45), rgba(238,232,251,.88)); backdrop-filter: blur(4px); }
.start-screen { flex-direction: column; text-align: center; justify-content: flex-start; padding-top: clamp(54px, 12vh, 110px); overflow-y: auto; }
.brand-chip {
  display: inline-flex;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(255,255,255,.76);
  border: 1px solid rgba(93,71,159,.1);
  font-size: clamp(10px, 2.3vw, 13px);
  font-weight: 700;
  color: var(--purple-dark);
  box-shadow: 0 8px 24px rgba(79,61,125,.09);
}
h1 { margin: 13px 0 2px; font-size: clamp(48px, 11vw, 82px); line-height: .98; letter-spacing: -.055em; color: #513b99; text-shadow: 0 4px 0 rgba(255,255,255,.65); }
.lead { width: min(92%, 430px); margin: 12px auto 18px; font-size: clamp(15px, 3.4vw, 20px); color: #655d78; line-height: 1.45; }
.how-to-play {
  width: min(100%, 430px);
  display: grid;
  gap: 8px;
  margin: 0 auto 18px;
  text-align: left;
}
.how-item {
  display: grid;
  grid-template-columns: 39px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px 11px;
  border-radius: 15px;
  background: rgba(255,255,255,.74);
  color: #5e566f;
  font-size: clamp(12px, 2.8vw, 15px);
}
.how-icon { width: 31px; height: 31px; border-radius: 10px; display: grid; place-items: center; font-weight: 900; color: white; box-shadow: inset 0 0 0 1px rgba(255,255,255,.45); }
.how-icon.normal { background: #eab84f; }
.how-icon.danger { background: var(--danger); }
.how-icon.slow { background: #7eb8dc; }
.how-icon.double { background: #8262cf; }
.primary-button, .secondary-button, .ghost-button {
  width: min(100%, 360px);
  min-height: 52px;
  border-radius: 17px;
  border: 0;
  cursor: pointer;
  font-weight: 800;
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease;
}
.primary-button { color: white; background: linear-gradient(135deg, #8268d2, #654bb6); box-shadow: 0 12px 28px rgba(94, 68, 174, .28); }
.secondary-button { color: #5e49a5; background: #eee9fb; border: 1px solid rgba(100,75,174,.12); }
.ghost-button { color: #655d78; background: transparent; min-height: 44px; }
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button:active, .secondary-button:active { transform: translateY(1px) scale(.99); }
.primary-button:disabled { opacity: .55; cursor: wait; }
.microcopy { margin: 8px 0 0; max-width: 380px; color: #827a91; font-size: 11px; line-height: 1.4; }

.countdown-screen { flex-direction: column; background: rgba(73,54,135,.25); color: white; text-shadow: 0 4px 20px rgba(50,35,100,.5); }
.countdown-number { font-size: clamp(100px, 26vw, 180px); font-weight: 900; line-height: .9; animation: pop .8s ease both; }
.countdown-screen p { font-size: clamp(16px, 4vw, 24px); font-weight: 800; }
@keyframes pop { 0% { opacity: 0; transform: scale(.5); } 50% { opacity: 1; transform: scale(1.08); } 100% { transform: scale(1); } }

.end-screen { background: rgba(239,235,251,.78); backdrop-filter: blur(8px); }
.result-card {
  width: min(100%, 430px);
  max-height: 94%;
  overflow-y: auto;
  padding: clamp(22px, 5vw, 34px);
  border-radius: 28px;
  text-align: center;
  background: rgba(255,255,255,.93);
  box-shadow: var(--shadow);
}
.result-kicker { color: var(--purple); text-transform: uppercase; letter-spacing: .11em; font-size: 11px; font-weight: 900; }
.result-card h2, .modal-card h2 { margin: 8px 0 10px; font-size: clamp(24px, 6vw, 34px); letter-spacing: -.03em; }
.result-score { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 7px 0 12px; }
.result-score strong { font-size: clamp(64px, 16vw, 96px); line-height: .9; color: #5d47a7; }
.result-score span { color: var(--muted); font-weight: 700; }
.result-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin-bottom: 18px; }
.result-meta span { padding: 7px 10px; border-radius: 999px; background: #f3f0fa; color: #746c82; font-size: 12px; }
.result-card .primary-button, .result-card .secondary-button { margin-top: 8px; }
.result-error, .form-error { margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: #fff0f1; color: #aa3f4b; font-size: 13px; line-height: 1.35; }

.modal-layer { z-index: 50; background: rgba(41,32,70,.48); backdrop-filter: blur(8px); }
.modal-card {
  position: relative;
  width: min(100%, 560px);
  max-height: min(92%, 820px);
  overflow: auto;
  padding: clamp(22px, 5vw, 32px);
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(32,23,62,.35);
}
.modal-card.compact { max-width: 430px; }
.modal-card.centered { text-align: center; }
.modal-close { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: #f1edf8; color: #716887; cursor: pointer; font-size: 26px; line-height: 1; }
.modal-card p { color: var(--muted); line-height: 1.5; }
.modal-card form { display: grid; gap: 13px; margin-top: 18px; }
.modal-card label { display: grid; gap: 6px; text-align: left; font-size: 13px; font-weight: 800; color: #5f5772; }
.modal-card input[type="text"], .modal-card input[type="tel"], .modal-card input:not([type]) {
  width: 100%; min-height: 49px; border: 1px solid #ddd6eb; border-radius: 14px; padding: 0 14px; color: var(--ink); outline: none; background: #fbfaff;
}
.modal-card input:focus { border-color: #8a6ed2; box-shadow: 0 0 0 4px rgba(126,99,201,.11); }
.consent-row { grid-template-columns: 22px 1fr !important; align-items: start; font-weight: 500 !important; line-height: 1.35; }
.consent-row input { width: 18px; height: 18px; accent-color: #7358c1; }
.success-mark { width: 72px; height: 72px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 50%; background: #def5ec; color: #3a9f78; font-size: 38px; font-weight: 900; }

.leaderboard-card { width: min(100%, 690px); }
.leaderboard-head { display: flex; justify-content: space-between; gap: 15px; align-items: flex-start; padding-right: 42px; }
.tournament-note { max-width: 210px; padding: 9px 11px; border-radius: 13px; background: #f3effd; color: #6651ad; font-size: 11px; line-height: 1.35; font-weight: 700; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 1px 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; border: 0; border-radius: 999px; padding: 9px 13px; background: #f0edf7; color: #70677e; font-size: 12px; font-weight: 800; cursor: pointer; }
.tab.active { background: #7357c3; color: white; }
.leaderboard-table-wrap { min-height: 260px; position: relative; }
.leaderboard-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.leaderboard-table th { text-align: left; color: #8a8297; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; padding: 9px 8px; border-bottom: 1px solid #eee9f5; }
.leaderboard-table th:last-child, .leaderboard-table td:last-child { text-align: right; }
.leaderboard-table td { padding: 11px 8px; border-bottom: 1px solid #f0edf5; }
.leaderboard-table tr:nth-child(-n+3) td:first-child { font-weight: 900; color: #674eae; }
.rank-medal { display: inline-grid; width: 27px; height: 27px; place-items: center; border-radius: 9px; background: #f2eefb; font-size: 12px; font-weight: 900; }
.loading-state, .empty-state { min-height: 220px; display: grid; place-items: center; color: #847c91; text-align: center; padding: 25px; }
.personal-rank { margin-top: 12px; padding: 12px 14px; border-radius: 15px; background: #ede8fb; color: #5e49a5; font-weight: 800; font-size: 13px; }

.site-footer { width: min(100%, 680px); display: flex; justify-content: space-between; gap: 12px; color: #827a91; font-size: 11px; padding: 0 4px; }
.site-footer a { color: inherit; text-decoration: none; }
.site-footer a:hover { color: #5e49a5; }

@media (max-width: 560px) {
  .page-shell { padding: 0; display: block; }
  .game-card, .game-stage { width: 100%; }
  .game-stage { min-height: 100svh; height: 100svh; aspect-ratio: auto; border-radius: 0; }
  #gameCanvas { object-fit: cover; }
  .site-footer { display: none; }
  .start-screen { padding-top: max(46px, calc(env(safe-area-inset-top) + 30px)); }
  .how-to-play { margin-bottom: 13px; }
  .modal-layer { padding: 10px; }
  .modal-card { max-height: 96%; border-radius: 22px; }
}

@media (max-height: 720px) {
  .start-screen { padding-top: 24px; }
  h1 { font-size: 52px; }
  .lead { margin-block: 7px 10px; }
  .how-to-play { gap: 5px; margin-bottom: 8px; }
  .how-item { padding-block: 5px; }
  .primary-button { min-height: 46px; }
  .microcopy { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
