:root {
  --bg: #090912;
  --panel: rgba(18, 20, 38, 0.92);
  --panel-strong: rgba(26, 29, 54, 0.98);
  --text: #f8fbff;
  --muted: #9ba7c7;
  --cyan: #00f2ea;
  --pink: #ff0050;
  --yellow: #ffd166;
  --green: #46e891;
  --danger: #ff4d6d;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 0, 80, 0.32), transparent 30%),
    radial-gradient(circle at 85% 18%, rgba(0, 242, 234, 0.26), transparent 32%),
    linear-gradient(135deg, #06060c 0%, #101326 55%, #070711 100%);
  color: var(--text);
  overflow-x: hidden;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  min-height: 100vh;
}

.host-panel {
  background: rgba(7, 8, 18, 0.86);
  border-right: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
  max-height: 100vh;
}

.brand-card, .control-card, .entry-count-card, .entries-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 24px;
}

.brand-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 17px;
  background: linear-gradient(135deg, var(--pink), var(--cyan));
  color: #fff;
  font-weight: 950;
  letter-spacing: -0.04em;
  box-shadow: 0 12px 38px rgba(255, 0, 80, 0.35);
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 800;
}
h1, h2, h3 { margin: 0; }
h1 { font-size: 1.25rem; }

.control-card {
  padding: 16px;
  margin-bottom: 14px;
}
.control-card h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}
label {
  display: block;
  margin: 10px 0 7px;
  color: #e8edff;
  font-weight: 750;
  font-size: 0.92rem;
}
input, textarea {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border-radius: 14px;
  padding: 11px 12px;
  outline: none;
}
textarea { resize: vertical; }
input:focus, textarea:focus {
  border-color: rgba(0, 242, 234, 0.7);
  box-shadow: 0 0 0 3px rgba(0, 242, 234, 0.12);
}
.inline-row { display: flex; gap: 8px; align-items: center; }
.inline-row input { min-width: 0; }
button {
  border: 0;
  border-radius: 14px;
  padding: 11px 14px;
  color: #fff;
  font-weight: 850;
  transition: transform 0.16s ease, filter 0.16s ease, background 0.16s ease;
}
button:hover { transform: translateY(-1px); filter: brightness(1.08); }
button:active { transform: translateY(1px); }
.primary-btn { background: linear-gradient(135deg, var(--pink), #9b5cff); }
.spin-btn { background: linear-gradient(135deg, var(--green), var(--cyan)); color: #061015; }
.ghost-btn { background: rgba(255,255,255,0.1); border: 1px solid var(--border); }
.danger-btn { background: rgba(255, 77, 109, 0.24); border: 1px solid rgba(255, 77, 109, 0.4); }
.full-btn { width: 100%; margin-top: 12px; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.helper-text { color: var(--muted); font-size: 0.82rem; line-height: 1.4; margin: 8px 0 0; }
.status-pill {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,0.06);
}
.status-pill.connected { color: var(--green); border-color: rgba(70, 232, 145, 0.45); }
.status-pill.error { color: var(--danger); border-color: rgba(255, 77, 109, 0.45); }
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}
.toggle-label { margin: 0; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--pink); }

.stage {
  position: relative;
  padding: 24px;
  overflow: hidden;
}
.top-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background: linear-gradient(135deg, rgba(255,0,80,0.18), rgba(0,242,234,0.16));
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.top-banner h2 {
  font-size: clamp(1.1rem, 2.6vw, 2.35rem);
  line-height: 1.05;
  text-shadow: 0 10px 32px rgba(0,0,0,0.42);
}
.entry-count-card {
  min-width: 116px;
  text-align: center;
  padding: 14px 16px;
}
.entry-count-card span {
  display: block;
  font-size: 2rem;
  font-weight: 950;
  color: var(--yellow);
}
.entry-count-card small {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
}
.wheel-layout {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(240px, 330px);
  gap: 22px;
  align-items: center;
  min-height: calc(100vh - 132px);
}
.wheel-wrap {
  position: relative;
  width: min(68vh, 66vw, 760px);
  aspect-ratio: 1;
  margin: 22px auto;
  display: grid;
  place-items: center;
}
#wheelCanvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  filter: drop-shadow(0 28px 70px rgba(0,0,0,0.52));
  transition: transform 5.2s cubic-bezier(.09,.87,.16,1);
}
.pointer {
  position: absolute;
  top: -2px;
  left: 50%;
  z-index: 4;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 22px solid transparent;
  border-right: 22px solid transparent;
  border-top: 54px solid var(--yellow);
  filter: drop-shadow(0 8px 12px rgba(0,0,0,0.45));
}
.wheel-center {
  position: absolute;
  z-index: 3;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  text-align: center;
  background: linear-gradient(135deg, #fff, #dce7ff);
  color: #09101f;
  border: 8px solid rgba(255,255,255,0.35);
  box-shadow: 0 20px 55px rgba(0,0,0,0.38);
}
.wheel-center strong { font-size: 1.75rem; letter-spacing: -0.05em; }
.wheel-center span { color: #43516e; font-weight: 850; margin-top: -24px; }
.entries-panel {
  padding: 16px;
  align-self: stretch;
  max-height: calc(100vh - 150px);
  overflow: auto;
}
.entries-panel h3 {
  margin: 6px 0 10px;
  font-size: 0.95rem;
  color: #eaf1ff;
}
.entries-list, .winners-list {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}
.entry-item, .winner-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255,255,255,0.07);
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: linear-gradient(135deg, var(--pink), var(--cyan));
  flex: 0 0 auto;
}
.entry-meta { min-width: 0; }
.entry-meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-meta small { color: var(--muted); }
.empty-list { color: var(--muted); font-size: 0.9rem; }
.activity-feed {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 48px));
  pointer-events: none;
}
.activity-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(255,0,80,0.94), rgba(0,242,234,0.92));
  box-shadow: 0 18px 50px rgba(0,0,0,0.42);
  animation: slideIn 0.24s ease both, slideOut 0.32s ease 3.4s forwards;
}
.activity-card strong { display: block; font-size: 1rem; }
.activity-card span { display: block; color: rgba(255,255,255,0.86); font-size: 0.86rem; }

