:root {
  --bg: #0a0a0d;
  --bg-elevated: #18161a;
  --bg-elevated-2: #221f24;
  --border: #322e33;
  --text: #f6f3ef;
  --text-muted: #9c9599;
  --accent: #ff6a1a;
  --accent-2: #ffab52;
  --accent-text: #150800;
  --danger: #ff4d4d;
  --warning: #ffcc4d;
  --radius: 16px;
  --radius-sm: 10px;
  --max-width: 480px;
  --shadow-glow: 0 0 0 1px rgba(255, 106, 26, 0.15), 0 8px 24px -8px rgba(255, 106, 26, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
  background-image:
    radial-gradient(600px circle at 10% -10%, rgba(255, 106, 26, 0.14), transparent 60%),
    radial-gradient(500px circle at 110% 20%, rgba(255, 106, 26, 0.08), transparent 55%);
  background-attachment: fixed;
  min-height: 100vh;
}

a { color: var(--accent-2); text-decoration: none; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.4em; letter-spacing: -0.01em; }
h1 { font-size: 1.7rem; font-weight: 800; }
h2 { font-size: 1.2rem; margin-top: 1.6em; }
h3 { font-size: 1.05rem; }

.subtitle { color: var(--text-muted); margin-top: 0; }
.muted { color: var(--text-muted); }
.error { color: var(--danger); }

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

button {
  cursor: pointer;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.6em 1em;
  min-height: 44px;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
button:active { transform: scale(0.96); }
button:disabled { opacity: 0.5; cursor: default; transform: none; }
button:hover:not(:disabled) { border-color: var(--accent); }

.primary-btn {
  background: linear-gradient(135deg, var(--accent), #ff8a3d);
  color: var(--accent-text);
  border: none;
  font-weight: 700;
  width: 100%;
  margin-top: 1em;
  box-shadow: var(--shadow-glow);
}
.primary-btn:hover:not(:disabled) { filter: brightness(1.08); }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6em 0.8em;
  min-height: 44px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 106, 26, 0.2);
}

label { display: block; margin-bottom: 0.6em; font-size: 0.9rem; color: var(--text-muted); }
label input, label select, label textarea { margin-top: 0.3em; color: var(--text); }

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

/* Layout generale */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  padding-top: calc(0.8rem + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(10, 10, 13, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-logo { display: block; filter: drop-shadow(0 2px 6px rgba(255, 106, 26, 0.4)); }
.topnav { display: flex; align-items: center; gap: 0.9rem; font-size: 0.9rem; }
.topnav a { color: var(--text-muted); transition: color 0.15s ease; }
.topnav a:hover { color: var(--accent-2); }
.logout-form { margin: 0; }
.logout-form button {
  background: none; border: none; color: var(--text-muted); padding: 0; min-height: auto;
  font-size: 0.9rem; text-decoration: underline;
}

/* Login */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.8rem;
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
  animation: fadeSlideIn 0.4s ease;
}
.auth-logo {
  display: block;
  margin: 0 auto 0.8em;
  filter: drop-shadow(0 4px 14px rgba(255, 106, 26, 0.45));
}
.auth-card h1 {
  text-align: center;
  margin-bottom: 1em;
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Dashboard */
.category-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-top: 1.2rem;
}
.category-card {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(160deg, var(--bg-elevated-2), var(--bg-elevated));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  min-height: 96px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  animation: fadeSlideIn 0.4s ease backwards;
}
.category-card:nth-child(1) { animation-delay: 0.02s; }
.category-card:nth-child(2) { animation-delay: 0.06s; }
.category-card:nth-child(3) { animation-delay: 0.10s; }
.category-card:nth-child(4) { animation-delay: 0.14s; }
.category-card:nth-child(5) { animation-delay: 0.18s; }
.category-card:active {
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
  transform: scale(0.97);
}
.category-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(120px circle at var(--x, 50%) var(--y, 0%), rgba(255, 106, 26, 0.25), transparent 70%);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.category-card:active::after { opacity: 1; }

/* Genera / esercizi */
.profile-select-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}
.profile-select-row select { flex: 1; min-width: 120px; }

.exercise-list { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1rem; }
.exercise-card, .exercise-log-card, .profile-card, .exclusions-card, .exercise-history-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  animation: fadeSlideIn 0.35s ease backwards;
}
.exercise-list .exercise-card:nth-child(1) { animation-delay: 0.02s; }
.exercise-list .exercise-card:nth-child(2) { animation-delay: 0.07s; }
.exercise-list .exercise-card:nth-child(3) { animation-delay: 0.12s; }
.exercise-list .exercise-card:nth-child(4) { animation-delay: 0.17s; }
.exercise-list .exercise-card:nth-child(5) { animation-delay: 0.22s; }
.exercise-card .muscles { color: var(--text-muted); font-size: 0.85rem; margin: 0.2em 0; text-transform: capitalize; }
.exercise-card .scheme { font-weight: 700; margin: 0.4em 0; color: var(--accent-2); }
.exercise-card .last-perf { color: var(--accent); font-size: 0.9rem; margin: 0.2em 0; }
.exercise-card .note { color: var(--text-muted); font-size: 0.85rem; }
.exercise-card details { margin-top: 0.6em; font-size: 0.85rem; color: var(--text-muted); }
.exercise-card details ol { padding-left: 1.2em; }
.video-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-top: 0.7em;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-2);
}
.video-link:hover { color: var(--accent); }
.exercise-card--fundamental {
  border-color: var(--accent);
  background: linear-gradient(160deg, rgba(255, 106, 26, 0.12), var(--bg-elevated) 60%);
  box-shadow: var(--shadow-glow);
}
.fundamental-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2em 0.7em;
  border-radius: 999px;
  margin: 0 0 0.5em;
}
.card-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.card-actions button { flex: 1; font-size: 0.85rem; }
.exclude-btn { color: var(--danger); }

