/*
 * MTG Card Alternatives - Fantasy Theme
 * Dark, mystical design inspired by Magic: The Gathering
 */

/* === ROOT VARIABLES === */
:root {
  --color-bg: #0a0a0f;
  --color-bg-secondary: #1a1a2e;
  --color-bg-card: #0D1428;
  --color-accent: #c9a961;
  --color-accent-bright: #e6c87e;
  --color-text: #e8e8e8;
  --color-text-dim: #a8a8b8;
  --color-border: #2d3748;
  --color-success: #48bb78;
  --color-error: #f56565;

  --font-display: 'Cinzel', serif;
  --font-body: 'Roboto', sans-serif;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(201, 169, 97, 0.3);

  /* Desaturated film-grain tile (inline SVG, no asset) */
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.85'/%3E%3C/svg%3E");
}

/* === RESET & BASE === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
}

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

/* === FANTASY BACKGROUND === */
.fantasy-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(88, 50, 120, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(120, 50, 88, 0.15) 0%, transparent 50%),
    linear-gradient(180deg, #0a0a0f 0%, #1a1a2e 100%);
  z-index: -1;
}

/* === TYPOGRAPHY === */
h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-accent-bright);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--color-accent-bright);
}

/* === LAYOUT === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* === HEADER === */
.site-header {
  background: rgba(26, 26, 46, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.site-header h1 {
  font-size: 1.75rem;
  margin: 0;
  background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-bright) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.logo-image {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

/* === MAIN CONTENT === */
.main-content {
  min-height: calc(100vh - 200px);
  padding: 2rem 0;
}

/* === HERO SECTION === */
.hero-section {
  text-align: center;
  padding: 4rem 0;
}

.hero-title {
  font-size: 3rem;
  margin-bottom: 1rem;
  text-shadow: var(--shadow-glow);
}

.hero-subtitle {
  font-size: 1.25rem;
  color: var(--color-text-dim);
  margin-bottom: 3rem;
}

/* === SEARCH === */
.search-container {
  max-width: 600px;
  margin: 0 auto 2rem;
  position: relative;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  padding: 1rem 3.5rem 1rem 1.5rem;
  font-size: 1.125rem;
  font-family: var(--font-body);
  background: var(--color-bg-card);
  border: 2px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-text);
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-glow);
}

.search-input::placeholder {
  color: var(--color-text-dim);
}

.search-icon {
  position: absolute;
  right: 1.25rem;
  font-size: 1.5rem;
  opacity: 0.7;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.search-icon:hover {
  opacity: 1;
  transform: scale(1.1);
}

/* === AUTOCOMPLETE === */
.autocomplete-results {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--color-bg-card);
  border: 2px solid var(--color-accent);
  border-radius: 12px;
  max-height: 400px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: none;
}

.autocomplete-results.active {
  display: block;
}

.autocomplete-item {
  padding: 0.875rem 1.25rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  transition: background 0.2s ease;
}

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

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: rgba(201, 169, 97, 0.15);
}

.autocomplete-item-name {
  font-weight: 500;
  color: var(--color-text);
}

.autocomplete-loading,
.autocomplete-no-results {
  padding: 1rem;
  text-align: center;
  color: var(--color-text-dim);
}

/* === SEARCH TIPS === */
.search-tips {
  margin-top: 1.5rem;
  color: var(--color-text-dim);
  font-size: 0.95rem;
}

.search-tip-link,
.search-tip-link:hover {
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
}

/* === FEATURES SECTION === */
.features-section {
  padding: 4rem 0;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 2rem;
}

.feature-card {
  background:
    var(--noise),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.3) 100%),
    var(--color-bg-card);
  background-blend-mode: overlay, normal, normal;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-accent);
}

.feature-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.feature-card h3 {
  margin-bottom: 0.5rem;
}

.feature-card p {
  color: var(--color-text-dim);
}

/* === CARD PAGE === */
.card-page {
  padding: 2rem 0;
}

.breadcrumb {
  margin-bottom: 2rem;
}

.breadcrumb-bottom {
  margin-bottom: 0;
  margin-top: 3rem;
  text-align: center;
}

.back-link {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.back-link:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-sm);
}

