/* === TOKENS === */
:root {
  --bg-deep: #0F0B1E;
  --bg-mid: #1A1333;
  --bg-card: #251E3E;
  --bg-input: #1E1636;
  --text: #FFFFFF;
  --text-dim: #B8B0D0;
  --text-muted: #7A7294;
  --accent: #FFD700;
  --accent-glow: rgba(255, 215, 0, 0.35);
  --border: rgba(255, 255, 255, 0.08);
  --danger: #FF4466;

  --tadc: #FF2D55;
  --tadc-alt: #FF6B8A;
  --murder-drones: #A044E8;
  --murder-drones-alt: #E2D926;
  --vocaloid: #06B6D4;
  --vocaloid-alt: #22D3EE;
  --oc: #F59E0B;
  --oc-alt: #FBBF24;

  --font: 'Fredoka', system-ui, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; }

/* === LAYOUT === */
#app {
  max-width: 540px;
  margin: 0 auto;
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-height: 100dvh;
}

/* === HEADER === */
.app-header { text-align: center; padding-top: 8px; }

.title {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--tadc), var(--murder-drones), var(--vocaloid));
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 6s ease-in-out infinite;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 400;
  margin-top: 2px;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* === FILTERS === */
.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  width: 100%;
  padding: 4px 0;
  scrollbar-width: none;
  justify-content: center;
  flex-wrap: wrap;
}
.filters::-webkit-scrollbar { display: none; }

.filter-btn {
  padding: 8px 16px;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: all 0.2s;
  min-height: 44px;
}
.filter-btn:hover { border-color: rgba(255,255,255,0.2); }
.filter-btn.active {
  background: rgba(255,255,255,0.12);
  border-color: var(--accent);
  color: var(--accent);
}

/* === WHEEL === */
.wheel-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}

.wheel-container {
  width: 100%;
  max-width: 460px;
  aspect-ratio: 1;
  position: relative;
}

#wheel {
  width: 100%;
  height: 100%;
  display: block;
}

#spin-btn {
  background: linear-gradient(135deg, var(--tadc), var(--murder-drones), var(--vocaloid));
  background-size: 200% 200%;
  animation: gradientShift 4s ease-in-out infinite, pulseGlow 2s ease-in-out infinite;
  color: white;
  border-radius: 100px;
  padding: 14px 56px;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 2px;
  transition: transform 0.15s, opacity 0.3s;
  min-height: 52px;
}
#spin-btn:active:not(:disabled) { transform: scale(0.94); }
#spin-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  animation: gradientShift 4s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 16px rgba(139,92,246,0.3), 0 0 32px rgba(255,45,85,0.15); }
  50% { box-shadow: 0 0 28px rgba(139,92,246,0.5), 0 0 56px rgba(255,45,85,0.25); }
}

/* === REVEAL OVERLAY === */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 24, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: overlayFadeIn 0.35s ease-out forwards;
}
.overlay.hidden { display: none; }

@keyframes overlayFadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* flash burst on reveal */
.reveal-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
  opacity: 0;
}
.reveal-flash.active {
  animation: flashBurst 0.5s ease-out forwards;
}
@keyframes flashBurst {
  0% { opacity: 0.7; }
  100% { opacity: 0; }
}

.reveal-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 28px 24px 24px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  position: relative;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  opacity: 0;
  transform: scale(0.3) rotate(-5deg);
}
.reveal-card.animate-in {
  animation: revealBounce 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s forwards;
}

@keyframes revealBounce {
  0% { transform: scale(0.3) rotate(-5deg); opacity: 0; }
  40% { opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* pulsing fandom glow around card */
.reveal-card.animate-in::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 22px;
  background: var(--reveal-glow);
  z-index: -1;
  opacity: 0;
  animation: glowPulse 2s ease-in-out 0.6s infinite;
}
@keyframes glowPulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.02); }
}

.reveal-fandom-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 100px;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0;
}
.reveal-card.animate-in .reveal-fandom-badge {
  animation: fadeSlideUp 0.35s ease-out 0.35s forwards;
}

.reveal-image-wrap {
  width: 220px;
  height: 220px;
  margin: 0 auto 16px;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  background: var(--bg-mid);
  opacity: 0;
  transform: scale(0.85);
}
.reveal-card.animate-in .reveal-image-wrap {
  animation: imageReveal 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) 0.4s forwards;
}
@keyframes imageReveal {
  0% { opacity: 0; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

.reveal-image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  font-weight: 700;
  opacity: 0.6;
}

.reveal-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: absolute;
  inset: 0;
}
.reveal-image[src=""] { display: none; }

.reveal-name {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 20px;
  opacity: 0;
}
.reveal-card.animate-in .reveal-name {
  animation: fadeSlideUp 0.4s ease-out 0.6s forwards;
}

@keyframes fadeSlideUp {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

.reveal-close-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text);
  padding: 10px 32px;
  border-radius: 100px;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.2s;
  min-height: 44px;
  opacity: 0;
}
.reveal-card.animate-in .reveal-close-btn {
  animation: fadeSlideUp 0.35s ease-out 0.8s forwards;
}
.reveal-close-btn:hover { background: rgba(255,255,255,0.18); }

/* === SPARKLES === */
.sparkles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 101;
}

.sparkle {
  position: absolute;
  border-radius: 50%;
  animation: sparkleFloat var(--duration) ease-out forwards;
  opacity: 0;
}

