/* ====== PWA FOUC PREVENTION & NATIVE LOADING BAR HIDE ====== */
/* Hide native browser loading indicators in PWA standalone mode */
@media all and (display-mode: standalone) {
  /* Hide any native loading progress bars */
  ::-webkit-progress-bar,
  ::-webkit-progress-value,
  ::-moz-progress-bar,
  progress {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
  }
}

/* Prevent Flash of Unstyled Content (FOUC) */
/* All form elements get immediate styling to prevent default browser appearance */
select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
button,
textarea {
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  background-color: transparent;
  border: none;
  outline: none;
}

/* Ensure select elements never show default browser styling */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 32px !important;
}

/* ====== CSS VARIABLES FOR DYNAMIC LAYOUT ====== */
:root{
  /* === Dynamic viewport + safe-area GLOBALI === */
  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* default fallback (verrà sovrascritto da viewport.js) */
  --dvh-px: 100dvh;
  
  --header-height: calc(calc(var(--dvh-px) * 0.13) + var(--safe-top));

  /* Height of the bar itself */
  --bottom-button-height: calc(var(--dvh-px) * 0.08);
  
  /* Dynamic bottom sheet height for scroll offset */
  --sheet-visible: 0px;

  /* Bar + safe area combined */
  --bottom-button-total: calc(var(--bottom-button-height) + var(--safe-bottom));

  /* Use svh first on iOS, then svh, then svh as fallback */
  --main-app-height-svh: calc(var(--dvh-px) - var(--header-height) - var(--bottom-button-total));
  --main-app-height-svh: calc(var(--dvh-px) - var(--header-height) - var(--bottom-button-total));
  --main-app-height:     calc(var(--dvh-px)  - var(--header-height) - var(--bottom-button-total));

  /* ====== MONOCHROME COLOR PALETTE (USER PROVIDED) ====== */
  /* Exact colors from user palette */
  --color-white: #FFFFFF;
  --color-black: #000000;
  --color-light-grey: #B0B0B0;
  --color-medium-grey: #7D7D7D;
  --color-dark-grey: #4D4D4D;
  
  /* Semantic aliases for commonly used colors */
  --color-bg-dark: #000000;
  --color-text-primary: #FFFFFF;
  --color-text-secondary: #B0B0B0;
  
  /* Gradients using palette */
  --gradient-dark: linear-gradient(135deg, #000000 0%, #000000 100%);
  --gradient-card: linear-gradient(135deg, #000000 0%, #000000 100%);
  --gradient-overlay: linear-gradient(to top, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.85) 80%, transparent 100%);
  
  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.35);
  --shadow-xl: 0 12px 48px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 20px rgba(255, 255, 255, 0.1);
  
  /* Borders */
  --border-subtle: 1px solid rgba(255, 255, 255, 0.08);

  /* Login layout helpers */
  --login-gap: clamp(14px, calc(var(--dvh-px) * 0.036), 26px);
  --login-card-max-height: clamp(208px, calc(var(--dvh-px) * 0.34), 328px);
  --training-selector-padding-y: clamp(10px, calc(var(--dvh-px) * 0.028), 18px);
  --training-selector-min-height: clamp(150px, calc(var(--dvh-px) * 0.32), 310px);
  --training-image-max-height: clamp(220px, calc(var(--dvh-px) * 0.42), 360px);
  --login-screen-height: min(
    calc(var(--dvh-px) - var(--header-height) - var(--safe-bottom)),
    calc(var(--dvh-px) - var(--header-height) - var(--safe-bottom)),
    calc(var(--dvh-px) - var(--header-height) - var(--safe-bottom))
  );
  --login-screen-height-js: var(--login-screen-height);
  --visible-svh: var(--dvh-px);
  --visible-vw: 100vw;
  --main-app-visible-height: var(--main-app-height-svh);
  --training-selector-js-height: var(--training-image-max-height);
  --bottom-sheet-max-height: clamp(420px, calc(var(--dvh-px) * 0.72), 560px);
  --bottom-sheet-padding-y: clamp(18px, calc(var(--dvh-px) * 0.035), 26px);
  --bottom-sheet-side-padding: clamp(18px, 4vw, 24px);
  --bottom-sheet-gap: clamp(12px, calc(var(--dvh-px) * 0.025), 18px);
  --bottom-sheet-carousel-height: clamp(160px, calc(var(--bottom-sheet-max-height) * 0.45), 280px);
}


/* ====== RESET BASE ====== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* CRITICAL: Force enable CSS animations on mobile */
*, *::before, *::after {
  animation-play-state: running !important;
  -webkit-animation-play-state: running !important;
}

/* === Layout di base: niente contenuti dietro le barre === */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* CRITICAL: No scroll on login page */
  width: 100%;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: none;
}

body {
  /* Usa SEMPRE l'altezza visibile reale */
  min-height: var(--dvh-px);
  background: var(--color-bg-dark);
  overscroll-behavior-y: contain;
}

/* Wrapper principale dell'app */
.app {
  min-height: var(--dvh-px);
  display: flex;
  flex-direction: column;
}

/* Header e Footer rispettano le safe-area */
.header, header {
  padding-top: max(12px, var(--safe-top));
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
}

.footer, .bottom-bar {
  padding-bottom: max(12px, var(--safe-bottom));
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
}

/* Se usi sezioni "full screen" (login, hero, ecc.) */
.screen, .full-height, .vh-100, .page {
  min-height: var(--dvh-px);          /* invece di 100vh */
  padding-bottom: var(--safe-bottom);  /* evita sovrapposizioni con la barra */
}

/* CRITICAL: Force dark background on html too (Safari iOS) */
html {
  background: var(--gradient-dark);
  background-color: var(--color-bg-dark) !important;
}

/* ====== iOS SAFARI BACKGROUND FIX ====== */

/* CRITICAL: Safari iOS fix for white background issue */
/* Create a fixed background layer that stays in place */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: var(--dvh-px);
  height: var(--dvh-px);
  height: var(--dvh-px);
  background: var(--gradient-dark);
  background-color: var(--color-bg-dark);
  z-index: -1; /* Behind all content */
  pointer-events: none; /* Don't interfere with clicks */
  /* Safari specific */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* Ensure all main sections have transparent/inherit background to see through */
#login-screen,
#main-app,
#setup-screen {
  position: relative;
  z-index: 1;
}


body {
  font-family: 'Staatliches', sans-serif;
  background: var(--gradient-dark);
  background-color: var(--color-bg-dark) !important;
  color: var(--color-white);

  /* CRITICAL: Ensure background fills everything */
  min-height: var(--dvh-px);
  min-height: var(--dvh-px);
  min-height: -webkit-fill-available;

  /* Safari iOS specific */
  -webkit-background-size: cover;
  background-size: cover;

}


header {
  text-align: center;
  /* Include safe area in padding */
  padding: env(safe-area-inset-top, 0px) 0 0 0;
  margin: 0 !important;
  /* CRITICAL: Fixed height includes safe area now */

  flex-shrink: 0;
  display: flex;
  flex-direction: column; /* Changed to column so logo can fill with padding */


  box-sizing: border-box;
  /* Ensure no extra space */
  overflow: visible; /* Changed to visible so logo can extend into safe area */

  align-items: center;       /* center horizontally */
  justify-content: center;   /* center vertically */
  height: var(--header-height);
  padding-top: env(safe-area-inset-top, 0px);
}

header img {
  /* Fill available space after safe area */
  height: auto; 
  max-height: none;
  width: auto;
  max-width: 70%;
  border-radius: 0;
  object-fit: contain;
  display: block;
  margin: 0 !important;
  padding: 0 !important;
}

header audio {
  /* Hide audio player completely */
  display: none !important;
  visibility: hidden;
}

header h1 {
  /* Hide h1 if present */
  display: none !important;
}

header h1 {
  margin-top: 2%;
  /* Font size relative to parent height */
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  color: #fff;
}

main {
  max-width: min(600px, 95vw);
  margin: 0 auto;
  padding-inline: 20px; /* horizontal padding only - don't override vertical */
  padding-top: 0;
  /* CRITICAL: Explicit background for iOS */
  background: transparent;
  position: relative;
  z-index: 1;
}

/* Expand main container when the login screen is visible so content can breathe */
body:has(#login-screen:not([style*="display: none"])) main {
  max-width: min(1100px, 94vw);
  width: 100%;
  min-height: min(
    var(--login-screen-height-js, var(--dvh-px)),
    calc(var(--dvh-px) - var(--header-height)),
    calc(var(--dvh-px) - var(--header-height)),
    calc(var(--dvh-px) - var(--header-height))
  );
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: clamp(16px, calc(var(--dvh-px) * 0.04), 32px);
  padding-top: clamp(12px, calc(var(--dvh-px) * 0.05), 28px);
  padding-inline: clamp(20px, 7vw, 72px);
  box-sizing: border-box;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}


/* Make space for Safari’s bottom bar / home indicator on login */
body:has(#login-screen:not([style*="display: none"])) main {
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px)) !important;
}

/* Fallback globale per la safe area inferiore - funziona su tutte le pagine */
main {
  padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)) !important;
}


/* ====== LOGIN SCREEN - FIT BOX WITH CONTAINER QUERIES ====== */
/* 
  LAYOUT STRUCTURE:
  - Uses container queries (cqh) for precise viewport-relative sizing
  - No scrolling: all elements bounded within the visual viewport
  - Each block gets a percentage allocation of container height
  - Responsive but constrained to never overflow
*/
/* ====== LOGIN SCREEN - FIT BOX WITH CONTAINER QUERIES ====== */
#login-screen {
  /* Take only the usable visual viewport driven by JS */
  block-size: var(--login-screen-height-js, var(--login-screen-height));
  max-height: var(--login-screen-height-js, var(--login-screen-height));
  overflow: auto; /* Allow graceful scroll if needed */
  padding: 12px 16px max(16px, env(safe-area-inset-bottom, 0px));

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(8px, 2.2cqh, 18px);

  container-type: size;
  width: 100%;
  max-width: min(1100px, 100%);
  margin: 0 auto;
  background: transparent;
  position: relative;
  box-sizing: border-box;

  --fs: clamp(12px, 1.8cqh, 16px);
  font-size: var(--fs);
}


/* HEIGHT BUDGET ALLOCATION - child elements bounded by cqh */
/* Helper text: "Tocca per selezionare..." */
.selector-instruction {
  max-block-size: 8cqh;
  font-size: clamp(12px, 1.8cqh, 16px);
  flex-shrink: 0;
}

/* Training selector container */
.training-selector-container {
  /* ✅ FIX: Rimosso max-block-size per permettere al wrapper quadrato di espandersi */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.5cqh, 12px);
  flex-shrink: 0;
}

/* The square hero / focus image card */
.training-image-wrapper {
  position: relative;
  width: min(80vw, 480px); /* ✅ Ridotto: 80% viewport, max 480px */
  height: min(80vw, 480px); /* ✅ Ridotto: 80% viewport, max 480px */
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: clamp(12px, 2vw, 18px);
  margin: 0 auto; /* ✅ CENTRA ORIZZONTALMENTE */
}

.training-base-image {
  width: 100%;
  height: 100%;
  object-fit: contain; /* ⚠️ TEST: Mostra TUTTA l'immagine per verificare se è quadrata */
  display: block; /* ✅ FIX: Rimuove spazio sotto l'immagine */
  object-position: center; /* ✅ Centrata perché wrapper e immagine sono entrambi quadrati */
  background: #000; /* Per vedere eventuali spazi vuoti */
}

/* Login card (title + inputs + button) */
.login-card {
  max-inline-size: min(92vi, 560px);
  max-block-size: 38cqh; /* Bounded slice for the form */
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 1.5cqh, 12px);
  flex-shrink: 0;
}

/* Inputs/buttons scale but are capped */
.login-card input,
.login-card button {
  block-size: clamp(36px, 6cqh, 48px);
  font-size: clamp(12px, 1.7cqh, 16px);
}

.login-card h3 {
  font-size: clamp(16px, 2.5cqh, 24px);
  margin: 0;
}

#login-screen > .training-selector-container {
  grid-row: 1;
  grid-column: 1;
  width: 100%;
  max-width: min(520px, 100%);
  align-self: stretch;
  height: 100%;
}

#login-screen > .login-card {
  grid-row: 2;
  grid-column: 1;
  width: min(100%, 420px);
  justify-self: center;
  max-height: var(--login-card-max-height);
}

#training-bottom-sheet {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
}

/*
  LOGIN CARD STYLING:
  - Takes 30-35% of available screen height
  - Width responsive to screen size
  - All internal elements scale proportionally
*/
.login-card {
  background: var(--gradient-card);
  backdrop-filter: blur(20px);
  border: var(--border-medium);
  border-radius: clamp(16px, 3vw, 24px);
  padding: clamp(18px, calc(var(--dvh-px) * 0.05), 24px) clamp(20px, 3.5vw, 28px);
  box-shadow: var(--shadow-xl);
  text-align: center;
  width: min(90vw, 400px); /* Expanded width for better balance */
  transition: all 0.3s ease;
  margin: 0;
  /* FLEX SIZING: Takes about 30-35% of available height */
  flex: 0 0 auto; /* Don't grow, don't shrink, auto height */
  min-height: fit-content;
  max-height: var(--login-card-max-height);
  display: flex;
  flex-direction: column;
  gap: clamp(12px, calc(var(--dvh-px) * 0.08), 16px); /* Consistent spacing between elements */
  justify-content: center;
  overflow: hidden;
}

