:root {
  color-scheme: light dark;
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --primary-light: #7dd3fc;
  --bg-main: #ffffff;
  --bg-card: #ffffff;
  --bg-light: rgba(14, 165, 233, 0.05);
  --bg-hover: rgba(14, 165, 233, 0.08);
  --border-light: rgba(14, 165, 233, 0.15);
  --border-medium: rgba(14, 165, 233, 0.25);
  --text-main: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --spacing-xs: 8px;
  --spacing-sm: 12px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-2xl: 48px;
  --spacing-3xl: 64px;
  --border-radius-sm: 8px;
  --border-radius-md: 12px;
  --border-radius-lg: 16px;
  --border-radius-xl: 24px;
  --border-radius-full: 9999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-light: rgba(14, 165, 233, 0.1);
    --bg-hover: rgba(14, 165, 233, 0.15);
    --border-light: rgba(148, 163, 184, 0.15);
    --border-medium: rgba(148, 163, 184, 0.25);
    --text-main: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
  }
}

/* Theme Variations */
body.theme-deep-sea {
  --primary: #4a5568;
  --primary-dark: #2d3748;
  --primary-light: #718096;
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --text-main: #cbd5e1;
}

body.theme-coral-reef {
  --primary: #f59e0b;
  --primary-dark: #d97706;
  --primary-light: #fbbf24;
  --bg-light: rgba(245, 158, 11, 0.08);
}

body.theme-arctic {
  --primary: #06b6d4;
  --primary-dark: #0891b2;
  --primary-light: #67e8f9;
  --bg-light: rgba(6, 182, 212, 0.08);
}

body.theme-philip {
  --primary: #a855f7;
  --primary-dark: #9333ea;
  --primary-light: #c084fc;
  --bg-light: rgba(168, 85, 247, 0.08);
}

body.theme-salmon {
  --primary: #f43f5e;
  --primary-dark: #e11d48;
  --primary-light: #fb7185;
  --bg-light: rgba(244, 63, 94, 0.08);
}

body.theme-shark {
  --primary: #64748b;
  --primary-dark: #475569;
  --primary-light: #94a3b8;
  --bg-light: rgba(100, 116, 139, 0.08);
}

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

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.9;
  }
}

@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

body {
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    'Helvetica Neue',
    Arial,
    sans-serif,
    'Apple Color Emoji',
    'Segoe UI Emoji',
    'Segoe UI Symbol';
  margin: 0;
  padding: var(--spacing-lg) var(--spacing-md);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  color: var(--text-main);
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
  max-width: 800px;
  margin: 0 auto var(--spacing-3xl) auto;
  text-align: center;
  width: 100%;
}

h1 {
  margin: 0;
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
  animation: slideInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  letter-spacing: -0.02em;
}

@supports not (background-clip: text) {
  h1 {
    color: var(--primary);
    background: none;
    -webkit-text-fill-color: inherit;
  }
}

.sub {
  color: var(--text-secondary);
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
  letter-spacing: -0.01em;
  animation: slideInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.1s backwards;
  line-height: 1.5;
}

.controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: var(--spacing-sm);
  animation: slideInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.2s backwards;
}

#countdown {
  font-weight: 700;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  color: var(--primary);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.achievement-header-icons {
  display: flex;
  gap: var(--spacing-xs);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--spacing-sm);
}

.achievement-icon {
  font-size: 1.5rem;
  padding: var(--spacing-xs);
  background: var(--bg-light);
  border-radius: var(--border-radius-md);
  cursor: help;
  transition: transform 0.2s ease;
  border: 1px solid var(--border-light);
}

.achievement-icon:hover {
  transform: scale(1.1);
}

