/* === Design Tokens === */
:root {
  --bg-primary: #050508;
  --bg-card: #0d0d14;
  --bg-input: #0a0a12;
  --accent-crimson: #8b1a3a;
  --accent-blood: #6b0f2a;
  --accent-rose: #a32255;
  --accent-deep-purple: #3d1552;
  --accent-violet: #5c2175;
  --text-primary: #d8d0d4;
  --text-secondary: #7a6e74;
  --text-muted: #4a3f44;
  --glow-crimson: 0 0 25px rgba(139, 26, 58, 0.6), 0 0 80px rgba(139, 26, 58, 0.2);
  --glow-blood: 0 0 30px rgba(107, 15, 42, 0.7), 0 0 100px rgba(107, 15, 42, 0.25);
  --glow-violet: 0 0 20px rgba(92, 33, 117, 0.5);
  --card-border: 1px solid rgba(139, 26, 58, 0.15);
  --radius: 4px;
  --font-heading: 'Cinzel', serif;
  --font-body: 'Crimson Text', Georgia, serif;
}

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

/* === Background Effects === */
#bg-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.noise-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  opacity: 0.09;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 512px 512px;
  mix-blend-mode: overlay;
}

.vignette {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(5, 5, 8, 0.85) 100%);
}

/* === Base === */
body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow-x: hidden;
}

body > *:not(#bg-canvas):not(.noise-overlay):not(.vignette) {
  position: relative;
  z-index: 2;
}

/* === Header === */
header {
  text-align: center;
  padding: 4rem 1rem 2.5rem;
  width: 100%;
  max-width: 800px;
}

.title {
  font-family: var(--font-heading);
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-crimson);
  text-shadow: var(--glow-crimson);
  margin-bottom: 0.5rem;
}

.subtitle {
  font-family: var(--font-body);
  color: var(--text-secondary);
  font-size: 1.05rem;
  font-style: italic;
  margin-bottom: 2.5rem;
  letter-spacing: 0.03em;
}

/* === Search === */
.search-box {
  display: flex;
  gap: 0;
  max-width: 420px;
  margin: 0 auto;
}

#token-input {
  flex: 1;
  padding: 0.9rem 1.2rem;
  font-family: var(--font-body);
  font-size: 1.05rem;
  background: var(--bg-input);
  border: 1px solid rgba(139, 26, 58, 0.2);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--text-primary);
  outline: none;
  -moz-appearance: textfield;
}

#token-input::-webkit-outer-spin-button,
#token-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#token-input:focus {
  border-color: var(--accent-crimson);
  box-shadow: inset 0 0 15px rgba(139, 26, 58, 0.15);
}

#token-input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

#search-btn {
  padding: 0.9rem 2rem;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--accent-blood);
  color: var(--text-primary);
  border: 1px solid rgba(139, 26, 58, 0.3);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.3s;
}

#search-btn:hover {
  background: var(--accent-crimson);
  box-shadow: var(--glow-crimson);
}

#search-btn:active {
  transform: scale(0.97);
}

/* === Loading === */
#loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
  font-style: italic;
}

.loader {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(139, 26, 58, 0.15);
  border-top-color: var(--accent-crimson);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Error === */
#error {
  text-align: center;
  padding: 2rem 1rem;
}

#error-msg {
  font-family: var(--font-body);
  color: var(--accent-rose);
  font-size: 1rem;
  font-style: italic;
}

/* === Results === */
#results {
  width: 100%;
  max-width: 800px;
  padding: 0 1rem 3rem;
  animation: fadeUp 0.7s ease-out;
}

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

/* === Explanation (top, below search) === */
.explanation-section {
  background: var(--bg-card);
  border: var(--card-border);
  border-radius: var(--radius);
  padding: 1.8rem 2rem;
  text-align: center;
  margin-bottom: 2rem;
  animation: fadeUp 0.5s ease-out both;
}

.explanation-header {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent-violet);
  margin-bottom: 0.8rem;
}

.explanation-text {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text-primary);
  font-style: italic;
  max-width: 640px;
  margin: 0 auto;
}

/* === Portrait Row (images + heart) === */
.portrait-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.portrait {
  flex: 0 0 300px;
  line-height: 0;
  animation: cardReveal 0.6s ease-out both;
}

.portrait:first-child { animation-delay: 0.1s; }
.portrait:last-child { animation-delay: 0.3s; }

