:root {
  --bg-color: #0f172a;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

  --accent: #3b82f6;
  --accent-hover: #2563eb;

  --success-bg: rgba(16, 185, 129, 0.2);
  --success-text: #34d399;
  --warning-bg: rgba(245, 158, 11, 0.2);
  --warning-text: #fbbf24;
  --error-bg: rgba(239, 68, 68, 0.2);
  --error-text: #f87171;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --transition-fast: 0.2s ease;
  --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Plus Jakarta Sans", sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  line-height: 1.6;
}

/* Background Blobs for Visual Interest */
.background-blobs {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: -1;
  pointer-events: none;
}

.blob {
  position: absolute;
  filter: blur(100px);
  opacity: 0.5;
  border-radius: 50%;
  animation: float 20s infinite alternate cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

.blob-1 {
  top: -10%;
  left: -10%;
  width: 50vw;
  height: 50vw;
  background: radial-gradient(
    circle,
    rgba(59, 130, 246, 0.3) 0%,
    rgba(147, 51, 234, 0.1) 100%
  );
  animation-delay: 0s;
}

.blob-2 {
  bottom: -20%;
  right: -10%;
  width: 60vw;
  height: 60vw;
  background: radial-gradient(
    circle,
    rgba(16, 185, 129, 0.2) 0%,
    rgba(59, 130, 246, 0.1) 100%
  );
  animation-delay: -5s;
}

.blob-3 {
  top: 40%;
  left: 50%;
  width: 40vw;
  height: 40vw;
  background: radial-gradient(
    circle,
    rgba(236, 72, 153, 0.2) 0%,
    rgba(139, 92, 246, 0.1) 100%
  );
  transform: translate(-50%, -50%);
  animation-delay: -10s;
}

@keyframes float {
  0% {
    transform: translate(0, 0) scale(1);
  }
  33% {
    transform: translate(5%, 5%) scale(1.05);
  }
  66% {
    transform: translate(-5%, 10%) scale(0.95);
  }
  100% {
    transform: translate(0, 0) scale(1);
  }
}

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 3rem;
}

header {
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
}

header h1 {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 20px rgba(255, 255, 255, 0.1);
}

header p {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* Glassmorphism Panel */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--glass-shadow);
}

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.color-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: center;
}

.color-input-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  background: rgba(15, 23, 42, 0.4);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: var(--transition-smooth);
  width: 140px;
  animation: fadeInScale 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.color-input-wrapper:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.color-picker {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker::-webkit-color-swatch {
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.1),
    0 4px 10px rgba(0, 0, 0, 0.2);
  transition: var(--transition-fast);
}

.color-picker:hover::-webkit-color-swatch {
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.05);
}

.hex-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  text-align: center;
  font-family: monospace;
  font-size: 0.9rem;
  transition: var(--transition-fast);
}

.hex-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.hex-input[aria-invalid="true"] {
  border-color: var(--error-text);
}

.remove-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid rgba(239, 68, 68, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
  opacity: 0;
  transform: scale(0.8);
}

.color-input-wrapper:hover .remove-btn {
  opacity: 1;
  transform: scale(1);
}

.color-input-wrapper:focus-within .remove-btn {
  opacity: 1;
  transform: scale(1);
}

.remove-btn:hover {
  background: #ef4444;
  color: white;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: var(--transition-fast);
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

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

.btn-primary:disabled {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.3);
  box-shadow: none;
  cursor: not-allowed;
}

.count-indicator {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

/* Results Section */
.results {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 1rem;
  gap: 1rem;
}

.results-header h2 {
  font-size: 1.8rem;
  font-weight: 700;
}

.results-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.legend {
  display: flex;
  gap: 0.5rem;
}

.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: var(--transition-fast);
}

.badge:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.badge.inactive {
  opacity: 0.4;
  background: transparent !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
  color: var(--text-secondary) !important;
}

.badge-aaa {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-text);
}

.badge-aa {
  background: rgba(52, 211, 153, 0.1);
  color: #34d399;
  border: 1px solid #34d399;
}

.badge-large {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-text);
}

.badge-fail {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-text);
}

