:root {
  --bg: #f4f4f6;
  --panel: #ffffff;
  --panel-2: #f4f4f6;
  --text: #18181b;
  --muted: #71717a;
  --border: #e4e4e7;
  --accent: #6d28d9;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c10;
    --panel: #17171c;
    --panel-2: #222229;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --border: #2e2e36;
    --accent: #a78bfa;
    --accent-text: #1b1033;
    --danger: #f87171;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font:
    15px/1.45 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
}
button,
input {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  padding: 16px;
  min-height: 100%;
}
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

/* ---------- Stage ---------- */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 16px;
  border-radius: 20px;
  overflow: hidden;
  min-height: 560px;
  background: #0b1026 center / cover no-repeat;
  transition: background 0.3s;
}
.stage:fullscreen {
  border-radius: 0;
  padding: 3vh 16px;
  min-height: 100vh;
}
.stage-title {
  margin: 0;
  max-width: 100%;
  padding: 8px 22px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: clamp(1.4rem, 3.2vw, 2.4rem);
  font-weight: 800;
  text-align: center;
  overflow-wrap: anywhere;
}
.stage:fullscreen .stage-title {
  font-size: clamp(1.8rem, 4.5vh, 3.2rem);
}

.wheel-wrap {
  position: relative;
  width: min(100%, 600px);
  aspect-ratio: 1;
}
.stage:fullscreen .wheel-wrap {
  width: min(92vw, 78vh);
}
.wheel-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}
.spin-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: 20%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid #fff;
  background: radial-gradient(circle at 35% 30%, #ffffff, #e4e4e7 60%, #a1a1aa);
  color: #18181b;
  font-weight: 900;
  font-size: clamp(0.85rem, 2.6vw, 1.4rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s;
}
.spin-hub:hover:not(:disabled) {
  transform: scale(1.06);
}
.spin-hub:disabled {
  cursor: default;
  color: #a1a1aa;
}

.stage-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  color: #fff;
}
.chip:hover {
  background: rgba(0, 0, 0, 0.5);
}
.hint {
  margin: 0;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.85rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
kbd {
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.2);
  font: inherit;
}

/* ---------- Panel ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100vh - 32px);
  position: sticky;
  top: 16px;
}
@media (max-width: 900px) {
  .panel {
    position: static;
    max-height: none;
  }
}
.panel[inert] {
  opacity: 0.6;
}
.tabs {
  display: flex;
  padding: 6px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}
.tabs button {
  flex: 1;
  padding: 9px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.tabs button[aria-selected='true'] {
  background: var(--panel-2);
  color: var(--text);
}
.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--border);
  font-size: 0.75rem;
}
.pane {
  padding: 16px;
  overflow-y: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-weight: 600;
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn.danger {
  color: var(--danger);
}
.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
}
.link.danger {
  color: var(--danger);
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
  flex: none;
}
.icon-btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.icon-btn.ghost:hover {
  color: var(--danger);
}
input[type='text'] {
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

.add-form {
  display: flex;
  gap: 8px;
}
.add-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.add-preview img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
}
.add-preview[hidden] {
  display: none;
}

.entry-list,
.result-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.entry input[type='text'] {
  border-color: transparent;
  background: transparent;
  padding: 6px 8px;
}
.entry input[type='text']:hover,
.entry input[type='text']:focus {
  border-color: var(--border);
  background: var(--panel);
}
.swatch {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
}
.swatch::-webkit-color-swatch-wrapper {
  padding: 0;
}
.swatch::-webkit-color-swatch {
  border: 0;
}
.swatch::-moz-color-swatch {
  border: 0;
}
.thumb {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  color: var(--muted);
  overflow: hidden;
  cursor: pointer;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumb.has-image {
  border-style: solid;
}
.empty {
  color: var(--muted);
  text-align: center;
  margin: 24px 0;
}
.empty[hidden] {
  display: none;
}
.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.field {
  display: grid;
  gap: 8px;
  margin: 0 0 20px;
  border: 0;
  padding: 0;
}
.field > span,
.field legend {
  font-weight: 600;
  padding: 0;
  margin-bottom: 8px;
}
.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.preset {
  height: 64px;
  border-radius: 10px;
  border: 2px solid transparent;
  background-size: cover;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  padding: 6px 8px;
}
.preset[aria-pressed='true'],
.bg-row .btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
.bg-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.bg-row input[type='color'] {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.result-item .dot {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
}
.result-item .meta {
  flex: 1;
  min-width: 0;
}
.result-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-item time {
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------- Result dialog ---------- */
.result-dialog {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  display: none;
  place-items: center;
}
.result-dialog[open] {
  display: grid;
}
.result-dialog::backdrop {
  background: rgba(5, 5, 15, 0.72);
}
.fireworks {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.result-card {
  position: relative;
  width: min(440px, 100%);
  padding: 28px 24px 24px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: pop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop-in {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .result-card {
    animation: none;
  }
}
.eyebrow {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
}
.result-image {
  width: 140px;
  height: 140px;
  margin: 16px auto 0;
  display: block;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--border);
}
.result-image[hidden] {
  display: none;
}
.result-label {
  margin: 12px 0 4px;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.result-saved {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.85rem;
}
.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  translate: -50% 20px;
  padding: 10px 18px;
  border-radius: 999px;
  background: #18181b;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    translate 0.2s;
  max-width: calc(100vw - 32px);
}
.toast.show {
  opacity: 1;
  translate: -50% 0;
}

/* ---------- Bulk add ---------- */
.bulk {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.bulk summary {
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.bulk[open] summary {
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.bulk-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}
.bulk-label {
  font-size: 0.85rem;
  color: var(--muted);
}
.bulk textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  font: inherit;
  color: inherit;
}
.bulk-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.bulk-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
}
.bulk-divider::before,
.bulk-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border);
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