.login-card:hover {
  box-shadow: var(--shadow-xl), var(--shadow-glow);
  border-color: rgba(255, 255, 255, 0.2);
}

/*
  LOGIN CARD TITLE:
  - Responsive font sizing that works on all screens
  - Using clamp() for smooth scaling
*/
.login-card h3 {
  font-size: clamp(18px, 4vw, 24px); /* Smooth scaling from 18px to 24px */
  color: var(--color-light-grey);
  margin: 0;
  font-weight: 500;
  letter-spacing: 0.03em;
  line-height: 1.2;
  flex-shrink: 0;
}

/*
  LOGIN INPUTS:
  - Comfortable touch targets (min height 48px)
  - Responsive sizing with good readability
*/
.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  padding: clamp(12px, calc(var(--dvh-px) * 0.08), 16px) clamp(14px, 2.5vw, 18px);
  margin: 0;
  border: var(--border-subtle);
  border-radius: clamp(10px, 1.8vw, 14px);
  background: rgba(255,255,255,0.05);
  color: var(--color-white);
  font-size: clamp(14px, 3.5vw, 18px); /* Readable font size */
  outline: none;
  transition: all 0.2s ease;
  font-family: 'Staatliches', sans-serif;
  flex-shrink: 0;
  min-height: 48px; /* Touch-friendly minimum */
  box-sizing: border-box;
}

.login-card input::placeholder {
  color: var(--color-light-grey);
  opacity: 0.7;
}

.login-card input:focus {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 0 0.5vw rgba(255,255,255,0.08);
}

/*
  LOGIN BUTTON:
  - Prominent and easy to tap (min height 52px)
  - Responsive sizing that works across devices
*/
.login-card button {
  width: 100%;
  padding: clamp(14px, calc(var(--dvh-px) * 0.02), 18px) clamp(16px, 2.5vw, 20px);
  background: var(--gradient-button);
  color: var(--color-black);
  font-size: clamp(15px, 3.8vw, 19px); /* Clear, readable button text */
  font-weight: 800;
  border: none;
  border-radius: clamp(10px, 1.8vw, 14px);
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  box-shadow: var(--shadow-md);
  margin: 0;
  flex-shrink: 0;
  min-height: 52px; /* Touch-friendly minimum */
  box-sizing: border-box;
}

.login-card button:hover {
  background: var(--gradient-button-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.login-card button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Mobile optimization - Fine-tuning for very small screens */
@media (max-width: 480px) {
  /* Better spacing on small screens */
  #login-screen {
    grid-template-rows: minmax(0, auto) auto;
    align-content: flex-start;
    row-gap: clamp(calc(var(--dvh-px) * 0.02), calc(var(--dvh-px) * 0.05), calc(var(--dvh-px) * 0.03));
    padding-top: calc(var(--dvh-px) * 0.02);
    padding-left: clamp(16px, 4vw, 24px);  /* Better horizontal spacing */
    padding-right: clamp(16px, 4vw, 24px); /* Better horizontal spacing */
    padding-bottom: max(env(safe-area-inset-bottom, 0px), clamp(12px, calc(var(--dvh-px) * 0.04), 20px));
  }

  .training-selector-container {
    justify-content: center;
    gap: clamp(14px, calc(var(--dvh-px) * 0.05), 22px);
    max-width: min(78vw, 380px);
  }
  
  /* Ensure training image stays readable but not too wide */
  .training-image-wrapper {
    max-width: min(70vw, 340px); /* Reduced width */
    min-height: clamp(120px, 3calc(var(--dvh-px) * 0.08), 220px);
  }
  
  /* Optimize login card for small screens */
  .login-card {
    padding: clamp(14px, calc(var(--dvh-px) * 0.02), 18px) clamp(16px, 3vw, 20px);
    gap: clamp(10px, calc(var(--dvh-px) * 0.05), 14px);
    width: min(80vw, 350px); /* Reduced width */
  }
  
  .login-card h3 {
    font-size: clamp(16px, 4.5vw, 22px);
  }
  
  .login-card input[type="text"],
  .login-card input[type="password"] {
    font-size: clamp(15px, 4vw, 18px);
    min-height: 46px;
  }
  
  .login-card button {
    font-size: clamp(16px, 4.2vw, 19px);
    min-height: 50px;
  }
  
  .selector-instruction {
    font-size: clamp(12px, 3.2vw, 16px);
  }
}

@media (max-height: 700px) {
  :root {
    --login-gap: clamp(10px, calc(var(--dvh-px) * 0.08), 20px);
    --training-selector-padding-y: clamp(8px, calc(var(--dvh-px) * 0.04), 14px);
    --training-selector-min-height: clamp(125px, calc(var(--dvh-px) * 0.30), 260px);
    --training-image-max-height: clamp(200px, calc(var(--dvh-px) * 0.40), 330px);
  }

  #login-screen {
    padding-top: clamp(8px, calc(var(--dvh-px) * 0.02), 14px);
    padding-bottom: max(env(safe-area-inset-bottom, 0px), clamp(10px, calc(var(--dvh-px) * 0.05), 16px));
  }

  .training-selector-container {
    gap: clamp(12px, calc(var(--dvh-px) * 0.04), 20px);
  }

  .training-image-wrapper {
    min-height: clamp(110px, calc(var(--dvh-px) * 0.34), 240px);
  }
}

@media (max-height: 580px) {
  :root {
    --login-gap: clamp(8px, calc(var(--dvh-px) * 0.02), 16px);
    --training-selector-padding-y: clamp(6px, calc(var(--dvh-px) * 0.02), 12px);
    --training-selector-min-height: clamp(110px, 2calc(var(--dvh-px) * 0.08), 220px);
    --training-image-max-height: clamp(180px, 3calc(var(--dvh-px) * 0.08), 260px);
  }

  #login-screen {
    padding-top: clamp(6px, calc(var(--dvh-px) * 0.02), 12px);
    padding-bottom: max(env(safe-area-inset-bottom, 0px), clamp(8px, calc(var(--dvh-px) * 0.02), 12px));
  }

  .training-selector-container {
    gap: clamp(10px, calc(var(--dvh-px) * 0.02), 18px);
  }

  .training-image-wrapper {
    min-height: clamp(90px, calc(var(--dvh-px) * 0.32), 200px);
  }
}

/* ====== SETUP SCREEN ====== */
#main-app {
  background: var(--gradient-dark);
  background-color: var(--color-bg-dark) !important;
  
  /* CRITICAL: Precise height calculation - ends exactly where button starts */
  height: min(var(--main-app-height-svh), var(--main-app-visible-height, var(--main-app-height-svh)));
  height: min(var(--main-app-height), var(--main-app-visible-height, var(--main-app-height))); /* Fallback */
  /* NO max-height - would override the calculated height! */
  
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  -webkit-overflow-scrolling: touch;
  
  /* NO padding-bottom - height is calculated precisely */
}

#setup-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--gradient-card);
  backdrop-filter: blur(10px);
  border-radius: clamp(16px, 3vw, 20px);
  box-shadow: var(--shadow-lg);
  /* Normal padding - no extra space needed */
  padding: clamp(18px, 3.5vw, 25px) clamp(15px, 3vw, 20px);
  margin: 20px auto;
  max-width: min(420px, 90vw);
  color: #fff;
  text-align: center;
}

#setup-screen h2 {
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 800;
  color: var(--color-white);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: clamp(18px, 3.5vw, 25px);
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#setup-screen label {
  font-weight: 700;
  margin-top: 20px;
  margin-bottom: 10px;
  width: 100%;
  max-width: min(340px, 85vw);
  text-align: center;
  font-size: clamp(14px, 2.8vw, 16px);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#setup-screen select {
  width: 100%;
  max-width: min(340px, 85vw);
  padding: 14px 16px;
  font-size: clamp(14px, 2.8vw, 16px);
  font-weight: 600;
  border-radius: clamp(10px, 2vw, 12px);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(240, 240, 240, 0.15));
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.4);
  margin-bottom: 10px;
  transition: all 0.3s ease;
  cursor: pointer;
  text-align: center;
}

#setup-screen select:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.25), rgba(240, 240, 240, 0.25));
  border-color: rgba(255, 255, 255, 0.6);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 255, 255, 0.3);
}

#setup-screen select:focus {
  outline: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(240, 240, 240, 0.3));
  border-color: var(--color-white);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

/* Pulsante Start Workout */
#start-button {
  display: none;
}

.start-button {
  background: linear-gradient(135deg, var(--color-white), var(--color-white));
  color: white;
  font-weight: bold;
  padding: 14px 24px;
  font-size: clamp(16px, 3vw, 18px);
  border-radius: 10px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: background 0.3s, transform 0.2s;
}

.start-button:hover:not(:disabled) {
  background: linear-gradient(135deg, #B0B0B0, var(--color-white));
  transform: translateY(-2px);
}

.start-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* BOTTOM BUTTONS CONTAINER - Settings + Start Workout */


/* START BUTTON - IN CONTAINER */
#start-button-bottom {
  flex: 1;
  max-width: min(400px, 70vw);
  /* Height relative to parent */
  height: 65%;
  padding: 0 5%;
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6), 0 0 0 1px rgba(255, 255, 255, 0.3);
  background: linear-gradient(135deg, var(--color-white), var(--color-white));
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Settings button in bottom container */
#bottom-buttons-container .settings-btn {
  flex-shrink: 0;
  /* Square button, height relative to parent */
  height: 65%;
  aspect-ratio: 1;
  font-size: clamp(1rem, 3vw, 1.3rem);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#start-button-bottom:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(255, 255, 255, 0.6), 0 0 0 2px rgba(255, 255, 255, 0.5);
  background: linear-gradient(135deg, #B0B0B0, var(--color-white));
}

#start-button-bottom:active:not(:disabled) {
  transform: translateY(-1px);
}

#start-button-bottom:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: linear-gradient(135deg, #B0B0B0, #7D7D7D);
}

/* Hide button when workout is active */
#exercise-container:not([style*="display: none"]) ~ #start-button-bottom,
body:has(#exercise-container[style*="display: flex"]) #start-button-bottom {
  display: none;
}

/* Pulsante Logout in alto a destra del blocco */
#logout-button {
  align-self: flex-end;
  margin-bottom: clamp(15px, 3vw, 20px);
  background-color: rgba(255,255,255,0.1);
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  color: #fff;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.3s;
}

#logout-button:hover {
  background-color: rgba(255,255,255,0.2);
}

/* ====== WORKOUT PREVIEW ====== */
#exercise-list {
  display: none !important;
}

#workout-preview {
  display: block !important;
  margin-top: 30px;
  width: 100%;
  max-width: min(340px, 85vw);
}

#workout-preview h3 {
  font-size: clamp(16px, 3vw, 18px);
  font-weight: 700;
  color: #fff;
  text-align: center;
  margin-bottom: clamp(12px, 2.5vw, 15px);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ====== INSTRUCTIONS SECTION (Collapsible) ====== */
#instructions-section {
  width: 100%;
  max-width: min(340px, 85vw);
  margin: 20px auto;
  background: var(--gradient-card);
  border: var(--border-subtle);
  border-radius: clamp(10px, 2vw, 12px);
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.instructions-header {
  padding: clamp(10px, 2vw, 12px) clamp(12px, 2.5vw, 16px);
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 10px);
  background: linear-gradient(135deg, #7D7D7D, #4D4D4D);
  color: #fff;
  cursor: pointer;
  user-select: none;
  transition: background 0.3s;
}

.instructions-header:hover {
  background: linear-gradient(135deg, #B0B0B0, #7D7D7D);
}

.instructions-icon {
  font-size: clamp(17px, 3.5vw, 20px);
}

.instructions-title {
  flex: 1;
  font-size: clamp(13px, 2.5vw, 15px);
  font-weight: 700;
  letter-spacing: 1.5px;
}

.collapse-icon {
  font-size: clamp(12px, 2.3vw, 14px);
  transition: transform 0.3s;
}

.instructions-header.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

.instructions-content {
  max-height: min(500px, calc(var(--dvh-px) * 0.60));
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.instructions-content.collapsed {
  max-height: 0;
}

#instructions-box {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 1));

  font-size: clamp(13px, 2.5vw, 15px);
  color: #4D4D4D;
  text-align: left;
  line-height: 1.6;
  margin: 0;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

#instructions-text {
  margin: 0;
  padding: 8px 12px;
  color: #000000;
  font-size: clamp(14px, 2.8vw, 16px);
  line-height: 1.8;
  letter-spacing: 0.3px;
  word-spacing: 0.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#instructions-image {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin-top: 10px;
}

/* ====== MATERIALE SECTION ====== */
#materiale-section {
  width: 100%;
  max-width: min(600px, 95vw); /* Increased from 340px to allow more items per row */
  margin: 20px auto;
  background: var(--gradient-card);
  border: var(--border-subtle);
  border-radius: clamp(10px, 2vw, 12px);
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.materiale-header {
  padding: clamp(10px, 2vw, 12px) clamp(12px, 2.5vw, 16px);
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 10px);
  background: linear-gradient(135deg, #4D4D4D, #7D7D7D);
  color: #fff;
}

.materiale-icon {
  font-size: clamp(17px, 3.5vw, 20px);
}

.materiale-title {
  flex: 1;
  font-size: clamp(13px, 2.5vw, 15px);
  font-weight: 700;
  letter-spacing: 1.5px;
}

.materiale-content {
  background:#FFFFFF;

}

#materiale-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: clamp(8px, 1.5vw, 10px);
  justify-items: center;
}

