:root {
  --match: #2f9e44;
  --match-text: #ffffff;
  --partial: #d68910;
  --partial-text: #ffffff;
  --no-match: #c0392b;
  --no-match-text: #ffffff;
  --bg: #120c08;
  --bg-alt: #1c140d;
  --card: #2a1e14;
  --card-border: #4a3420;
  --gold: #d9ae4e;
  --gold-bright: #f6dd8c;
  --gold-deep: #8a651f;
  --crimson: #8f1c22;
  --ember: #d9531f;
  --ink: #080503;
  --text: #f3e6d0;
  --muted: #b19b7c;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg) url("../img/background.jpg") center top / cover no-repeat fixed;
  color: var(--text);
  position: relative;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(8, 5, 3, 0.55), rgba(8, 5, 3, 0.72) 45%, rgba(8, 5, 3, 0.85) 100%),
    radial-gradient(circle at 15% 20%, rgba(143, 28, 34, 0.22), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(217, 174, 78, 0.13), transparent 45%),
    radial-gradient(circle at 50% 100%, rgba(217, 83, 31, 0.09), transparent 55%);
  z-index: 0;
}

header {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 2rem 1rem 0;
  background:
    radial-gradient(ellipse 620px 220px at 50% 35%, rgba(217, 83, 31, 0.14), transparent 70%),
    linear-gradient(180deg, rgba(143, 28, 34, 0.2), transparent);
}

.ornament-divider {
  position: relative;
  max-width: 620px;
  height: 14px;
  margin: 1.1rem auto 0;
}

.ornament-divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--gold-deep) 12%,
    var(--gold) 50%,
    var(--gold-deep) 88%,
    transparent
  );
}

.ornament-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 9px;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold-deep));
  transform: translate(-50%, -50%) rotate(45deg);
  box-shadow: 0 0 8px rgba(217, 174, 78, 0.55);
}

.language-bar {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  max-width: 1100px;
  margin: 0 auto 0.75rem;
  padding: 0 1rem;
}

.flag-button {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--card);
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.flag-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.flag-button:hover {
  transform: translateY(-1px);
}

.flag-button:focus-visible {
  outline: none;
  border-color: var(--gold);
}

.flag-button.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(217, 174, 78, 0.3);
}

.flag-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding-bottom: 1.25rem;
}

.banner-icon {
  height: 56px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 7px rgba(217, 83, 31, 0.45));
}

.banner-icon-wide {
  height: 44px;
}

header h1 {
  margin: 0;
  font-family: "Yuji Syuku", "Noto Serif", Georgia, serif;
  font-size: 3.1rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  line-height: 1;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold) 45%, var(--gold-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow:
    0 1px 0 rgba(8, 5, 3, 0.55),
    0 3px 6px rgba(8, 5, 3, 0.5),
    0 0 22px rgba(217, 83, 31, 0.3);
}

.subtitle {
  color: var(--muted);
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
}

main {
  position: relative;
  z-index: 2;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

#guess-form {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  align-items: flex-start;
}

.input-wrapper {
  position: relative;
  flex: 1;
}

#guess-input {
  width: 100%;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  box-shadow: inset 0 2px 4px rgba(8, 5, 3, 0.4);
}

#guess-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: inset 0 2px 4px rgba(8, 5, 3, 0.4), 0 0 0 3px rgba(217, 174, 78, 0.22);
}

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.suggestion-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.suggestion-main {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.suggestion-maps {
  font-size: 0.78rem;
  color: var(--muted);
  overflow-wrap: break-word;
}

.suggestion-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex-shrink: 0;
}

.suggestion-portrait {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--card-border);
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.2);
}

.suggestion-item:hover,
.suggestion-item.suggestion-active {
  background: rgba(217, 174, 78, 0.2);
}

.suggestion-empty {
  padding: 0.65rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

#guess-form button {
  padding: 0.8rem 1.75rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-radius: 8px;
  border: 1px solid var(--gold-deep);
  background: linear-gradient(180deg, var(--ember), var(--crimson) 65%, #4d0f13);
  color: #fdf0e6;
  text-shadow: 0 1px 2px rgba(8, 5, 3, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), inset 0 -3px 4px rgba(8, 5, 3, 0.35);
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}

#guess-form button:hover:not(:disabled) {
  filter: brightness(1.15);
}

#guess-form button:active:not(:disabled) {
  transform: translateY(1px);
}

#guess-form button:disabled,
#guess-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#win-banner {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold);
  margin: 0 0 1.25rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: rgba(217, 174, 78, 0.08);
  border: 1px solid rgba(217, 174, 78, 0.35);
}

.win-banner-celebrate {
  animation: win-banner-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: rgba(217, 174, 78, 0.14);
  border-color: rgba(217, 174, 78, 0.6);
  box-shadow: 0 0 26px rgba(217, 83, 31, 0.35), 0 0 0 1px rgba(217, 174, 78, 0.25) inset;
}

