/* ─── Reset & base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f0f2f5;
  --bg-subtle:   #e8eaef;
  --surface:     #ffffff;
  --surface-2:   #f5f6f8;
  --card:        rgba(255, 255, 255, 0.85);
  --border:      rgba(0, 0, 0, 0.08);
  --border-hover:rgba(0, 120, 90, 0.2);
  --accent:      #0fa87a;
  --accent-mid:  #3b8ef7;
  --accent-dim:  rgba(15, 168, 122, 0.1);
  --accent2:     #5c6fff;
  --accent2-dim: rgba(92, 111, 255, 0.08);
  --gradient:    linear-gradient(135deg, #0fa87a 0%, #3b8ef7 50%, #5c6fff 100%);
  --text:        #1a2332;
  --text-bright: #0d1520;
  --muted:       #6b7a90;
  --danger:      #d93025;
  --radius:      14px;
  --radius-sm:   10px;
  --transition:  0.22s cubic-bezier(.4,0,.2,1);
  --shadow:      0 4px 20px rgba(0, 0, 0, 0.06);
  --shadow-lg:   0 8px 40px rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 0 40px rgba(15, 168, 122, 0.06);
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

/* ─── Ambient background glows ────────────────────────────────────── */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}
.bg-glow--1 {
  width: 700px; height: 700px;
  top: -250px; left: -200px;
  background: radial-gradient(circle, rgba(15, 168, 122, 0.1), transparent 70%);
  animation: drift 18s ease-in-out infinite alternate;
}
.bg-glow--2 {
  width: 600px; height: 600px;
  bottom: -150px; right: -150px;
  background: radial-gradient(circle, rgba(92, 111, 255, 0.08), transparent 70%);
  animation: drift 22s ease-in-out infinite alternate-reverse;
}
@keyframes drift {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(40px, 30px) scale(1.08); }
}

/* ─── Header ──────────────────────────────────────────────────────── */
header {
  position: relative;
  z-index: 1;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(245, 246, 248, 0.9) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 2rem 2rem 1.6rem;
}
header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 3px;
  background: var(--gradient);
  opacity: 0.6;
}
.header-inner { max-width: 1240px; margin: 0 auto; }
header h1 {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-icon {
  -webkit-text-fill-color: initial;
  font-size: 1.6rem;
}
.byline {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 0.25rem;
  letter-spacing: 0.01em;
}
.subtitle {
  color: var(--muted);
  margin-top: 0.45rem;
  font-size: 0.92rem;
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* ─── Main layout ─────────────────────────────────────────────────── */
main {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 1.8rem 1.2rem;
  gap: 1.6rem;
  align-items: flex-start;
}

/* ─── Primate grid section ────────────────────────────────────────── */
.grid-section { flex: 1; min-width: 0; }

.controls-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.controls-bar label {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.controls-bar select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 2rem 0.5rem 0.85rem;
  font-size: 0.88rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%237b8db8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}
.controls-bar select:hover {
  border-color: var(--border-hover);
}
.controls-bar select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), 0 2px 8px rgba(15, 168, 122, 0.06);
}

.status-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.1rem;
  transition: all var(--transition);
}
.status-bar.two-selected {
  color: var(--accent);
  border-color: rgba(15, 168, 122, 0.2);
  background: rgba(15, 168, 122, 0.04);
}

.primate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 0.9rem;
}

/* ─── Primate card ────────────────────────────────────────────────── */
.primate-card {
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 0.75rem 0.9rem;
  cursor: pointer;
  user-select: none;
  transition:
    border-color var(--transition),
    background var(--transition),
    transform var(--transition),
    box-shadow var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  position: relative;
  overflow: hidden;
}
.primate-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: radial-gradient(ellipse at 50% 0%, rgba(59, 142, 247, 0.05) 0%, transparent 70%);
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}
.primate-card:hover::before { opacity: 1; }
.primate-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-4px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(15, 168, 122, 0.06);
}
.primate-card.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 2px var(--accent-dim), 0 8px 28px rgba(15, 168, 122, 0.12);
}
.primate-card.selected::before {
  opacity: 1;
  background: radial-gradient(ellipse at 50% 0%, rgba(15, 168, 122, 0.07) 0%, transparent 70%);
}
.primate-card.unavailable {
  opacity: 0.35;
  filter: grayscale(100%);
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}
.primate-card.unavailable:hover {
  border-color: var(--border);
}
.primate-card.unavailable::before { opacity: 0 !important; }
.primate-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  transition: filter var(--transition);
}
.primate-card:hover .card-photo {
  filter: brightness(1.08);
}
.card-emoji-fallback {
  font-size: 2.2rem;
  line-height: 1;
}
.card-common {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-bright);
  line-height: 1.25;
  margin-top: 0.15rem;
}
.card-species {
  font-size: 0.73rem;
  color: var(--muted);
  font-style: italic;
  line-height: 1.2;
}
.card-unavailable {
  display: none;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--danger);
  border: 1px solid rgba(217, 48, 37, 0.2);
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
  margin-top: 0.15rem;
}
.primate-card.unavailable .card-unavailable {
  display: inline-block;
}
.card-check {
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
  color: var(--accent);
  transform: scale(0.5);
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(15, 168, 122, 0.14);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.7rem;
}
.primate-card.unavailable .card-check { display: none; }
.primate-card.selected .card-check {
  opacity: 1;
  transform: scale(1);
}