/* Log serie */
.sets-grid { margin-top: 0.6rem; }
.sets-grid-header, .set-row {
  display: grid;
  grid-template-columns: 2rem 1fr 1fr;
  gap: 0.5rem;
  align-items: center;
  padding: 0.3rem 0;
}
.sets-grid-header { color: var(--text-muted); font-size: 0.8rem; }
.field { margin-top: 1rem; }

.sets-table { width: 100%; border-collapse: collapse; margin-top: 0.6rem; font-size: 0.9rem; }
.sets-table th, .sets-table td { text-align: left; padding: 0.3rem 0.4rem; border-bottom: 1px solid var(--border); }

/* Profili */
.equipment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0.8rem 0;
}
.equipment-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
  margin: 0;
  transition: border-color 0.15s ease;
}
.equipment-chip:has(input:checked) { border-color: var(--accent); }
.profile-card { margin-bottom: 1rem; }
.save-status { font-size: 0.85rem; color: var(--accent-2); margin-left: 0.6rem; }

.exclusion-search { position: relative; margin: 0.8rem 0; }
.search-results {
  list-style: none;
  margin: 0.2rem 0 0;
  padding: 0;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
}
.search-results li { padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); }
.search-results li:hover { background: var(--bg-elevated); color: var(--accent-2); }
.search-results li:last-child { border-bottom: none; }
.search-results:empty { border: none; }

.exclusion-list { list-style: none; padding: 0; margin: 0.6rem 0 0; }
.exclusion-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.remove-exclusion-btn { font-size: 0.8rem; color: var(--danger); min-height: auto; padding: 0.3em 0.6em; }

/* Storico */
.filter-row { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; }
.filter-row select { flex: 1; }
.session-list { list-style: none; padding: 0; }
.session-list li { border-bottom: 1px solid var(--border); padding: 0.7rem 0; transition: background 0.15s ease; }
.session-list li:hover { background: rgba(255, 106, 26, 0.05); }
.session-list .empty { color: var(--text-muted); border-bottom: none; }
.history-chart { width: 100%; height: auto; margin: 0.8rem 0; }

/* Timer di recupero */
.rest-timer-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.8rem calc(0.6rem + env(safe-area-inset-bottom));
  background: rgba(24, 22, 26, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px -10px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.3s ease;
}
.rest-timer-bar.is-done { animation: timerFlash 0.5s ease 3; }
@keyframes timerFlash {
  0%, 100% { background: rgba(24, 22, 26, 0.92); }
  50% { background: rgba(255, 106, 26, 0.35); }
}

.timer-ring-btn {
  position: relative;
  flex-shrink: 0;
  width: 60px;
  height: 60px;
  padding: 0;
  min-height: 0;
  border-radius: 50%;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.timer-ring-btn:active { transform: scale(0.94); }
.timer-ring { width: 60px; height: 60px; transform: rotate(-90deg); position: absolute; inset: 0; }
.timer-ring-bg, .timer-ring-progress {
  fill: none;
  stroke-width: 6;
}
.timer-ring-bg { stroke: var(--border); }
.timer-ring-progress {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 175.9;
  stroke-dashoffset: 175.9;
  transition: stroke-dashoffset 1s linear, stroke 0.2s ease;
}
.timer-ring-progress.is-low { stroke: var(--danger); }
.timer-time {
  position: relative;
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.timer-presets {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.timer-presets::-webkit-scrollbar { display: none; }
.timer-presets button {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0.4em 0.9em;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--bg-elevated-2);
}
.timer-presets button.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  border-color: transparent;
}

.timer-reset-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
  color: var(--text-muted);
}

/* Lascia spazio in fondo alla pagina sessione così il timer fisso non copre l'ultimo contenuto */
.page--has-timer { padding-bottom: 6rem; }

@media (min-width: 540px) {
  .category-grid { grid-template-columns: repeat(3, 1fr); }
  .rest-timer-bar { max-width: var(--max-width); left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; }
}
