:root {
  --bg: #111827;
  --bg-2: #0b1120;
  --surface: #1f2937;
  --surface-2: #273449;
  --border: #374151;
  --text: #f9fafb;
  --text-dim: #9ca3af;
  --accent: #ec4899;
  --accent-2: #f472b6;
  --accent-ink: #1a0a13;
  --danger: #fb7185;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 11px;
  --pointer: #f9fafb;
}

[data-theme="light"] {
  --bg: #fdf2f8;
  --bg-2: #fce7f3;
  --surface: #ffffff;
  --surface-2: #fdf2f8;
  --border: #f3c6df;
  --text: #1f2937;
  --text-dim: #6b7280;
  --accent: #db2777;
  --accent-2: #ec4899;
  --accent-ink: #ffffff;
  --danger: #e11d48;
  --shadow: 0 16px 40px rgba(190, 24, 93, 0.18);
  --pointer: #1f2937;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 700px at 110% -10%, rgba(236, 72, 153, 0.18), transparent 55%),
    radial-gradient(900px 600px at -10% 110%, rgba(99, 102, 241, 0.14), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) clamp(14px, 4vw, 28px) calc(20px + env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: clamp(14px, 3vw, 24px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 42px; height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), #8b5cf6 70%, #22d3ee);
  box-shadow: 0 6px 18px rgba(236, 72, 153, 0.4);
}

.brand h1 {
  font-size: clamp(1.15rem, 4.4vw, 1.5rem);
  margin: 0;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px; height: 44px;
  flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.94); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(16px, 3vw, 26px);
  flex: 1;
}

@media (min-width: 820px) {
  .layout {
    grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.95fr);
    align-items: start;
  }
}

/* ---------- Wheel ---------- */
.wheel-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.wheel-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}

#wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--bg-2);
  box-shadow:
    0 0 0 8px rgba(255, 255, 255, 0.04),
    0 0 0 10px var(--border),
    var(--shadow);
  transform: rotate(0deg);
  touch-action: manipulation;
}

.pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 17px solid transparent;
  border-right: 17px solid transparent;
  border-top: 30px solid var(--accent);
  filter: drop-shadow(0 4px 5px rgba(0,0,0,0.45));
  z-index: 4;
}

.spin-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: clamp(78px, 22%, 104px);
  height: clamp(78px, 22%, 104px);
  border-radius: 50%;
  border: 4px solid var(--bg);
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  font-weight: 800;
  font-size: clamp(0.92rem, 2.6vw, 1.05rem);
  letter-spacing: 0.01em;
  cursor: pointer;
  z-index: 3;
  box-shadow: 0 8px 22px rgba(236, 72, 153, 0.5);
  transition: transform .15s ease, filter .2s ease;
}
.spin-hub:hover { filter: brightness(1.07); }
.spin-hub:active { transform: translate(-50%, -50%) scale(0.93); }
.spin-hub:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

.status {
  margin: 0;
  min-height: 1.3em;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.92rem;
  max-width: 420px;
}

/* ---------- Panel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(14px, 3vw, 20px);
  box-shadow: var(--shadow);
}

.add-row {
  display: flex;
  gap: 8px;
}

#optInput {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 1rem;
}
#optInput::placeholder { color: var(--text-dim); }
#optInput:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.opt-del:focus-visible,
.recent-chip:focus-visible,
.spin-hub:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .12s ease, filter .2s ease, background .2s ease;
}
.btn:active { transform: scale(0.96); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 8px 12px; font-size: 0.85rem; }

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 10px;
}
.list-head h2 {
  font-size: 1.05rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-badge {
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 2px 9px;
  min-width: 24px;
  text-align: center;
}

.opt-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
}

.opt-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  border: 1px solid var(--border);
  animation: rise .2s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.swatch {
  width: 16px; height: 16px;
  flex: 0 0 auto;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
}
.opt-text {
  flex: 1;
  min-width: 0;
  font-size: 0.96rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opt-del {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background .2s ease;
}
.opt-del:hover { background: rgba(251, 113, 133, 0.14); }

.empty-hint {
  color: var(--text-dim);
  font-size: 0.88rem;
  margin: 12px 2px 0;
}

.recent {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.recent h3 {
  font-size: 0.92rem;
  margin: 0 0 10px;
  color: var(--text-dim);
}
.recent-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.recent-chip {
  max-width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.82rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color .2s ease, background .2s ease;
}
.recent-chip:hover { border-color: var(--accent); background: var(--surface-2); }

.foot {
  margin-top: 22px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 11, 20, 0.72);
  backdrop-filter: blur(5px);
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 30px 24px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: pop .3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.win-label {
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.win-name {
  margin: 0 0 22px;
  font-size: clamp(1.5rem, 7vw, 2.1rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
  word-break: break-word;
  overflow-wrap: anywhere;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-actions .btn { width: 100%; }

/* Confetti */
.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.confetti span {
  position: absolute;
  top: -14px;
  width: 9px; height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation: drop linear forwards;
}
@keyframes drop {
  to { transform: translateY(560px) rotate(540deg); opacity: 0; }
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 60;
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  max-width: calc(100vw - 32px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  #wheel { transition: none !important; }
}
