/* =============================================================
   Token

   Ogni colore è dichiarato una volta sola con light-dark(chiaro, scuro):
   è `color-scheme` a decidere quale dei due vale. Di default segue il
   sistema; il pulsante del tema scrive data-theme sull'elemento root e
   forza uno dei due, in entrambe le direzioni.

   I contrasti testo/sfondo rispettano WCAG AA (>= 4.5) su tutti e tre i
   livelli di testo e in tutti e due i temi.
   ============================================================= */

:root {
  color-scheme: light dark;

  --bg: light-dark(#ffffff, #0c0d10);
  --bg-soft: light-dark(#f6f7f9, #121419);
  --surface: light-dark(#ffffff, #14161b);
  --surface-hover: light-dark(#fbfbfc, #1a1d24);

  --text: light-dark(#14161a, #f2f4f7); /* 18.1 : 17.6 */
  --text-muted: light-dark(#5f6672, #9aa3b2); /*  5.8 :  7.6 */
  --text-faint: light-dark(#6f7683, #7b8391); /*  4.6 :  5.1 */

  --border: light-dark(#e5e7eb, #23262e);
  --border-strong: light-dark(#d1d5db, #333844);

  --accent: light-dark(#2563eb, #4d8bff);
  --accent-contrast: light-dark(#ffffff, #06080d);
  --success: light-dark(#15803d, #4ade80);

  --shadow-sm: 0 1px 2px light-dark(rgb(16 20 28 / 0.05), rgb(0 0 0 / 0.4));
  --shadow-md: 0 8px 24px -8px light-dark(rgb(16 20 28 / 0.14), rgb(0 0 0 / 0.6));
  --shadow-lg: 0 32px 64px -24px light-dark(rgb(16 20 28 / 0.3), rgb(0 0 0 / 0.8));

  --glow: radial-gradient(
    60rem 32rem at 50% -12rem,
    light-dark(rgb(37 99 235 / 0.12), rgb(77 139 255 / 0.16)),
    transparent 70%
  );

  --radius: 14px;
  --radius-lg: 22px;
  --maxw: 62rem;
  --ease: cubic-bezier(0.22, 0.72, 0.28, 1);
}

/* Scelta manuale dell'utente: vince sulla preferenza di sistema */
:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

/* =============================================================
   Base
   ============================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0 1.25rem 4rem;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
}

.glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--glow);
  pointer-events: none;
}

.icon {
  width: 1.5rem;
  height: 1.5rem;
  flex: none;
}
.icon-sm {
  width: 1.125rem;
  height: 1.125rem;
}
.icon-xs {
  width: 0.875rem;
  height: 0.875rem;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* =============================================================
   Barra superiore
   ============================================================= */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.25rem 0;
}

.lang-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.lang-option {
  padding: 0.35rem 0.85rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.lang-option.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}

.icon-button:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* =============================================================
   Hero
   ============================================================= */

main {
  max-width: var(--maxw);
  margin: 0 auto;
}

.hero {
  padding: 2.5rem 0 3.5rem;
  text-align: center;
}

.avatar {
  display: grid;
  place-items: center;
  width: 5.5rem;
  height: 5.5rem;
  margin: 0 auto 1.5rem;
  border-radius: 999px;
  background: linear-gradient(140deg, var(--accent), #7c3aed);
  color: #fff;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-name {
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.hero-tagline {
  margin-top: 0.6rem;
  color: var(--accent);
  font-size: 1.0625rem;
  font-weight: 600;
}

.hero-bio {
  max-width: 34rem;
  margin: 1rem auto 0;
  color: var(--text-muted);
  text-wrap: pretty;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.fact {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.fact .icon {
  color: var(--text-faint);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 2rem;
}

/* =============================================================
   Bottoni
   ============================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.3rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.btn.is-copied {
  color: var(--success);
  border-color: var(--success);
}

/* =============================================================
   Gruppi di link
   ============================================================= */

.group + .group {
  margin-top: 3rem;
}

.group-head {
  margin-bottom: 1.1rem;
}

.group-head h2 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text);
}

.group-head p {
  color: var(--text-faint);
  font-size: 0.9rem;
}

.cards {
  display: grid;
  /* il min() evita che la larghezza minima della colonna (17rem) sfondi
     lo schermo sui dispositivi molto stretti, sotto i ~300px */
  grid-template-columns: repeat(auto-fit, minmax(min(17rem, 100%), 1fr));
  gap: 0.75rem;
}

.card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 1.15rem 1.15rem 1.15rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

/* Barra colorata del brand sul bordo sinistro */
.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--brand);
  opacity: 0;
}

.card:hover {
  background: var(--surface-hover);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--border));
  box-shadow: var(--shadow-md);
}

.card:hover::before {
  opacity: 1;
}

.card-featured {
  border-color: color-mix(in srgb, var(--brand) 35%, var(--border));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--brand) 7%, var(--surface)),
    var(--surface)
  );
}

.card-featured::before {
  opacity: 1;
}

.card-icon {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  flex: none;
  border-radius: 10px;
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: var(--brand);
}

.card-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

/* Stretched link: l'ancora copre tutta la card, ma il bottone QR
   resta cliccabile perché è sopra nello stacking context */
.card-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 650;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card-arrow {
  color: var(--text-faint);
  opacity: 0;
  transform: translate(-2px, 2px);
}

.card:hover .card-arrow,
.card-link:focus-visible .card-arrow {
  opacity: 1;
  transform: none;
}

.card-handle {
  color: var(--text-muted);
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-desc {
  margin-top: 0.35rem;
  color: var(--text-faint);
  font-size: 0.8125rem;
  line-height: 1.45;
}

.qr-button {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-soft);
  color: var(--text-faint);
  cursor: pointer;
}

.qr-button:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, transparent);
}

.qr-button:focus-visible {
  outline-color: var(--brand);
}

/* =============================================================
   Overlay QR
   ============================================================= */

.qr-dialog {
  width: min(24rem, calc(100vw - 2.5rem));
  padding: 2rem 1.75rem 1.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.qr-dialog::backdrop {
  background: rgb(8 10 14 / 0.6);
  backdrop-filter: blur(4px);
}

.qr-close {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}

.qr-close:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.qr-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.qr-url {
  margin-top: 0.15rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.qr-frame {
  margin: 1.25rem 0 0.9rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Sfondo sempre bianco: i QR hanno moduli chiari trasparenti,
     su fondo scuro non sarebbero leggibili dalla fotocamera */
  background: #fff;
}

.qr-frame img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 6px;
}

.qr-hint {
  color: var(--text-faint);
  font-size: 0.8125rem;
}

.qr-actions {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.qr-actions .btn {
  flex: 1;
}

/* =============================================================
   Footer
   ============================================================= */

.footer {
  max-width: var(--maxw);
  margin: 4rem auto 0;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-mail {
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 1px;
}

.footer-mail:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.footer-meta {
  margin-top: 0.75rem;
  color: var(--text-faint);
  font-size: 0.8125rem;
}

.footer-meta a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
}

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

/* =============================================================
   Movimento — solo se l'utente non ha chiesto di ridurlo
   ============================================================= */

@media (prefers-reduced-motion: no-preference) {
  .lang-option,
  .icon-button,
  .btn,
  .card,
  .card::before,
  .card-arrow,
  .qr-button,
  .footer-mail,
  .footer-meta a {
    transition:
      background-color 0.18s var(--ease),
      border-color 0.18s var(--ease),
      color 0.18s var(--ease),
      opacity 0.18s var(--ease),
      transform 0.18s var(--ease),
      box-shadow 0.18s var(--ease),
      filter 0.18s var(--ease);
  }

  .card:hover {
    transform: translateY(-2px);
  }

  .btn-primary:hover {
    transform: translateY(-1px);
  }

  .qr-dialog[open] {
    animation: pop 0.22s var(--ease);
  }

  .is-ready .hero > *,
  .is-ready .group {
    animation: rise 0.5s var(--ease) backwards;
  }

  .is-ready .hero-name {
    animation-delay: 0.04s;
  }
  .is-ready .hero-tagline {
    animation-delay: 0.08s;
  }
  .is-ready .hero-bio {
    animation-delay: 0.12s;
  }
  .is-ready .facts {
    animation-delay: 0.16s;
  }
  .is-ready .hero-actions {
    animation-delay: 0.2s;
  }
  .is-ready .group:nth-of-type(2) {
    animation-delay: 0.24s;
  }
  .is-ready .group:nth-of-type(3) {
    animation-delay: 0.3s;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
}

/* =============================================================
   Mobile
   ============================================================= */

@media (max-width: 30rem) {
  body {
    padding-inline: 1rem;
  }

  .hero {
    padding: 1.5rem 0 2.5rem;
  }

  .hero-actions .btn {
    flex: 1;
  }

  .card-desc {
    display: none;
  }
}

/* =============================================================
   Stampa — tutti i QR visibili, per usare la pagina come volantino
   ============================================================= */

@media print {
  .topbar,
  .glow,
  .hero-actions,
  .qr-dialog,
  .card-arrow {
    display: none !important;
  }

  body {
    padding: 0;
    background: #fff;
    color: #000;
  }

  .cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .card {
    break-inside: avoid;
    box-shadow: none;
  }

  /* Il QR di ogni card viene stampato accanto al link */
  .qr-button {
    width: 5rem;
    height: 5rem;
    border: 0;
    background: none;
  }

  .qr-button::after {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    background-image: var(--print-qr);
    background-size: contain;
    background-repeat: no-repeat;
  }

  .qr-button .icon {
    display: none;
  }
}