.millennium-badge {
  background: linear-gradient(90deg, #9333ea, #ec4899, #f59e0b, #ec4899, #9333ea);
  background-size: 200% 100%;
  animation: shimmer 3s linear infinite;
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: var(--border-radius-full);
  font-weight: 700;
  font-size: 0.9rem;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  box-shadow: var(--shadow-lg);
}

.toolbar {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  justify-content: center;
  animation: slideInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.3s backwards;
  margin-top: var(--spacing-md);
}

.btn {
  padding: var(--spacing-sm) var(--spacing-lg);
  border: 2px solid transparent;
  border-radius: var(--border-radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  box-shadow: var(--shadow-sm);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-light);
  color: var(--text-main);
  border-color: var(--border-light);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-secondary:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.btn-block {
  width: 100%;
}

.btn-small {
  padding: 6px 14px;
  font-size: 0.85rem;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-medium);
  background: var(--bg-light);
  color: var(--text-main);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-small:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
  color: var(--primary);
}

main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0 0 var(--spacing-3xl) 0;
}

#wrap {
  max-width: 800px;
  width: 100%;
  display: grid;
  gap: var(--spacing-lg);
}

.card {
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-xl);
  padding: var(--spacing-2xl);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  opacity: 0;
  transition: opacity 0.3s ease;
}

.card:hover {
  border-color: var(--border-medium);
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
}

.card:hover::before {
  opacity: 1;
}

.millennium-card {
  border: 2px solid #9333ea;
  background: linear-gradient(135deg, rgba(147, 51, 234, 0.05), rgba(236, 72, 153, 0.05));
  animation: pulse 2s ease-in-out infinite, fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-xl), 0 0 40px rgba(147, 51, 234, 0.2);
}

.millennium-card::before {
  background: linear-gradient(90deg, #9333ea, #ec4899, #f59e0b);
  opacity: 1;
}

.ultra-card {
  border: 2px solid #f59e0b;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.05), rgba(251, 191, 36, 0.05));
  box-shadow: var(--shadow-lg), 0 0 30px rgba(245, 158, 11, 0.15);
}

.ultra-card::before {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  opacity: 1;
}

.meta {
  display: flex;
  gap: var(--spacing-md);
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--border-light);
}

.num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--primary);
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.tag {
  font-size: 0.75rem;
  padding: 4px 12px;
  border-radius: var(--border-radius-full);
  background: var(--bg-light);
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid var(--border-light);
}

.fav-btn, .share-btn {
  background: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-sm);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px 10px;
  transition: all 0.2s ease;
  margin-left: auto;
}

.fav-btn:hover, .share-btn:hover {
  transform: scale(1.15);
  background: var(--bg-hover);
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.emoji {
  font-size: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  font-family:
    'Apple Color Emoji',
    'Segoe UI Emoji',
    'Segoe UI Symbol',
    sans-serif;
  line-height: 1;
  flex-shrink: 0;
  animation: float 3s ease-in-out infinite;
}

.fact {
  margin: 0;
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  line-height: 1.7;
  letter-spacing: -0.01em;
  font-weight: 500;
  color: var(--text-main);
}

.tiny {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: var(--spacing-lg);
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--border-light);
  font-style: italic;
  text-align: center;
}

.hidden {
  display: none !important;
}

/* Modal Styles */
.modal {
  display: flex;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
  padding: var(--spacing-md);
}

.modal-content {
  background: var(--bg-card);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-xl);
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-xl);
  animation: slideInUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-large {
  max-width: 900px;
}

.modal-header {
  padding: var(--spacing-lg) var(--spacing-xl);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.close-btn {
  background: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-sm);
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  padding: 4px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-medium);
  transform: scale(1.1);
}

.modal-body {
  padding: var(--spacing-xl);
  overflow-y: auto;
  flex: 1;
}

/* Archive Styles */
.search-input {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid var(--border-light);
  border-radius: var(--border-radius-md);
  font-size: 1rem;
  margin-bottom: var(--spacing-md);
  background: var(--bg-light);
  color: var(--text-main);
  font-family: inherit;
  transition: all 0.2s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.archive-content {
  display: grid;
  gap: var(--spacing-md);
  max-height: 60vh;
  overflow-y: auto;
}

.archive-item {
  padding: var(--spacing-md);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-md);
  background: var(--bg-light);
  transition: all 0.2s ease;
}

.archive-item:hover {
  border-color: var(--border-medium);
  background: var(--bg-hover);
  transform: translateX(4px);
}

.archive-item.seen {
  opacity: 0.7;
}

