:root {
  --brass: #d4b06a;
  --brass-dim: #a8894f;
  --ink: #eef0ea;
  --ink-dim: #b9beb2;
  --panel: rgba(14, 20, 16, 0.72);
  --panel-line: rgba(212, 176, 106, 0.25);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #070b08;
  font-family: "Outfit", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#scene {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

#vig {
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 52%, rgba(0, 0, 0, 0.55) 100%);
  z-index: 2;
}

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud button, #powerRail, #spinPop { pointer-events: auto; }
#hud[hidden] { display: none; }

button {
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
  border: none;
  cursor: pointer;
}

#topbar {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  left: calc(var(--safe-l) + 12px);
  right: calc(var(--safe-r) + 12px);
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px;
}

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px; font-weight: 600;
  letter-spacing: 0.02em;
}

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--brass);
  box-shadow: 0 0 8px var(--brass);
}
.dot.opp { background: #7fa8ff; box-shadow: 0 0 8px #7fa8ff; }

.racks { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }
.rack {
  display: flex; align-items: center; gap: 7px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 4px 10px;
}
.rack-name { font-size: 11px; font-weight: 700; color: var(--ink-dim); letter-spacing: 0.06em; text-transform: uppercase; }
.rack-balls { display: flex; gap: 4px; min-height: 12px; }
.rack.lead { border-color: var(--panel-line); }
.mini-ball {
  width: 12px; height: 12px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 7px; font-weight: 900; color: #111;
  background: #ddd;
  box-shadow: inset -1px -2px 3px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.5);
  opacity: 0.28;
}
.mini-ball.got { opacity: 1; }

#toast {
  position: absolute;
  top: calc(var(--safe-t) + 64px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 10px 18px;
  font-size: 15px; font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  max-width: min(86vw, 420px);
  animation: toast-in 0.25s ease;
  z-index: 6;
}
#toast[hidden] { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

#hint {
  position: absolute;
  bottom: calc(var(--safe-b) + 24px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px; font-weight: 600;
  color: var(--ink-dim);
  background: rgba(10, 14, 11, 0.55);
  border-radius: 999px;
  padding: 7px 14px;
  white-space: nowrap;
}
#hint[hidden] { display: none; }

#kudos {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 30px; font-weight: 900;
  letter-spacing: 0.14em;
  background: linear-gradient(160deg, #fdf0c8, var(--brass) 60%, #b8924e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(212, 176, 106, 0.55));
  animation: kudos-pop 1.15s cubic-bezier(0.18, 1.5, 0.4, 1) forwards;
  white-space: nowrap;
  pointer-events: none;
}
#kudos[hidden] { display: none; }
@keyframes kudos-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
  18% { opacity: 1; transform: translateX(-50%) scale(1.12); }
  30% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(0.96); }
}

#foulFlash {
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 110px rgba(214, 48, 60, 0.55);
  transition: opacity 0.9s ease;
  z-index: 4;
}
#foulFlash.on { opacity: 1; transition: opacity 0.06s ease; }

/* ---------- power rail ---------- */

#powerRail {
  position: absolute;
  right: calc(var(--safe-r) + 10px);
  top: 50%;
  transform: translateY(-50%);
  width: 56px; height: min(46vh, 340px);
  display: flex; align-items: stretch; justify-content: center;
  touch-action: none;
}
#powerTrack {
  width: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  position: relative;
}
#powerFill {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 0%;
  background: linear-gradient(180deg, #ffd98a, #e0653a);
  border-radius: 999px;
  transition: height 0.05s linear;
}
#powerGrip {
  position: absolute;
  top: -6px; left: 50%;
  transform: translate(-50%, 0);
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--brass);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

/* ---------- side buttons ---------- */

#sideBtns {
  position: absolute;
  left: calc(var(--safe-l) + 10px);
  bottom: calc(var(--safe-b) + 14px);
  display: flex; flex-direction: column; gap: 10px;
}
.icon-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--ink);
  font-size: 19px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.on { border-color: var(--panel-line); color: var(--brass); }

