:root {
  --bg-gradient: radial-gradient(circle at 50% 20%, #1a103c 0%, #0c081e 50%, #05030a 100%);
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-glow: rgba(138, 92, 246, 0.25);
  --neon-cyan: #00f2fe;
  --neon-purple: #9d4edd;
  --neon-pink: #ff007f;
  --neon-gold: #ffd60a;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed; /* Prevents unwanted bounce or horizontal shifts */
  inset: 0;
  background: var(--bg-gradient);
  font-family: 'Outfit', 'Montserrat', sans-serif;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.ambient-glow {
  position: absolute;
  width: 60vw;
  height: 60vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(112, 0, 255, 0.15) 0%, rgba(0,0,0,0) 70%);
  top: -10vw;
  left: -10vw;
  pointer-events: none;
  filter: blur(50px);
  z-index: 0;
}

.ambient-glow-2 {
  position: absolute;
  width: 50vw;
  height: 50vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 242, 254, 0.12) 0%, rgba(0,0,0,0) 70%);
  bottom: -10vw;
  right: -10vw;
  pointer-events: none;
  filter: blur(60px);
  z-index: 0;
}

#physics-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
}

.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4), 
              inset 0 1px 0 rgba(255, 255, 255, 0.2),
              0 0 40px var(--glass-glow);
}

#input-modal {
  position: relative;
  z-index: 10;
  width: 90%;
  max-width: 500px;
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

#input-modal.hide {
  opacity: 0;
  transform: scale(0.9) translateY(40px);
  pointer-events: none;
}

.modal-header {
  text-align: center;
}

.modal-header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #fff 30%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
  margin-bottom: 0.3rem;
}

.modal-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 400;
}

textarea {
  width: 100%;
  height: 170px;
  padding: 1.1rem;
  background: rgba(10, 8, 22, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  outline: none;
  transition: border 0.3s, box-shadow 0.3s;
}

textarea:focus {
  border-color: var(--neon-purple);
  box-shadow: 0 0 20px rgba(157, 78, 221, 0.4);
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.btn-primary {
  background: linear-gradient(135deg, #9d4edd 0%, #ff007f 100%);
  color: #fff;
  border: none;
  padding: 1rem 2rem;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(255, 0, 127, 0.35);
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 35px rgba(255, 0, 127, 0.5);
  filter: brightness(1.1);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
  padding: 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* Status HUD */
#mixing-hud {
  position: absolute;
  top: 1.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  z-index: 5;
  opacity: 0;
  transform: translateY(-20px);
  transition: all 0.5s ease;
  pointer-events: none;
}

#mixing-hud.show {
  opacity: 1;
  transform: translateY(0);
}

.hud-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(20, 15, 38, 0.75);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.6rem 1.4rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neon-cyan);
  box-shadow: 0 0 10px var(--neon-cyan);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  0% { opacity: 0.3; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1.3); }
}

/* Quick Access Trigger for Winners History */
#history-toggle-btn {
  position: absolute;
  top: 1.5rem;
  left: 1.5rem;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(20, 15, 38, 0.85);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#history-toggle-btn.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#history-toggle-btn:hover {
  background: rgba(30, 22, 60, 0.95);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 16px rgba(0, 242, 254, 0.35);
  transform: translateY(-2px);
}

/* Persistent Winners Sidebar Panel */
#winners-panel {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  width: 290px;
  max-height: calc(100vh - 3rem);
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  z-index: 25;
  opacity: 0;
  transform: translateX(50px);
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#winners-panel.show {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.winners-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 0.6rem;
}

.winners-panel-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--neon-cyan);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.winners-count-badge {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.2rem 0.6rem;
  background: rgba(0, 242, 254, 0.15);
  border: 1px solid rgba(0, 242, 254, 0.3);
  border-radius: 999px;
  color: var(--neon-cyan);
}

.btn-panel-action {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-panel-action:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.winners-list-container {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 380px;
  padding-right: 4px;
}

.winners-list-container::-webkit-scrollbar {
  width: 4px;
}
.winners-list-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.winner-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  animation: slideInWinner 0.4s ease forwards;
}

@keyframes slideInWinner {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.winner-rank {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--neon-gold);
  min-width: 22px;
}

.winner-mini-ball {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 900;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.winner-item-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Result Stage Overlay */
#result-view {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, rgba(12, 8, 30, 0.75) 0%, rgba(5, 3, 10, 0.92) 80%);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

#result-view.show {
  opacity: 1;
  pointer-events: auto;
}

.winner-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2.5rem 3.2rem;
  max-width: 90%;
  transform: scale(0.7) translateY(50px);
  transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#result-view.show .winner-card {
  transform: scale(1) translateY(0);
}

.winner-label {
  font-size: 1.05rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--neon-cyan);
  text-shadow: 0 0 12px rgba(0, 242, 254, 0.6);
  margin-bottom: 1.2rem;
}

.winning-ball-spotlight {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  margin: 0 auto 1.3rem;
  position: relative;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
}

.winner-name-display {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: #fff;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.5), 0 0 60px var(--neon-purple);
  margin-bottom: 0.4rem;
  line-height: 1.1;
  max-width: 600px;
  word-break: break-word;
}

.remaining-count-badge {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  letter-spacing: 0.5px;
}
.remaining-count-badge span {
  color: var(--neon-cyan);
  font-weight: 800;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 360px;
}

.btn-continue {
  background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
  color: #030a1c;
  border: none;
  padding: 0.95rem 1.8rem;
  font-size: 1.05rem;
  font-weight: 800;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 242, 254, 0.4);
  transition: all 0.25s ease;
  letter-spacing: 0.5px;
}

.btn-continue:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 15px 40px rgba(0, 242, 254, 0.6);
}

.btn-scratch {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff;
  padding: 0.8rem 1.6rem;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-scratch:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.btn-view-summary {
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid rgba(0, 242, 254, 0.3);
  color: var(--neon-cyan);
  padding: 0.75rem 1.6rem;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-view-summary:hover {
  background: rgba(0, 242, 254, 0.22);
  border-color: var(--neon-cyan);
  color: #fff;
}

/* Final Complete Summary Modal */
#summary-modal {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, rgba(12, 8, 30, 0.85) 0%, rgba(5, 3, 10, 0.95) 80%);
  backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#summary-modal.show {
  opacity: 1;
  pointer-events: auto;
}

.summary-card {
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  padding: 2.2rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  transform: scale(0.9) translateY(20px);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#summary-modal.show .summary-card {
  transform: scale(1) translateY(0);
}

.summary-header {
  text-align: center;
}

.summary-header h2 {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, #00f2fe 0%, #9d4edd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.2rem;
}

.summary-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.summary-list-box {
  overflow-y: auto;
  max-height: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding-right: 4px;
}

.summary-list-box::-webkit-scrollbar {
  width: 4px;
}
.summary-list-box::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

@media (max-width: 850px) {
  #winners-panel {
    top: auto;
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
    width: auto;
    max-height: 180px;
  }
  .winners-list-container {
    max-height: 110px;
  }
}

@media (max-width: 600px) {
  #input-modal { padding: 1.8rem; }
  .winner-card { padding: 2rem 1.4rem; }
  .winner-name-display { font-size: 2.2rem; }
  .winning-ball-spotlight { width: 90px; height: 90px; }
  .summary-card { padding: 1.6rem; }
}
