:root {
  --bg: #0d0d0d;
  --card: #1a1a1a;
  --card2: #222;
  --border: #2a2a2a;
  --primary: #6366f1;
  --primary-dim: #4f52c4;
  --accent: #22d3ee;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #f1f5f9;
  --muted: #64748b;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  height: 100%;
  overscroll-behavior: none;
}

/* XP HEADER */
#xp-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 8px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#level-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

#level-num {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#level-name {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

#xp-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

#xp-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

#xp-label {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}

/* MAIN */
#app-content {
  margin-top: 80px;
  padding: 16px;
  padding-bottom: 100px;
  min-height: calc(100vh - 150px);
}

/* BOTTOM NAV */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.nav-btn span {
  font-size: 10px;
  font-weight: 500;
}

.nav-btn.active {
  color: var(--primary);
}

/* CARDS */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dim));
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-ghost {
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

/* FORM ELEMENTS */
.form-group {
  margin-bottom: 14px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input, select, textarea {
  width: 100%;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

select option { background: var(--card); }

/* EXERCISE LOG */
.exercise-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.exercise-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card2);
}

.exercise-name {
  font-weight: 600;
  font-size: 15px;
}

.exercise-xp-badge {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  background: rgba(34,211,238,0.1);
  padding: 2px 8px;
  border-radius: 10px;
}

.sets-table {
  width: 100%;
  border-collapse: collapse;
}

.sets-table th {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  padding: 8px 8px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.sets-table td {
  padding: 6px 4px;
  text-align: center;
}

.sets-table input {
  width: 100%;
  min-width: 45px;
  padding: 8px 4px;
  text-align: center;
  font-size: 14px;
  border-radius: 6px;
}

.set-xp-cell {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  min-width: 36px;
}

.set-row.completed { background: rgba(34,197,94,0.05); }
.set-row.skipped { background: rgba(239,68,68,0.05); }

/* PR BADGE */
.pr-badge {
  display: inline-block;
  background: var(--warning);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

/* HISTORY */
.session-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: border-color 0.2s;
}

.session-item:active { border-color: var(--primary); }

.session-date { font-size: 13px; color: var(--muted); }
.session-plan { font-weight: 600; margin-top: 2px; }
.session-xp {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

/* MODAL / OVERLAY SESSION DETAIL */
.session-detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  overflow-y: auto;
  padding: 16px;
  padding-top: 0;
}

.session-detail-header {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 16px 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

/* SCHEDE */
.plan-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.plan-tab {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}

.plan-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.exercise-edit-row {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}

.ex-edit-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
}

.ex-edit-row input {
  font-size: 14px;
  padding: 8px 10px;
}

.ex-edit-row .small-input {
  width: 56px;
  text-align: center;
}

/* CHART */
.chart-container {
  position: relative;
  height: 180px;
  margin-top: 10px;
}

/* TOAST */
#toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  white-space: nowrap;
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }

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

/* LEVEL UP OVERLAY */
#levelup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
}

#levelup-overlay.hidden { display: none; }

#levelup-card {
  background: var(--card);
  border: 1px solid var(--primary);
  border-radius: 20px;
  padding: 40px 30px;
  text-align: center;
  max-width: 300px;
  width: 90%;
  box-shadow: 0 0 40px rgba(99,102,241,0.3);
}

#levelup-emoji { font-size: 56px; margin-bottom: 12px; }
#levelup-card h2 {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

#levelup-card p { color: var(--muted); margin-bottom: 24px; }
#levelup-card button {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 32px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* STREAK */
.streak-display {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.streak-fire { font-size: 22px; }

/* HERO CARD */
.hero-card {
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
  border: none;
}
.hero-level-num {
  font-size: 56px;
  font-weight: 900;
  color: rgba(255,255,255,0.95);
  line-height: 1;
}
.hero-level-name {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
}
.hero-xp-bar {
  height: 8px;
  background: rgba(255,255,255,0.25);
  border-radius: 4px;
  margin-top: 14px;
  overflow: hidden;
}
.hero-xp-fill {
  height: 100%;
  border-radius: 4px;
  background: rgba(255,255,255,0.85);
  transition: width 0.8s cubic-bezier(0.4,0,0.2,1);
}

/* WEEK CALENDAR */
.week-calendar {
  display: flex;
  justify-content: space-between;
  padding: 4px 0 2px;
}
.week-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.week-day-label {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}
.week-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card2);
  transition: background 0.2s;
}
.week-dot.trained { background: var(--primary); border-color: var(--primary); }
.week-dot.today { border-color: var(--accent); border-width: 2.5px; }
.week-dot.trained.today { background: var(--accent); border-color: var(--accent); }

/* LEVEL ROADMAP */
.level-roadmap {
  display: flex;
  overflow-x: auto;
  gap: 10px;
  padding: 4px 0 6px;
  scrollbar-width: none;
}
.level-roadmap::-webkit-scrollbar { display: none; }
.level-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.level-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid transparent;
  transition: transform 0.2s;
}
.level-circle.done { color: #fff; }
.level-circle.current {
  color: #fff;
  transform: scale(1.12);
  border-width: 3px;
  border-color: rgba(255,255,255,0.7);
}
.level-circle.future {
  background: var(--card2) !important;
  border-color: var(--border) !important;
  color: var(--muted);
}
.level-node-name {
  font-size: 9px;
  color: var(--muted);
  text-align: center;
  max-width: 44px;
  line-height: 1.2;
}
/* MULTIPLIER BADGE */
.multiplier-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}
.multiplier-badge.boost {
  background: rgba(34,197,94,0.12);
  color: var(--success);
  border: 1px solid rgba(34,197,94,0.3);
}
.multiplier-badge.malus {
  background: rgba(239,68,68,0.12);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
}
.multiplier-badge.normal {
  background: var(--card2);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* PROGRESS TABS */
.section-tabs {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.section-tabs::-webkit-scrollbar { display: none; }

.section-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.section-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.progress-card {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.progress-card:active { border-color: var(--primary); }
.progress-card.no-data { opacity: 0.45; cursor: default; }
.progress-card-name { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.progress-stats { display: flex; gap: 20px; }
.progress-stat { text-align: center; }
.progress-stat-value { font-size: 17px; font-weight: 700; color: var(--accent); }
.progress-stat-value.pr { color: var(--warning); }
.progress-stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* SECTION SELECT INLINE (progressi) */
.section-select-inline {
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

/* PESI ULTIMA SETTIMANA (log allenamento) */
.last-weights {
  padding: 8px 16px 10px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
}
.last-weights-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.last-session {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 3px 0;
  font-size: 12px;
}
.last-session-date {
  color: var(--muted);
  flex-shrink: 0;
  width: 34px;
}
.last-session-sets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.last-session-sets span {
  color: var(--accent);
  font-weight: 600;
}

/* CHART OVERLAY */
.chart-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  padding: 16px;
  overflow-y: auto;
}
.chart-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-top: 8px;
}

/* SECTION DIVIDER */
.section-divider {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 6px 2px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  margin-top: 6px;
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  fill: var(--border);
  margin-bottom: 12px;
}

.empty-state p { font-size: 14px; }

/* SECTION TITLE */
.section-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
}

.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-accent { color: var(--accent); }
.text-warning { color: var(--warning); }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.hidden { display: none !important; }