#spinMini {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff, #cfd2c9 70%, #9a9d92);
  position: relative;
  display: block;
}
#spinMiniDot {
  position: absolute;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #d33;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
}

/* ---------- spin popover ---------- */

#spinPop {
  position: absolute;
  left: calc(var(--safe-l) + 12px);
  bottom: calc(var(--safe-b) + 76px);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}
#spinPop[hidden] { display: none; }
.spin-title { font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); }
#spinBall {
  width: 128px; height: 128px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #ffffff, #d9dcd2 62%, #a3a698 92%);
  box-shadow: inset -6px -10px 22px rgba(0, 0, 0, 0.25), 0 6px 18px rgba(0, 0, 0, 0.45);
  position: relative;
  touch-action: none;
}
#spinDot {
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #c8372d;
  border: 2px solid rgba(255, 255, 255, 0.85);
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
#spinReset {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 13px; font-weight: 700;
}

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

#menu, #over {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 20px calc(var(--safe-r) + 20px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 20px);
  background: radial-gradient(90% 70% at 50% 30%, rgba(7, 12, 9, 0.25), rgba(4, 7, 5, 0.82));
}
#menu[hidden], #over[hidden] { display: none; }

.menu-card {
  width: min(92vw, 380px);
  background: rgba(12, 18, 14, 0.82);
  border: 1px solid var(--panel-line);
  border-radius: 26px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 30px 26px calc(24px);
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

.menu-emoji { font-size: 44px; }
.menu-title {
  font-size: 42px; font-weight: 900;
  letter-spacing: 0.01em;
  margin-top: 4px;
  background: linear-gradient(160deg, #f4e5c0, var(--brass) 60%, #8f7038);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.menu-sub { font-size: 14.5px; color: var(--ink-dim); margin-top: 4px; font-weight: 500; }

.seg {
  display: flex;
  margin-top: 20px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.seg-btn {
  border-radius: 999px;
  padding: 9px 16px;
  background: transparent;
  color: var(--ink-dim);
  font-size: 13.5px; font-weight: 700;
}
.seg-btn.on { background: var(--brass); color: #17130a; }

.primary {
  margin-top: 18px;
  width: 100%;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(160deg, #f0d9a8, var(--brass) 55%, #b08c4a);
  color: #17130a;
  font-size: 19px; font-weight: 900;
  letter-spacing: 0.03em;
  box-shadow: 0 10px 26px rgba(212, 176, 106, 0.28);
  transition: transform 0.12s ease;
}
.primary:active { transform: scale(0.97); }

.ghost {
  margin-top: 10px;
  width: 100%;
  padding: 13px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--ink);
  font-size: 15px; font-weight: 700;
}

.menu-hints {
  margin-top: 18px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12.5px; color: var(--ink-dim); font-weight: 500;
}

/* ---------- loader ---------- */

#loader {
  position: fixed; inset: 0;
  z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(100% 80% at 50% 20%, #12251a 0%, #0a150e 55%, #050a07 100%);
  transition: opacity 0.45s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.loader-emoji { font-size: 52px; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.loader-title {
  font-size: 34px; font-weight: 900;
  background: linear-gradient(160deg, #f4e5c0, var(--brass) 60%, #8f7038);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.loader-bar {
  width: min(60vw, 240px); height: 6px;
  background: rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  overflow: hidden;
}
.loader-fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brass-dim), #ffd98a);
  transition: width 0.25s ease;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { 0% { filter: brightness(0.9); } 50% { filter: brightness(1.25); } 100% { filter: brightness(0.9); } }
.loader-sub { font-size: 13px; color: var(--ink-dim); font-weight: 600; }

@media (max-width: 700px) {
  .menu-title { font-size: 36px; }
  #powerRail { height: min(40vh, 300px); }
}
