* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

body {
  font-family: Arial, sans-serif;
  background-color: whitesmoke;
}

/* CSS */
.button-spin {
  backface-visibility: hidden;
  background: grey;
  border: 0;
  border-radius: 0.375rem;
  box-sizing: border-box;
  color: #fff;
  cursor: pointer;
  display: inline-block;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
  padding: 1rem 1.25rem;
  position: relative;
  text-align: left;
  text-decoration: none;
  transform: translateZ(0) scale(1);
  transition: transform 0.2s;
  -moz-user-select: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.button-spin:disabled {
  color: #787878;
  cursor: auto;
}

.button-spin:not(:disabled):hover {
  transform: scale(1.05);
}

.button-spin:not(:disabled):hover:active {
  transform: scale(1.05) translateY(0.125rem);
}

.button-spin:focus {
  outline: 0 solid transparent;
}

.button-spin:focus:before {
  border-width: 0.125rem;
  content: '';
  left: -0.375rem;
  pointer-events: none;
  position: absolute;
  top: -0.375rem;
  transition: border-radius;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

.button-spin:focus:not(:focus-visible) {
  outline: 0 solid transparent;
}

.button-spin:not(:disabled):active {
  transform: translateY(0.125rem);
}

#questionContainer {
  width: 100%;
  margin-bottom: 20px;
}

#nameQuestion {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 5px;
  background-color: rgba(255, 255, 255, 0.7);
  text-align: center;
}

#nameQuestion::placeholder {
  color: #999;
  font-style: italic;
  text-align: center;
}

#mainContainer {
  display: flex;
  justify-content: center;
  height: 100vh;
}

#controls {
  flex: 1;
  position: relative;
  padding: 4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}

#controls #inputContainer {
  width: 100%;
  position: relative;
}

#controls #inputContainer input {
  width: calc(100% - 70px); /* Leave space for the button */
  padding: 10px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 5px;
  background-color: rgba(255, 255, 255, 0.7);
}

#controls #inputContainer #addNameButton {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  margin: 0;
  padding: 8px 12px;
  font-size: 18px;
  width: 60px;
  border: 2px solid #ddd;
  border-radius: 5px;
  background-color: rgba(255, 255, 255, 0.7);
  color: #333;
  cursor: pointer;
}

#wheelContainer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  flex: 2;
  position: relative;
  margin: 20px;
}

#wheelContainer.winner-mode {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  margin: 0;
  z-index: 1;
}

.slide {
  transition: padding 500ms;
}

#nameInput {
  padding: 10px;
  font-size: 16px;
  margin-right: 10px;
}

#nameInput::placeholder {
  color: #999;
  font-style: italic;
}

#addNameButton,
#spinButton {
  padding: 10px 20px;
  font-size: 16px;
  margin: 10px;
  cursor: pointer;
  border: 2px solid #ddd;
  border-radius: 5px;
  background-color: rgba(255, 255, 255, 0.7);
  color: #333;
}

#spinButton {
  opacity: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
  background: rgba(61, 61, 61, 0.142);
  color: rgb(237, 236, 236);
  z-index: 10;
  transition: all 0.3s ease;
  cursor: default;
  pointer-events: none;
}

#spinButton:hover {
  transform: translate(-50%, -50%) scale(1.05);
}

#spinButton:active {
  transform: translate(-50%, -50%) scale(0.95);
}

#nameList {
  list-style: none;
  padding: 0;
  margin: 20px 0;
  width: 100%;
}

#nameList li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  margin: 5px 0;
  color: #fff;
  font-weight: bold;
  border-radius: 5px;
}

#nameList span {
  font-weight: bold;
  font-size: 20px;
  cursor: pointer;
  color: white;
}

#nameList li:hover span {
  color: red;
}

/* Modal styling */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  padding: 20px;
  color: white;
  z-index: 9999;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  opacity: 0;
  justify-content: center;
  align-items: center;
}

.close-modal {
  position: absolute;
  top: 20px;
  right: 30px;
  color: #e13535;
  font-size: 40px;
  font-weight: normal;
  cursor: pointer;
  pointer-events: auto;
  z-index: 10000;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  user-select: none;
}

.close-modal:hover {
  color: #333;
}

.modal h2 {
  text-align: center;
  color: #fff;
  font-size: 140px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-14deg);
  margin: 0;
  transform-origin: center;
}

.animated {
  animation-name: grow;
  animation-duration: 900ms;
  animation-timing-function: ease-in-out;
  animation-fill-mode: forwards;
}

@keyframes grow {
  0% {
    opacity: 0;
    transform: scale(0) rotateY(20deg);
  }
  40% {
    transform: scale(1.1);
  }
  50% {
    transform: scale(0.9);
  }
  60% {
    opacity: 1;
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.95);
  }
  80% {
    transform: scale(1.02);
  }
  90% {
    transform: scale(0.98) rotateY(0);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes bounceWinner {
  0% {
    transform: translate(-52%, -48%) rotate(6deg);
  }
  25% {
    transform: translate(-50%, -50%) rotate(-6deg);
  }
  50% {
    transform: translate(-48%, -52%) rotate(6deg);
  }
  75% {
    transform: translate(-50%, -50%) rotate(-6deg);
  }
  100% {
    transform: translate(-52%, -48%) rotate(6deg);
  }
}
#winnerName {
  animation: bounceWinner 3s infinite ease-in-out;
}

