:root {
  --card-width: clamp(320px, min(62vw, 820px), 820px);
  --card-image-width: calc((var(--card-width) - 50px) * 0.42857);
  --title-icon-width: clamp(80px, 10vw, 150px);
  --title-font-size: clamp(1.5em, 2vw, 2.5em);
  --lesson-title-font-size: clamp(0.6rem, 1.5vw, 1.2rem);
  --lesson-desc-font-size: clamp(0.45rem, 1.3vw, 1rem);
  --lesson-button-font-size: clamp(0.92rem, 0.76rem + 0.55vw, 1.18rem);
  --lesson-button-height: clamp(50px, 3.9vw, 60px);
  --action-circle-size: clamp(50px, 3.9vw, 60px);
  --carousel-side-padding: clamp(16px, 5vw, 80px);
}

/* Container specifico per le view Lezioni e Guide */
#lessons-view .container,
#guides-view .container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 1440px;
  min-height: 100vh;
  margin: 0 auto;
  overflow-y: auto;
  padding: 4vh clamp(16px, 2vw, 32px) 0;
}

/* Nuovo wrapper per il contenuto principale (titolo + carosello) */
.content-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  flex-grow: 1;
  width: 100%;
  min-height: 0;
}

/* Header */
.title-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 20px;
  margin: 0;
  text-align: center;
}
.title-container h1 {
  margin: 0;
  font-size: var(--title-font-size);
  color: #222222;
}
.title-icon {
  width: var(--title-icon-width);
  height: auto;
}

/* Pulsante "Torna indietro" */
.back-button {
  position: absolute;
  top: 20px;
  left: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 15px 20px;
  background-color: #c6421c;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}
.back-button:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 12px rgba(0,0,0,0.3);
}

/* Carosello */
.carousel-wrapper {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.carousel-wrapper::before,
.carousel-wrapper::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: clamp(28px, 5vw, 72px);
  pointer-events: none;
  z-index: 1050;
}

.carousel-wrapper::before {
  left: 0;
  background: linear-gradient(to right, #ffffff 0%, rgba(255,255,255,0) 100%);
}

.carousel-wrapper::after {
  right: 0;
  background: linear-gradient(to left, #ffffff 0%, rgba(255,255,255,0) 100%);
}
.lessons-carousel,
.guides-carousel {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  gap: 20px;
  overflow: visible;
  padding: 8px var(--carousel-side-padding);
  box-sizing: border-box;
  scroll-snap-type: none;
  touch-action: pan-x pinch-zoom;
  --edge-shift: 0px;
  --carousel-translate: 0px;
  transform: translate3d(calc(var(--carousel-translate) + var(--edge-shift)), 0, 0);
  transition: none;
  will-change: transform;
  overscroll-behavior-x: contain;
}

.lessons-carousel.is-touch-dragging,
.guides-carousel.is-touch-dragging {
  transition: none;
}

.lessons-carousel.is-animating,
.guides-carousel.is-animating {
  transition: transform 0.42s ease;
}

.lessons-carousel.is-touch-dragging .lesson-card,
.guides-carousel.is-touch-dragging .lesson-card {
  pointer-events: none;
  transition: none;
}

.lessons-carousel::before,
.lessons-carousel::after,
.guides-carousel::before,
.guides-carousel::after {
  content: "";
  flex: 0 0 max(0px, calc((100% - var(--card-width)) / 2));
}
/* Card (stile condiviso per Lezioni e Guide) */
.lesson-card {
  flex: 0 0 auto;
  display: flex;
  background-color: #ffffff;
  border: none;
  border-radius: 10px;
  width: var(--card-width);
  aspect-ratio: 7 / 3;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  padding: 25px;
  gap: 25px;
  transition: transform 0.35s ease, opacity 0.35s ease;
  transform-origin: center center;
  box-shadow: 0 18px 40px rgba(0,0,0,0.08);
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-x pinch-zoom;
  will-change: transform, opacity;
}

/* Immagine della card */
.lesson-preview {
  display: block;
  width: var(--card-image-width);
  height: var(--card-image-width);
  border-radius: 10px;
  object-fit: cover;
  -webkit-user-drag: none;
  touch-action: pan-x pinch-zoom;
}

/* Blocco informazioni */
.lesson-info {
  display: flex;
  flex-direction: column;
  padding: 10px;
  flex: 1;
  min-height: 0;
  max-width: 100%;
  overflow: visible;
  touch-action: pan-x pinch-zoom;
}

/* Titolo e descrizione */
.lesson-title {
  font-size: var(--lesson-title-font-size);
  font-weight: bold;
  margin-bottom: 0.5em;
  align-self: flex-start;
  user-select: none;
  -webkit-user-select: none;
}
.lesson-text-content {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  margin-bottom: 0.7em;
  font-size: var(--lesson-desc-font-size);
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.14) transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y pinch-zoom;
  overscroll-behavior-y: contain;
}
.lesson-text-content::-webkit-scrollbar {
  width: 4px;
}
.lesson-text-content::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.14);
  border-radius: 999px;
}
.lesson-text-content::-webkit-scrollbar-track {
  background: transparent;
}
.lesson-text-content::before,
.lesson-text-content::after {
  content: "";
  position: sticky;
  left: 0;
  display: block;
  width: 100%;
  height: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 1;
}
.lesson-text-content::before {
  top: 0;
  margin-bottom: -14px;
  background: linear-gradient(to bottom, rgba(255,255,255,0.8), rgba(255,255,255,0));
}
.lesson-text-content::after {
  bottom: 0;
  margin-top: -14px;
  background: linear-gradient(to top, rgba(255,255,255,0.8), rgba(255,255,255,0));
}
.lesson-text-content.show-top-fade::before,
.lesson-text-content.show-bottom-fade::after {
  opacity: 1;
}
.lesson-description {
  color: #333;
  line-height: 1.3em;
  white-space: normal;
}