/* Small screens: force 2 columns max */

/* Medium screens: 3 columns */

/* Larger screens: auto-fit with minimum 120px items */

.materiale-item {
  background: linear-gradient(135deg, #7D7D7D, #4D4D4D);
  color: white;
  padding: 10px 16px;
  border-radius: clamp(16px, 3vw, 20px);
  font-size: clamp(12px, 2.3vw, 14px);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%; /* Make items fill their grid cell */
  max-width: min(160px, 75vw);
  white-space: nowrap;
  transition: all 0.2s ease;
}

.materiale-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
}

.materiale-item::before {
  content: "";
  font-size: clamp(16px, 3vw, 18px);
}


#exercise-visuals {
  display: block !important;
  width: 100%;
  max-width: min(340px, 85vw);
  margin-top: clamp(18px, 3.5vw, 25px);
  margin-bottom: clamp(18px, 3.5vw, 25px);
}

#exercise-grid {
  display: flex;
  flex-direction: column;
  gap: clamp(15px, 3vw, 20px);
  width: 100%;
}

/* Workout Section */
.workout-section {
  width: 100%;
  background: var(--gradient-card);
  border-radius: clamp(12px, 2.3vw, 14px);
  overflow: hidden;
  border: var(--border-subtle);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  margin-bottom: clamp(12px, 2.5vw, 16px);
}

.section-header {
  padding: clamp(12px, 2.4vw, 14px) clamp(14px, 2.8vw, 18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--color-white);
  font-weight: 800;
  gap: 10px;
  background: linear-gradient(135deg, #4D4D4D, #7D7D7D);
  border-bottom: var(--border-subtle);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.section-icon {
  font-size: clamp(18px, 3.6vw, 22px);
  flex-shrink: 0;
  opacity: 0.9;
}

.section-title {
  font-size: clamp(14px, 2.8vw, 16px);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  flex: 1;
}

.section-count {
  font-size: clamp(11px, 2.2vw, 13px);
  background: rgba(255, 255, 255, 0.1);
  padding: 5px 12px;
  border-radius: 20px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.section-cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 2vw, 12px);
  padding: clamp(10px, 2vw, 12px);
  background: rgba(0, 0, 0, 0.1);
}

.exercise-card {
  background: linear-gradient(135deg, #FFFFFF, var(--color-white));
  padding: 12px;
  border-radius: clamp(12px, 2.4vw, 14px);
  color: var(--color-black);
  box-shadow: var(--shadow-md);
  text-align: center;
  border: 1px solid var(--color-light-grey);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}

.exercise-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-white);
}

.exercise-card img {
  width: 100%;
  object-fit: cover;
  object-position: center;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 2px solid #FFFFFF;
  flex-shrink: 0;
  clip-path: inset(3% 0 3% 0);
}

.exercise-name {
  font-weight: 700;
  font-size: clamp(11px, 2.2vw, 13px);
  color: #000000;
  line-height: 1.3;
  margin-top: 8px;
  text-align: center;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.exercise-details {
  display: flex;
  flex-direction: row;
  gap: clamp(6px, 2vw, 10px);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  justify-content: center;
  flex-wrap: wrap;
}

.exercise-equipment,
.exercise-reps {
  display: none;
}

.exercise-info-item {
  display: inline-block;
  background: rgba(125, 125, 125, 0.12);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: clamp(10px, 2vw, 12px);
  color: #000000;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.05em;
}

.exercise-equipment strong,
.exercise-reps strong {
  color: var(--color-light-grey);
  font-weight: 700;
}

/* ====== SECTIONED PREVIEW STYLES ====== */
.workout-section {
  background: var(--gradient-card);
  border: var(--border-subtle);
  border-radius: clamp(10px, 2vw, 12px);
  overflow: hidden;
  margin-bottom: clamp(12px, 2.5vw, 16px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.section-header {
  padding: clamp(10px, 2vw, 12px) clamp(12px, 2.5vw, 16px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: clamp(13px, 2.5vw, 15px);
  color: #fff;
}

.section-icon {
  font-size: clamp(17px, 3.5vw, 20px);
  margin-right: 8px;
}

.section-title {
  flex: 1;
  font-size: clamp(13px, 2.5vw, 15px);
  font-weight: 700;
  letter-spacing: 1.5px;
}

.section-count {
  background: rgba(255, 255, 255, 0.25);
  padding: 4px 10px;
  border-radius: clamp(10px, 2vw, 12px);
  font-size: clamp(11px, 2.2vw, 13px);
  font-weight: 600;
}

.section-cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(8px, 2vw, 12px);
  padding: clamp(10px, 2vw, 12px);
}

/* ====== WORKOUT SECTION - CLEAN RESPONSIVE ====== */

#exercise-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  height: var(--dvh-px);
  height: var(--dvh-px);
  max-height: var(--dvh-px);
  max-height: var(--dvh-px);
  /* Responsive padding with safe areas */
  padding: max(calc(var(--dvh-px) * 0.05), env(safe-area-inset-top)) clamp(8px, 2vw, 10px) max(calc(var(--dvh-px) * 0.05), env(safe-area-inset-bottom)) clamp(8px, 2vw, 10px);
  gap: clamp(2px, calc(var(--dvh-px) * 0.05), 4px);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden !important;
  -webkit-overflow-scrolling: none;
  overscroll-behavior: none;
  text-align: center;
}

/* Prevent scrolling on body when workout is active */
body:has(#exercise-container[style*="display: flex"]) {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* ====== TIMER - RESPONSIVE SIZE ====== */
#timer.full-timer {
  display: block;
  /* Responsive font size - scales with viewport */
  font-size: clamp(2.5rem, 8vw, 3.8rem);
  font-weight: bold;
  color: var(--color-light-grey);
  text-align: center;
  z-index: 2;
  line-height: 1;
  margin: 0;
  padding: clamp(4px, calc(var(--dvh-px) * 0.01), 8px) clamp(8px, 2vw, 10px);
  flex-shrink: 0;
  flex-grow: 0;
  width: 100%;
}

/* ====== EXERCISE NAME - RESPONSIVE SIZE ====== */
#exercise-name {
  /* Responsive font size */
  font-size: clamp(15px, 4vw, 18px);
  font-weight: bold;
  color: #fff;
  margin: 0 clamp(8px, 2vw, 10px) clamp(2px, calc(var(--dvh-px) * 0.05), 4px) clamp(8px, 2vw, 10px);
  text-align: center;
  line-height: 1.2;
  flex-shrink: 0;
  flex-grow: 0;
  /* Responsive min-height */
  min-height: clamp(42px, calc(var(--dvh-px) * 0.08), 48px);
  max-height: none;
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(6px, calc(var(--dvh-px) * 0.05), 8px) clamp(10px, 2.5vw, 14px);
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  border-radius: 10px;
  z-index: 10;
  position: relative;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  width: clamp(calc(100% - 16px), 95%, calc(100% - 20px));
  max-width: min(600px, 95vw);
}

/* ====== GIF - ALWAYS 9:16 VERTICAL ====== */
#exercise-gif,
#next-exercise-gif {
  /* CRITICAL: Responsive width that maintains 9:16 aspect ratio */
  width: min(85vw, calc(var(--dvh-px) * 0.75));
  max-width: 90vw;
  /* CRITICAL: Force 9:16 vertical aspect ratio */
  aspect-ratio: 9 / 16;
  /* Let height be calculated by aspect-ratio */
  height: auto;
  /* Cover and center the image */
  object-fit: cover;
  object-position: center;
  display: block;
  margin: 0 auto;
  border-radius: clamp(10px, 2vw, 12px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  /* CRITICAL: Crop 5% from top and bottom */
  clip-path: inset(5% 0 5% 0);
  flex-shrink: 0;
}

/* ====== CONTROLS - RESPONSIVE ====== */
/* ====== FAB BUTTON (alto a destra) ====== */
.fab-button {
  flex-shrink: 0;
  width: clamp(40px, 10vw, 48px);
  height: clamp(40px, 10vw, 48px);
  border-radius: 50%;
  background: linear-gradient(135deg, #4D4D4D, #2D2D2D);
  border: 2px solid rgba(176, 176, 176, 0.4);
  color: #FFFFFF;
  font-size: clamp(18px, 4.5vw, 22px);
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), 0 0 20px rgba(176, 176, 176, 0.2);
  transition: all 0.3s ease;
  z-index: 101;
}

.fab-button:hover {
  background: linear-gradient(135deg, #5D5D5D, #3D3D3D);
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5), 0 0 25px rgba(176, 176, 176, 0.3);
}

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

.fab-button.active {
  background: linear-gradient(135deg, var(--color-light-grey), #FFFFFF);
  color: #000000;
  border-color: #FFFFFF;
}

/* ====== CONTROLS CONTAINER (seconda riga) ====== */
#controls-container {
  width: 100%;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  gap: clamp(6px, 2vw, 10px);
  padding: clamp(8px, 2vw, 12px) clamp(10px, 2vw, 14px);
  background: rgba(0, 0, 0, 0.9);
  border-bottom: 2px solid rgba(176, 176, 176, 0.2);
  flex-shrink: 0;
  flex-grow: 0;
  z-index: 99;
  transition: all 0.3s ease;
  transform-origin: top;
}

/* Stati nascosto/visibile con animazione */
#controls-container.controls-hidden {
  display: none;
  opacity: 0;
  transform: translateY(-10px);
}

#controls-container.controls-visible {
  display: flex;
  opacity: 1;
  transform: translateY(0);
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Overlay per chiudere menu */
.controls-overlay-hidden {
  display: none;
}

#controls-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 98;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#controls-overlay.controls-overlay-visible {
  display: block;
  opacity: 1;
}

#pause-button,
.settings-btn,
.nav-btn {
  /* Responsive padding and font - più compatti */
  padding: clamp(6px, calc(var(--dvh-px) * 0.015), 9px) clamp(10px, 2.5vw, 16px);
  font-size: clamp(12px, 3vw, 15px);
  font-weight: bold;
  border: none;
  border-radius: 8px;
  background-color: #000000;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: all 0.2s ease;
  flex: 1;
  min-width: 0;
}

#pause-button:hover,
.settings-btn:hover,
.nav-btn:hover {
  background-color: #4D4D4D;
  transform: translateY(-2px);
}

.nav-btn {
  font-size: clamp(16px, 4vw, 20px);
  padding: clamp(6px, calc(var(--dvh-px) * 0.015), 9px) clamp(8px, 2vw, 12px);
  background-color: rgba(176, 176, 176, 0.1);
  border: 1px solid rgba(176, 176, 176, 0.3);
  line-height: 1;
}

.nav-btn:hover {
  background-color: rgba(176, 176, 176, 0.2);
  border-color: rgba(176, 176, 176, 0.5);
}

.nav-btn:active {
  transform: scale(0.95);
}

.add-time-btn {
  /* Match navigation button styling */
  padding: clamp(6px, calc(var(--dvh-px) * 0.015), 9px) clamp(10px, 2.5vw, 16px);
  font-size: clamp(12px, 3vw, 15px);
  font-weight: bold;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: all 0.2s ease;
  flex: 1;
  min-width: 0;
  /* Match nav button gray styling */
  background-color: rgba(176, 176, 176, 0.1);
  border: 1px solid rgba(176, 176, 176, 0.3);
}

.add-time-btn:hover {
  background-color: rgba(176, 176, 176, 0.2);
  border-color: rgba(176, 176, 176, 0.5);
  transform: translateY(-2px);
}

.add-time-btn:active {
  transform: scale(0.95);
}

.settings-btn {
  font-size: clamp(15px, 4vw, 18px);
  padding: clamp(6px, calc(var(--dvh-px) * 0.015), 9px) clamp(10px, 2.5vw, 14px);
}

