:root {
  color-scheme: light dark;

  --bg: var(--tg-theme-bg-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f4f5f7);
  --section-bg: var(--tg-theme-section-bg-color, #ffffff);

  --text: var(--tg-theme-text-color, #17191d);
  --subtitle: var(--tg-theme-subtitle-text-color, #6d7480);
  --hint: var(--tg-theme-hint-color, #7c8491);

  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2481cc);

  --border: rgba(127, 127, 127, 0.22);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.07);

  --radius-sm: 12px;
  --radius: 16px;
  --radius-lg: 20px;

  --content-width: 680px;
  --nav-height: 76px;
}

/* =========================================================
   RESET
========================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  scroll-behavior: smooth;
}

body {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 0 0 calc(var(--nav-height) + env(safe-area-inset-bottom));
  overflow-x: hidden;

  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;

  font-size: 16px;
  line-height: 1.5;

  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  -webkit-appearance: none;
  appearance: none;
}

svg {
  display: block;
}

.hidden {
  display: none !important;
}

/* =========================================================
   CONTENITORE PRINCIPALE
========================================================= */

main,
.main-content {
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
}

/* =========================================================
   GATE CODICE ACCESSO
========================================================= */

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;

  display: flex;
  align-items: center;
  justify-content: center;

  padding:
    calc(24px + env(safe-area-inset-top))
    24px
    calc(24px + env(safe-area-inset-bottom));

  background: var(--bg);
}

.gate-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 22px;

  text-align: center;

  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.gate-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 22px;

  background: linear-gradient(
    135deg,
    var(--accent),
    #7967ff
  );

  color: #ffffff;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -1px;

  box-shadow: 0 10px 25px rgba(36, 129, 204, 0.25);
}

.gate h1 {
  margin: 0 0 8px;

  color: var(--text);
  font-size: 23px;
  line-height: 1.25;
  font-weight: 750;
}

.gate p {
  margin: 0 0 22px;

  color: var(--hint);
  font-size: 14px;
  line-height: 1.45;
}

.code-input {
  width: 100%;
  height: 56px;
  padding: 12px 16px;

  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;

  background: var(--secondary-bg);
  color: var(--text);

  text-align: center;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: 7px;

  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

.code-input::placeholder {
  color: var(--hint);
  opacity: 0.7;
}

.code-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(
    in srgb,
    var(--accent) 18%,
    transparent
  );
}

.gate-error {
  min-height: 20px;
  margin-top: 10px;

  color: #e55353;
  font-size: 13px;
  font-weight: 500;
}

/* =========================================================
   HEADER
========================================================= */

header {
  position: sticky;
  top: 0;
  z-index: 20;

  width: 100%;
  padding:
    calc(12px + env(safe-area-inset-top))
    18px
    12px;

  background: var(--bg);
  border-bottom: 1px solid var(--border);

  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
}