.apca-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.apca-mode-toggle input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.apca-mode-toggle input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Utilities */
.hidden {
  display: none !important;
}

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

/* Combinations Grid */
.combinations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.combo-card {
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--glass-shadow);
  transition: var(--transition-smooth);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.combo-card:hover {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.4);
  border-color: rgba(255, 255, 255, 0.15);
  z-index: 10;
}

.combo-preview {
  padding: 2rem 1.5rem;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 1rem;
  position: relative;
}

.combo-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(0, 0, 0, 0.05) 100%
  );
  pointer-events: none;
}

.preview-text-normal {
  font-size: 1rem;
  font-weight: 500;
}

.preview-text-large {
  font-size: 1.5rem;
  font-weight: 700;
}

.combo-details {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.combo-colors-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: monospace;
}

.combo-swap {
  opacity: 0.5;
}

.scores-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.combo-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.apca-row {
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
  padding-top: 0.5rem;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.stat-label[title] {
  cursor: help;
}

.stat-right {
  display: flex;
  align-items: center;
}

.ratio {
  font-size: 1.15rem;
  font-weight: 800;
  font-family: monospace;
  margin-right: 0.5rem;
}

.status-badge {
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.status-aaa {
  background: var(--success-bg);
  color: var(--success-text);
}

.status-aa {
  background: rgba(52, 211, 153, 0.1);
  color: #34d399;
}

.status-large {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.status-fail {
  background: var(--error-bg);
  color: var(--error-text);
}

footer {
  text-align: center;
  padding: 2rem 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

footer a {
  color: var(--accent);
  text-decoration: none;
  transition: var(--transition-fast);
}

footer a:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}

/* Acronym Glossary Accordion */
.glossary-accordion {
  margin-top: 3rem;
  padding: 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: var(--transition-smooth);
}

.glossary-accordion summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none; /* Remove default arrow in Firefox/WebKit */
  outline: none;
}

.glossary-accordion summary::-webkit-details-marker {
  display: none; /* Remove default arrow in WebKit */
}

.summary-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.summary-title svg {
  color: var(--accent);
}

.glossary-accordion .chevron {
  transition: transform 0.3s ease;
  color: var(--text-secondary);
}

.glossary-accordion[open] .chevron {
  transform: rotate(180deg);
}

.glossary-content {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.glossary-content dl {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin: 0;
}

.glossary-content dt {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

.glossary-content dd {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.6;
}

.glossary-content strong {
  color: var(--text-primary);
}

/* Color Blindness Filters */
.filter-protanopia .combo-preview {
  filter: url("#protanopia");
}
.filter-deuteranopia .combo-preview {
  filter: url("#deuteranopia");
}
.filter-tritanopia .combo-preview {
  filter: url("#tritanopia");
}
.filter-protanomaly .combo-preview {
  filter: url("#protanomaly");
}
.filter-deuteranomaly .combo-preview {
  filter: url("#deuteranomaly");
}
.filter-tritanomaly .combo-preview {
  filter: url("#tritanomaly");
}
.filter-achromatopsia .combo-preview {
  filter: url("#achromatopsia");
}
.filter-achromatomaly .combo-preview {
  filter: url("#achromatomaly");
}

/* Settings Popover */
.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.popover {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
  width: 90%;
  max-width: 400px;
  background: rgba(15, 23, 42, 0.85); /* Slightly darker for modal pop */
  transition:
    opacity 0.3s ease,
    transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.popover.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

.popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.popover-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.popover-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  color: var(--text-primary);
}

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

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

.custom-select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1em;
}

.custom-select:focus {
  outline: none;
  border-color: var(--accent);
}

.custom-select optgroup,
.custom-select option {
  background: var(--bg-color);
  color: var(--text-primary);
}

.btn:focus-visible,
.badge:focus-visible,
.close-btn:focus-visible,
.remove-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  background: rgba(15, 23, 42, 0.4);
  border-radius: var(--radius-md);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  header h1 {
    font-size: 2.5rem;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .results-tools {
    width: 100%;
    justify-content: flex-start;
  }

  .combinations-grid {
    grid-template-columns: 1fr;
  }
}