.winner-overlay[hidden],
.winner-overlay.is-hidden {
  display: none !important;
  pointer-events: none !important;
}

.winner-overlay.is-open {
  display: grid;
  pointer-events: auto;
}

.winner-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(5, 6, 14, 0.78);
  backdrop-filter: blur(10px);
}
.winner-card {
  width: min(720px, calc(100vw - 36px));
  border-radius: 34px;
  border: 1px solid rgba(255,255,255,0.18);
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.22), transparent 32%),
    linear-gradient(135deg, var(--pink), #8f5cff 46%, var(--cyan));
  padding: clamp(28px, 7vw, 74px);
  text-align: center;
  box-shadow: 0 28px 120px rgba(0,0,0,0.58);
  animation: winnerPop 0.42s cubic-bezier(.11,1.48,.42,1) both;
}
.winner-card p {
  margin: 0 0 8px;
  color: rgba(255,255,255,0.82);
  font-size: 1.25rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 950;
}
.winner-card h2 {
  font-size: clamp(2.4rem, 8vw, 6rem);
  line-height: 0.95;
  margin-bottom: 24px;
  text-shadow: 0 14px 40px rgba(0,0,0,0.38);
}
.confetti-piece {
  position: fixed;
  top: -20px;
  width: 10px;
  height: 18px;
  z-index: 35;
  border-radius: 3px;
  animation: confettiFall 3.1s linear forwards;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(34px) scale(.94); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes slideOut {
  to { opacity: 0; transform: translateX(34px) scale(.94); }
}
@keyframes winnerPop {
  from { opacity: 0; transform: scale(.76) rotate(-2deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.9; }
}

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 1fr; }
  .host-panel { max-height: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .wheel-layout { grid-template-columns: 1fr; min-height: auto; }
  .wheel-wrap { width: min(82vw, 680px); }
  .entries-panel { max-height: none; }
}
@media (max-width: 640px) {
  .stage, .host-panel { padding: 12px; }
  .top-banner { align-items: stretch; flex-direction: column; }
  .entry-count-card { width: 100%; }
  .button-grid, .inline-row { grid-template-columns: 1fr; flex-direction: column; align-items: stretch; }
  .inline-row button { width: 100%; }
  .wheel-center { width: 92px; height: 92px; border-width: 6px; }
  .wheel-center strong { font-size: 1.24rem; }
  .wheel-center span { font-size: 0.74rem; margin-top: -18px; }
}