#pane-entries {
  position: relative;
}
.drop-hint {
  display: none;
  position: absolute;
  inset: 8px;
  z-index: 2;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 88%, var(--accent));
  color: var(--accent);
  font-weight: 700;
  pointer-events: none;
}
#pane-entries.dragging .drop-hint {
  display: grid;
}

/* ---------- Sign-in ---------- */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 16px;
  background:
    radial-gradient(circle at 20% 15%, #4f46e5 0, transparent 50%),
    radial-gradient(circle at 85% 30%, #0891b2 0, transparent 45%),
    radial-gradient(circle at 50% 95%, #a21caf 0, transparent 55%), #0b1026;
}
.login-card {
  width: min(400px, 100%);
  padding: 32px 24px;
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
}
.login-card h1 {
  margin: 8px 0 4px;
  font-size: 1.6rem;
}
.login-logo {
  font-size: 3rem;
  line-height: 1;
}
.provider-list {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}
.provider-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.provider-btn:hover {
  border-color: var(--accent);
}
.provider-btn svg {
  width: 20px;
  height: 20px;
  stroke: none;
}
.login-error {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  font-size: 0.9rem;
}
.login-error[hidden] {
  display: none;
}

/* ---------- Account bar ---------- */
.account {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.account[hidden] {
  display: none;
}
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 0.8rem;
}
.account-meta {
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}
.account-meta strong,
.account-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-meta span {
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------- App navigation ---------- */
.app-nav {
  display: flex;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.app-nav a {
  flex: 1;
  padding: 8px 6px;
  white-space: nowrap;
  font-size: 0.9rem;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.app-nav a:hover {
  background: var(--panel-2);
  color: var(--text);
}
.app-nav a[aria-current='page'] {
  background: var(--panel-2);
  color: var(--text);
}

.app-nav .nav-home {
  flex: none;
  padding: 8px 10px;
}

.login-back {
  margin: 20px 0 0;
  font-size: 0.9rem;
}
.login-back a {
  color: var(--muted);
}

.login-terms {
  margin: 20px 0 0;
  font-size: 0.8rem;
  line-height: 1.5;
}
.login-terms a {
  color: inherit;
}
