:root {
  color-scheme: dark;
  --bg: #071016;
  --surface: #0f1b24;
  --surface-2: #132632;
  --border: #244253;
  --text: #f5fbff;
  --muted: #a8bbc7;
  --accent: #2dd4bf;
  --accent-2: #60a5fa;
  --danger: #fb7185;
  --warning: #fbbf24;
  --success: #34d399;
  --shadow: rgba(1, 8, 12, 0.38);
}

body.theme-light {
  color-scheme: light;
  --bg: #eef5f8;
  --surface: #ffffff;
  --surface-2: #e7f0f5;
  --border: #c7d8e1;
  --text: #10202a;
  --muted: #516878;
  --shadow: rgba(31, 50, 61, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(45, 212, 191, 0.18), transparent 32%),
    radial-gradient(circle at 88% 20%, rgba(96, 165, 250, 0.2), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.wheel-app-shell {
  min-height: 100vh;
}

.wheel-app {
  display: grid;
  gap: 1rem;
  min-height: 100vh;
  padding: clamp(0.75rem, 2vw, 1.5rem);
}

.live-app {
  align-content: start;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
}

.app-title {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
  letter-spacing: 0;
}

.app-subtitle {
  margin: 0.55rem 0 0;
  max-width: 56rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

.app-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.app-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.wheel-stage,
.panel {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 20px 44px var(--shadow);
}

.wheel-stage {
  position: sticky;
  top: 1rem;
  display: grid;
  gap: 1rem;
  justify-items: center;
  padding: clamp(0.85rem, 2vw, 1.25rem);
}

.live-stage {
  position: static;
  max-width: min(100%, 48rem);
  justify-self: center;
}

.live-stage .wheel-wrap {
  width: min(92vw, 42rem);
}

.wheel-wrap {
  position: relative;
  width: min(92vw, 36rem);
  aspect-ratio: 1;
}

.wheel-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 9999px;
  filter: drop-shadow(0 24px 35px var(--shadow));
  transition: transform var(--spin-duration, 5200ms) var(--spin-easing, cubic-bezier(0.14, 0.84, 0.24, 1));
}

.spin-button {
  position: absolute;
  inset: 50% auto auto 50%;
  width: clamp(5.4rem, 17vw, 7.5rem);
  height: clamp(5.4rem, 17vw, 7.5rem);
  border: 0;
  border-radius: 9999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #061117;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 16px 38px rgba(45, 212, 191, 0.25);
  transform: translate(-50%, -50%);
  z-index: 3;
}

.preview-stage .spin-button {
  width: clamp(4.8rem, 15vw, 6.4rem);
  height: clamp(4.8rem, 15vw, 6.4rem);
  padding: 0.35rem;
  font-size: 0.9rem;
}

.pointer {
  position: absolute;
  z-index: 4;
  width: 0;
  height: 0;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.3));
}

.pointer-top {
  top: -0.35rem;
  left: 50%;
  border-left: 1.05rem solid transparent;
  border-right: 1.05rem solid transparent;
  border-top: 2rem solid var(--warning);
  transform: translateX(-50%);
}

.pointer-right {
  top: 50%;
  right: -0.35rem;
  border-top: 1.05rem solid transparent;
  border-bottom: 1.05rem solid transparent;
  border-right: 2rem solid var(--warning);
  transform: translateY(-50%);
}

.pointer-bottom {
  bottom: -0.35rem;
  left: 50%;
  border-left: 1.05rem solid transparent;
  border-right: 1.05rem solid transparent;
  border-bottom: 2rem solid var(--warning);
  transform: translateX(-50%);
}

.pointer-left {
  top: 50%;
  left: -0.35rem;
  border-top: 1.05rem solid transparent;
  border-bottom: 1.05rem solid transparent;
  border-left: 2rem solid var(--warning);
  transform: translateY(-50%);
}

.winner-strip {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface-2);
  padding: 0.85rem;
}

.winner-strip strong {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.35rem;
}

.muted {
  color: var(--muted);
}

.panel {
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 72%, transparent);
}

.tab-button {
  border: 1px solid transparent;
  border-radius: 0.65rem;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 0.65rem 0.9rem;
}