/* Settings Popup Overlay */
#settings-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-content {
  background: linear-gradient(135deg, #4D4D4D, #000000);
  padding: clamp(24px, 5vw, 32px);
  border-radius: clamp(16px, 3vw, 20px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  text-align: center;
  width: 90%;
  max-width: 320px;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.settings-content h3 {
  color: var(--color-white);
  font-size: clamp(20px, 4.5vw, 24px);
  margin-bottom: clamp(15px, 3vw, 20px);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.settings-content label {
  display: block;
  color: #fff;
  font-weight: 600;
  margin-bottom: 10px;
  font-size: clamp(14px, 2.8vw, 16px);
}

.settings-content select {
  width: 100%;
  padding: clamp(10px, 2vw, 12px) clamp(12px, 2.5vw, 16px);
  font-size: clamp(14px, 2.8vw, 16px);
  font-weight: 600;
  border-radius: clamp(10px, 2vw, 12px);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(240, 240, 240, 0.15));
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.4);
  margin-bottom: clamp(15px, 3vw, 20px);
  cursor: pointer;
}

.settings-content select:focus {
  outline: none;
  border-color: var(--color-white);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

#close-settings {
  width: 100%;
  padding: clamp(12px, 2.5vw, 14px);
  background: linear-gradient(135deg, #FFFFFF, #E0E0E0);
  color: #000000;
  font-size: clamp(14px, 2.8vw, 16px);
  font-weight: bold;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#close-settings:hover {
  background: linear-gradient(135deg, #B0B0B0, var(--color-white));
  transform: translateY(-2px);
}

/* Exit Workout Button - Red warning style */
#exit-workout-button {
  width: 100%;
  padding: clamp(12px, 2.5vw, 14px);
  background: linear-gradient(135deg, #4D4D4D, #3D3D3D) !important;
  color: white !important;
  font-size: clamp(14px, 2.8vw, 16px);
  font-weight: bold;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 10px !important;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#exit-workout-button::before {
  content: "";
  width: 12px;
  height: 12px;
  background: #e74c3c;
  border-radius: 50%;
  flex-shrink: 0;
}

#exit-workout-button:hover {
  background: linear-gradient(135deg, #B0B0B0, #7D7D7D) !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

#exit-workout-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(231, 76, 60, 0.3);
}

/* Volume Slider in Settings Popup */
.settings-content #volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  margin: 10px 0;
}

.settings-content #volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.settings-content #volume-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Setup Settings Popup - Same styling as workout settings */
#setup-settings-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#close-setup-settings,
#logout-button {
  width: 100%;
  padding: clamp(10px, 2vw, 12px);
  font-size: clamp(14px, 2.8vw, 16px);
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 10px;
}

#close-setup-settings {
  background: linear-gradient(135deg, var(--color-white), var(--color-white));
  color: white;
}

#close-setup-settings:hover {
  background: linear-gradient(135deg, #B0B0B0, var(--color-white));
  transform: translateY(-2px);
}

#logout-button {
  background: linear-gradient(135deg, #7D7D7D, #4D4D4D);
  color: white;
}

#logout-button:hover {
  background: linear-gradient(135deg, #B0B0B0, #7D7D7D);
  transform: translateY(-2px);
}


.audio-setup-wrapper,
.audio-workout-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: center;
}

.audio-setup-wrapper select,
.audio-workout-wrapper select {
  padding: 6px 10px;
  font-size: 1rem;
  border-radius: 6px;
  background: #000000;
  color: #fff;
  border: none;
}

audio {
  display: none;
}


/* ====== TOP SELECTOR ABOVE SETUP CARD ====== */
#topbar-select {
  max-width: min(420px, 90vw);
  margin: 10px auto 0;
  padding: 14px 16px;
  text-align: center;
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(10px);
  border-radius: clamp(12px, 2.5vw, 16px);
  box-shadow: var(--shadow-lg);
}

#topbar-select label {
  display: block;
  font-weight: 700;
  font-size: clamp(14px, 2.8vw, 16px);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

#topbar-select select {
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  width: 100%;
  max-width: min(340px, 85vw);
  padding: 14px 40px 14px 16px;
  font-size: clamp(14px, 2.8vw, 16px);
  font-weight: 600;
  border-radius: clamp(10px, 2vw, 12px);
  background: linear-gradient(135deg, rgba(106,176,76,0.15), rgba(88,160,57,0.15));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px;
  color: #fff;
  border: 2px solid rgba(106,176,76,0.4);
  transition: all 0.3s ease;
  cursor: pointer;
  text-align: center;
  text-align-last: center;
  font-family: 'Staatliches', sans-serif;
}


/* ====== COMPREHENSIVE SPACE OPTIMIZATION ====== */
/* Ensures no content is hidden behind sticky buttons and optimizes space usage */

/* Setup Screen Sections - Tighter spacing */
#instructions-section,
#materiale-section {
  margin-bottom: clamp(15px, 3vw, 20px); /* Reduced from default */
}

#workout-preview-title {
  margin: 20px 0 15px !important; /* Reduced from 30px 0 20px */
}

#exercise-visuals {
  margin-top: 15px !important; /* Reduced from 20px */
  margin-bottom: clamp(15px, 3vw, 20px);
}

#start-point-selector {
  margin: 20px 0 30px !important; /* Optimized margins */
}

/* Exercise cards - more compact on mobile */
.exercise-card {
  min-height: 130px; /* Reduced from 140px */
  padding: 8px; /* Reduced from 10px */
}

.exercise-card img {
  margin-bottom: 6px; /* Reduced from 8px */
}

.exercise-name {
  margin-top: 6px;
  font-size: clamp(10px, 2vw, 12px);
  min-height: clamp(26px, 4.8vw, 30px);
  color: #000000;
}

.exercise-details {
  margin-top: 6px;
  padding-top: 6px;
  gap: clamp(4px, 1.5vw, 8px);
}

/* Workout sections - tighter spacing */
.workout-section {
  margin-bottom: clamp(12px, 2.5vw, 15px); /* Reduced spacing between sections */
}

.section-header {
  padding: 10px 14px; /* Slightly reduced */
}

.section-cards-grid {
  padding: 10px; /* Reduced from 12px */
  gap: clamp(8px, 1.5vw, 10px); /* Reduced from 12px */
}

/* Bottom button container - ensure it doesn't overlap */


#start-button-bottom {
  max-width: min(400px, 90vw);
  margin: 0 auto;
}

/* Mobile optimizations */

/* Small phones (< 375px) */

/* Tablets and larger phones */

/* Desktop and large tablets */


/* Very small phones during workout */


/* Ensure content is never cut off - force scroll if needed */
#main-app {
  scroll-behavior: smooth;
  scroll-padding-bottom: var(--footer-total); /* Padding when scrolling to anchors */
}

/* Improve scrollbar appearance */
#main-app::-webkit-scrollbar {
  width: 8px;
}

#main-app::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}

#main-app::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 10px;
}

#main-app::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.7);
}
/* ====== TRIPLE VISUAL CUE SYSTEM ====== */


/* 1. EXERCISE NAME BAR - GOLDEN EFFECT at 10 seconds */
#exercise-name.next-preview-active {
  background: linear-gradient(135deg, rgba(176, 176, 176, 0.95), rgba(125, 125, 125, 0.95)) !important;
  border: 3px solid var(--color-light-grey) !important;
  box-shadow: 
    0 8px 32px rgba(176, 176, 176, 0.5),
    0 0 60px rgba(176, 176, 176, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3) !important;
  animation: barPulse 2s ease-in-out infinite !important;
  color: #000 !important;
}

#exercise-name.next-preview-active strong {
  color: #000 !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

#exercise-name.next-preview-active div {
  color: #000000 !important;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5) !important;
}

@keyframes barPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 
      0 8px 32px rgba(176, 176, 176, 0.5),
      0 0 60px rgba(176, 176, 176, 0.4);
  }
  50% {
    transform: scale(1.02);
    box-shadow: 
      0 10px 40px rgba(176, 176, 176, 0.7),
      0 0 80px rgba(176, 176, 176, 0.6);
  }
}

/* 2. TIMER COLOR TRANSITIONS */
#timer.full-timer.warning-10 {
  color: var(--color-light-grey);
  text-shadow: 
    0 0 20px rgba(176, 176, 176, 0.8),
    0 0 40px rgba(176, 176, 176, 0.5);
  animation: timerGlow 1s ease-in-out infinite;
}

#timer.full-timer.warning-6 {
  color: #B0B0B0;
  text-shadow: 
    0 0 25px rgba(255, 140, 0, 0.9),
    0 0 50px rgba(255, 140, 0, 0.6);
  animation: timerGlow 0.8s ease-in-out infinite;
}

#timer.full-timer.warning-3 {
  color: #B0B0B0;
  text-shadow: 
    0 0 30px rgba(255, 68, 68, 1),
    0 0 60px rgba(255, 68, 68, 0.7);
  animation: timerGlow 0.5s ease-in-out infinite;
}

@keyframes timerGlow {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.85;
  }
}

/* 3. GIF BORDER GLOW (at 10 seconds) */
#exercise-gif.gif-glow {
  border: 4px solid var(--color-light-grey);
  box-shadow: 
    0 0 30px rgba(176, 176, 176, 0.8),
    0 0 60px rgba(176, 176, 176, 0.5),
    0 4px 20px rgba(0,0,0,0.3);
  animation: gifPulse 2s ease-in-out infinite;
}

@keyframes gifPulse {
  0%, 100% {
    border-color: var(--color-light-grey);
    box-shadow: 
      0 0 30px rgba(176, 176, 176, 0.8),
      0 0 60px rgba(176, 176, 176, 0.5),
      0 4px 20px rgba(0,0,0,0.3);
  }
  50% {
    border-color: #B0B0B0;
    box-shadow: 
      0 0 40px rgba(176, 176, 176, 1),
      0 0 80px rgba(176, 176, 176, 0.7),
      0 6px 25px rgba(0,0,0,0.4);
  }
}

/* RESPONSIVE ADJUSTMENTS */

/* ====== WORKOUT PROGRESS BAR ====== */

/* ====== PROGRESS BAR + FAB HEADER ====== */
#workout-progress-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 12px);
  /* CRITICAL: Add safe area for notch/status bar */
  padding-top: max(8px, env(safe-area-inset-top, 8px));
  padding-left: clamp(10px, 2vw, 14px);
  padding-right: clamp(10px, 2vw, 14px);
  padding-bottom: 6px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid rgba(176, 176, 176, 0.3);
  flex-shrink: 0;
  flex-grow: 0;
  z-index: 100;
}

#workout-progress-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#progress-bar-wrapper {
  margin-bottom: 4px;
}

#progress-bar {
  position: relative;
  width: 100%;
  height: clamp(18px, calc(var(--dvh-px) * 0.03), 22px);
  background: rgba(255, 255, 255, 0.08);
  border-radius: clamp(10px, 2vw, 12px);
  overflow: hidden;
  border: var(--border-subtle);
  box-shadow: var(--shadow-inset);
}

#progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--color-light-grey), #FFFFFF);
  border-radius: clamp(12px, 2.4vw, 14px);
  transition: width 0.5s ease;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

#progress-percentage {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(10px, 2vw, 12px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  z-index: 1;
}

#progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

#progress-info span {
  font-size: clamp(8px, 1.6vw, 10px);
  font-weight: 600;
  color: var(--color-light-grey);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Responsive adjustments */



/* ====== MOBILE VIEWPORT FIX ====== */

/* Ensure exercise container uses all available space on all browsers */
@supports (height: var(--dvh-px)) {
  #exercise-container {
    height: var(--dvh-px) !important;
  }
}

/* Safari fallback */
@supports (height: -webkit-fill-available) {
  #exercise-container {
    height: -webkit-fill-available !important;
  }
}

/* Prevent any scrolling during workout */
body:has(#exercise-container[style*="display: flex"]),
body:has(#exercise-container[style*="display: flex"]) html {
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
  height: 100% !important;
  overscroll-behavior: none !important;
}
/* ====== RESPONSIVE ADJUSTMENTS - ORIENTATION BASED ====== */

/* Landscape optimization - reduce vertical space usage */
@media (orientation: landscape) {
  :root {
    --header-height: calc(var(--dvh-px) * 0.10);
    --bottom-button-height: calc(var(--dvh-px) * 0.10);
  }

  #exercise-gif {
    width: min(40vw, calc(var(--dvh-px) * 0.65));
  }

  #timer {
    font-size: clamp(calc(var(--dvh-px) * 0.06), 12vw, calc(var(--dvh-px) * 0.10));
  }

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

/* Portrait is default - no override needed since main definition already handles it */


#exercise-container {
  display: flex;
  flex-direction: column;
  height: var(--dvh-px);
  max-height: var(--dvh-px);
  min-height: 0;
}

/* Non-GIF parts keep their natural size */
#workout-progress-container,
#timer,
#exercise-name,
#controls-container {
  flex-shrink: 0;
}


/* --- Cropped GIF fills the leftover height, for ANY crop % --- */
#exercise-gif-viewport {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Set crop as FRACTIONS (0–1). Change these two only. */
#exercise-gif {
  --clip-top: 0.13;      /* 13% top crop  → set 0.05 for 5%, etc. */
  --clip-bottom: 0.07;   /*  7% bottom crop */

  /* After cropping (top+bottom), the visible height = 100% */
  height: calc(100% / (1 - (var(--clip-top) + var(--clip-bottom)))) !important;
  width: auto !important;
  max-width: none !important;

  aspect-ratio: 9 / 16;
  object-fit: cover;
  object-position: center;

  /* Convert the FRACTIONS above into percentages for clip-path */
  clip-path: inset(calc(var(--clip-top) * 100%) 0 calc(var(--clip-bottom) * 100%) 0);

  display: block;
  margin: 0;
  border-radius: clamp(10px, 2vw, 12px);
}

/* Remove #main-app background during workout */
#main-app:has(#exercise-container[style*="display: flex"]) {
  background: transparent !important;
  background-color: transparent !important;
}

/* LETTER-SPACING TUNING */
body, button, select, label, .exercise-name, .section-title, .section-count {
  letter-spacing: 0.15em;
}

h1, h2, h3, .settings-content h3, #workout-preview-title {
  letter-spacing: 0.1em;
}

