:root {
  --font-heading: 'Dancing Script', cursive;
  --font-body: 'Be Vietnam Pro', system-ui, sans-serif;
  --wheel-size: min(85vmin, 380px);
  --segment-red: #c0392b;
  --segment-red-light: #f5b7b1;
  --segment-red-dark: #641e16;
  --segment-yellow: #ffe3a4;
  --segment-yellow-light: #fff5e0;
  --segment-yellow-dark: #e6c97a;
  --wheel-rim-width: 14px;
  --rim-red-dark: #641e16;
  --rim-red-light: #c0392b;
  --pointer: #f1c40f;
  --bg: #1a1a2e;
  --text: #eee;
  --btn: #c0392b;
  --btn-hover: #a93226;
}

* {
  box-sizing: border-box;
}

#bgMusic {
  position: absolute;
  left: -9999px;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* Confetti canvas above popup, does not block clicks */
body > canvas {
  position: fixed !important;
  top: 0;
  left: 0;
  z-index: 10000 !important;
  pointer-events: none;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg) url('/images/background/Back%20PC.png') center center / cover no-repeat;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.container {
  text-align: center;
  max-width: 420px;
  margin-top: 26vh;
}

@keyframes bulbs-dim {
  0%, 100% { opacity: 1; filter: brightness(1); }
  50% { opacity: 0.5; filter: brightness(0.6); }
}

/* Firework layer: particles + sparks (same as ball-lottery-machine) */
.firework-container {
  pointer-events: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  margin-top: -4px;
  border-radius: 50%;
  transform-origin: center center;
  pointer-events: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

@keyframes explode {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx), var(--ty)) scale(0);
  }
}

.spark {
  position: absolute;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  margin-top: -5px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, rgba(255, 220, 100, 0.8) 50%, transparent 70%);
  box-shadow: 0 0 8px #fff;
  pointer-events: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  animation: sparkle 0.8s ease-out forwards;
}

@keyframes sparkle {
  0% {
    opacity: 1;
    transform: scale(0) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.2) rotate(180deg);
  }
  100% {
    opacity: 0;
    transform: scale(0.5) rotate(360deg);
  }
}

h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
  background: linear-gradient(180deg, #f7dc6f 0%, #d4ac0d 40%, #b8860b 70%, #9a7d0a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4)) drop-shadow(0 -1px 0 rgba(255, 255, 255, 0.2));
}

.subtitle {
  margin: 0 0 1.5rem;
  opacity: 0.8;
  font-size: 0.95rem;
}

.wheel-wrapper {
  position: relative;
  width: var(--wheel-size);
  height: var(--wheel-size);
  margin: 0 auto 1.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

/* Single red rim: gradient dark → light → dark */
.wheel-wrapper::before {
  content: '';
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    transparent 0%,
    transparent 65%,
    var(--rim-red-dark) 65%,
    var(--rim-red-light) 78%,
    var(--rim-red-dark) 100%
  );
  pointer-events: none;
}

/* Yellow "light bulbs" inside the rim band – same dimming effect as title */
.wheel-wrapper::after {
  content: '';
  position: absolute;
  z-index: 0;
  /* Inset so the dotted circle sits in the middle of the rim (between wheel edge and outer edge) */
  inset: calc(var(--wheel-rim-width) / 2);
  border-radius: 50%;
  border: 4px dotted #f1c40f;
  pointer-events: none;
  animation: bulbs-dim 2s ease-in-out infinite;
}

@keyframes pointer-pulse {
  0%, 100% { filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)) brightness(1); opacity: 1; }
  50% { filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)) brightness(0.6); opacity: 0.85; }
}

.pointer {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 24px solid var(--pointer);
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
  animation: pointer-pulse 1.5s ease-in-out infinite;
}

.wheel {
  width: calc(100% - 2 * var(--wheel-rim-width));
  height: calc(100% - 2 * var(--wheel-rim-width));
  border-radius: 50%;
  overflow: hidden;
  box-sizing: border-box;
  position: relative;
  z-index: 1;
  cursor: pointer;
}

/* Round center button – red metallic "Quay" */
.wheel-center-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  background: linear-gradient(180deg, #e74c3c 0%, #c0392b 40%, #922b21 70%, #641e16 100%);
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.25),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3),
    0 4px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}

.wheel-center-btn:hover:not(:disabled) {
  transform: translate(-50%, -50%) scale(1.05);
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.3),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25),
    0 6px 12px rgba(0, 0, 0, 0.45);
}

.wheel-center-btn:active:not(:disabled) {
  transform: translate(-50%, -50%) scale(0.98);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.3),
    inset 0 -1px 2px rgba(255, 255, 255, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.35);
}