/* Confetti container */
.confetti-container {
  position: fixed;
  top: -30px;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* Individual confetti pieces */
.confetti {
  position: absolute;
  width: 15px;
  height: 8px;
  border-radius: 5px;
  animation: fall var(--fall-duration) infinite ease-in forwards;
  animation-delay: var(--delay);
  transform-origin: center;
}

/* Falling animation */
@keyframes fall {
  0% {
    transform: translateY(-100px) rotate(var(--rotation-start));
  }
  100% {
    transform: translateY(calc(100vh + 30px)) rotate(var(--rotation-end));
  }
}

/* Wheel text overlay */
#wheelTextOverlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  z-index: 1;
}

#wheelText {
  text-align: center;
  font-size: 130px;
  color: white;
  font-weight: normal;
  line-height: 0.9;
  white-space: normal;
  word-spacing: 999px;
  max-width: 80%;
  transform: translateY(-15%);
}

.bubbles-container {
  position: fixed;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  top: 0;
  left: 0;
  z-index: -999;
  pointer-events: none;
}

.bubble {
  position: absolute;
  background: rgba(245, 71, 251, 0.2);
  border-radius: 50%;
  opacity: 0.8;
  top: -200px;
  animation: bubble-animation infinite linear;
}

@keyframes bubble-animation {
  0% {
    transform: translateY(-200px);
  }
  100% {
    transform: translateY(140vh);
  }
}

/* MOBILE STYLE IMPROVEMENTS */
@media (max-width: 600px) {
  html, body {
    width: 100vw;
    min-height: 100vh;
    overflow-x: hidden;
  }

  #mainContainer {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    min-height: 100vh;
    height: auto;
    padding: 0;
  }

  #controls {
    order: 2;
    width: 100vw;
    padding: 1.5rem 1rem;
    min-width: 0;
    max-width: 100vw;
  }

  #controls #inputContainer {
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-bottom: 1rem;
  }

  #controls #questionContainer {
    width: 100%;
    margin-bottom: 1rem;
  }

  #controls #questionContainer input {
    font-size: 18px;
    padding: 12px;
    width: 100%;
    border-radius: 6px;
  }

  #controls #inputContainer input {
    font-size: 18px;
    padding: 12px;
    flex: 1;
    min-width: 0;
    border-radius: 6px;
    border: 2px solid #ddd;
    background-color: rgba(255, 255, 255, 0.7);
    height: 50px;
  }

  #controls #inputContainer #addNameButton {
    position: static;
    transform: none;
    margin: 0;
    font-size: 22px;
    padding: 8px 16px;
    border-radius: 6px;
    min-width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ddd;
    background-color: rgba(255, 255, 255, 0.7);
    color: #333;
    flex-shrink: 0;
  }

  #nameList {
    margin: 16px 0 0 0;
    width: 100%;
  }

  #nameList li {
    padding: 14px;
    font-size: 17px;
  }

  #nameList span {
    font-size: 22px;
  }

  #wheelContainer {
    order: 1;
    width: 100vw;
    min-width: 0;
    padding: 15px;
    margin: 0;
  }

  #wheelContainer.winner-mode {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    z-index: 1;
  }

  /* Canvas responsive sizing */
  #wheelCanvas {
    width: 90vw !important;
    height: 90vw !important;
    max-width: 90vw !important;
    max-height: 90vw !important;
    min-width: 220px;
    min-height: 220px;
    display: block;
    margin: 10px auto;
    background: none;
    touch-action: none;
  }

  /* Spin button responsive sizing */
  #spinButton {
    font-size: 22px;
    font-weight: bold;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.3s ease;
    cursor: default;
    pointer-events: none;
  }

  /* Modal adjustments */
  .modal {
    padding: 10px;
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
  }
  
  .close-modal {
    top: 15px;
    right: 15px;
    font-size: 30px;
    width: 35px;
    height: 35px;
  }
  
  .modal h2, #winnerName {
    font-size: 2.2em !important;
    min-width: 0;
    max-width: 90vw;
    padding: 0 10px;
    word-break: break-word;
    left: 50%;
    top: 45%;
  }

  /* Wheel text mobile styles */
  #wheelText {
    font-size: calc(90vw / 7) !important;
    max-width: 80%;
    word-spacing: 999px;
  }

  /* Confetti adjustments */
  .confetti {
    width: 10px;
    height: 6px;
  }

  /* Bubbles */
  .bubbles-container {
    width: 100vw;
    height: 100vh;
    min-width: 0;
    min-height: 0;
  }
}

/* Tablet support */
@media (min-width: 601px) and (max-width: 900px) {
  #mainContainer {
    flex-direction: column;
    align-items: center;
    height: auto;
    min-height: 100vh;
  }
  #controls {
    padding: 2rem 2rem;
  }
  #wheelContainer {
    padding: 20px;
  }
  #wheelCanvas {
    width: 420px !important;
    height: 420px !important;
    max-width: 95vw !important;
    max-height: 95vw !important;
    margin: 15px auto;
  }
  #spinButton {
    width: 75px;
    height: 75px;
    font-size: 20px;
    font-weight: bold;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.3s ease;
    cursor: default;
    pointer-events: none;
  }
}