.start-button, #pause-button, #prev-exercise-button, #next-exercise-button, #settings-button, #setup-settings-button {
  letter-spacing: 0.13em;
}

/* Ensure selects and option texts inherit spacing */
select option { letter-spacing: inherit; }


/* === Info line (peso, reps, durata) per corrente e prossimo === */
.exercise-info-line{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:24px;
  padding:6px 0 2px;
  font-size:16px;
  letter-spacing:.06em;
  width:100%;
  max-width:min(600px,95vw);
}
.exercise-info-line .info-item{
  flex:1 1 0;
  text-align:center;
  font-weight:700;
  white-space:nowrap;
}

/* Colori coerenti su barra nera (corrente) */
#exercise-name .exercise-info-line .info-item{
  color:var(--color-light-grey);
}
/* Colori coerenti su riquadro “prossimo esercizio” (giallo) */
#exercise-name.next-preview-active .exercise-info-line .info-item{
  color:#000;
}

.exercise-info-line {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  gap: 24px;
  padding: 4px 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.05em;
  width: 100%;
}

.exercise-info-line .info-item {
  flex: 1;
  text-align: center;
  color: var(--color-light-grey);
}


/* ====== RESET BASE ====== */
* { box-sizing: border-box; margin: 0; padding: 0; }



/* Default (will be overridden by theme) */
html { background: #000000; }
body {
  font-family: 'Staatliches', sans-serif;
  background: #000000;
  color: #fff;
  min-height: var(--dvh-px);
  min-height: var(--dvh-px);
  min-height: -webkit-fill-available;
  -webkit-background-size: cover;
  background-size: cover;
  background-attachment: fixed;
}

header {
  text-align: center;
  padding: 1% 0;
  height: var(--header-height);
  flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-sizing: border-box;
}

header img { width: auto; max-width: 70%; max-height: none; border-radius: 8px; }
header h1 { margin-top: 2%; font-size: clamp(0.9rem, 3vw, 1.2rem); color: #fff; }

main { max-width: min(600px, 95vw); margin: 0 auto; padding-inline: 20px; padding-top: 0; background: transparent; position: relative; z-index: 1; }

/* ====== SETUP SCREEN ====== */
#main-app {
  background: transparent;
  height: min(var(--main-app-height-svh), var(--main-app-visible-height, var(--main-app-height-svh)));
  height: min(var(--main-app-height), var(--main-app-visible-height, var(--main-app-height)));
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

#setup-screen {
  display: flex; flex-direction: column; align-items: center;
  background: var(--gradient-card);
  backdrop-filter: blur(10px);
  border-radius: clamp(16px, 3vw, 20px);
  box-shadow: var(--shadow-lg);
  padding: clamp(18px, 3.5vw, 25px) clamp(15px, 3vw, 20px);
  margin: 20px auto; max-width: min(420px, 90vw); color: #fff; text-align: center;
}

#setup-screen h2 {
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 800; color: #FFFFFF;
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: clamp(18px, 3.5vw, 25px);
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#setup-screen label {
  font-weight: 700; margin-top: 20px; margin-bottom: 10px; width: 100%; max-width: min(340px, 85vw);
  text-align: center; font-size: clamp(14px, 2.8vw, 16px); color: #fff; text-transform: uppercase; letter-spacing: 0.5px;
}

#setup-screen select,
#topbar-select select,
.settings-content select,
.audio-setup-wrapper select,
.audio-workout-wrapper select {
  width: 100%; max-width: min(340px, 85vw);
  padding: 14px 16px; font-size: clamp(14px, 2.8vw, 16px);
  font-weight: 600; border-radius: clamp(10px, 2vw, 12px);
  background: #4D4D4D; color: #FFFFFF; border: 1px solid #4D4D4D;
  margin-bottom: 10px; transition: all 0.2s ease; cursor: pointer; text-align: center;
}
#setup-screen select:hover { background: #4D4D4D; border-color: #7D7D7D; transform: translateY(-1px); }

.start-button { background: #4D4D4D; color: white; font-weight: 700; padding: 14px 24px; font-size: clamp(16px, 3vw, 18px); border-radius: 10px; border: 1px solid #4D4D4D; cursor: pointer; box-shadow: var(--shadow-lg); transition: all 0.2s ease; }
.start-button:hover:not(:disabled) { background: #4D4D4D; transform: translateY(-2px); }
.start-button:disabled { opacity: .5; cursor: not-allowed; }



#start-button-bottom {
  flex: 1; max-width: min(400px, 90vw); height: 65%;
  padding: 0 5%; font-size: clamp(0.9rem, 2.5vw, 1.1rem); font-weight: 700;
  background: #4D4D4D; color: #fff; border: 1px solid #4D4D4D; border-radius: 8px;
  cursor: pointer; transition: all .2s ease; display: flex; align-items: center; justify-content: center;
}
#start-button-bottom:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0,0,0,.45); background:#4D4D4D; }

#bottom-buttons-container .settings-btn {
  height: 65%; aspect-ratio: 1; font-size: clamp(1rem, 3vw, 1.3rem);
  background:#000000; color:#FFFFFF; border:1px solid #4D4D4D; border-radius:8px; box-shadow:0 6px 16px rgba(0,0,0,.35);
}

#logout-button { align-self: flex-end; margin-bottom: clamp(15px,3vw,20px); background: #4D4D4D; border: 1px solid #2d2f35; padding: 8px 16px; border-radius: 6px; color: #fff; font-weight: bold; cursor: pointer; transition: background .2s; }
#logout-button:hover { background:#4D4D4D; }

/* ====== PREVIEW / INSTRUCTIONS / MATERIALE ====== */
#workout-preview { display: block !important; margin-top: 30px; width: 100%; max-width: min(340px,85vw); }
#workout-preview h3 { font-size: clamp(16px, 3vw, 18px); font-weight: 700; color: #fff; text-align: center; margin-bottom: clamp(12px, 2.5vw, 15px); text-transform: uppercase; letter-spacing: .5px; }

#instructions-section { width:100%; max-width:min(340px,85vw); margin:20px auto; background: rgba(255,255,255,0.04); border:1px solid rgba(255,255,255,0.08); border-radius: clamp(10px,2vw,12px); overflow:hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.25); }
.instructions-header { padding: clamp(10px,2vw,12px) clamp(12px,2.5vw,16px); display:flex; align-items:center; gap: clamp(8px,1.5vw,10px); background: linear-gradient(135deg,#4D4D4D,#4D4D4D); color:#FFFFFF; cursor:pointer; user-select:none; transition: filter .2s; }
.instructions-header:hover { filter: brightness(1.05); }
.instructions-icon { font-size: clamp(17px,3.5vw,20px); }
.instructions-title { flex:1; font-size: clamp(13px,2.5vw,15px); font-weight:700; letter-spacing:1.5px; }
.collapse-icon { font-size: clamp(12px,2.3vw,14px); transition: transform .3s; }
.instructions-header.collapsed .collapse-icon { transform: rotate(-90deg); }
.instructions-content { max-height: min(500px,calc(var(--dvh-px) * 0.60)); overflow: hidden; transition: max-height .3s ease-out; }
.instructions-content.collapsed { max-height: 0; }
#instructions-box { 
  background:#FFFFFF;  
  font-size: clamp(13px,2.5vw,15px); 
  color:#000000; 
  text-align:left; 
  line-height:1.6; 
  max-height: min(400px, calc(var(--dvh-px) * 0.50)); 
  overflow-y: auto; 
  overflow-x: hidden;
  position: relative;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
/* Custom scrollbar for instructions */
#instructions-box::-webkit-scrollbar { width: 6px; }
#instructions-box::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); border-radius: 3px; }
#instructions-box::-webkit-scrollbar-thumb { background: #B0B0B0; border-radius: 3px; }
#instructions-box::-webkit-scrollbar-thumb:hover { background: #7D7D7D; }
#instructions-text { margin:0; padding: 12px 16px; color:#000000; font-size: clamp(14px,2.8vw,16px); line-height:1.8; letter-spacing:0.3px; word-spacing:0.5px; white-space:pre-wrap; word-wrap:break-word; }
#instructions-image { width:100%; height:auto; border-radius:8px; margin-top:10px; }

#materiale-section { width:100%; max-width:min(600px,95vw); margin:20px auto; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: clamp(10px,2vw,12px); overflow:hidden; box-shadow:0 4px 12px rgba(0,0,0,.25); }
.materiale-header { padding: clamp(10px,2vw,12px) clamp(12px,2.5vw,16px); display:flex; align-items:center; gap: clamp(8px,1.5vw,10px); background: linear-gradient(135deg,#4D4D4D,#4D4D4D); color:#FFFFFF; }
.materiale-content { background:#FFFFFF }
#materiale-list { display:grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: clamp(8px,1.5vw,10px); justify-items:center; }
.materiale-item { background: #4D4D4D; color: #FFFFFF; padding:10px 16px; border-radius: clamp(16px,3vw,20px); font-size: clamp(12px,2.3vw,14px); font-weight:600; box-shadow: 0 2px 8px rgba(0,0,0,.25); width:100%; max-width:min(160px,75vw); white-space:nowrap; }

#exercise-visuals { display:block !important; width:100%; max-width:min(340px,85vw); margin-top: clamp(18px,3.5vw,25px); margin-bottom: clamp(18px,3.5vw,25px); }

#exercise-grid { display:flex; flex-direction:column; gap: clamp(15px,3vw,20px); width:100%; }

.workout-section { width:100%; background: rgba(255,255,255,0.04); border-radius: clamp(12px,2.3vw,14px); overflow:hidden; border:2px solid #FFFFFF; box-shadow: 0 2px 8px rgba(0,0,0,.2); margin-bottom: clamp(12px,2.5vw,16px); }
.section-header { padding: clamp(10px,2vw,12px) clamp(12px,2.5vw,16px); display:flex; align-items:center; justify-content:space-between; color:#FFFFFF; font-weight:700; gap:8px; background: #4D4D4D; }
.section-icon { font-size: clamp(17px,3.5vw,20px); flex-shrink: 0; }
.section-title { font-size: clamp(13px,2.5vw,15px); text-transform: uppercase; letter-spacing: 1.5px; flex:1; }
.section-count { font-size: clamp(11px,2.2vw,13px); background: rgba(255,255,255,0.12); padding: 4px 10px; border-radius: clamp(10px,2vw,12px); font-weight:600; }

.section-cards-grid { display:grid; grid-template-columns: 1fr 1fr; gap: clamp(8px,2vw,12px); padding: clamp(10px,2vw,12px); background: rgba(0,0,0,0.08); }
.exercise-card { background:#fbfbfc; padding:10px; border-radius: clamp(10px,2vw,12px); color:#000000; box-shadow: 0 2px 8px rgba(0,0,0,.12); text-align:center; border: 2px solid #FFFFFF; transition: all .2s ease; display:flex; flex-direction:column; min-height:140px; }
.exercise-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.18); }
.exercise-card img { width:100%; object-fit:cover; object-position:center; border-radius:8px; margin-bottom:8px; border:1px solid rgba(0,0,0,0.08); flex-shrink:0; clip-path: inset(3% 0 3% 0); }
.exercise-name { font-weight:700; font-size: clamp(11px,2.2vw,13px); color:#000000; line-height:1.3; margin-top:8px; text-align:center; min-height:32px; display:flex; align-items:center; justify-content:center; }
.exercise-details { display:flex; flex-direction:row; gap:clamp(6px,2vw,10px); margin-top:8px; padding-top:8px; border-top:1px solid rgba(0,0,0,0.08); justify-content:center; flex-wrap:wrap; }
.exercise-equipment,.exercise-reps { display:none; }
.exercise-info-item { display:inline-block; background:rgba(125,125,125,0.12); padding:5px 10px; border-radius:6px; font-size:clamp(10px,2vw,12px); color:#000000; font-weight:700; white-space:nowrap; letter-spacing:0.05em; }
.exercise-last-weight { background:rgba(76,175,80,0.15); color:#2E7D32; border:1px solid rgba(76,175,80,0.3); }

/* Letter spacing kept */
body, button, select, label, .exercise-name, .section-title, .section-count { letter-spacing: .15em; }
h1, h2, h3, .settings-content h3, #workout-preview-title { letter-spacing: .1em; }
.start-button, #pause-button, #prev-exercise-button, #next-exercise-button, #settings-button, #setup-settings-button { letter-spacing: .13em; }
select option { letter-spacing: inherit; }


/* =========================
   EXPERT UI HIERARCHY SYSTEM
   Clear visual differentiation between interaction types
   ========================= */

/* ========================================
   1. PRIMARY ACTION BUTTONS (CTA)
   Purpose: Main user flow actions
   Visual: White, bold, prominent shadows
   Usage: Start Workout, Login, Continue
   ======================================== */
:root {
  --primary-bg: #FFFFFF;
  --primary-text: #000000;
  --primary-border: #E0E0E0;
  --primary-shadow: 0 6px 20px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.3);
  --primary-shadow-hover: 0 10px 30px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.4);
  --primary-shadow-active: 0 2px 8px rgba(0,0,0,0.25);
}

#start-button-bottom,
.start-button,
#login-button {
  appearance: none;
  background: var(--primary-bg) !important;
  color: var(--primary-text) !important;
  border: 2px solid var(--primary-border) !important;
  border-radius: 12px;
  padding: clamp(14px, 3vw, 18px) clamp(20px, 4vw, 28px);
  font-size: clamp(15px, 3.2vw, 18px);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
  box-shadow: var(--primary-shadow);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

#start-button-bottom:hover,
.start-button:hover,
#login-button:hover {
  transform: translateY(-3px);
  box-shadow: var(--primary-shadow-hover);
  background: #FFFFFF !important;
}

#start-button-bottom:active,
.start-button:active,
#login-button:active {
  transform: translateY(0);
  box-shadow: var(--primary-shadow-active);
}

/* ========================================
   2. SECONDARY BUTTONS (Navigation & Tools)
   Purpose: Support actions, navigation, settings
   Visual: Dark grey, subtle, less prominent
   Usage: Settings, Pause, Navigation arrows
   ======================================== */
:root {
  --secondary-bg: #4D4D4D;
  --secondary-text: #FFFFFF;
  --secondary-border: #7D7D7D;
  --secondary-shadow: 0 3px 10px rgba(0,0,0,0.3);
  --secondary-shadow-hover: 0 5px 15px rgba(0,0,0,0.4);
}

#pause-button,
.nav-btn,
.settings-btn,
#setup-settings-button,
#close-settings,
#close-setup-settings {
  appearance: none;
  background: var(--secondary-bg) !important;
  color: var(--secondary-text) !important;
  border: 1px solid var(--secondary-border) !important;
  border-radius: 10px;
  padding: clamp(10px, 2.2vw, 14px) clamp(16px, 3.2vw, 20px);
  font-size: clamp(13px, 2.8vw, 15px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: var(--secondary-shadow);
  transition: all 0.2s ease;
}

#pause-button:hover,
.nav-btn:hover,
.settings-btn:hover,
#setup-settings-button:hover,
#close-settings:hover,
#close-setup-settings:hover {
  background: #5D5D5D !important;
  transform: translateY(-2px);
  box-shadow: var(--secondary-shadow-hover);
  border-color: #8D8D8D !important;
}

#pause-button:active,
.nav-btn:active,
.settings-btn:active,
#setup-settings-button:active,
#close-settings:active,
#close-setup-settings:active {
  transform: translateY(0);
  background: #3D3D3D !important;
}

/* ========================================
   3. DESTRUCTIVE BUTTONS (Dangerous Actions)
   Purpose: Exit, logout, terminate session
   Visual: Outlined/hollow, strong border, no fill
   Usage: Exit Workout, Logout, End Session
   ======================================== */
:root {
  --destructive-bg: rgba(0, 0, 0, 0.3);
  --destructive-text: #FFFFFF;
  --destructive-border: #FFFFFF;
  --destructive-border-hover: #B0B0B0;
  --destructive-shadow: 0 0 0 1px rgba(255,255,255,0.2) inset, 0 3px 10px rgba(0,0,0,0.3);
  --destructive-shadow-hover: 0 0 0 2px rgba(255,255,255,0.4) inset, 0 5px 15px rgba(0,0,0,0.4);
}

#exit-workout-button,
#logout-button,
#reset-start-point {
  appearance: none;
  background: var(--destructive-bg) !important;
  color: var(--destructive-text) !important;
  border: 2px solid var(--destructive-border) !important;
  border-radius: 10px;
  padding: clamp(10px, 2.2vw, 13px) clamp(16px, 3.2vw, 20px);
  font-size: clamp(13px, 2.8vw, 15px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: var(--destructive-shadow);
  transition: all 0.2s ease;
  backdrop-filter: blur(5px);
}

#exit-workout-button:hover,
#logout-button:hover,
#reset-start-point:hover {
  background: rgba(255, 255, 255, 0.1) !important;
  border-color: var(--destructive-border-hover) !important;
  box-shadow: var(--destructive-shadow-hover);
  transform: translateY(-1px);
}

#exit-workout-button:active,
#logout-button:active,
#reset-start-point:active {
  transform: translateY(0);
  background: rgba(0, 0, 0, 0.5) !important;
}

/* ========================================
   4. DISABLED STATE
   Purpose: Clearly show when actions are unavailable
   Visual: Low contrast, no shadow, no hover
   ======================================== */
button:disabled,
#start-button-bottom:disabled,
.start-button:disabled,
#login-button:disabled {
  background: rgba(77, 77, 77, 0.3) !important;
  color: #7D7D7D !important;
  border-color: #4D4D4D !important;
  box-shadow: none !important;
  cursor: not-allowed !important;
  transform: none !important;
  opacity: 0.5;
}

button:disabled:hover,
#start-button-bottom:disabled:hover,
.start-button:disabled:hover {
  transform: none !important;
  box-shadow: none !important;
}

/* ========================================
   5. READ-ONLY SECTIONS (Information Display)
   Purpose: Headers, info cards, stats - NOT clickable
   Visual: Flat, no shadows, no hover, clear borders
   Usage: Instructions header, Material section, Progress info
   ======================================== */

/* Instructions Section - Read Only */
.instructions-header,
.materiale-header {
  background: linear-gradient(135deg, rgba(77, 77, 77, 0.3) 0%, rgba(77, 77, 77, 0.2) 100%);
  border: 1px solid rgba(176, 176, 176, 0.2);
  border-radius: 10px;
  padding: clamp(12px, 2.5vw, 16px) clamp(15px, 3vw, 20px);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: default;
  box-shadow: none; /* NO shadow - flat appearance */
  transition: none; /* NO hover effects */
}

/* Info Cards - Read Only */


#workout-preview-title {
  background: rgba(77, 77, 77, 0.15);

  border-radius: 8px;
  padding: clamp(12px, 2.5vw, 16px);
  box-shadow: none; /* Flat - no depth */
  cursor: default;
  transition: none;
}

