:root {
  --bg-dark: #0f0a1f;
  --bg-card: #1a1230;
  --bg-panel: #241a3d;
  --accent-gold: #f59e0b;
  --accent-purple: #a855f7;
  --accent-blue: #3b82f6;
  --text-primary: #f0e6ff;
  --text-secondary: #a89ec4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg-dark);
  background-image: 
    radial-gradient(ellipse at 20% 20%, rgba(168, 85, 247, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(59, 130, 246, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(245, 158, 11, 0.05) 0%, transparent 70%);
  min-height: 100vh;
  color: var(--text-primary);
  overflow-x: hidden;
}

.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
  position: relative;
}

/* Sparkles */
.sparkle-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.sparkle {
  position: absolute;
  background: white;
  border-radius: 50%;
  opacity: 0;
  animation: sparkle-float 4s ease-in-out infinite;
}

@keyframes sparkle-float {
  0%, 100% { opacity: 0; transform: translateY(100vh) scale(0); }
  50% { opacity: 0.8; transform: translateY(-100px) scale(1); }
}

/* Confetti */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 20px;
  animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* Header */
.app-header {
  text-align: center;
  padding: 2rem 1rem;
  position: relative;
  z-index: 1;
}

.app-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 900;
  background: linear-gradient(
    90deg,
    #f59e0b 0%,
    #ef4444 20%,
    #a855f7 40%,
    #3b82f6 60%,
    #22c55e 80%,
    #f59e0b 100%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradient-shift 3s linear infinite;
  text-shadow: 0 0 40px rgba(245, 158, 11, 0.3);
}

@keyframes gradient-shift {
  to { background-position: 200% center; }
}

.app-subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-top: 0.5rem;
}

.card-counter {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--bg-panel);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  border: 1px solid rgba(168, 85, 247, 0.3);
  font-size: 0.9rem;
}

.counter-value {
  color: var(--accent-gold);
  font-weight: 700;
}

/* Main Content */
.main-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  position: relative;
  z-index: 1;
}

@media (min-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr 400px;
  }
  
  .collection-section {
    grid-column: 1 / -1;
  }
}

/* Section Titles */
.section-title {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  color: var(--accent-gold);
  margin-bottom: 1.5rem;
  text-shadow: 0 0 20px rgba(245, 158, 11, 0.3);
}

/* Creation Panel */
.creation-panel {
  background: var(--bg-panel);
  border-radius: 20px;
  padding: 2rem;
  border: 1px solid rgba(168, 85, 247, 0.2);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.fantasy-input,
.fantasy-select {
  background: var(--bg-dark);
  border: 2px solid rgba(168, 85, 247, 0.3);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.fantasy-input:focus,
.fantasy-select:focus {
  outline: none;
  border-color: var(--accent-purple);
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.3);
}

.fantasy-select {
  cursor: pointer;
}

/* Stats Section */
.stats-section {
  margin-top: 1.5rem;
}

.stats-section h3 {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg-dark);
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(168, 85, 247, 0.2);
}

.stat-input span {
  font-size: 0.8rem;
}

.stat-input input {
  width: 60px;
  text-align: center;
  background: transparent;
  border: none;
  color: var(--accent-gold);
  font-size: 1.2rem;
  font-weight: 700;
  font-family: inherit;
}

.stat-input input:focus {
  outline: none;
}

.dice-btn {
  margin-top: 1rem;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  color: white;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.dice-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 5px 20px rgba(168, 85, 247, 0.4);
}

/* Rarity Section */
.rarity-section {
  margin-top: 1.5rem;
}

