:root {
  --bg-color: var(--tg-theme-bg-color, #0f172a);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #1e293b);
  --text-color: var(--tg-theme-text-color, #f8fafc);
  --hint-color: var(--tg-theme-hint-color, #94a3b8);
  --button-color: var(--tg-theme-button-color, #2563eb);
  --button-text-color: var(--tg-theme-button-text-color, #ffffff);
  --accent-border: rgba(148, 163, 184, 0.22);
  --shadow-strong: 0 18px 45px rgba(2, 6, 23, 0.45);
  --radius-lg: 20px;
  --radius-md: 14px;
}

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

html,
body {
  min-height: 100%;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.app-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background-color: var(--secondary-bg);
  border: 1px solid var(--accent-border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--hint-color);
}

.app-header h1 {
  font-size: clamp(1.5rem, 5vw, 1.95rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.subtitle {
  font-size: 0.92rem;
  color: var(--hint-color);
  max-width: 34ch;
  line-height: 1.4;
}

.wheel-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.wheel-stage {
  position: relative;
  width: min(86vw, 370px);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
}

#wheelCanvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  box-shadow: var(--shadow-strong);
  border: 5px solid var(--secondary-bg);
}

.pointer {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 26px solid var(--button-color);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
  z-index: 3;
}

.pointer::after {
  content: "";
  position: absolute;
  top: -29px;
  left: -6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--button-text-color);
  border: 2px solid var(--button-color);
}

.wheel-hub {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--button-color) 82%, #ffffff), var(--button-color));
  color: var(--button-text-color);
  border: 4px solid #ffffff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.28), 0 10px 24px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  z-index: 4;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.18s ease, filter 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.wheel-hub::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3px solid var(--button-color);
  opacity: 0;
  pointer-events: none;
}

.wheel-hub:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.38), 0 12px 28px rgba(0, 0, 0, 0.5);
}

.wheel-hub:active:not(:disabled) {
  transform: scale(0.92);
}

.wheel-hub:disabled {
  cursor: not-allowed;
}

.hub-icon {
  display: inline-block;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}

.wheel-hub.is-clicked {
  animation: hubPop 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.wheel-hub.is-clicked::after {
  animation: hubRipple 0.65s cubic-bezier(0.16, 1, 0.3, 1);
}

.wheel-hub.is-clicked .hub-icon {
  animation: cartDash 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.wheel-hub.is-spinning {
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.45), 0 0 24px var(--button-color);
}

.wheel-hub.is-spinning .hub-icon {
  animation: cartVibrate 0.28s ease-in-out infinite alternate;
}

@keyframes hubPop {
  0% { transform: scale(1); }
  25% { transform: scale(0.84); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes hubRipple {
  0% {
    opacity: 0.9;
    transform: scale(0.95);
  }
  100% {
    opacity: 0;
    transform: scale(1.95);
  }
}

@keyframes cartDash {
  0% { transform: translateX(0) rotate(0deg) scale(1); }
  25% { transform: translateX(-5px) rotate(-14deg) scale(0.92); }
  60% { transform: translateX(6px) rotate(12deg) scale(1.2); }
  100% { transform: translateX(0) rotate(0deg) scale(1); }
}

@keyframes cartVibrate {
  from { transform: rotate(-6deg) scale(1.03); }
  to { transform: rotate(6deg) scale(1.03); }
}

.controls {
  width: 100%;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 22px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.14s ease, filter 0.14s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

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

.btn-primary {
  background-color: var(--button-color);
  color: var(--button-text-color);
  flex: 1 1 190px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
}

.btn-secondary {
  background-color: var(--secondary-bg);
  color: var(--text-color);
  border: 1px solid var(--accent-border);
  flex: 0 1 auto;
}

.status-text {
  min-height: 1.25em;
  font-size: 0.85rem;
  color: var(--hint-color);
  text-align: center;
}

/* Modal */
.modal-backdrop[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
  animation: fadeIn 0.2s ease-out;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  background-color: var(--secondary-bg);
  color: var(--text-color);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-lg);
  padding: 24px 22px 22px;
  box-shadow: var(--shadow-strong);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: popUp 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--accent-border);
  background: var(--bg-color);
  color: var(--text-color);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 36px;
}

.modal-emoji {
  font-size: 1.75rem;
  line-height: 1;
}

.modal-category {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-color);
  color: var(--button-color);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-title {
  font-size: 1.25rem;
  line-height: 1.28;
  font-weight: 800;
}

.modal-explanation {
  font-size: 0.97rem;
  line-height: 1.55;
  color: var(--text-color);
  opacity: 0.92;
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.toast[hidden] {
  display: none;
}

.toast {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-color);
  color: var(--bg-color);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
  z-index: 30;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popUp {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* --- Motivos Navideños --- */
.app {
  position: relative;
  z-index: 2;
}

.badge {
  border-color: rgba(239, 68, 68, 0.45);
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.2);
}

.christmas-lights {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-around;
  padding: 0 8px;
  pointer-events: none;
  z-index: 15;
  overflow: hidden;
}

.christmas-lights span {
  position: relative;
  width: 12px;
  height: 18px;
  border-radius: 50% 50% 50% 50% / 35% 35% 65% 65%;
  margin-top: 6px;
  animation: twinkle 1.6s infinite alternate ease-in-out;
}

.christmas-lights span::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 3px;
  width: 6px;
  height: 6px;
  background: #334155;
  border-radius: 2px;
}

.christmas-lights span:nth-child(4n+1) {
  background: #ef4444;
  box-shadow: 0 0 12px #ef4444;
  animation-delay: 0s;
}

.christmas-lights span:nth-child(4n+2) {
  background: #22c55e;
  box-shadow: 0 0 12px #22c55e;
  animation-delay: 0.4s;
}

.christmas-lights span:nth-child(4n+3) {
  background: #facc15;
  box-shadow: 0 0 12px #facc15;
  animation-delay: 0.8s;
}

.christmas-lights span:nth-child(4n+4) {
  background: #38bdf8;
  box-shadow: 0 0 12px #38bdf8;
  animation-delay: 1.2s;
}

@keyframes twinkle {
  0% {
    opacity: 0.45;
    transform: scale(0.92);
  }
  100% {
    opacity: 1;
    transform: scale(1.06);
  }
}

.snowflakes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.snowflake {
  position: absolute;
  top: -10%;
  color: rgba(255, 255, 255, 0.78);
  font-size: 1.1rem;
  user-select: none;
  animation: snowfall linear infinite;
}

.snowflake:nth-child(1)  { left: 6%;  font-size: 0.9rem; animation-duration: 9s;  animation-delay: 0s; }
.snowflake:nth-child(2)  { left: 16%; font-size: 1.3rem; animation-duration: 12s; animation-delay: 1.5s; }
.snowflake:nth-child(3)  { left: 26%; font-size: 1rem;   animation-duration: 8s;  animation-delay: 3s; }
.snowflake:nth-child(4)  { left: 37%; font-size: 1.2rem; animation-duration: 11s; animation-delay: 0.8s; }
.snowflake:nth-child(5)  { left: 48%; font-size: 0.85rem;animation-duration: 10s; animation-delay: 2.2s; }
.snowflake:nth-child(6)  { left: 59%; font-size: 1.35rem;animation-duration: 13s; animation-delay: 4s; }
.snowflake:nth-child(7)  { left: 69%; font-size: 0.95rem;animation-duration: 9.5s;animation-delay: 1s; }
.snowflake:nth-child(8)  { left: 79%; font-size: 1.15rem;animation-duration: 11.5s;animation-delay: 2.7s; }
.snowflake:nth-child(9)  { left: 88%; font-size: 1rem;   animation-duration: 8.5s;animation-delay: 0.4s; }
.snowflake:nth-child(10) { left: 95%; font-size: 1.25rem;animation-duration: 10.5s;animation-delay: 3.5s; }

@keyframes snowfall {
  0% {
    transform: translateY(0) translateX(0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.85;
  }
  90% {
    opacity: 0.85;
  }
  100% {
    transform: translateY(115vh) translateX(24px) rotate(360deg);
    opacity: 0;
  }
}