#materiale-list,

#progress-info {
  background: rgba(77, 77, 77, 0.15);
  border: 1px solid rgba(176, 176, 176, 0.15);
  border-radius: 8px;
  padding: clamp(12px, 2.5vw, 16px);
  box-shadow: none; /* Flat - no depth */
  cursor: default;
  transition: none;
}

#materiale-list{background: rgb(255, 255, 255)}
/* Progress Bar Container - Read Only */
#workout-progress-container {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(176, 176, 176, 0.2);
  border-radius: 8px;
  padding: clamp(10px, 2vw, 14px);
  box-shadow: none;
}

/* Ensure headers have no interactive appearance */
#workout-preview-title,
.instructions-title,
.materiale-title {
  cursor: default;
  user-select: none;
  pointer-events: none;
}

/* Remove any hover effects from read-only elements */
.instructions-header:hover,
.materiale-header:hover,
#instructions-box:hover,
#materiale-list:hover,
#progress-info:hover {
  transform: none;
  box-shadow: none;
}

/* ========================================
   6. FOCUS STATES (Accessibility)
   Purpose: Keyboard navigation and screen readers
   ======================================== */
button:focus-visible,
#start-button-bottom:focus-visible,
.start-button:focus-visible,
#login-button:focus-visible {
  outline: none;
  box-shadow: var(--primary-shadow-hover), 0 0 0 4px rgba(255,255,255,0.3);
}

.nav-btn:focus-visible,
.settings-btn:focus-visible,
#pause-button:focus-visible,
#close-settings:focus-visible,
#close-setup-settings:focus-visible {
  outline: none;
  box-shadow: var(--secondary-shadow-hover), 0 0 0 3px rgba(255,255,255,0.15);
}

#exit-workout-button:focus-visible,
#logout-button:focus-visible,
#reset-start-point:focus-visible {
  outline: none;
  box-shadow: var(--destructive-shadow-hover), 0 0 0 3px rgba(255,255,255,0.25);
}

/* ========================================
   7. GENERIC BUTTON RESET
   Purpose: Ensure all other buttons follow system
   ======================================== */
button {
  appearance: none;
  border-radius: 10px;
  text-transform: uppercase;
  cursor: pointer;
  font-family: 'Staatliches', sans-serif;
  letter-spacing: 0.1em;
}

/* Remove any gradient backgrounds */
button,
#start-button-bottom,
.start-button,
#login-button,
#close-settings,
#close-setup-settings {
  background-image: none !important;
}





/* Replace every bottom-buttons-container block with this ONE */
#bottom-buttons-container{
  position: fixed;
  left: 0; right: 0; bottom: 0;
  width: 100vw;
  height: var(--footer-total);           /* exact rendered height */
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 0 20px;                       
  padding-bottom: env(safe-area-inset-bottom, 0px); /* iOS safe area */
  background: linear-gradient(to top, rgba(0,0,0,.95), rgba(0,0,0,.9) 80%, transparent);
  backdrop-filter: blur(10px);
  z-index: 9999;
  transform: translateZ(0);
}

/* Hide bottom buttons on login screen */
#login-screen ~ #bottom-buttons-container,
body:has(#login-screen:not([style*="display: none"])) #bottom-buttons-container {
  display: none !important;
}

/* Show bottom buttons only when main-app is visible */
#main-app:not([style*="display: none"]) ~ #bottom-buttons-container {
  display: flex !important;
}


/* Replace ALL other #main-app rules for height/padding with this */
#main-app{
  height: min(
    calc(var(--dvh-px) - var(--header-height) - var(--footer-total)),
    var(--main-app-visible-height, calc(var(--dvh-px) - var(--header-height) - var(--footer-total)))
  );
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;

  /* NO padding-bottom - container height already ends at footer's edge */
}

/* Add bottom margin to last element so content doesn't touch button when scrolled */
#main-app > *:last-child {
  margin-bottom: clamp(25px, 5vw, 35px);
}






/* Remove any older footer rule that sets a fixed height + big vertical % padding */


:root{
  --footer-base: 72px;                   /* tune to your design */
  --footer-safe: env(safe-area-inset-bottom, 0px);
  --footer-total: calc(var(--footer-base) + var(--footer-safe));
}
/* ====== TRAINING SELECTOR (LOGIN SCREEN) ====== */
/*
  TRAINING SELECTOR:
  - Expands to fill available space above the login card
  - Flex column keeps instruction text and artwork evenly spaced
  - Maintains aspect ratio of the training image
*/
.training-selector-container {
  margin: 0;
  width: 100%;
  max-width: 600px; /* ✅ FIX: Aumentato per contenere wrapper di 560px */
  padding: var(--training-selector-padding-y) 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, calc(var(--dvh-px) * 0.03), 24px);
  min-height: var(--training-selector-min-height);
  /* ✅ FIX: Rimosso max-height e overflow hidden per mostrare l'immagine completa */
}

/*
  INSTRUCTION TEXT:
  - Clear and readable on all screens
  - Subtle animation to draw attention
*/
.selector-instruction {
  text-align: center;
  color: var(--color-light-grey);
  font-size: clamp(13px, 3vw, 17px); /* Smooth scaling */
  margin: 0;
  font-weight: 300;
  letter-spacing: 0.5px;
  animation: pulse-subtle 2s ease-in-out infinite;
  flex-shrink: 0;
  line-height: 1.3;
}

@keyframes pulse-subtle {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/*
  TRAINING IMAGE WRAPPER:
  - Maintains square aspect ratio (1:1)
  - Scales to fit available space
  - Responsive across all devices
*/
.training-image-wrapper {
  position: relative;
  width: 100%; /* Fill container width */
  max-width: min(85vw, 460px); /* Allow image to scale with container */
  margin: 0 auto;
  border-radius: clamp(12px, 2vw, 18px);
  overflow: hidden;
  box-shadow: 0 clamp(6px, 1vw, 12px) clamp(20px, 4vw, 40px) rgba(0, 0, 0, 0.5);
  flex: 1 1 auto;
  /* CRITICAL: Maintain square aspect ratio */
  aspect-ratio: 1 / 1;
  /* Limit height based on available viewport */
  max-height: min(
    100%,
    var(--training-image-max-height),
    var(--training-selector-js-height, var(--training-image-max-height))
  );
  min-height: clamp(130px, calc(var(--dvh-px) * 0.32), 300px); /* Minimum readable size */
}

.training-base-image {
  width: 100%;
  height: 100%;
  object-fit: cover; /* ✅ Riempie completamente il wrapper */
  display: block;
  object-position: center;
}

/* Clickable zones overlaid on image - EXACT size match */
.training-zone {
  position: absolute;
  /* Zones cover exact image area */
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: transparent;
  border: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  /* Mobile optimizations */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: box-shadow, border-color;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Zone positioning - L-shaped layout - EXACT image coverage */
.nutrition-zone {
  top: 0;
  left: 0;
  width: 30%;
  height: 100%;
  background: linear-gradient(to right, rgba(176, 176, 176, 0.05), transparent);
  border-right: 1px solid rgba(125, 125, 125, 0.2);
}

.aerobic-zone {
  top: 0;
  left: 30%;
  width: 70%; /* ✅ FIX: 30% + 70% = 100% */
  height: 43%;
  background: linear-gradient(to bottom, rgba(125, 125, 125, 0.05), transparent);
  border-bottom: 1px solid rgba(125, 125, 125, 0.2);
}

.muscle-zone {
  top: 43%;
  left: 30%;
  width: 70%; /* ✅ FIX: 30% + 70% = 100% */
  height: 57%;
  background: linear-gradient(to bottom, rgba(77, 77, 77, 0.05), transparent);
}

/* Hover/Tap effects */
.training-zone:active {
  transform: scale(0.98);
  background: rgba(255, 255, 255, 0.1);
}

.training-zone.tapped {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid var(--color-white);
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.2);
  animation: tap-pulse 0.6s ease-out;
}

/* Specific border styling for each zone when tapped */
.nutrition-zone.tapped {
  border-right: 2px solid var(--color-white);
  border-top: 2px solid var(--color-white);
  border-bottom: 2px solid var(--color-white);
  border-left: 2px solid var(--color-white);
}

.aerobic-zone.tapped {
  border-top: 2px solid var(--color-white);
  border-right: 2px solid var(--color-white);
  border-bottom: 2px solid var(--color-white);
  border-left: none;
}

.muscle-zone.tapped {
  border-bottom: 2px solid var(--color-white);
  border-right: 2px solid var(--color-white);
  border-top: 2px solid var(--color-white);
  border-left: none;
}

@keyframes tap-pulse {
  0% {
    box-shadow: inset 0 0 0 rgba(255, 255, 255, 0);
  }
  50% {
    box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.4);
  }
  100% {
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.2);
  }
}

