:root {
  --ground: #23324D;
  --surface: #2F4266;
  --surface-hover: #38507C;
  --ink: #F4F1EA;
  --muted: #C8CFDC;
  --accent: #C9A24A;
  --accent-hover: #D6B15E;
  --on-accent: #1B2740;
  --gutter: 20px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
}
* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; background: var(--ground); }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100svh;
  -webkit-tap-highlight-color: transparent;
}
main {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: max(28px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right))
           0 max(var(--gutter), env(safe-area-inset-left));
  max-width: 560px;
  margin: 0 auto;
}
header { padding-top: 12px; }
h1 {
  font-size: clamp(2.5rem, 12vw, 3.75rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
  font-weight: 700;
}
.role { margin-top: 14px; color: var(--muted); font-size: 1.0625rem; }
.choose {
  margin-top: 44px;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ricerca: compare solo con molte lingue */
.search { margin-top: 16px; }
.search[hidden] { display: none; }
.search input {
  width: 100%;
  min-height: 56px;
  padding: 0 18px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem; /* 16px: iOS non ingrandisce la pagina */
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--muted); opacity: 1; }
.search input:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* le altre lingue: tre composizioni secondo quante sono */
.others { margin-top: 16px; display: grid; gap: 10px; }
.others:empty, .others[hidden] { display: none; }
.others.few  { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.others.some { grid-template-columns: repeat(2, 1fr); }
.others.many { grid-template-columns: 1fr; gap: 6px; }
.none { margin-top: 16px; color: var(--muted); }
.none[hidden] { display: none; }

.lang {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
  min-height: 56px;
  padding: 0 18px;
  font-size: 1.0625rem;
  font-weight: 600;
  touch-action: manipulation;
  transition: transform 140ms var(--ease), background-color 140ms var(--ease);
}
.lang[hidden] { display: none; }
.lang span { overflow-wrap: anywhere; }
.lang:active { transform: scale(0.98); }
.lang:focus-visible, .main-lang:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
@media (hover: hover) { .lang:hover { background: var(--surface-hover); } }

.flag { display: block; flex: none; width: 36px; height: 27px; object-fit: cover; }
.main-lang .flag { width: 72px; height: 54px; }

.spacer { flex: 1; min-height: 32px; }

/* il bottone grande resta in basso, sotto il pollice, anche con la lista lunga */
.dock {
  position: sticky;
  bottom: 0;
  background: var(--ground);
  padding: 12px 0 max(24px, env(safe-area-inset-bottom));
}
.main-lang {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  text-decoration: none;
  background: var(--accent);
  color: var(--on-accent);
  min-height: 112px;
  padding: 18px 22px;
  touch-action: manipulation;
  transition: transform 140ms var(--ease), background-color 140ms var(--ease);
}
.main-lang:active { transform: scale(0.98); }
@media (hover: hover) { .main-lang:hover { background: var(--accent-hover); } }
.main-lang .text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.main-lang .name { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; }
.main-lang .tag { font-size: 1.0625rem; font-weight: 500; }
.save {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  margin-top: 10px;
  padding: 0 18px;
  text-decoration: none;
  color: var(--ink);
  border: 2px solid var(--accent);
  font-size: 1.0625rem;
  font-weight: 600;
  touch-action: manipulation;
  transition: transform 140ms var(--ease), background-color 140ms var(--ease);
}
.save[hidden] { display: none; }
.save:active { transform: scale(0.98); }
.save:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
@media (hover: hover) { .save:hover { background: var(--surface); } }
.hint { margin-top: 14px; text-align: center; color: var(--muted); font-size: 0.9375rem; }

/* ingresso: animazione che parte da sola e poi si toglie di mezzo (non blocca il feedback al tocco).
   Senza JS tutto è già visibile; .settled arriva a fine ingresso, così la ricerca non rianima nulla. */
@keyframes rise  { from { opacity: 0; transform: translateY(16px); } }
@keyframes flagin { from { opacity: 0; transform: scale(0.88); } }
.js:not(.settled) .rise {
  animation: rise 420ms var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 70ms);
}
.js:not(.settled) .flag {
  animation: flagin 360ms var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 70ms + 160ms);
}
@media (prefers-reduced-motion: reduce) {
  .js:not(.settled) .rise, .js:not(.settled) .flag { animation: none; }
  .lang, .main-lang, .save { transition-duration: 1ms; }
  .lang:active, .main-lang:active, .save:active { transform: none; }
}

/* personalizzazione (impostata dal pannello): angoli, bandiere */
.lang, .main-lang, .save, .search input { border-radius: var(--radius, 0); }
.flag { border-radius: calc(var(--radius, 0px) / 5); }
.noflags .flag { display: none; }