.brand {
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;

  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-badge {
  flex: 0 0 42px;

  width: 42px;
  height: 42px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 13px;

  background: linear-gradient(
    135deg,
    var(--accent),
    #7967ff
  );

  color: #ffffff;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.brand-name {
  min-width: 0;

  color: var(--text);
  font-size: 18px;
  font-weight: 750;
  line-height: 1.2;

  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =========================================================
   TITOLO PAGINA
========================================================= */

.page-title {
  width: calc(100% - 32px);
  max-width: calc(var(--content-width) - 32px);

  margin: 24px auto 4px;

  color: var(--text);
  font-size: clamp(24px, 5vw, 30px);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.page-intro {
  width: calc(100% - 32px);
  max-width: calc(var(--content-width) - 32px);

  margin: 0 auto 20px;

  color: var(--hint);
  font-size: 15px;
  line-height: 1.55;
}

/* =========================================================
   RICERCA
========================================================= */

.search-wrap {
  width: 100%;
  max-width: var(--content-width);

  margin: 0 auto;
  padding: 0 16px 8px;
}

.search {
  width: 100%;
  height: 54px;
  padding: 0 17px;

  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;

  background: var(--secondary-bg);
  color: var(--text);

  font-size: 16px;

  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

.search::placeholder {
  color: var(--hint);
  opacity: 0.85;
}

.search:focus {
  background: var(--section-bg);
  border-color: var(--accent);

  box-shadow: 0 0 0 3px color-mix(
    in srgb,
    var(--accent) 15%,
    transparent
  );
}

/* =========================================================
   LISTA DOMANDE / ACCORDION
========================================================= */

.list {
  width: 100%;
  max-width: var(--content-width);

  margin: 0 auto;
  padding: 8px 16px 18px;

  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item {
  width: 100%;

  overflow: hidden;

  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);

  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.035);

  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}

.item.open {
  border-color: color-mix(
    in srgb,
    var(--accent) 38%,
    var(--border)
  );

  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.07);
}

/*
  Questa regola corregge la freccia gigante.
  La domanda occupa tutto lo spazio disponibile,
  mentre la freccia rimane sempre 20x20 px.
*/

.item-head {
  width: 100%;
  min-height: 62px;
  padding: 16px;

  display: grid;
  grid-template-columns: minmax(0, 1fr) 22px;
  align-items: center;
  gap: 14px;

  cursor: pointer;
  user-select: none;

  background: transparent;
  color: var(--text);

  font-size: 15.5px;
  font-weight: 650;
  line-height: 1.4;
}

.item-head:hover {
  background: color-mix(
    in srgb,
    var(--secondary-bg) 60%,
    transparent
  );
}

.item-head:active {
  background: var(--secondary-bg);
}

.item-head > span:first-child,
.item-head > div:first-child,
.item-head .question,
.item-head .title {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: normal;
}

/* Correzione dimensione icona freccia */

.item-head .chev {
  width: 20px !important;
  height: 20px !important;
  min-width: 20px;
  max-width: 20px;

  margin: 0;

  display: block;
  justify-self: end;

  color: var(--hint);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  flex: none;

  transform: rotate(0deg);
  transform-origin: center;
  transition:
    transform 0.22s ease,
    color 0.22s ease;
}

/* Nel caso .chev sia un contenitore con SVG interno */

.item-head .chev svg {
  width: 20px !important;
  height: 20px !important;
  display: block;
}

.item.open .item-head .chev {
  color: var(--accent);
  transform: rotate(90deg);
}

.item-body {
  max-height: 0;
  padding: 0 16px;

  overflow: hidden;

  opacity: 0;

  border-top: 1px solid transparent;

  transition:
    max-height 0.3s ease,
    padding 0.3s ease,
    opacity 0.2s ease,
    border-color 0.2s ease;
}

.item.open .item-body {
  max-height: 3000px;
  padding: 16px;

  opacity: 1;
  border-top-color: var(--border);
}

.item-body .text {
  margin: 0;

  color: var(--text);
  opacity: 0.86;

  font-size: 14.5px;
  line-height: 1.65;

  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.item-body p:first-child {
  margin-top: 0;
}

.item-body p:last-child {
  margin-bottom: 0;
}

.item-body a {
  color: var(--link);
  font-weight: 550;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.item-body a:hover {
  text-decoration: underline;
}

.rating {
  display: inline-flex;
  align-items: center;

  margin-top: 14px;
  padding: 5px 11px;

  border-radius: 999px;

  background: var(--secondary-bg);
  color: var(--hint);

  font-size: 12px;
  font-weight: 550;
}

.empty {
  width: 100%;
  padding: 46px 20px;

  text-align: center;
  color: var(--hint);
  font-size: 15px;
}

/* =========================================================
   CONTATTI
========================================================= */

.contact {
  width: calc(100% - 32px);
  max-width: calc(var(--content-width) - 32px);

  margin: 8px auto 18px;
  padding: 22px 18px;

  background: var(--section-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);

  text-align: center;
  box-shadow: var(--shadow);
}

.contact p {
  margin: 0 0 15px;

  color: var(--hint);
  font-size: 14.5px;
  line-height: 1.5;
}

.btn {
  min-height: 48px;
  padding: 12px 22px;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  border: 0;
  border-radius: 13px;

  background: var(--accent);
  color: var(--accent-text);

  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;

  cursor: pointer;

  box-shadow: 0 7px 18px color-mix(
    in srgb,
    var(--accent) 25%,
    transparent
  );

  transition:
    opacity 0.2s ease,
    transform 0.15s ease;
}

.btn:active {
  opacity: 0.85;
  transform: scale(0.98);
}

/* =========================================================
   FOOTER
========================================================= */

footer {
  width: 100%;
  max-width: var(--content-width);

  margin: 0 auto;
  padding: 22px 16px 18px;

  color: var(--hint);
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
}

/* =========================================================
   NAVIGAZIONE IN BASSO
========================================================= */

.nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;

  min-height: var(--nav-height);

  display: flex;
  align-items: stretch;

  padding:
    7px
    6px
    calc(7px + env(safe-area-inset-bottom));

  background: var(--section-bg);
  border-top: 1px solid var(--border);

  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.06);
}

.nav button {
  flex: 1;
  min-width: 0;
  min-height: 58px;
  padding: 6px 3px;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;

  border: 0;
  border-radius: 12px;

  background: transparent;
  color: var(--hint);

  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.2;

  cursor: pointer;

  transition:
    color 0.2s ease,
    background 0.2s ease;
}

.nav button:active {
  background: var(--secondary-bg);
}

.nav button.active {
  color: var(--accent);
  font-weight: 650;
}

.nav button svg {
  width: 23px !important;
  height: 23px !important;
  min-width: 23px;
  max-width: 23px;

  fill: none;
  stroke: currentColor;
}

/* =========================================================
   RESPONSIVE
========================================================= */

@media (max-width: 420px) {
  .page-title {
    margin-top: 20px;
    font-size: 25px;
  }

  .page-intro {
    font-size: 14.5px;
  }

  .item-head {
    min-height: 60px;
    padding: 15px;
    font-size: 15px;
  }

  .item.open .item-body {
    padding: 15px;
  }

  .brand-badge {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .brand-name {
    font-size: 17px;
  }
}

/* =========================================================
   TEMA SCURO DI RISERVA
   Utilizzato quando Telegram non fornisce le sue variabili
========================================================= */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #101217);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #191c23);
    --section-bg: var(--tg-theme-section-bg-color, #1c2028);

    --text: var(--tg-theme-text-color, #f1f3f7);
    --subtitle: var(--tg-theme-subtitle-text-color, #a5acb8);
    --hint: var(--tg-theme-hint-color, #8d95a3);

    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
  }
}

/* =========================================================
   ACCESSIBILITÀ
========================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}