@keyframes cardReveal {
  from { opacity: 0; transform: scale(0.94) translateY(15px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.portrait img,
.portrait .img-fallback:not([hidden]) {
  box-shadow:
    0 0 15px rgba(139, 26, 58, 0.4),
    0 0 40px rgba(139, 26, 58, 0.15),
    0 0 80px rgba(92, 33, 117, 0.1);
  animation: portraitGlow 3s ease-in-out infinite alternate;
}

@keyframes portraitGlow {
  0% {
    box-shadow:
      0 0 15px rgba(139, 26, 58, 0.4),
      0 0 40px rgba(139, 26, 58, 0.15),
      0 0 80px rgba(92, 33, 117, 0.1);
  }
  100% {
    box-shadow:
      0 0 20px rgba(139, 26, 58, 0.6),
      0 0 50px rgba(139, 26, 58, 0.25),
      0 0 100px rgba(92, 33, 117, 0.2),
      0 0 4px rgba(255, 200, 200, 0.15);
  }
}

.portrait img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
  border: var(--card-border);
}

.img-fallback[hidden] {
  display: none;
}

.img-fallback {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-crimson);
  text-shadow: var(--glow-crimson);
  background:
    radial-gradient(ellipse at center, rgba(92, 33, 117, 0.08) 0%, transparent 70%),
    linear-gradient(135deg, #0a0a12 0%, #12081a 50%, #0d0d14 100%);
  border-radius: var(--radius);
  border: 1px solid rgba(92, 33, 117, 0.25);
}

/* === Match Badge (between portraits) === */
.match-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
  flex-shrink: 0;
}

.heart-pulse {
  font-size: 2.8rem;
  line-height: 1;
  animation: pulse 1.8s ease-in-out infinite;
}

.heart-icon {
  display: inline-block;
  filter: drop-shadow(0 0 8px rgba(92, 33, 117, 0.7)) drop-shadow(0 0 25px rgba(92, 33, 117, 0.35));
}

@keyframes pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(92, 33, 117, 0.7)) drop-shadow(0 0 25px rgba(92, 33, 117, 0.35)); }
  50% { transform: scale(1.15); filter: drop-shadow(0 0 14px rgba(92, 33, 117, 0.9)) drop-shadow(0 0 45px rgba(92, 33, 117, 0.5)); }
}

.match-text {
  font-family: var(--font-heading);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-crimson);
  text-shadow: var(--glow-crimson);
  margin-top: 0.5rem;
  text-align: center;
  white-space: nowrap;
}

.match-score {
  font-family: var(--font-body);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  font-style: italic;
}

/* === Info Row (names + traits below portraits) === */
.info-row {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-top: 1rem;
}

.info-panel {
  flex: 1;
  max-width: 350px;
  background: var(--bg-card);
  border: var(--card-border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  animation: fadeUp 0.5s ease-out 0.4s both;
}

.info-name {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
  padding-bottom: 0.5rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid rgba(139, 26, 58, 0.15);
}

.info-traits {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.trait-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid rgba(139, 26, 58, 0.06);
  padding: 0.2rem 0;
}

.trait-label {
  color: var(--text-muted);
  text-transform: uppercase;
  font-family: var(--font-heading);
  font-size: 0.55rem;
  letter-spacing: 0.08em;
}

.trait-value {
  color: var(--text-primary);
  text-align: right;
  font-size: 0.78rem;
}

.trait-highlight {
  color: var(--accent-rose);
}

/* === Footer === */
footer {
  margin-top: auto;
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* === Responsive === */
@media (max-width: 768px) {
  .title {
    font-size: 1.8rem;
  }

  header {
    padding: 2.5rem 1rem 1.5rem;
  }

  .portrait-row {
    flex-direction: column;
    align-items: center;
  }

  .portrait {
    flex: 0 0 auto;
    width: 70%;
    max-width: 280px;
  }

  .match-badge {
    flex-direction: row;
    gap: 0.8rem;
    padding: 0.8rem 0;
  }

  .heart-pulse {
    font-size: 2rem;
  }

  .match-text {
    margin-top: 0;
  }

  .match-score {
    margin-top: 0;
  }

  .info-row {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }

  .info-panel {
    max-width: 100%;
    width: 100%;
  }

  .explanation-section {
    padding: 1.2rem 1rem;
    margin-bottom: 1.5rem;
  }

  .explanation-text {
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  .title {
    font-size: 1.4rem;
    letter-spacing: 0.05em;
  }

  .search-box {
    flex-direction: column;
  }

  #token-input {
    border-right: 1px solid rgba(139, 26, 58, 0.2);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  #search-btn {
    border-left: 1px solid rgba(139, 26, 58, 0.3);
    border-radius: 0 0 var(--radius) var(--radius);
  }

  .portrait {
    width: 80%;
    max-width: 260px;
  }
}