.tab-button.active {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.panel-body {
  display: grid;
  gap: 0.85rem;
  padding: clamp(0.75rem, 2vw, 1rem);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  justify-content: space-between;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.65rem;
  border: 1px solid var(--border);
  border-radius: 0.68rem;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 850;
  padding: 0.62rem 0.9rem;
  text-decoration: none;
}

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

.button.danger {
  border-color: color-mix(in srgb, var(--danger) 70%, var(--border));
  color: #fecdd3;
}

body.theme-light .button.danger {
  color: #9f1239;
}

.button.ghost {
  background: transparent;
}

.segment-list {
  display: grid;
  gap: 0.55rem;
}

.segment-card {
  display: grid;
  gap: 0.65rem;
  border: 1px solid var(--border);
  border-left: 0.35rem solid var(--segment-color, var(--accent));
  border-radius: 0.65rem;
  background: var(--surface-2);
  padding: 0.55rem;
}

.segment-card.compact {
  padding-block: 0.42rem;
}

.segment-card.drag-over {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
}

.segment-head {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.segment-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  text-align: left;
}

.color-swatch {
  width: 1rem;
  height: 1rem;
  border: 1px solid color-mix(in srgb, var(--segment-color) 70%, white);
  border-radius: 999px;
  background: var(--segment-color);
}

.segment-copy {
  display: grid;
  min-width: 0;
}

.segment-title {
  min-width: 0;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment-meta {
  color: var(--muted);
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment-quick-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
  align-items: center;
}

.icon-button {
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  background: var(--surface);
  color: var(--text);
  font-weight: 900;
}

.segment-grid,
.settings-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 2.55rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: var(--surface);
  color: var(--text);
  padding: 0.58rem 0.7rem;
  outline: none;
}

.field input[type="color"] {
  min-height: 2.55rem;
  padding: 0.15rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.button:focus-visible,
.icon-button:focus-visible,
.segment-summary:focus-visible,
.spin-button:focus-visible,
.tab-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 42%, transparent);
  outline-offset: 2px;
}

.field-error {
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 800;
}

.segment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.mini-button {
  min-height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  padding: 0.4rem 0.62rem;
}

.mini-button.active {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
  border-color: var(--accent);
}

.image-preview {
  width: 2.35rem;
  height: 2.35rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: var(--surface);
  object-fit: cover;
}

.config-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.status {
  min-height: 1.4rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--success);
}

.preset-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

.preset-card {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface-2);
  padding: 0.9rem;
}

.preset-card h3 {
  margin: 0;
}

.preset-card p {
  color: var(--muted);
  line-height: 1.45;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  display: grid;
  gap: 1rem;
  width: min(94vw, 34rem);
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  padding: 1rem;
}

.modal-card h2 {
  margin: 0;
  font-size: clamp(1.7rem, 5vw, 2.4rem);
}

.winner-image {
  width: 100%;
  max-height: 18rem;
  border-radius: 0.75rem;
  object-fit: cover;
  background: var(--surface-2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.confetti-piece {
  position: fixed;
  top: -1rem;
  z-index: 70;
  width: 0.7rem;
  height: 1rem;
  border-radius: 0.18rem;
  pointer-events: none;
  animation: confetti-fall 1600ms ease-out forwards;
}

@keyframes confetti-fall {
  to {
    transform: translate(var(--x), 105vh) rotate(760deg);
    opacity: 0;
  }
}

@media (min-width: 760px) {
  .segment-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (min-width: 1180px) {
  .app-layout {
    grid-template-columns: minmax(31rem, 0.9fr) minmax(34rem, 1.1fr);
  }
}

@media (max-width: 759px) {
  .wheel-stage {
    position: static;
  }

  .app-title {
    font-size: 2rem;
  }

  .app-subtitle {
    font-size: 0.92rem;
  }

  .segment-head {
    align-items: flex-start;
  }

  .segment-summary {
    flex: 1 1 12rem;
  }

  .segment-quick-actions {
    flex: 1 1 100%;
    justify-content: flex-start;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab-button {
    white-space: nowrap;
  }

  .app-actions,
  .toolbar,
  .button {
    width: 100%;
  }
}