.rarity-section h3 {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.rarity-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.rarity-btn {
  padding: 0.6rem 1rem;
  border: 2px solid var(--rarity-color);
  background: transparent;
  color: var(--rarity-color);
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.rarity-btn:hover,
.rarity-btn.selected {
  background: var(--rarity-color);
  color: var(--bg-dark);
  box-shadow: 0 0 20px var(--rarity-color);
}

/* Generate Buttons */
.generate-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.generate-btn {
  flex: 1;
  min-width: 150px;
  padding: 1rem 1.5rem;
  border: none;
  border-radius: 12px;
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
}

.generate-btn.primary {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  box-shadow: 0 5px 30px rgba(245, 158, 11, 0.4);
}

.generate-btn.secondary {
  background: var(--bg-dark);
  color: var(--text-primary);
  border: 2px solid var(--accent-purple);
}

.generate-btn.thinking {
  background: linear-gradient(135deg, #06b6d4, #8b5cf6);
  color: white;
  box-shadow: 0 5px 30px rgba(6, 182, 212, 0.3);
}

.generate-btn.thinking:hover:not(:disabled) {
  box-shadow: 0 10px 40px rgba(139, 92, 246, 0.5);
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 10px 40px rgba(245, 158, 11, 0.5);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Card Display */
.card-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 500px;
}

.card-loading {
  text-align: center;
}

.card-skeleton {
  width: 280px;
  height: 400px;
  background: var(--bg-panel);
  border-radius: 20px;
  border: 3px solid var(--accent-purple);
  position: relative;
  overflow: hidden;
}

.skeleton-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(168, 85, 247, 0.3),
    transparent
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.current-card-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.card-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.action-btn {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-btn.save { background: #22c55e; color: white; }
.action-btn.regen { background: var(--accent-blue); color: white; }
.action-btn.share { background: var(--accent-purple); color: white; }

.action-btn:hover {
  transform: scale(1.05);
}

.empty-display {
  text-align: center;
  color: var(--text-secondary);
}

.empty-card {
  width: 200px;
  height: 280px;
  background: var(--bg-panel);
  border: 3px dashed rgba(168, 85, 247, 0.3);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  color: var(--accent-purple);
  margin: 0 auto 1rem;
}

/* Card Component */
.card-frame {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.card-frame.large {
  width: 280px;
  height: 400px;
}

.card-frame.small {
  width: 140px;
  height: 200px;
}

.card-frame:hover {
  transform: scale(1.03);
}

.card-inner {
  width: 100%;
  height: 100%;
  background: linear-gradient(145deg, #2a1f4a, #1a1230);
  border: 4px solid var(--rarity-color);
  border-radius: 16px;
  position: relative;
  box-shadow: var(--rarity-glow), inset 0 0 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.rarity-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: var(--rarity-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.8rem;
  color: var(--bg-dark);
  z-index: 5;
}

.card-art {
  flex: 0 0 60%;
  overflow: hidden;
  border-bottom: 2px solid var(--rarity-color);
}

.card-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-name-banner {
  background: linear-gradient(90deg, var(--rarity-color), transparent);
  padding: 0.4rem 0.6rem;
}

.card-name {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-frame.small .card-name {
  font-size: 0.6rem;
}

.card-type-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.7);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.6rem;
  color: var(--text-secondary);
}

.card-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.25rem;
  padding: 0.5rem;
  flex: 1;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.stat-icon {
  font-size: 0.9rem;
}

.stat-value {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--accent-gold);
}

.card-serial {
  text-align: center;
  font-size: 0.5rem;
  color: var(--text-secondary);
  padding-bottom: 0.3rem;
  font-family: monospace;
}

.holographic-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 0, 0, 0.1) 0%,
    rgba(255, 165, 0, 0.1) 15%,
    rgba(255, 255, 0, 0.1) 30%,
    rgba(0, 255, 0, 0.1) 45%,
    rgba(0, 255, 255, 0.1) 60%,
    rgba(0, 0, 255, 0.1) 75%,
    rgba(255, 0, 255, 0.1) 90%,
    rgba(255, 0, 0, 0.1) 100%
  );
  background-size: 400% 400%;
  animation: holographic 3s ease infinite;
  pointer-events: none;
  border-radius: 16px;
}

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

/* Collection Section */
.collection-section {
  background: var(--bg-panel);
  border-radius: 20px;
  padding: 2rem;
  border: 1px solid rgba(168, 85, 247, 0.2);
}

.collection-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: var(--bg-dark);
  padding: 1rem;
  border-radius: 12px;
  text-align: center;
  border: 1px solid rgba(168, 85, 247, 0.2);
}

.stat-label {
  display: block;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.stat-number {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.stat-box.rarest .stat-number {
  font-size: 1rem;
  color: var(--accent-purple);
}

/* Rarity Breakdown */
.rarity-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.rarity-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.rarity-label {
  width: 80px;
  font-size: 0.8rem;
  font-weight: 600;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-dark);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  transition: width 0.5s ease;
  border-radius: 4px;
}

.rarity-count {
  width: 30px;
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Collection Filters */
.collection-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: center;
}

.filter-group,
.sort-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-group label,
.sort-group label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.filter-btn {
  padding: 0.4rem 0.8rem;
  border: 1px solid rgba(168, 85, 247, 0.3);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover,
.filter-btn.active {
  background: var(--accent-purple);
  color: white;
  border-color: var(--accent-purple);
}

.sort-select {
  background: var(--bg-dark);
  border: 1px solid rgba(168, 85, 247, 0.3);
  color: var(--text-primary);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-family: inherit;
  cursor: pointer;
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

@media (min-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

.gallery-item {
  transition: transform 0.3s ease;
}

.gallery-item:hover {
  transform: translateY(-5px);
}

.empty-collection {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-secondary);
  padding: 3rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-content {
  position: relative;
  animation: modal-pop 0.3s ease;
}

@keyframes modal-pop {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: var(--bg-panel);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--accent-purple);
}

/* Idea Modal */
.idea-modal-content {
  background: var(--bg-panel);
  border-radius: 20px;
  padding: 2rem;
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  border: 2px solid rgba(6, 182, 212, 0.3);
  box-shadow: 0 0 60px rgba(139, 92, 246, 0.3);
}

.idea-modal-title {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  color: #06b6d4;
  margin-bottom: 0.5rem;
  text-align: center;
}

.idea-modal-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.api-key-section {
  margin-bottom: 1.5rem;
}

.api-key-section label {
  display: block;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.api-key-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: #06b6d4;
  text-decoration: none;
}

.api-key-link:hover {
  text-decoration: underline;
}

.idea-prompt-section {
  margin-bottom: 1.5rem;
}

.idea-prompt-section label {
  display: block;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.fantasy-textarea {
  width: 100%;
  background: var(--bg-dark);
  border: 2px solid rgba(168, 85, 247, 0.3);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
  transition: all 0.3s ease;
}

.fantasy-textarea:focus {
  outline: none;
  border-color: #06b6d4;
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.3);
}

.idea-btn {
  width: 100%;
  margin-top: 1rem;
}

.idea-error {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid #ef4444;
  color: #ef4444;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.thinking-process {
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.thinking-process h4 {
  color: #06b6d4;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.thinking-process p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.5;
  max-height: 100px;
  overflow-y: auto;
}

.ideas-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.idea-card {
  background: var(--bg-dark);
  border: 2px solid rgba(168, 85, 247, 0.3);
  border-radius: 12px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.idea-card:hover {
  border-color: #06b6d4;
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.3);
  transform: translateY(-2px);
}

.idea-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.idea-name {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.idea-rarity {
  font-weight: 600;
  font-size: 0.8rem;
}

.idea-card-body {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.idea-type,
.idea-style {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  background: rgba(168, 85, 247, 0.2);
  border-radius: 4px;
  color: var(--text-secondary);
}

.idea-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-style: italic;
  margin-bottom: 0.5rem;
}

.idea-use-hint {
  font-size: 0.75rem;
  color: #06b6d4;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.idea-card:hover .idea-use-hint {
  opacity: 1;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
  position: relative;
  z-index: 1;
}

.powered-by {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.flavor-text {
  font-style: italic;
  font-size: 0.85rem;
  color: var(--accent-purple);
  margin-bottom: 1rem;
  animation: fade-in 0.5s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.remix-link {
  color: var(--accent-gold);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s ease;
}

.remix-link:hover {
  color: #fbbf24;
  text-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}