.zone-label {
  position: absolute;
  color: transparent;
  font-size: clamp(16px, 4vw, 20px);
  font-weight: bold;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  letter-spacing: clamp(1.5px, 0.4vw, 2px);
  text-transform: uppercase;
  line-height: 1.2;
}

.tap-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateZ(0);
  -webkit-transform: translate(-50%, -50%) translateZ(0);
  font-size: clamp(20px, 5vw, 28px);
  font-weight: bold;
  color: var(--color-white);
  text-transform: uppercase;
  letter-spacing: clamp(2px, 0.5vw, 3px);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  text-shadow: 
    0 0 clamp(8px, 2vw, 10px) rgba(0, 0, 0, 0.8),
    0 0 clamp(15px, 4vw, 20px) rgba(0, 0, 0, 0.6),
    0 clamp(1px, 0.3vw, 2px) clamp(3px, 0.8vw, 4px) rgba(0, 0, 0, 0.9);
  will-change: opacity, transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Ripple container */
.ripple-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* Ripple rings - real DOM elements for better mobile support */
.ripple-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  transform: translate(-50%, -50%) translateZ(0);
  -webkit-transform: translate(-50%, -50%) translateZ(0);
  opacity: 0;
  pointer-events: none;
  will-change: width, height, opacity;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.ripple-1 {
  border: clamp(2px, 0.5vw, 3px) solid rgba(176, 176, 176, 0.5);
  z-index: 6;
}

.ripple-2 {
  border: clamp(1px, 0.3vw, 2px) solid rgba(125, 125, 125, 0.4);
  z-index: 5;
}

/* Apply animations when zone is animating - MOBILE OPTIMIZED */
.training-zone.animating .ripple-1 {
  animation: ripple-wave 2s ease-out forwards !important;
  -webkit-animation: ripple-wave 2s ease-out forwards !important;
}

.training-zone.animating .ripple-2 {
  animation: ripple-wave-delayed 2s ease-out 0.3s forwards !important;
  -webkit-animation: ripple-wave-delayed 2s ease-out 0.3s forwards !important;
}

/* Ripple wave animation - First ring */
@keyframes ripple-wave {
  0% {
    width: 0;
    height: 0;
    opacity: 0;
    transform: translate(-50%, -50%) translateZ(0);
  }
  10% {
    opacity: 1;
  }
  100% {
    width: min(300px, 80vw);
    height: min(300px, 80vw);
    opacity: 0;
    border-width: 1px;
    transform: translate(-50%, -50%) translateZ(0);
  }
}

@-webkit-keyframes ripple-wave {
  0% {
    width: 0;
    height: 0;
    opacity: 0;
    -webkit-transform: translate(-50%, -50%) translateZ(0);
  }
  10% {
    opacity: 1;
  }
  100% {
    width: min(300px, 80vw);
    height: min(300px, 80vw);
    opacity: 0;
    border-width: 1px;
    -webkit-transform: translate(-50%, -50%) translateZ(0);
  }
}

/* Ripple wave animation - Second ring (delayed) */
@keyframes ripple-wave-delayed {
  0% {
    width: 0;
    height: 0;
    opacity: 0;
    transform: translate(-50%, -50%) translateZ(0);
  }
  10% {
    opacity: 1;
  }
  100% {
    width: min(350px, 90vw);
    height: min(350px, 90vw);
    opacity: 0;
    border-width: 1px;
    transform: translate(-50%, -50%) translateZ(0);
  }
}

@-webkit-keyframes ripple-wave-delayed {
  0% {
    width: 0;
    height: 0;
    opacity: 0;
    -webkit-transform: translate(-50%, -50%) translateZ(0);
  }
  10% {
    opacity: 1;
  }
  100% {
    width: min(350px, 90vw);
    height: min(350px, 90vw);
    opacity: 0;
    border-width: 1px;
    -webkit-transform: translate(-50%, -50%) translateZ(0);
  }
}

/* Glowing animation effect - more subtle to complement ripples */
@keyframes glow-pulse {
  0% {
    box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0);
    border-color: transparent;
  }
  30% {
    box-shadow: inset 0 0 40px rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
  }
  100% {
    box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0);
    border-color: transparent;
  }
}

@-webkit-keyframes glow-pulse {
  0% {
    box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0);
    border-color: transparent;
  }
  30% {
    box-shadow: inset 0 0 40px rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
  }
  100% {
    box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0);
    border-color: transparent;
  }
}

/* Text fade in/out animation with mobile optimization */
@keyframes text-appear {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5) translateZ(0);
  }
  40% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) translateZ(0);
  }
  60% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) translateZ(0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5) translateZ(0);
  }
}

@-webkit-keyframes text-appear {
  0% {
    opacity: 0;
    -webkit-transform: translate(-50%, -50%) scale(0.5) translateZ(0);
  }
  40% {
    opacity: 1;
    -webkit-transform: translate(-50%, -50%) scale(1) translateZ(0);
  }
  60% {
    opacity: 1;
    -webkit-transform: translate(-50%, -50%) scale(1) translateZ(0);
  }
  100% {
    opacity: 0;
    -webkit-transform: translate(-50%, -50%) scale(0.5) translateZ(0);
  }
}

/* Apply animation to zones - MOBILE OPTIMIZED WITH !important */
.training-zone.animating {
  animation: glow-pulse 2s ease-out forwards !important;
  -webkit-animation: glow-pulse 2s ease-out forwards !important;
  border: 2px solid transparent !important;
}

.training-zone.animating .tap-text {
  animation: text-appear 2s ease-out forwards !important;
  -webkit-animation: text-appear 2s ease-out forwards !important;
}

/* Position tap icons appropriately for each zone */
.nutrition-zone .tap-icon {
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
}

.aerobic-zone .tap-icon {
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
}

.muscle-zone .tap-icon {
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
}


/* Bottom Sheet */
.bottom-sheet {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.bottom-sheet.active {
  pointer-events: all;
  opacity: 1;
}

.bottom-sheet-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.bottom-sheet.active .bottom-sheet-overlay {
  opacity: 1;
}

.bottom-sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: env(safe-area-inset-bottom, 0px); /* ✅ CRITICAL: Sopra la barra Safari */
  background: var(--color-dark-grey);
  border-radius: clamp(20px, 5vw, 24px) clamp(20px, 5vw, 24px) 0 0;
  /* Non andare sotto la barra di Safari */
  padding: var(--bottom-sheet-padding-y) var(--bottom-sheet-side-padding) max(16px, var(--safe-bottom));
  /* Limite d'altezza = viewport visibile */
  height: calc(var(--dvh-px) * 0.85);
  max-height: calc(var(--dvh-px) * 0.85 - var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  gap: var(--bottom-sheet-gap);
  overflow: hidden;
  will-change: transform;
}

.bottom-sheet.active .bottom-sheet-panel {
  transform: translateY(0);
}

/* Contenuto scrollabile del bottom sheet */
.bottom-sheet__body {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  max-height: calc(var(--dvh-px) - 96px); /* spazio per header del sheet */
  padding: 12px 16px max(16px, var(--safe-bottom));
}

/* Se hai CTA o action bar fissata dentro il sheet */
.bottom-sheet__actions {
  position: sticky;
  bottom: 0;
  padding: 12px 16px max(16px, var(--safe-bottom));
  background: inherit;
}

.bottom-sheet-handle {
  width: clamp(35px, 8vw, 40px);
  height: clamp(3px, calc(var(--dvh-px) * 0.08), 4px);
  background: var(--color-medium-grey);
  border-radius: clamp(1.5px, calc(var(--dvh-px) * 0.04), 2px);
  margin: 0 auto clamp(15px, calc(var(--dvh-px) * 0.03), 20px);
  opacity: 0.5;
}

.bottom-sheet-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--bottom-sheet-gap);
  flex: 1 1 auto;
}

.bottom-sheet-content h3 {
  color: var(--color-white);
  font-size: clamp(20px, 5vw, 24px);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Carousel Container */
.carousel-container {
  position: relative;
  width: 100%;
  /* ✅ FIX: dimensioni esplicite per evitare problemi di flexbox layout su Safari */
  flex: 0 0 clamp(160px, calc(var(--dvh-px) * 0.32), 280px);
  height: clamp(160px, calc(var(--dvh-px) * 0.32), 280px);
  max-height: clamp(160px, calc(var(--dvh-px) * 0.32), 280px);
  min-height: clamp(160px, calc(var(--dvh-px) * 0.32), 280px);
  overflow: hidden;
  border-radius: clamp(10px, 2.5vw, 12px);
}

.carousel-wrapper {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
}

.carousel-track {
  display: flex;
  height: 100%;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

.carousel-slide {
  min-width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
}

.carousel-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Carousel Navigation Buttons */
.carousel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.9);
  color: var(--color-black);
  border: none;
  width: clamp(35px, 8vw, 45px);
  height: clamp(35px, 8vw, 45px);
  border-radius: 50%;
  font-size: clamp(20px, 5vw, 28px);
  cursor: pointer;
  z-index: 10;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.carousel-btn:hover {
  background: var(--color-white);
  transform: translateY(-50%) scale(1.1);
}

.carousel-btn:active {
  transform: translateY(-50%) scale(0.95);
}

.carousel-btn.prev {
  left: clamp(8px, 2vw, 12px);
}

.carousel-btn.next {
  right: clamp(8px, 2vw, 12px);
}

.carousel-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.carousel-btn:disabled:hover {
  transform: translateY(-50%) scale(1);
}

/* Carousel Dots */
.carousel-dots {
  display: flex;
  justify-content: center;
  gap: clamp(6px, 1.5vw, 8px);
  margin-top: clamp(10px, calc(var(--dvh-px) * 0.02), 12px);
  padding: clamp(5px, calc(var(--dvh-px) * 0.01), 8px) 0;
  flex-shrink: 0;
}

.carousel-dot {
  width: clamp(7px, 1.8vw, 10px);
  height: clamp(7px, 1.8vw, 10px);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 0;
}

.carousel-dot.active {
  background: var(--color-white);
  transform: scale(1.3);
}

.carousel-dot:hover:not(.active) {
  background: rgba(255, 255, 255, 0.5);
  transform: scale(1.1);
}

.bottom-sheet-content p {
  color: rgba(176, 176, 176, 0.8);
  font-size: clamp(12px, 2.5vw, 13px);
  margin: 0;
  line-height: 1.4;
  flex-shrink: 0;
  font-style: italic;
  text-align: center;
}

/* Main text that syncs with carousel */
.sheet-main-text {
  color: rgba(200, 200, 200, 0.95) !important;
  font-size: clamp(13px, 3vw, 15px) !important;
  font-style: normal !important;
  font-weight: 400;
  line-height: 1.5;
  text-align: center;
  margin: 0;
  padding: 0 clamp(10px, 2vw, 15px);
  flex-shrink: 0;
}

/* Carousel text overlay (shown when details expanded) */
.carousel-text-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, 
    rgba(0, 0, 0, 0.9) 0%, 
    rgba(0, 0, 0, 0.75) 40%,
    rgba(0, 0, 0, 0.5) 70%,
    rgba(0, 0, 0, 0.3) 100%);
  display: none;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.5vw, 20px);
  z-index: 10;
  pointer-events: none;
}

