:root {
  --color-bg: #fafaf8;
  --color-surface: #ffffff;
  --color-text: #1c1a17;
  --color-muted: #8a8480;
  --color-border: #e4e0da;

  --color-a: #ff5ca8;
  --color-a-soft: #fde8f2;
  --color-b: #3aa5d8;
  --color-b-soft: #e8ecff;
  --color-c: #7a7470;
  --color-c-soft: #eeeceb;
  --color-c-dark: #4a4744;

  --color-accent: #4fae74;
  --color-accent-soft: #e4f4ea;

  --radius: 32px;
  --shadow: 0 4px 20px rgba(28, 26, 23, 0.08);

  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--color-text);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;   /* never scroll sideways on any phone */
}

body {
  margin: 0;
  background: var(--color-bg);
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100%;
}

/* ── Header ─────────────────────────────────────────── */

header {
  max-width: 900px;
  margin: 0 auto;
  padding: 4.5rem 2rem 3rem;
  animation: fade-up 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem 3.5rem;
  flex-wrap: wrap;
}

/* ── Hero illustration (flat globe + bike) ───────────── */

.scene {
  flex: 0 0 auto;
  width: min(380px, 46vw);
  margin-left: auto;
  transform: translateY(24px);
}

.scene svg {
  display: block;
  width: 100%;
  height: auto;        /* self-size from the viewBox ratio — no reliance on aspect-ratio support */
  overflow: visible;
}

/* Still illustration — the only motion is the two flags changing country */
.glow {
  transform-box: fill-box;
  transform-origin: center;
}

.flag-cloth {
  transform-box: fill-box;
  transform-origin: 0% 50%;
  transform: skewX(-7deg) scaleX(0.98);
}

.ff {
  opacity: 0;
  animation: flag-cycle 24s linear infinite;
}

/* rear rider's flag */
.flag-a .ff:nth-child(1) { animation-delay: 0s; }
.flag-a .ff:nth-child(2) { animation-delay: -3s; }
.flag-a .ff:nth-child(3) { animation-delay: -6s; }
.flag-a .ff:nth-child(4) { animation-delay: -9s; }
.flag-a .ff:nth-child(5) { animation-delay: -12s; }
.flag-a .ff:nth-child(6) { animation-delay: -15s; }
.flag-a .ff:nth-child(7) { animation-delay: -18s; }
.flag-a .ff:nth-child(8) { animation-delay: -21s; }

/* front rider's flag — offset ~half a cycle (and half a slot), so it shows a
   different country AND changes at a different moment than the rear flag */
.flag-b .ff:nth-child(1) { animation-delay: -13.5s; }
.flag-b .ff:nth-child(2) { animation-delay: -16.5s; }
.flag-b .ff:nth-child(3) { animation-delay: -19.5s; }
.flag-b .ff:nth-child(4) { animation-delay: -22.5s; }
.flag-b .ff:nth-child(5) { animation-delay: -25.5s; }
.flag-b .ff:nth-child(6) { animation-delay: -28.5s; }
.flag-b .ff:nth-child(7) { animation-delay: -31.5s; }
.flag-b .ff:nth-child(8) { animation-delay: -34.5s; }

@keyframes flag-cycle {
  0%     { opacity: 0; }
  1.5%   { opacity: 1; }
  11%    { opacity: 1; }
  12.5%  { opacity: 0; }
  100%   { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ff { animation: none; }
  .flag-a .ff:nth-child(1) { opacity: 1; }
  .flag-b .ff:nth-child(5) { opacity: 1; }
}

header h1 {
  margin: 0;
  font-family: 'Caveat', cursive;
  font-weight: 700;
  font-size: clamp(4rem, 10vw, 8rem);
  line-height: 0.95;
  letter-spacing: -0.01em;
  color: #3e9e61;
}

header h1 em {
  font-style: italic;
  color: #3e9e61;
  display: block;
}

.tagline {
  margin: 1.75rem 0 0;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  color: var(--color-muted);
  line-height: 1.6;
  max-width: 38rem;
}

/* ── Main / Form ─────────────────────────────────────── */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 0 5rem;
}

