:root {
  --night: #160a2e;
  --panel: #241347;
  --ink: #f4ecff;
  --gold: #ffd25a;
  --orange: #ff8a2b;
  --green: #4fe07a;
  --cyan: #3fe3ff;
  --purple: #c46bff;
  --pink: #ff4fa8;
  --display: "Lilita One", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: linear-gradient(#3a1d6e, #26124b);
  box-shadow: 0 2px 0 #12072a, 0 4px 14px rgba(0, 0, 0, 0.4);
  position: relative;
  z-index: 2;
}

.brand {
  font-family: var(--display);
  font-size: 22px;
  color: var(--gold);
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 #a3440f, 0 0 12px rgba(255, 160, 60, 0.5);
  white-space: nowrap;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
  font-family: var(--display);
  font-size: 18px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stat small {
  font-family: system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.6;
}
.stat.balls { align-items: center; font-size: 22px; color: #fff; padding-left: 8px; }
.stat.balls.low { color: #ff6b6b; animation: pulse 0.6s ease-in-out infinite alternate; }
.stat.balls.bump { animation: bump 0.25s ease-out; }
@keyframes pulse { to { opacity: 0.55; } }
@keyframes bump { 40% { transform: scale(1.18); } }

.ball-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 18%, #c9cfdc 45%, #6b7184 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}


@media (max-width: 560px) {
  #bar { gap: 6px; padding: 6px 8px; }
  .brand { display: none; }
  .stat { padding: 3px 9px; font-size: 16px; }
  .stat.balls { font-size: 19px; }
  .stat.best small { display: none; }
}
@media (max-width: 380px) {
  .stat.best { display: none; }
}

#stage {
  flex: 1;
  position: relative;
  min-height: 0;
  background: radial-gradient(ellipse at 50% 30%, #2a1356 0%, var(--night) 70%);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 4, 24, 0.66);
  backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }

.card {
  width: min(420px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 24px 24px 20px;
  border-radius: 22px;
  background: linear-gradient(#2f1862, #1e0f40);
  border: 2px solid rgba(255, 210, 90, 0.5);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.3), 0 18px 50px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h1, .card h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: normal;
  color: var(--gold);
  text-shadow: 0 3px 0 #a3440f, 0 0 18px rgba(255, 160, 60, 0.45);
}
.card h1 { font-size: 46px; }
.card h2 { font-size: 32px; }
.lede { margin: 0; font-size: 16px; color: #e3d6ff; }

.legend {
  list-style: none;
  margin: 4px 0;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 14.5px;
  line-height: 1.35;
  color: #d9ccf5;
}
.legend li { display: flex; gap: 10px; align-items: center; }
.legend b { color: #fff; }
.legend i { flex: none; }

.peg {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor, inset 0 -2px 0 rgba(0, 0, 0, 0.3);
}
.peg.orange { background: var(--orange); color: var(--orange); }
.peg.green { background: var(--green); color: var(--green); }
.peg.split { background: var(--cyan); color: var(--cyan); }
.peg.mult { background: var(--purple); color: var(--purple); }
.pocket {
  width: 16px;
  height: 14px;
  border: 3px solid var(--gold);
  border-top: 0;
  border-radius: 0 0 6px 6px;
}

.keys { margin: 2px 0 0; font-size: 12.5px; line-height: 1.6; color: #a99bcc; }

.primary, .soft {
  padding: 13px 20px;
  border-radius: 14px;
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.02em;
}
.primary {
  background: linear-gradient(#ffd25a, #ff9a2b);
  color: #4a1b00;
  box-shadow: 0 4px 0 #a3440f, 0 0 20px rgba(255, 170, 60, 0.4);
}
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #a3440f; }
.soft {
  background: rgba(255, 255, 255, 0.1);
  color: #e3d6ff;
  font-size: 18px;
  padding: 10px 16px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.results {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 16px;
  margin: 4px 8px;
  text-align: left;
  font-size: 16px;
}
.results dt { color: #b8a8e0; }
.results dd { margin: 0; font-family: var(--display); font-size: 19px; text-align: right; font-variant-numeric: tabular-nums; }
.results dd:first-of-type { color: var(--gold); font-size: 24px; }

.badge {
  margin: -4px auto 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--pink);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  animation: pulse 0.5s ease-in-out infinite alternate;
}
.badge[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