.card-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.card-title-row .card-name {
  margin-bottom: 0;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.suggest-link {
  color: var(--color-accent);
  font-size: 0.9rem;
  text-decoration: none;
}

.suggest-link:hover {
  text-decoration: underline;
}

.card-name {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.alternatives-count {
  font-size: 1.125rem;
  color: var(--color-text-dim);
}

/* === SEARCHED CARD SECTION (image + oracle text) === */
.searched-card-section {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 1.5rem;
  margin: 1rem auto;
  max-width: 500px;
}

@media (max-width: 768px) {
  .searched-card-section {
    flex-direction: column;
    align-items: center;
  }
}

.card-oracle-panel {
  flex: 0 1 auto;
  width: fit-content;
  min-width: 160px;
  max-width: 320px;
  height: 237px; /* matches card image height: 170px × (88/63) */
  display: flex;
  flex-direction: column;
  border: 3px solid #2c1a0e;
  box-shadow:
    inset 0 0 0 2px #c9a84c,
    0 6px 20px rgba(0, 0, 0, 0.6);
  overflow: visible;
  font-family: 'Georgia', 'Times New Roman', serif;
  color: #1a0a00;
}


.card-oracle-panel__name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  position: relative;
  overflow: visible;
  padding: 0.55rem 1rem;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  color: #e8c96a;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 6px rgba(0, 0, 0, 0.7);
}

.card-oracle-panel__name-row::before {
  content: '';
  position: absolute;
  inset: -6px -20px;
  background-image: url("/ui/tile-border-dark.webp");
  background-size: 100% 100%;
  z-index: 0;
  pointer-events: none;
}

.card-oracle-panel__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.03em;
  position: relative;
  z-index: 1;
}

.card-oracle-panel__mana {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.card-oracle-panel__mana .mana-symbol {
  width: 0.9em;
  height: 0.9em;
}

.card-oracle-panel__type {
  background: #e8d9a8;
  color: #1a0a00;
  padding: 0.45rem 0.55rem 0.2rem;
  font-family: var(--font-display);
  font-size: 0.65rem;
  letter-spacing: 0.02em;
  border-bottom: 2px solid #c9a84c;
}

.card-oracle-panel__body {
  flex: 1;
  overflow-y: auto;
  background: linear-gradient(160deg, #f5e8c4 0%, #ede0ad 60%, #f2e5bc 100%);
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #b89540 #ede0ad;
}

.card-oracle-panel__content {
  margin: auto 0;
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
  line-height: 1.55;
  text-align: center;
}

.card-flavor-text {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #b89540;
  font-style: italic;
  color: #3a2410;
  font-size: 0.68rem;
}

.dfc-separator {
  display: block;
  text-align: center;
  color: #7a5520;
  font-weight: 700;
  margin: 0.6rem 0;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
}

.mana-symbol {
  width: 1em;
  height: 1em;
  vertical-align: middle;
  display: inline-block;
}

/* === SEARCHED CARD IMAGE === */
.searched-card {
  display: flex;
  justify-content: center;
  margin: 0;
  width: 170px;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .searched-card {
    width: 130px;
  }
}

@media (max-width: 768px) {
  .card-oracle-panel {
    height: auto;
  }
}

.searched-card-image-wrapper {
  position: relative;
  display: inline-block;
}

.searched-card-image-wrapper:hover {
  position: relative;
  z-index: 1000;
  /* 170px base -> ~280px, matching the alternative card width */
  transform: scale(1.65);
}

/* Cancel the wrapper scale on the badge so it keeps its real size (1 / 1.65) */
.searched-card-image-wrapper:hover .price-badge {
  transform: scale(0.606);
  transform-origin: bottom left;
}

.searched-card-image {
  width: 100%;
  max-width: 170px;
  border-radius: 4.75%;
  box-shadow: 0 0 0 1px rgba(201, 169, 97, 0.3), var(--shadow-lg), var(--shadow-glow);
}

@media (max-width: 768px) {
  .searched-card-image {
    max-width: 130px;
  }
}

/* === CARDS GRID === */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2rem;
}

.card-item {
  background:
    var(--noise),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.3) 100%),
    var(--color-bg-card);
  background-blend-mode: overlay, normal, normal;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.card-item:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--color-accent);
}

.card-image-link {
  display: block;
  width: 100%;
  height: 100%;
}

.card-image-wrapper {
  position: relative;
  aspect-ratio: 5 / 7;
  overflow: hidden;
  background: var(--color-bg-secondary);
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.card-item:hover .card-image {
  transform: scale(1.05);
}

.card-image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-dim);
  font-style: italic;
}

.price-badge {
  position: absolute;
  bottom: 0.75rem;
  left: 0.75rem;
  background: rgba(72, 187, 120, 0.95);
  color: var(--color-bg);
  padding: 0.375rem 0.75rem;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.card-info {
  padding: 1.5rem;
}

.card-title {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--color-accent-bright);
}

.card-title a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.card-title a:hover {
  color: var(--color-accent);
}

.card-ext-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 0.4rem;
  margin-top: 0.85rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--color-border);
}

.card-ext-links::before {
  content: '⚔';
  font-size: 1rem;
  color: var(--color-accent);
  opacity: 0.6;
  margin-right: 0.1rem;
}

.card-ext-link {
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--color-text-dim);
  transition: color 0.2s ease;
  white-space: nowrap;
}

.card-ext-link::after {
  content: '·';
  margin-left: 0.4rem;
  color: var(--color-border);
}

.card-ext-link:last-child::after {
  content: none;
}

.card-ext-link:hover {
  color: var(--color-accent-bright);
}