#search-form {
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  padding: 2rem 2rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  animation: fade-up 0.7s 0.12s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  /* keep the form (and its open dropdown panels) above the result cards,
     which each create their own stacking context via card-pop's transform */
  position: relative;
  z-index: 20;
}

.form-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  flex: 1 1 200px;
  gap: 0.4rem;
}

.field-gender {
  flex: 0 1 150px;
}

.field label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.form-fields .field label { color: var(--color-accent); }

select {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.8rem 2.75rem 0.8rem 1rem;
  border-radius: 12px;
  border: 2px solid var(--color-border);
  background-color: var(--color-surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 18 18'%3E%3Cpath d='M4 7l5 5 5-5' stroke='%231c1a17' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 18px;
  color: var(--color-text);
  appearance: none;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:hover {
  border-color: var(--color-accent);
}

select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

/* ── Custom Dropdown ─────────────────────────────────────── */

.dropdown {
  position: relative;
  width: 100%;
}

.dropdown-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dropdown-trigger:focus-visible {
  outline: none;
}

/* Open dropdown outline uses the shared accent color */
.form-fields .dropdown-trigger.open {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.dropdown-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-chevron {
  flex-shrink: 0;
  color: var(--color-muted);
  transition: transform 0.2s ease;
}

.dropdown-trigger.open .dropdown-chevron {
  transform: rotate(180deg);
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-radius: 16px;
  border: 2px solid var(--color-border);
  box-shadow: 0 12px 40px rgba(28, 26, 23, 0.13);
  z-index: 200;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.dropdown-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.dropdown-search {
  padding: 0.6rem 0.6rem 0.4rem;
  border-bottom: 1px solid var(--color-border);
}

.dropdown-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  font-family: 'Nunito', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s ease;
}

.dropdown-search input:focus { border-color: var(--color-accent); }

.dropdown-search input::placeholder {
  color: var(--color-muted);
  font-weight: 400;
}

.dropdown-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem 0;
  max-height: 260px;
  overflow-y: auto;
}

.dropdown-list::-webkit-scrollbar { width: 4px; }
.dropdown-list::-webkit-scrollbar-track { background: transparent; }
.dropdown-list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }

.dropdown-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  transition: background 0.1s ease, color 0.1s ease;
  border-radius: 0;
}

.dropdown-option:hover,
.dropdown-option.highlighted {
  background: rgba(0, 0, 0, 0.05);
  color: var(--color-text);
}

.dropdown-option.selected {
  color: var(--color-accent);
}

.dropdown-check {
  font-size: 0.75rem;
  color: var(--color-accent);
  width: 14px;
  flex-shrink: 0;
  opacity: 0;
}

.dropdown-option.selected .dropdown-check {
  opacity: 1;
}

.dropdown-label {
  flex: 1;
}

/* languages with no crossover match for the other selected language */
.dropdown-option.disabled {
  color: var(--color-muted);
  opacity: 0.5;
  cursor: not-allowed;
}

.dropdown-option.disabled:hover,
.dropdown-option.disabled.highlighted {
  background: transparent;
}

.dropdown-nomatch {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-muted);
  flex-shrink: 0;
}

.form-submit {
  display: flex;
  align-items: center;
}

.form-submit button {
  background: #f78bb0;
  color: #1c1a17;
  border: none;
  cursor: pointer;
  padding: 0.8rem 2.75rem;
  font-family: 'Nunito', sans-serif;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.01em;
  border-radius: 999px;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.2s ease;
}

.form-submit button:hover {
  background: #ec6f9e;
  transform: scale(1.07);
}

.form-submit button:focus {
  outline: none;
}

.form-submit button:active {
  transform: scale(0.95);
}

/* ── Status + Results ────────────────────────────────── */

#status {
  margin: 2.5rem 2rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-muted);
}

#results {
  list-style: none;
  padding: 0 2rem;
  margin: 1rem 0 0;
  display: grid;
  gap: 1rem;
  position: relative;
  z-index: 1;
}

/* ── Keyframes ───────────────────────────────────────── */