.carousel-text-overlay p {
  color: #FFFFFF !important;
  font-size: clamp(13px, 3vw, 15px) !important;
  font-weight: 500 !important;
  line-height: 1.3 !important;
  text-align: center !important;
  margin: 0 !important;
  padding: 0 clamp(5px, 1.5vw, 10px) !important;
  font-style: normal !important;
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.9);
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  max-width: 100%;
  hyphens: auto;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.sheet-btn {
  padding: clamp(14px, calc(var(--dvh-px) * 0.03), 16px) clamp(20px, 4vw, 24px);
  border-radius: clamp(10px, 2.5vw, 12px);
  font-size: clamp(14px, 3vw, 16px);
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sheet-btn.primary {
  background: var(--color-white);
  color: var(--color-black);
}

.sheet-btn.primary:active {
  transform: scale(0.97);
  background: var(--color-light-grey);
}

.sheet-btn.secondary {
  background: transparent;
  color: var(--color-white);
  border: 2px solid var(--color-medium-grey);
}

.sheet-btn.secondary:active {
  transform: scale(0.97);
  background: rgba(255, 255, 255, 0.05);
}

/* Details Toggle Button */
.details-toggle-btn {
  width: 100%;
  padding: 10px 15px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  color: var(--color-white);
  font-family: 'Staatliches', sans-serif;
  font-size: clamp(13px, 2.8vw, 15px);
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: clamp(8px, calc(var(--dvh-px) * 0.05), 12px) 0;
  flex-shrink: 0;
}

.details-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

.details-toggle-btn:active {
  transform: scale(0.98);
}

.details-toggle-btn .toggle-icon {
  font-size: clamp(16px, 3.5vw, 20px);
  transition: transform 0.3s ease;
}

.details-toggle-btn.expanded .toggle-icon {
  transform: rotate(180deg);
}

/* Details Section */
.details-section {
  display: none;
  flex-direction: column;
  gap: clamp(10px, calc(var(--dvh-px) * 0.02), 14px);
  margin: clamp(8px, calc(var(--dvh-px) * 0.05), 12px) 0;
  flex-shrink: 1;
  animation: slideDown 0.3s ease;
  overflow-y: auto;
  padding-right: 5px;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.detail-item {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: clamp(12px, calc(var(--dvh-px) * 0.05), 16px) clamp(14px, 3vw, 18px);
}

.detail-item h4 {
  color: var(--color-white);
  font-family: 'Staatliches', sans-serif;
  font-size: clamp(14px, 3vw, 16px);
  letter-spacing: 1px;
  margin: 0 0 clamp(6px, calc(var(--dvh-px) * 0.01), 8px) 0;
  text-transform: uppercase;
}

.detail-item p {
  color: rgba(176, 176, 176, 0.95);
  font-size: clamp(12px, 2.5vw, 13px);
  line-height: 1.5;
  margin: 0;
}

/* When details are expanded - carousel becomes smaller */
.bottom-sheet.details-expanded .carousel-container {
  flex: 0 0 clamp(80px, calc(var(--dvh-px) * 0.18), 120px);
  max-height: clamp(80px, calc(var(--dvh-px) * 0.18), 120px);
  min-height: clamp(80px, calc(var(--dvh-px) * 0.18), 120px);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.bottom-sheet.details-expanded .details-section {
  max-height: calc(var(--dvh-px) * 0.50);
  overflow-y: auto;
  flex: 1 1 auto;
}

/* Smooth scrollbar for details */
.details-section::-webkit-scrollbar {
  width: 6px;
}

.details-section::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.details-section::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.details-section::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Mobile optimization - Minor adjustments only */
/* Landscape orientation - optimize for horizontal space */
@media (max-height: 600px) and (orientation: landscape) {
  /* Use more horizontal space, less vertical */
  #login-screen {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: clamp(16px, 5cqw, 32px);
    padding: clamp(16px, calc(var(--dvh-px) * 0.04), 26px) clamp(4vw, 6vw, 8vw);
  }
  
  .training-selector-container {
    /* ✅ FIX: Rimosso max-block-size */
    max-inline-size: 55cqw;
    flex: 1;
  }
  
  .login-card {
    max-block-size: 70cqh;
    max-inline-size: 40cqw;
    flex: 0 0 auto;
  }
  
  .training-image-wrapper {
    width: min(40vw, 420px);   /* ✅ FIX: Larghezza forzata */
    height: min(40vw, 420px);  /* ✅ FIX: Altezza UGUALE */
  }
}

/* Tablet devices - optimize for medium screens */
@media (min-width: 481px) and (max-width: 1024px) {
  #login-screen {
    gap: clamp(10px, 2.5cqh, 20px);
    padding-left: clamp(28px, 6vw, 64px);
    padding-right: clamp(28px, 6vw, 64px);
  }
  
  .training-selector-container {
    max-inline-size: min(70vw, 540px);
    /* ✅ FIX: Rimosso max-block-size */
    gap: clamp(12px, 2cqh, 20px);
  }
  
  .training-image-wrapper {
    width: min(62vw, 500px);   /* ✅ FIX: Larghezza forzata */
    height: min(62vw, 500px);  /* ✅ FIX: Altezza UGUALE */
  }
  
  .login-card {
    max-inline-size: min(65vw, 420px);
    max-block-size: 40cqh;
  }
  
  .login-card h3 {
    font-size: clamp(18px, 2.5cqh, 24px);
  }
  
  .login-card input[type="text"],
  .login-card input[type="password"] {
    font-size: clamp(15px, 1.9cqh, 18px);
  }
  
  .login-card button {
    font-size: clamp(16px, 2cqh, 19px);
  }
  
  .selector-instruction {
    font-size: clamp(14px, 1.9cqh, 17px);
  }
}

/* Desktop and larger - prevent elements from getting too large */
@media (min-width: 1025px) {
  #login-screen {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: clamp(24px, 5cqw, 48px);
    padding-left: clamp(32px, 6vw, 80px);
    padding-right: clamp(32px, 6vw, 80px);
  }

  .training-selector-container {
    /* ✅ FIX: Rimosso max-block-size */
    max-inline-size: 55cqw;
    flex: 1;
  }

  .login-card {
    max-block-size: 70cqh;
    max-inline-size: 40cqw;
    flex: 0 0 auto;
    max-width: 440px;
  }
  
  .training-image-wrapper {
    width: min(36vw, 420px);   /* ✅ FIX: Larghezza forzata */
    height: min(36vw, 420px);  /* ✅ FIX: Altezza UGUALE */
  }
  
  .login-card h3 {
    font-size: clamp(20px, 2cqh, 26px);
  }
  
  .login-card input[type="text"],
  .login-card input[type="password"] {
    font-size: clamp(16px, 1.8cqh, 19px);
  }
  
  .login-card button {
    font-size: clamp(17px, 2cqh, 20px);
  }
  
  .selector-instruction {
    font-size: clamp(15px, 1.8cqh, 18px);
  }
  
  /* Add hover effects only on desktop */
  .training-zone:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
  }
  
  .carousel-btn:hover {
    background: var(--color-white);
    transform: translateY(-50%) scale(1.15);
  }
  
  .sheet-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  }
  
  .login-card:hover {
    box-shadow: var(--shadow-xl), var(--shadow-glow);
    border-color: rgba(255, 255, 255, 0.25);
  }
}

body:has(#exercise-container[style*="display: flex"]) {
  overflow: hidden !important;
  position: fixed !important;
}


/* === LOGIN SCREEN: FIT TO VISIBLE HEIGHT + NO SCROLL (OVERRIDES) === */
#login-screen{
  /* Use JS-measured visible height, fall back to CSS calc */
  block-size: var(--login-screen-height-js, var(--login-screen-height));
  max-block-size: var(--login-screen-height-js, var(--login-screen-height));
  /* Prevent any scroll inside login screen */
  overflow: clip; /* replaces previous overflow:auto */
  /* Make the container a sizing context for cqh/cqw units */
  container-type: size;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;

  /* Ensure padding itself doesn’t create overflow */
  padding-block: 12px max(16px, env(safe-area-inset-bottom, 0px));
  padding-inline: 16px;
  gap: clamp(14px, 2.6cqh, 28px);/* vertical space between sections */
}

/* Allocate a fixed % of the login screen height to each block via cqh */
.selector-instruction{
  /* ~8% of container height */
  flex: 0 0 8cqh;
  max-block-size: 8cqh;
  min-block-size: 0;
}

.training-selector-container{
  /* ✅ FIX: Rimosso flex e max-block-size per permettere espansione naturale */
  min-block-size: 0; /* allow flexbox to actually clamp */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Keep the square hero bounded inside its slice */
.training-image-wrapper{
  width: min(80vw, 480px);   /* ✅ Ridotto */
  height: min(80vw, 480px);  /* ✅ Ridotto */
  aspect-ratio: 1 / 1;
}

/* ~38% of container height for the login card */
.login-card{
  flex: 0 0 38cqh;
  max-block-size: 38cqh;
  min-block-size: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-block-start: clamp(8px, 1.2cqh, 14px);
  /* Inputs/buttons scale with height portion; no hard mins that force overflow */
}

.login-card input,
.login-card button{
  /* Touch target scales with container height; avoid tall mins that push overflow */
  block-size: clamp(36px, 6cqh, 48px);
  font-size: clamp(12px, 1.7cqh, 16px);
}

/* Disable page scrolling while login is visible */
html.no-scroll,
body.no-scroll{
  height: var(--dvh-px);    /* true dynamic viewport height */
  overflow: hidden;  /* no page scroll */
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
}


/* === FINAL MOBILE-SAFE OVERRIDES FOR LOGIN LAYOUT (append at EOF) === */

/* Lock screen size to the JS-measured visible viewport height */
#login-screen{
  block-size: var(--login-screen-height-js, var(--login-screen-height));
  max-block-size: var(--login-screen-height-js, var(--login-screen-height));
  container-type: size;              /* enables cqh/cqw sizing */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow: clip;                    /* hard stop: no inner scroll */
  padding-block: 12px max(16px, env(safe-area-inset-bottom, 0px));
  padding-inline: 16px;
  gap: 2cqh;                         /* vertical space we account for */
}

/* Make flex children clamp instead of forcing overflow */
#login-screen > * { min-block-size: 0; }

/* Helper text */
.selector-instruction{
  flex: 0 0 6cqh;
  max-block-size: 6cqh;
  min-block-size: 0;
  font-size: clamp(12px, 1.8cqh, 16px);
}

/* Selector block */
.training-selector-container{
  /* ✅ FIX: Rimosso flex e max-block-size per permettere espansione naturale */
  min-block-size: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.5cqh, 12px);
}

/* Square hero inside the selector */
.training-image-wrapper{
  width: min(80vw, 480px);   /* ✅ Ridotto */
  height: min(80vw, 480px);  /* ✅ Ridotto */
  aspect-ratio: 1 / 1;
  min-block-size: 0;
}

/* ✅ Immagine riempie completamente il wrapper */
.training-base-image{
  width: 100%;
  height: 100%;
  object-fit: cover !important;
  object-position: center;
  display: block;
}

/* Login card */
.login-card{
  flex: 0 0 36cqh;
  max-block-size: 36cqh;
  min-block-size: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 1.5cqh, 12px);
}

/* Inputs/buttons scale with container height; avoid tall mins that push overflow */
.login-card input,
.login-card button{
  block-size: clamp(36px, 6cqh, 48px);
  font-size: clamp(12px, 1.7cqh, 16px);
}

/* Ensure page cannot scroll while login is visible (JS toggles the class) */
html.no-scroll, body.no-scroll{
  height: var(--dvh-px);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
}

/* Tablet/Desktop can breathe more without affecting mobile fit */
@media (min-width: 768px){
  #login-screen{
    gap: clamp(16px, 2.5cqh, 28px);
    padding-inline: clamp(24px, 6vw, 72px);
  }
}


/* === PAGE-SAFE WRAPPER FOR NON-WORKOUT PAGES === */
/* Wrapper "sicuro" per pagine non-workout */
.page-safe {
  /* Altezza reale visibile meno l'header */
  min-block-size: calc(var(--dvh-px) - var(--header-height));
  /* Evita che il contenuto finisca sotto le barre */
  padding-block-start: var(--safe-top);
  padding-block-end: var(--safe-bottom); /* SOLO safe-area, non CTA (è absolute) */
  overflow-x: hidden;
}

/* CTA/bottom sheet "appoggiata" al safe-area */
#start-cta, 
#training-bottom-sheet .bottom-sheet-panel,
.bottom-sheet-fixed {
  position: absolute; /* absolute/fixed = NON prende spazio nel flow */
  bottom: var(--safe-bottom); /* <- non tocca la toolbar */
  padding-block-end: max(16px, var(--safe-bottom));
}

/* Scroll container */
.scroll-container {
  overflow-y: auto;
  overflow-x: hidden;
}

/* Qualsiasi sezione che arriva fino in fondo deve rispettare i safe-area */
.page-safe [data-reach-bottom="true"] {
  padding-block-end: max(16px, var(--safe-bottom));
}

/* ====== AUTH MODAL STYLES (LOGIN/SIGNUP) ====== */
.auth-modal input {
  font-family: 'Roboto Mono', monospace !important;
}

/* Password input wrapper per il toggle show/hide */
.auth-modal .password-wrapper {
  position: relative !important;
  width: 100% !important;
  margin-bottom: 12px !important;
  display: block !important;
}

.auth-modal .password-wrapper input {
  width: 100% !important;
  padding-right: 45px !important;
  margin-bottom: 0 !important;
  display: block !important;
  box-sizing: border-box !important;
}

.auth-modal .password-toggle {
  position: absolute !important;
  right: 12px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer !important;
  padding: 5px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s ease !important;
  color: #B0B0B0 !important;
  width: 30px !important;
  height: 30px !important;
  z-index: 10 !important;
}

.auth-modal .password-toggle:hover {
  color: #FFFFFF !important;
  transform: translateY(-50%) scale(1.1) !important;
}

.auth-modal .password-toggle svg {
  width: 20px !important;
  height: 20px !important;
  pointer-events: none !important;
}