:root {
  --bg: #f3f7fc;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-solid: #ffffff;
  --border: #d7dfeb;
  --text: #1f2937;
  --muted: #64748b;
  --primary: #6657f6;
  --primary-2: #836dfd;
  --primary-soft: rgba(102, 87, 246, 0.12);
  --success-bg: #ecfdf5;
  --success-border: #b7ebc7;
  --success-text: #047857;
  --danger-bg: #fff5f5;
  --danger-border: #fecaca;
  --danger-text: #b91c1c;
  --shadow: 0 18px 44px rgba(17, 24, 39, 0.12);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --sidebar-width: 430px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, #eef3ff, #f8fbff 36%, #eff4fb 72%, #edf2f9 100%);
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  height: 100vh;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(360px, var(--sidebar-width)) minmax(0, 1fr);
  gap: 16px;
}

.glass-panel {
  background: var(--panel);
  border: 1px solid rgba(215, 223, 235, 0.95);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
}

.sidebar__header,
.sidebar__toolbar,
.sidebar__content,
.sidebar__footer,
.stage__header,
.stage__footer {
  padding-left: 18px;
  padding-right: 18px;
}

.sidebar__header {
  padding-top: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand__logo {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 14px 28px rgba(102, 87, 246, 0.24);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 24px;
  flex: 0 0 auto;
}

.brand__text h1,
.stage__title-wrap h2,
.panel__head h2,
.results-panel h3,
.modal__body h3 {
  margin: 0;
}

.brand__text h1 {
  font-size: 1.16rem;
  line-height: 1.15;
}

.brand__text p,
.panel__sub,
.stage__title-wrap p,
.sidebar__footer,
.switch-row span,
.modal__body p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.brand__text p {
  font-size: 0.92rem;
}

.sidebar__toolbar {
  padding-top: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.sidebar__content {
  min-height: 0;
  overflow: auto;
  padding-top: 16px;
  padding-bottom: 18px;
  display: grid;
  gap: 14px;
}

.sidebar__footer {
  padding-top: 12px;
  padding-bottom: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.83rem;
}

.panel,
.results-panel__section {
  border: 1px solid rgba(215, 223, 235, 0.82);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.97), rgba(249,251,255,0.94));
}

.panel {
  padding: 14px;
}

.panel__head,
.results-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel__head h2,
.results-panel__head h3 {
  font-size: 1rem;
}

.panel__meta {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.panel__sub {
  font-size: 0.92rem;
  margin-bottom: 12px;
}

.textarea,
.field input,
.field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.textarea:focus,
.field input:focus,
.field select:focus {
  border-color: #9dacfb;
  box-shadow: 0 0 0 4px rgba(102, 87, 246, 0.12);
}

.textarea {
  min-height: 260px;
  resize: vertical;
  padding: 14px;
  line-height: 1.55;
}

.grid {
  display: grid;
  gap: 10px;
}

.grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 0.87rem;
  font-weight: 700;
}

.field input,
.field select {
  min-height: 44px;
  padding: 10px 12px;
}

.switch-list {
  display: grid;
  gap: 10px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
}

.switch-row strong {
  display: block;
  font-size: 0.92rem;
}

.switch-row span {
  display: block;
  font-size: 0.8rem;
}

.switch {
  appearance: none;
  width: 50px;
  height: 29px;
  border-radius: 999px;
  border: none;
  background: #d7deea;
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.18s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.14);
  transition: transform 0.18s ease;
}

.switch:checked {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.switch:checked::after {
  transform: translateX(21px);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, #fff, #f8fbff);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 6px;
}

.stat-card strong {
  font-size: 1.5rem;
  line-height: 1;
}

.btn {
  min-height: 46px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  padding: 10px 14px;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
  border-color: #c3cedf;
}

.btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn--primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.btn--soft {
  background: #fff;
}

.btn--success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.btn--danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.stage {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.stage__header {
  padding-top: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage__title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.stage__title-wrap h2 {
  font-size: 1.04rem;
}

.stage__title-wrap p {
  font-size: 0.86rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.stage__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.stage__body {
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
}

.wheel-panel {
  border: 1px solid rgba(215, 223, 235, 0.84);
  border-radius: 22px;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.9) 0 18%, rgba(240,245,255,0.68) 38%, rgba(233,239,249,0.32) 60%, rgba(255,255,255,0) 78%),
    linear-gradient(180deg, rgba(252,253,255,0.74), rgba(244,247,251,0.46));
  display: grid;
  place-items: center;
  padding: 18px;
  min-height: 0;
  overflow: hidden;
}

.wheel-wrap {
  position: relative;
  width: min(100%, calc(100vh - 220px), 920px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

#wheelCanvas {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 24px 36px rgba(18, 30, 54, 0.16));
}

.wheel-pointer {
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 24px solid transparent;
  border-bottom: 24px solid transparent;
  border-right: 38px solid #f59e0b;
  z-index: 6;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.18));
}

.wheel-pointer::after {
  content: "";
  position: absolute;
  top: -8px;
  left: 16px;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 16px solid #ffd166;
}

.wheel-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 5;
  pointer-events: none;
}