/* Container pulsanti */
.lesson-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: auto;
  overflow: visible;
}
.actions-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
}

/* Pulsante "Guarda lezione" (o "Guida") */
.lesson-view-btn {
  background-color: #76b9c9;
  color: #16323a;
  border: none;
  border-radius: 6px;
  min-height: var(--lesson-button-height);
  padding: 0.65em 0.95em;
  cursor: pointer;
  font-size: var(--lesson-button-font-size);
  white-space: nowrap;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  text-align: center;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 3px rgba(0,0,0,0.2);
  flex: 1;
}
.lesson-view-btn i {
  margin-right: 0;
}
.lesson-view-btn:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.lesson-view-btn--asklea {
  background-color: #6601ff;
  color: #fff;
  text-decoration: none;
}

/* Pulsante "Download" */
.lesson-download-btn,
.custom-download-btn {
  background-color: #c6421c;
  color: #fff;
  text-decoration: none;
  border: none;
  border-radius: 50%;
  width: var(--action-circle-size);
  height: var(--action-circle-size);
  min-width: var(--action-circle-size);
  aspect-ratio: 1 / 1;
  cursor: pointer;
  font-size: 1.1em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 3px rgba(0,0,0,0.2);
}
.lesson-download-btn:hover,
.custom-download-btn:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.back-button:focus-visible,
.carousel-nav-button:focus-visible,
.lesson-view-btn:focus-visible,
.lesson-download-btn:focus-visible,
.custom-download-btn:focus-visible {
  outline: 3px solid #1b5fcc;
  outline-offset: 3px;
}

/* Pulsanti di navigazione del carosello */
.carousel-nav-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background-color: rgba(239,76,35,0.8);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 1em;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.5s ease, background-color 0.2s ease;
  z-index: 1100;
}

.carousel-nav-button i {
  margin: 0;
  display: block;
}

.carousel-nav-button:hover {
  background-color: rgba(239,76,35,1);
}

#carouselPrev { left: 20px; }
#carouselNext { right: 20px; }
#carouselPrevGuides { left: 20px; }
#carouselNextGuides { right: 20px; }

/* Layout Mobile */
@media (max-width: 600px) {
  .carousel-wrapper::before,
  .carousel-wrapper::after {
    width: 20px;
  }

  .title-container {
    height: 15vh;
    padding-top: 5vh;
  }
  .lessons-carousel,
  .guides-carousel {
    height: 75vh;
    gap: 16px;
    padding-inline: 20px;
  }
  .lesson-title {
    font-size: clamp(1rem, 3vw, 1.3rem);
  }
  .lesson-description {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  }
  .lesson-view-btn {
    min-height: clamp(52px, 8vw, 60px);
    font-size: clamp(0.98rem, 2.9vw, 1.08rem);
  }
  .lesson-download-btn,
  .custom-download-btn {
    width: clamp(52px, 13vw, 60px);
    height: clamp(52px, 13vw, 60px);
    min-width: clamp(52px, 13vw, 60px);
  }
  .lesson-card {
    flex-direction: column;
    width: min(80vw, 420px);
    max-width: 500px;
    padding: 15px;
    gap: 15px;
    aspect-ratio: unset;
  }
  .lesson-preview {
    width: 100%;
    height: auto;
    aspect-ratio: 1/1;
  }
  .lesson-info {
    width: 100%;
    margin-top: 15px;
    min-height: 0;
  }
  .lessons-carousel::before,
  .lessons-carousel::after,
  .guides-carousel::before,
  .guides-carousel::after {
    content: "";
    flex: 0 0 max(0px, calc((100% - min(80vw, 420px)) / 2));
  }
}

/* Nuovo override per ridurre la dimensione del logo nel titolo di lezioni e guide */
#lessons-view .title-container .title-icon,
#guides-view .title-container .title-icon {
  width: clamp(60px, 8vw, 100px);
}

/* Regola per nascondere le frecce del carosello quando il modal è aperto */
body.modal-open .carousel-nav-button {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
