* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg1: #1e1b4b;
  --bg2: #0f172a;
  --accent: #ffd84a;
  --danger: #ef4466;
  --text: #f8fafc;
  --muted: #a5b4fc;
  --glass: rgba(255, 255, 255, 0.08);
}

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

#game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none; /* prevent scrolling / zoom gestures */
  background:
    radial-gradient(circle at 20% 10%, rgba(129, 140, 248, 0.25), transparent 50%),
    radial-gradient(circle at 80% 90%, rgba(236, 72, 153, 0.18), transparent 50%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  padding: 16px;
  pointer-events: none;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
  padding: 8px 16px;
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.stat span:last-child { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.stat.bump span:last-child { animation: bump 0.25s ease; }
.stat.low span:last-child { color: var(--danger); }

/* ---------- Play field ---------- */
#field { position: absolute; inset: 0; }

.item {
  position: absolute;
  top: 0; left: 0;
  width: var(--size);
  height: var(--size);
  cursor: pointer;
  will-change: transform;
}
.item img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  animation: spin var(--spin) linear infinite;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
}
.item.hit img { animation: pop 0.25s ease-out forwards; }

.float-text {
  position: absolute;
  font-weight: 800;
  font-size: 1.4rem;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: floatUp 0.7s ease-out forwards;
}
.float-text.good { color: var(--accent); }
.float-text.bad { color: var(--danger); }

.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  background: var(--accent);
  animation: burst 0.6s ease-out forwards;
}

.ripple {
  position: absolute;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  pointer-events: none;
  animation: ripple 0.4s ease-out forwards;
}

#game.shake { animation: shake 0.3s ease; }

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
}
.screen.active { display: flex; animation: fadeIn 0.35s ease; }

h1 {
  font-size: clamp(2.4rem, 9vw, 4.5rem);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
h1 span {
  background: linear-gradient(90deg, var(--accent), #fb923c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
h2 { font-size: clamp(2rem, 7vw, 3rem); font-weight: 900; }

.rules { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.rule {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--glass);
  font-size: 0.95rem;
}
.rule img { width: 28px; height: 28px; }
.sub, .best { color: var(--muted); }

.btn {
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  color: #1e1b4b;
  padding: 14px 40px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #fb923c);
  box-shadow: 0 8px 24px rgba(251, 146, 60, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(251, 146, 60, 0.45); }
.btn:active { transform: scale(0.96); }

.results { display: flex; gap: 16px; }
.results div {
  display: flex;
  flex-direction: column;
  min-width: 120px;
  padding: 16px 20px;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.results span:last-child { font-size: 2.6rem; font-weight: 900; }
.record { color: var(--accent); font-weight: 700; animation: pulse 1s ease infinite; }

/* ---------- Animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { to { transform: scale(1.6); opacity: 0; } }
@keyframes floatUp {
  from { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
  to { opacity: 0; transform: translate(-50%, -150%) scale(1.2); }
}
@keyframes burst {
  from { opacity: 1; transform: translate(0, 0) scale(1); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}
@keyframes ripple { to { transform: scale(3); opacity: 0; } }
@keyframes bump { 50% { transform: scale(1.3); } }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.97); } }
@keyframes pulse { 50% { transform: scale(1.08); } }

@media (prefers-reduced-motion: reduce) {
  .item img { animation: none; }
}