.wheel-center::before {
  content: "";
  width: 18.5%;
  aspect-ratio: 1;
  border-radius: 50%;
  position: absolute;
  background: radial-gradient(circle at 35% 35%, #fff, #eff3ff 54%, #d7def7 100%);
  border: 10px solid rgba(255,255,255,0.96);
  box-shadow: 0 16px 28px rgba(15, 23, 42, 0.16), inset 0 4px 18px rgba(255,255,255,0.92);
}

.wheel-center__button {
  width: 13%;
  aspect-ratio: 1;
  min-width: 74px;
  min-height: 74px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, #fff, #eef2ff);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.96), 0 8px 16px rgba(15, 23, 42, 0.12);
  font-size: clamp(0.86rem, 0.9vw, 1rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease;
  pointer-events: auto;
  z-index: 1;
}

.wheel-center__button:hover:not(:disabled) {
  transform: scale(1.03);
}

.wheel-center__button:active:not(:disabled) {
  transform: scale(0.985);
}

.results-panel {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
}

.results-panel__section {
  padding: 14px;
}

.results-panel__section--list {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.results-panel h3 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.winner-highlight {
  border: 1px solid #fdba74;
  background: linear-gradient(135deg, #fff7ed, #fffaf3);
  color: #9a3412;
  border-radius: 16px;
  min-height: 56px;
  display: flex;
  align-items: center;
  padding: 14px;
  font-weight: 800;
  word-break: break-word;
}

.winner-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  align-content: start;
}

.winner-list__empty,
.winner-item {
  border-radius: 14px;
}

.winner-list__empty {
  border: 1px dashed var(--border);
  color: var(--muted);
  background: rgba(255,255,255,0.5);
  padding: 14px;
  line-height: 1.45;
}

.winner-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: #fff;
}

.winner-item__index {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.84rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.winner-item__name {
  font-weight: 700;
  line-height: 1.35;
  word-break: break-word;
}

.stage__footer {
  padding-top: 12px;
  padding-bottom: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.history-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-chip {
  padding: 8px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: #334155;
  font-size: 0.84rem;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(15, 23, 42, 0.54);
  padding: 20px;
  z-index: 100;
}

.modal.is-open {
  display: grid;
}

.modal__card {
  width: min(560px, 100%);
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 26px 70px rgba(15, 23, 42, 0.3);
  border: 1px solid rgba(255,255,255,0.76);
  overflow: hidden;
}

.modal__body {
  padding: 22px 22px 18px;
  text-align: center;
  background: linear-gradient(180deg, #fffdf7, #fff);
}

.modal__icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 10px;
}

.modal__body h3 {
  font-size: 2rem;
}

.modal__winner {
  margin: 14px auto 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  padding: 14px 18px;
  border-radius: 18px;
  border: 1px solid #fdba74;
  background: linear-gradient(135deg, #fff7ed, #fffaf3);
  color: #9a3412;
  font-size: clamp(1.16rem, 3.2vw, 1.85rem);
  font-weight: 900;
  word-break: break-word;
}

.modal__actions {
  padding: 18px 22px 22px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  display: grid;
  gap: 10px;
}

.toast {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(20, 27, 39, 0.94);
  color: #fff;
  max-width: 360px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.2);
  animation: toastIn 0.18s ease;
}

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

@media (max-width: 1280px) {
  .stage__body {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .stage {
    order: 1;
    min-height: 76vh;
  }

  .sidebar {
    order: 2;
  }

  .stage__body {
    grid-template-columns: 1fr;
  }

  .results-panel {
    max-height: 400px;
  }

  .wheel-wrap {
    width: min(92vw, calc(100vh - 240px), 760px);
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .sidebar__header,
  .sidebar__toolbar,
  .sidebar__content,
  .sidebar__footer,
  .stage__header,
  .stage__footer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .sidebar__toolbar,
  .grid--2,
  .grid--3,
  .modal__actions {
    grid-template-columns: 1fr;
  }

  .stage__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .stage__actions {
    width: 100%;
  }

  .stage__actions .btn {
    flex: 1;
  }

  .wheel-panel {
    padding: 10px;
  }

  .wheel-wrap {
    width: min(96vw, calc(100vh - 250px), 640px);
  }

  .wheel-pointer {
    right: -4px;
    border-top-width: 20px;
    border-bottom-width: 20px;
    border-right-width: 30px;
  }
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 18px;
  border-radius: 2px;
  opacity: 0.95;
  will-change: transform, opacity;
  animation-name: confetti-fall, confetti-sway;
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: 1, infinite;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0.95;
  }
}

@keyframes confetti-sway {
  0% {
    margin-left: 0;
  }
  50% {
    margin-left: 26px;
  }
  100% {
    margin-left: -26px;
  }
}

.winner-item {
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
}

.winner-item:hover {
  border-color: #f59e0b;
  background: #fffaf3;
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(245, 158, 11, 0.12);
}

.winner-item:active {
  transform: translateY(0);
}