.archive-item.favorite {
  border-color: #fbbf24;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.05), rgba(245, 158, 11, 0.05));
}

/* Deck Filters */
.deck-filters {
  display: flex;
  gap: var(--spacing-md);
  flex-wrap: wrap;
  margin-bottom: var(--spacing-lg);
  padding: var(--spacing-md);
  background: var(--bg-light);
  border-radius: var(--border-radius-md);
  border: 1px solid var(--border-light);
}

.deck-filter-checkbox {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

/* Stats Styles */
.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md) 0;
  border-bottom: 1px solid var(--border-light);
}

.stat-item:last-child {
  border-bottom: none;
}

.stat-label {
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.stat-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-light);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: help;
  border: 1px solid var(--border-light);
}

.stat-value {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-light);
  border-radius: var(--border-radius-full);
  overflow: hidden;
  margin: var(--spacing-sm) 0 var(--spacing-md) 0;
  border: 1px solid var(--border-light);
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--border-radius-full);
}

/* Achievements */
.achievements-heading {
  margin: var(--spacing-xl) 0 var(--spacing-md) 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  border-top: 1px solid var(--border-light);
  padding-top: var(--spacing-xl);
}

.achievements-list {
  display: grid;
  gap: var(--spacing-md);
}

.achievement-badge {
  display: flex;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
  background: var(--bg-light);
  border-radius: var(--border-radius-md);
  border: 1px solid var(--border-light);
  align-items: center;
}

.achievement-badge-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.achievement-badge-title {
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.achievement-badge-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Settings Styles */
.setting-item {
  margin-bottom: var(--spacing-xl);
}

.setting-item:last-child {
  margin-bottom: 0;
}

.setting-item label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-sm);
  font-weight: 600;
  color: var(--text-main);
}

.slider {
  width: 100%;
  height: 8px;
  border-radius: var(--border-radius-full);
  background: var(--bg-light);
  outline: none;
  -webkit-appearance: none;
  border: 1px solid var(--border-light);
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: all 0.2s ease;
  border: 3px solid white;
  box-shadow: var(--shadow-md);
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: var(--shadow-lg), 0 0 12px var(--primary);
}

.slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 3px solid white;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-md);
}

.slider::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: var(--shadow-lg), 0 0 12px var(--primary);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: var(--spacing-xs);
}

.theme-select {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid var(--border-light);
  border-radius: var(--border-radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 1rem;
  cursor: pointer;
  margin-top: var(--spacing-xs);
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s ease;
}

.theme-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--primary);
  border-radius: 4px;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: var(--spacing-lg);
  right: var(--spacing-lg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  max-width: 400px;
}

.toast {
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--border-radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-light);
  animation: slideInUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-weight: 500;
  border-left: 4px solid var(--primary);
}

.toast-success {
  border-left-color: #10b981;
}

.toast-error {
  border-left-color: #ef4444;
}

.toast-info {
  border-left-color: var(--primary);
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: var(--spacing-md);
  }

  h1 {
    font-size: 1.75rem;
  }

  header {
    margin-bottom: var(--spacing-2xl);
  }

  .toolbar {
    flex-direction: column;
    width: 100%;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .card {
    padding: var(--spacing-lg);
  }

  .modal-content {
    width: 95%;
    margin: var(--spacing-sm);
    max-height: 90vh;
  }

  .modal-header {
    padding: var(--spacing-md) var(--spacing-lg);
  }

  .modal-body {
    padding: var(--spacing-lg);
  }

  .deck-filters {
    flex-direction: column;
  }

  #toast-container {
    left: var(--spacing-md);
    right: var(--spacing-md);
    bottom: var(--spacing-md);
    max-width: none;
  }
}

@media (max-width: 480px) {
  .meta {
    gap: var(--spacing-sm);
  }

  .fav-btn, .share-btn {
    font-size: 1rem;
    padding: 4px 8px;
  }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-light);
  border-radius: var(--border-radius-sm);
}

::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: var(--border-radius-sm);
  border: 2px solid var(--bg-card);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}

/* Focus Visible for Accessibility */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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