.card-ext-link--buy {
  color: #8a7a4a;
}

.card-ext-link--buy:hover {
  color: var(--color-accent);
}

/* === ERROR PAGES === */
.error-page {
  text-align: center;
  padding: 4rem 0;
}

.error-page h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.error-page p {
  font-size: 1.125rem;
  color: var(--color-text-dim);
  margin-bottom: 2rem;
}

.no-results {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--color-text-dim);
  font-size: 1.125rem;
}

/* === FOOTER === */
.site-footer {
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  padding: 2rem 0;
  text-align: center;
  margin-top: 4rem;
}

.site-footer p {
  color: var(--color-text-dim);
  font-size: 0.95rem;
}

.site-footer a {
  color: var(--color-accent);
}

/* === LEGAL PAGES === */
.legal-page {
  padding: 2rem 0;
}

.legal-page h1 {
  font-size: 2.5rem;
  margin-bottom: 2rem;
  text-align: center;
}

.legal-page h2 {
  font-size: 1.5rem;
  margin-top: 2rem;
  margin-bottom: 1rem;
  color: var(--color-accent-bright);
}

.legal-content {
  max-width: 800px;
  margin: 0 auto 3rem;
  background:
    var(--noise),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 65%, rgba(0, 0, 0, 0.28) 100%),
    var(--color-bg-card);
  background-blend-mode: overlay, normal, normal;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 2rem;
  line-height: 1.8;
}

.legal-content p {
  margin-bottom: 1rem;
}

.legal-content a {
  color: var(--color-accent);
  text-decoration: underline;
}

.legal-content a:hover {
  color: var(--color-accent-bright);
}

.legal-page .back-link {
  display: inline-block;
  margin: 0 auto;
  text-align: center;
}

/* === CARDS LIST (INDEX PAGE) === */
.cards-list {
  max-width: 800px;
  margin: 0 auto 3rem;
}

.letter-divider {
  font-size: 2rem;
  color: var(--color-accent-bright);
  border-bottom: 2px solid var(--color-accent);
  padding: 1rem 0 0.5rem;
  margin: 2rem 0 1rem;
  font-family: var(--font-display);
}

.card-list-item {
  padding: 0.75rem 1rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  transition: all 0.2s ease;
}

.card-list-item:hover {
  border-color: var(--color-accent);
  background: rgba(201, 169, 97, 0.05);
  transform: translateX(4px);
}

.card-link {
  display: block;
  color: var(--color-text);
  font-size: 1.125rem;
  font-weight: 500;
  transition: color 0.2s ease;
}

.card-link:hover {
  color: var(--color-accent-bright);
}

/* === PAGINATION === */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  margin: 3rem 0;
}

.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  list-style: none;
  padding: 0;
}

.pagination a,
.pagination span {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
  transition: all 0.2s ease;
  min-width: 40px;
  text-align: center;
}

.pagination a:hover {
  border-color: var(--color-accent);
  background: rgba(201, 169, 97, 0.1);
  color: var(--color-accent-bright);
}

.pagination .current {
  background: var(--color-accent);
  color: var(--color-bg);
  border-color: var(--color-accent);
  font-weight: 700;
}

.pagination .disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pagination .prev,
.pagination .next {
  font-weight: 600;
}

.pagination .first,
.pagination .last {
  font-weight: 600;
}

/* === SIMILARITY BAR (image-based) === */
.similarity-bar-container {
  margin: 0.5rem 0 0.9rem;
  padding: 0 0.5rem;
}

.similarity-bar-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.similarity-label-text {
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #a88030;
  text-shadow: 0 0 8px rgba(201, 169, 97, 0.4);
}

.similarity-percent {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-accent-bright);
  text-shadow: 0 0 10px rgba(230, 200, 126, 0.7);
  letter-spacing: 0.05em;
}

.similarity-bar-track {
  position: relative;
  line-height: 0;
}

/* Dimmed full-width image acts as the empty track */
.similarity-bar-empty-img {
  width: 100%;
  display: block;
  filter: brightness(0.28) saturate(0.2);
}

/* Clipped overlay — reveals the real image from left to sim_pct */
.similarity-bar-fill-wrapper {
  position: absolute;
  inset: 0;
}

.similarity-bar-fill-img {
  width: 100%;
  display: block;
}

/* Outline overlay — sits on top of everything, preserves the gold ornament edges */
.similarity-bar-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* === OVERRIDE NOTES === */
.card-override-note {
  font-style: italic;
  color: var(--color-text-dim);
  font-size: 0.95rem;
  margin-top: 0.3rem;
  line-height: 1.4;
}

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

  .hero-subtitle {
    font-size: 1rem;
  }

  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
  }

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

  .card-name {
    font-size: 2rem;
  }

  .legal-content {
    padding: 1.5rem;
  }

  .legal-page h1 {
    font-size: 2rem;
  }
}