@keyframes win-banner-pop {
  0% {
    transform: scale(0.82);
    opacity: 0;
  }
  55% {
    transform: scale(1.06);
    opacity: 1;
  }
  75% {
    transform: scale(0.97);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes winner-row-glow {
  0%,
  100% {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 -3px 5px rgba(8, 5, 3, 0.3), 0 0 0 rgba(217, 174, 78, 0);
  }
  50% {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 -3px 5px rgba(8, 5, 3, 0.3), 0 0 18px 2px rgba(217, 174, 78, 0.55);
  }
}

.guess-row-winner .cell {
  animation: winner-row-glow 1.4s ease-in-out 2;
}

.win-celebration {
  position: fixed;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 100;
}

.win-particle {
  position: absolute;
  top: 0;
  left: 0;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  transform: translate(-50%, -50%);
  animation: win-particle-burst 1.2s cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
  box-shadow: 0 0 6px 1px rgba(217, 83, 31, 0.7);
}

@keyframes win-particle-burst {
  0% {
    transform: translate(-50%, -50%) translate(0, 0);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) translate(var(--dx), calc(var(--dy) + 70px));
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .win-banner-celebrate,
  .guess-row-winner .cell {
    animation: none;
  }
}

.hidden {
  display: none;
}

#results {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#results-body {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.results-header,
.guess-row {
  display: grid;
  grid-template-columns: 0.9fr 1.4fr 1.1fr 1.3fr 1.5fr 0.7fr 0.6fr 1.7fr 0.9fr;
  gap: 0.5rem;
}

.results-header {
  font-weight: 700;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}

.results-header > span {
  /* Without this, a grid item won't shrink below its text's natural width, so a long
     translated label (e.g. Italian "Immagine") overflows into the next column instead
     of wrapping within its own narrow track. */
  min-width: 0;
  overflow-wrap: break-word;
}

.guess-row {
  animation: drop-in 0.25s ease;
}

@keyframes drop-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cell {
  min-width: 0;
  padding: 0.7rem 0.5rem;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 -3px 5px rgba(8, 5, 3, 0.3);
  text-align: center;
  overflow-wrap: break-word;
  hyphens: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  font-size: 0.92rem;
}

.cell-portrait {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
}

.cell-portrait-clickable {
  cursor: pointer;
}

.cell-match {
  background: var(--match) !important;
  border-color: var(--match) !important;
  color: var(--match-text);
  font-weight: 700;
}

.cell-partial {
  background: var(--partial) !important;
  border-color: var(--partial) !important;
  color: var(--partial-text);
  font-weight: 700;
}

.cell-no-match {
  background: var(--no-match) !important;
  border-color: var(--no-match) !important;
  color: var(--no-match-text);
  font-weight: 700;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  max-width: 100%;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.25);
  overflow-wrap: break-word;
  hyphens: auto;
}

.pill-nowrap {
  white-space: nowrap;
  hyphens: none;
  overflow-wrap: normal;
}

.pill-match {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

.pill-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.cell-arrow-wrap {
  position: relative;
  overflow: hidden;
}

.cell-value {
  position: relative;
  z-index: 1;
}

.cell-arrow-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cell-arrow-shape {
  width: 52px;
  height: 44px;
  max-width: 70%;
  max-height: 70%;
  background: rgba(0, 0, 0, 0.45);
}

.cell-arrow-up .cell-arrow-shape {
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

.cell-arrow-down .cell-arrow-shape {
  clip-path: polygon(50% 100%, 0% 0%, 100% 0%);
}

.header-with-info {
  position: relative;
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  margin: 0;
  padding: 0.5rem 0.75rem;
  list-style: none;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  text-align: left;
  text-transform: none;
  font-weight: 400;
  letter-spacing: normal;
}

.popover li {
  padding: 0.2rem 0;
  font-size: 0.85rem;
  color: var(--text);
}

.popover-text {
  left: auto;
  right: 0;
  max-width: 220px;
}

.popover-text p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text);
}

.info-button {
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: none;
  flex-shrink: 0;
}

.info-button:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.pill-clickable {
  cursor: pointer;
}

.pill-clickable:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.4);
}

.popover-floating {
  position: fixed;
  max-width: min(500px, calc(100vw - 1.5rem));
}

.map-popover-image {
  display: block;
  border-radius: 6px;
}

.map-popover-image--map {
  width: 100%;
  height: min(60vh, 360px);
  object-fit: contain;
  background: var(--bg);
}

.map-popover-image--thumbnail {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(60vh, 450px);
  margin: 0 auto;
}

.monster-popover-image {
  display: block;
  width: min(320px, 60vw);
  height: min(320px, 60vw);
  object-fit: cover;
  border-radius: 8px;
  margin: 0 auto;
  background: var(--bg);
}

.map-popover-fallback {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.25rem 0;
}

footer {
  position: relative;
  z-index: 1;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 1.5rem 0 2rem;
}

.social-links {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.social-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.social-link img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.social-link:hover {
  transform: translateY(-1px);
  filter: brightness(1.15);
}

.footer-discord {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  opacity: 0.85;
}

@media (max-width: 700px) {
  .results-header {
    display: none;
  }

  .guess-row {
    grid-template-columns: 1fr 1fr;
  }
}