/* ─── Result panel ────────────────────────────────────────────────── */
.result-panel {
  width: 300px;
  flex-shrink: 0;
  position: sticky;
  top: 1.5rem;
}
.result-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.3rem;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
  overflow: hidden;
}
.result-inner::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gradient);
  border-radius: var(--radius) var(--radius) 0 0;
}
.result-inner h2 {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* gene info box */
.gene-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  margin-top: 0.9rem;
  position: relative;
  overflow: hidden;
}
.gene-info::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gradient);
  opacity: 0.45;
}
.gene-info h3 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.55rem;
}
.gene-info p {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
}

/* placeholder */
.result-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.9rem;
  flex: 1;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}
.dna-icon {
  font-size: 2.8rem;
  filter: drop-shadow(0 0 10px rgba(0, 149, 110, 0.15));
}

/* result content */
.result-data { display: flex; flex-direction: column; gap: 1rem; }

.result-species {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.result-species-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.86rem;
}
.species-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--gradient);
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(15, 168, 122, 0.2);
}
.species-name { font-weight: 600; color: var(--text-bright); }
.species-sci  { color: var(--muted); font-style: italic; font-size: 0.8rem; }

.result-divider {
  border: none;
  border-top: 1px solid var(--border);
}

/* big similarity number */
.similarity-block { text-align: center; padding: 0.3rem 0; }
.similarity-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.similarity-value {
  font-size: 3.6rem;
  font-weight: 900;
  line-height: 1;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(15, 168, 122, 0.12));
}
.similarity-suffix {
  font-size: 1.5rem;
  font-weight: 700;
}

.similarity-plain {
  margin-top: 0.45rem;
  font-size: 0.92rem;
  color: var(--text);
  font-weight: 600;
}

/* progress bar */
.progress-wrap {
  background: rgba(100, 130, 200, 0.1);
  border-radius: 999px;
  height: 7px;
  overflow: hidden;
  margin-top: 0.7rem;
  position: relative;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--gradient);
  transition: width 0.7s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 0 10px rgba(15, 168, 122, 0.18);
  position: relative;
}

/* relationship badge */
.relationship {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent-dim) 0%, var(--accent2-dim) 100%);
  border: 1px solid rgba(15, 168, 122, 0.15);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.25rem 0.8rem;
  text-align: center;
  align-self: center;
  letter-spacing: 0.02em;
}

/* bases compared */
.bases-compared {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* loading / error */
.loading-msg {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  animation: pulse 1.4s ease-in-out infinite;
}
.error-msg { color: var(--danger); font-size: 0.85rem; text-align: center; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* ─── Footer ──────────────────────────────────────────────────────── */
footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--border);
  padding: 1rem 2rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* ─── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #ccd0d8; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a0a8b4; }

/* ─── Selection highlight ─────────────────────────────────────────── */
::selection {
  background: var(--accent-dim);
  color: var(--text-bright);
}

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 720px) {
  main { flex-direction: column; padding: 1rem; }
  .grid-section { display: contents; }
  .controls-bar { order: 1; flex-direction: column; align-items: flex-start; width: 100%; }
  .controls-bar select { width: 100%; }
  #status-bar { order: 2; }
  .result-panel { width: 100%; position: static; order: 3; }
  .primate-grid { order: 4; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  header { padding: 1.5rem 1rem 1.2rem; }
  header h1 { font-size: 1.5rem; }
  .bg-glow { display: none; }
}