@keyframes card-pop {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Cards ───────────────────────────────────────────── */

.result-card {
  border: none;
  border-radius: 40px;
  box-shadow: none;
  padding: 2rem 2.5rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.18s ease-out;
  animation: card-pop 0.3s ease-out both;
}

#results > .result-card:nth-child(odd):hover  { transform: scale(1.02) rotate(-0.4deg); }
#results > .result-card:nth-child(even):hover { transform: scale(1.02) rotate(0.4deg); }

/* Cycling card colors — warm, playful, daylight */
#results > .result-card:nth-child(6n+1) { background: #ffb347; }
#results > .result-card:nth-child(6n+2) { background: #87d7f5; }
#results > .result-card:nth-child(6n+3) { background: #98e0b0; }
#results > .result-card:nth-child(6n+4) { background: #ffaec0; }
#results > .result-card:nth-child(6n+5) { background: #c4a7e7; }
#results > .result-card:nth-child(6n+6) { background: #ffd166; }

.card-header {
  background: transparent;
  margin: 0 0 1.25rem;
  padding: 0;
}

.result-card h2 {
  margin: 0 0 0.4rem;
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  font-size: 2.2rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: #0a0a0a;
}

.gender-badge,
.gender-badge--m,
.gender-badge--mandf,
.card-header .gender-badge,
.card-header .gender-badge--m,
.card-header .gender-badge--mandf {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.25rem 0.8rem;
  background: rgba(0, 0, 0, 0.15);
  color: rgba(0, 0, 0, 0.6);
}

/* ── Language Blocks ─────────────────────────────────── */

.language-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0;
}

.language-pair.single {
  grid-template-columns: 1fr;
}

.language-block,
.language-block.lang-a,
.language-block.lang-b {
  padding: 0.75rem 1rem;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.13);
}

.language-block strong,
.language-block.lang-a strong,
.language-block.lang-b strong {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(0, 0, 0, 0.5);
}

.language-block .spelling {
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  display: block;
  margin-bottom: 0.2rem;
  color: #0a0a0a;
  letter-spacing: -0.01em;
}

.language-block p {
  margin: 0;
  color: rgba(0, 0, 0, 0.58);
  line-height: 1.45;
  font-size: 0.82rem;
}

/* ── Also Valid In ───────────────────────────────────── */

.other-languages {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(0, 0, 0, 0.15);
}

.other-languages summary {
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-style: normal;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.65);
  font-size: 0.88rem;
  list-style: none;
}

.other-languages summary::-webkit-details-marker { display: none; }

.other-languages summary::before {
  content: '+ ';
  font-style: normal;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.8rem;
}

.other-languages[open] > summary::before {
  content: '− ';
}

.other-languages summary:hover {
  color: rgba(0, 0, 0, 0.85);
}

.other-languages ul {
  margin: 0.75rem 0 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 0.4rem;
}

.other-languages li {
  font-size: 0.85rem;
  color: rgba(0, 0, 0, 0.65);
  line-height: 1.5;
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.1);
}

.other-languages li strong {
  color: rgba(0, 0, 0, 0.8);
  font-weight: 600;
}

.other-meaning {
  color: rgba(0, 0, 0, 0.55);
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 760px) {
  /* stack the title over a centered illustration */
  .brand {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .scene {
    order: -1;                 /* illustration above the title reads nicely on phones */
    transform: none;           /* drop the desktop vertical nudge (it overlapped the tagline) */
    margin: 0 auto;
    width: min(300px, 72%);
  }

  header h1 {
    font-size: clamp(3.5rem, 20vw, 6rem);
  }
}

@media (max-width: 600px) {
  header {
    padding: 2.5rem 1.5rem 2rem;
  }

  .tagline {
    margin-top: 1.25rem;
  }

  #search-form {
    padding: 1.5rem 1.5rem 1.25rem;
  }

  #status, #results {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  .form-fields {
    flex-direction: column;
    gap: 1.1rem;
  }

  /* in a column, flex-basis is the *vertical* size — reset it so each field
     hugs its content instead of stretching to 200px tall (the weird spacing) */
  .field,
  .field-gender {
    flex: 0 0 auto;
  }

  /* full-width, easy-to-tap CTA */
  .form-submit button {
    width: 100%;
  }

  .language-pair {
    grid-template-columns: 1fr;
  }

  .result-card {
    padding: 1.5rem 1.5rem;
    border-radius: 28px;
  }

  .result-card h2 {
    font-size: 1.8rem;
  }
}