.sparkle-star {
  position: absolute;
  border-radius: 0;
  background: none !important;
  animation: sparkleStarFloat var(--duration) ease-out forwards;
  opacity: 0;
}

@keyframes sparkleFloat {
  0% { opacity: 0; transform: scale(0) translate(0, 0); }
  15% { opacity: 1; transform: scale(1.2) translate(var(--dx), var(--dy)); }
  50% { opacity: 0.8; transform: scale(1) translate(calc(var(--dx) * 2), calc(var(--dy) * 2)); }
  100% { opacity: 0; transform: scale(0.2) translate(calc(var(--dx) * 3), calc(var(--dy) * 3.5)); }
}

@keyframes sparkleStarFloat {
  0% { opacity: 0; transform: scale(0) rotate(0deg) translate(0, 0); }
  20% { opacity: 1; transform: scale(1) rotate(90deg) translate(var(--dx), var(--dy)); }
  60% { opacity: 0.7; transform: scale(0.8) rotate(180deg) translate(calc(var(--dx) * 2.2), calc(var(--dy) * 2.2)); }
  100% { opacity: 0; transform: scale(0) rotate(270deg) translate(calc(var(--dx) * 3), calc(var(--dy) * 3)); }
}

/* === LOGIN MODAL === */
.login-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  max-width: 320px;
  width: 88%;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: revealBounce 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.login-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--accent);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-form input {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.95rem;
  text-align: center;
}
.login-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-error {
  font-size: 0.8rem;
  color: var(--danger);
  font-weight: 600;
}
.login-error.hidden { display: none; }

.btn-login {
  margin-top: 6px;
  padding: 12px 24px;
  border-radius: 100px;
  background: linear-gradient(135deg, var(--tadc), var(--murder-drones), var(--vocaloid));
  background-size: 200% 200%;
  animation: gradientShift 4s ease-in-out infinite;
  color: white;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  min-height: 48px;
  transition: transform 0.15s;
}
.btn-login:active { transform: scale(0.95); }

.login-card.shake {
  animation: shakeForm 0.4s ease-out;
}

@keyframes shakeForm {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-12px); }
  30% { transform: translateX(10px); }
  45% { transform: translateX(-8px); }
  60% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

/* === MANAGE PANEL === */
.manage-panel {
  background: var(--bg-mid);
  width: 100%;
  max-width: 440px;
  max-height: 85dvh;
  border-radius: 20px 20px 0 0;
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease-out;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(100%); }
  to { transform: translateX(-50%) translateY(0); }
}

.manage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.manage-header h2 { font-size: 1.15rem; font-weight: 700; }
.manage-close {
  font-size: 1.6rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}
.manage-close:hover { background: rgba(255,255,255,0.08); }

.manage-body {
  overflow-y: auto;
  padding: 16px 20px 32px;
  flex: 1;
}
.manage-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.manage-add h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.add-form input[type="text"],
.add-form select {
  flex: 1;
  min-width: 120px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
}
.add-form input[type="text"]:focus,
.add-form select:focus {
  outline: none;
  border-color: var(--accent);
}

.add-form input[type="color"] {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  padding: 4px;
}

.file-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(255,255,255,0.2);
  background: var(--bg-input);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
  transition: border-color 0.2s;
  min-height: 44px;
}
.file-upload-label:hover { border-color: var(--accent); }
.file-input { display: none; }

.image-preview-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
}
.image-preview-strip:empty { display: none; }
.image-preview-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.btn-add {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.2s;
  min-height: 44px;
}
.btn-add:hover { background: rgba(255,255,255,0.18); }

/* Character list */
.fandom-group {
  margin-bottom: 16px;
}
.fandom-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  cursor: pointer;
}
.fandom-group-title {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.fandom-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.fandom-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}
.fandom-delete-btn {
  font-size: 0.7rem;
  color: var(--danger);
  opacity: 0.6;
  padding: 4px 8px;
  border-radius: 4px;
  transition: opacity 0.2s;
}
.fandom-delete-btn:hover { opacity: 1; }

.char-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 8px 18px;
  border-bottom: 1px solid var(--border);
}
.char-thumb {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
}
.char-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.char-name {
  flex: 1;
  font-size: 0.9rem;
}
.char-img-count {
  font-size: 0.7rem;
  color: var(--text-muted);
}
.char-add-img-btn {
  font-size: 0.75rem;
  color: var(--vocaloid);
  padding: 4px 8px;
  border-radius: 4px;
  transition: opacity 0.2s;
}
.char-delete-btn {
  color: var(--danger);
  opacity: 0.5;
  font-size: 1.1rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: opacity 0.2s, background 0.2s;
}
.char-delete-btn:hover {
  opacity: 1;
  background: rgba(255,68,102,0.1);
}

/* === MANAGE TOGGLE === */
#manage-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: transform 0.2s, background 0.2s;
  z-index: 50;
}
#manage-toggle:hover {
  background: var(--bg-mid);
  transform: scale(1.08);
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 24px;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 200;
  animation: toastIn 0.3s ease-out;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.toast.hidden { display: none; }

@keyframes toastIn {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* === RESPONSIVE === */
@media (min-width: 600px) {
  #app { padding: 24px 24px 40px; gap: 24px; }
  .title { font-size: 2.5rem; }
  .wheel-container { max-width: 500px; }
  .manage-panel {
    max-height: 80dvh;
    border-radius: 20px;
    bottom: auto;
    position: relative;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