.wheel-center-btn:disabled {
  opacity: 0.8;
  cursor: not-allowed;
}

.wheel-inner {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  transform-origin: center center;
  transition: transform 0.1ms linear;
  border-radius: 50%;
  overflow: hidden;
}

.wheel.spinning .wheel-inner {
  transition: none;
}

.segment {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  transform-origin: 50% 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: clamp(0.65rem, 2.5vw, 0.85rem);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  overflow: hidden;
  /* wedge with curved outer edge via SVG clipPath */
  clip-path: url(#segmentWedge);
}

/* Radial gradient per slice: center (lighter) → rim (darker), stronger contrast */
.segment:nth-child(1) { transform: rotate(0deg);   background: radial-gradient(circle at 50% 50%, var(--segment-red-light) 0%, var(--segment-red) 35%, var(--segment-red-dark) 100%); }
.segment:nth-child(2) { transform: rotate(36deg);  background: radial-gradient(circle at 50% 50%, var(--segment-yellow-light) 0%, var(--segment-yellow) 35%, var(--segment-yellow-dark) 100%); }
.segment:nth-child(3) { transform: rotate(72deg);  background: radial-gradient(circle at 50% 50%, var(--segment-red-light) 0%, var(--segment-red) 35%, var(--segment-red-dark) 100%); }
.segment:nth-child(4) { transform: rotate(108deg); background: radial-gradient(circle at 50% 50%, var(--segment-yellow-light) 0%, var(--segment-yellow) 35%, var(--segment-yellow-dark) 100%); }
.segment:nth-child(5) { transform: rotate(144deg); background: radial-gradient(circle at 50% 50%, var(--segment-red-light) 0%, var(--segment-red) 35%, var(--segment-red-dark) 100%); }
.segment:nth-child(6) { transform: rotate(180deg); background: radial-gradient(circle at 50% 50%, var(--segment-yellow-light) 0%, var(--segment-yellow) 35%, var(--segment-yellow-dark) 100%); }
.segment:nth-child(7) { transform: rotate(216deg); background: radial-gradient(circle at 50% 50%, var(--segment-red-light) 0%, var(--segment-red) 35%, var(--segment-red-dark) 100%); }
.segment:nth-child(8) { transform: rotate(252deg); background: radial-gradient(circle at 50% 50%, var(--segment-yellow-light) 0%, var(--segment-yellow) 35%, var(--segment-yellow-dark) 100%); }
.segment:nth-child(9) { transform: rotate(288deg); background: radial-gradient(circle at 50% 50%, var(--segment-red-light) 0%, var(--segment-red) 35%, var(--segment-red-dark) 100%); }
.segment:nth-child(10) { transform: rotate(324deg); background: radial-gradient(circle at 50% 50%, var(--segment-yellow-light) 0%, var(--segment-yellow) 35%, var(--segment-yellow-dark) 100%); }

.segment img {
  position: absolute;
  left: 64%;
  top: 12%;
  transform: translate(-50%, -50%) rotate(18deg);
  width: 10%;
  height: 10%;
  object-fit: cover;
  border-radius: 4px;
  pointer-events: none;
}

.segment.segment-text .segment-text-content {
  position: absolute;
  left: 64%;
  top: 12%;
  transform: translate(-50%, -50%) rotate(18deg);
  width: 55%;
  max-width: 4.5em;
  text-align: center;
  font-size: clamp(0.5rem, 1.8vw, 0.65rem);
  line-height: 1.25;
  overflow-wrap: break-word;
  word-wrap: break-word;
  white-space: normal;
  pointer-events: none;
  color: #e74c3c;
  font-weight: 700;
  text-shadow: none;
}

.btn-spin {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--btn);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-spin:hover:not(:disabled) {
  background: var(--btn-hover);
}

.btn-spin:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.result {
  min-height: 1.5em;
  margin: 1rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.error {
  color: #e74c3c;
  min-height: 1em;
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
}

.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.popup-overlay[hidden] {
  display: none;
}

.popup {
  max-width: 320px;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 16px 48px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
}

.popup-header {
  background: #641e16;
  padding: 1rem 1.5rem;
  text-align: center;
}

.popup-title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.25rem;
  margin: 0;
  color: #fff;
}

.popup-body {
  background: #fff;
  padding: 1.5rem 1.5rem;
  text-align: center;
}

.popup-result {
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 1rem;
  color: #1a1a2e;
}

.btn-popup-close {
  font-family: var(--font-body);
  padding: 0.6rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: #641e16;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-popup-close:hover {
  filter: brightness(1.1);
}
