/* Ferro — dark theme, mobile-first, grandi target touch (D7) */
:root {
  --bg: #0e0f13;
  --card: #151821;
  --line: #272c39;
  --text: #eceef3;
  --dim: #98a0ae;
  --accent: #ff7a1a;
  --accent-soft: rgba(255, 122, 26, 0.12);
  --ok: #3ddc84;
  --err: #ff5c5c;
  --radius: 16px;
  --tab-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}

/* --- topbar + banner sync (B16) --- */
.hdr {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(14, 15, 19, 0.92);
  backdrop-filter: blur(8px);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.sync {
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 8px 12px;
}
.logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 3px;
  text-transform: uppercase;
}
.logo span { color: var(--accent); }
.conn {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--dim);
  transition: background 0.3s;
}
.conn.ok { background: var(--ok); }
.conn.bad { background: var(--err); }
.top-right { display: flex; align-items: center; gap: 10px; }
.credits-link {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.credits-link:hover, .credits-link:focus { color: var(--accent); outline: none; }

/* --- vista --- */
main {
  flex: 1;
  padding: 18px 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom));
}

/* --- tab bottom --- */
.tabs {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  display: flex;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(14, 15, 19, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  background: none;
  border: none;
  cursor: pointer;
  min-height: var(--tab-h);
  -webkit-tap-highlight-color: transparent;
}
.tab .ico { font-size: 22px; }
.tab[aria-selected="true"] { color: var(--accent); }

/* --- card e contenuto --- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card h2 {
  font-size: 18px;
  margin-bottom: 8px;
}
.card p { color: var(--dim); font-size: 15px; line-height: 1.45; }

/* --- crediti (B18) --- */
.credits h3 {
  color: var(--text);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 14px 0 4px;
}
.credits p { margin-bottom: 2px; }
.credits a { color: var(--accent); text-decoration: none; word-break: break-all; }
.credits a:hover { text-decoration: underline; }
.credits .end { margin-top: 18px; font-size: 13px; }

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--dim);
}
.empty .big { font-size: 40px; display: block; margin-bottom: 12px; }

.list { list-style: none; }
.list li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  font-size: 16px;
}

/* --- bottoni grandi (mani sporche/fredde, D7) --- */
.btn {
  display: inline-block;
  min-height: 52px;
  padding: 0 24px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid rgba(255, 122, 26, 0.4);
  border-radius: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }

/* --- gestione schede (B6) --- */
.btn.new-plan { display: block; width: 100%; margin-bottom: 14px; }
.btn.add { display: block; width: 100%; margin-top: 12px; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--dim); }
.btn.other { display: block; width: 100%; margin-top: 10px; }
.btn.danger {
  background: rgba(255, 92, 92, 0.12);
  border-color: rgba(255, 92, 92, 0.5);
  color: #ff9d9d;
}

.plan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.plan-head h2 { margin-bottom: 0; }

.days { list-style: none; margin-top: 14px; }
.day-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.day-row:last-child { border-bottom: none; }
.day-name {
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  padding: 10px 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}
.chev { color: var(--dim); font-size: 13px; }

/* --- esercizi nel giorno (B7) --- */
.day-exs { flex: 1 1 100%; padding: 0 0 10px; min-width: 0; }
.ex-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
}
.ex-main { flex: 1; min-width: 0; }
.ex-name {
  display: block;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ex-meta { color: var(--dim); font-size: 13px; }
.ex-none { color: var(--dim); font-size: 14px; padding: 6px 0; }
.btn.add.small { min-height: 44px; font-size: 15px; margin-top: 8px; }

/* --- picker esercizi (B7) --- */
.picker-back {
  position: fixed;
  inset: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
}
.picker-head { display: flex; align-items: center; justify-content: space-between; }
.picker-head h2 { font-size: 18px; }
.picker-search, .picker-muscle {
  width: 100%;
  min-height: 52px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  font-size: 16px;
  outline: none;
}
.picker-search:focus { border-color: var(--accent); }
.picker-list {
  flex: 1;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.picker-row:active { background: var(--accent-soft); }
.picker-row:last-child { border-bottom: none; }
.picker-plan {
  margin: 0;
  padding: 12px 14px 4px;
  color: var(--dim);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* --- modale parametri esercizio (B7) --- */
.modal .modal-sub { font-weight: 700; color: var(--text); }
.modal .field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0;
}
.modal .field span { color: var(--dim); font-size: 15px; }
.modal .field input {
  width: 120px;
  min-height: 52px;
  text-align: center;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 17px;
  outline: none;
}
.modal .field input:focus { border-color: var(--accent); }

.row-actions { display: flex; gap: 4px; }
.mini {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--dim);
  background: none;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mini:active { background: var(--accent-soft); }
.mini:disabled { opacity: 0.3; }

/* --- modale (input/conferma) --- */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.modal h3 { font-size: 18px; margin-bottom: 8px; }
.modal p { color: var(--dim); font-size: 15px; line-height: 1.45; margin-bottom: 6px; }
.modal input {
  width: 100%;
  min-height: 52px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 14px;
  font-size: 17px;
  margin: 12px 0 14px;
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; padding: 0 10px; }

/* --- giorni della settimana (B8) --- */
.day-weeks { display: flex; gap: 4px; margin-bottom: 8px; }
.wk {
  flex: 1;
  min-height: 44px;
  background: var(--card);
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.wk.on {
  background: var(--accent-soft);
  border-color: rgba(255, 122, 26, 0.4);
  color: var(--accent);
}

/* --- tab Allenamento (B8) --- */
.page-title { font-size: 20px; margin: 0 0 12px; }
.day-tag {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(255, 122, 26, 0.4);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.tr-list { list-style: none; margin-top: 12px; counter-reset: ex; }
.tr-ex {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  counter-increment: ex;
}
.tr-ex-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.tr-ex-head::before {
  content: counter(ex);
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.tr-ex-head .ex-name { flex: 1; white-space: normal; }

/* --- log serie (B9) --- */
.set-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.set-num { width: 20px; text-align: center; color: var(--dim); font-size: 13px; flex: 0 0 auto; }
.set-kg,
.set-reps {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  padding: 0 10px;
  outline: none;
}
.set-kg:focus,
.set-reps:focus { border-color: var(--accent); }
.set-head {
  margin: 0 0 2px;
  color: var(--dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.set-head span:first-child { flex: 0 0 20px; }
.set-head span:nth-child(2),
.set-head span:nth-child(3) { flex: 1; text-align: center; }
.btn.complete {
  display: block;
  width: 100%;
  margin-top: 16px;
  min-height: 56px;
  font-size: 17px;
  background: var(--accent);
  border-color: var(--accent);
  color: #181008;
}

/* --- toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 92%;
  background: #1d212c;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  z-index: 60;
  text-align: center;
}

/* --- Dettaglio esercizio (B10) --- */
.det-back {
  position: fixed;
  inset: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
}
.det { display: flex; flex-direction: column; gap: 12px; }
.det-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.det-head h2 { font-size: 20px; }
.det-media {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* B17 — skeleton (shimmer) finché la GIF non è caricata: l'apertura del
   dettaglio non resta "vuota" mentre scarica un file pesante. */
.det-media::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(100deg, #10131a 40%, #1a2029 50%, #10131a 60%);
  background-size: 200% 100%;
  animation: det-shimmer 1.1s linear infinite;
}
.det-media.loaded::before,
.det-media.empty::before { display: none; }
@keyframes det-shimmer { to { background-position: -200% 0; } }
.det-gif { width: 100%; display: block; object-fit: contain; background: #000; }
.det-muscles { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
}
.chip.primary { border-color: var(--accent); color: var(--accent); }
.chip.gear { opacity: .75; font-size: 13px; }
.det-desc { font-size: 16px; line-height: 1.55; white-space: pre-line; }
/* il nome dell'esercizio è toccabile (apre il dettaglio) */
.tr-ex-head, .ex-main { cursor: pointer; border-radius: 10px; }
.tr-ex-head:hover, .ex-main:hover { background: rgba(255, 255, 255, .04); }
.ex-info { font-size: 14px; opacity: .7; }

/* --- Timer riposo + ripresa sessione (B11) --- */
.btn.rest {
  width: 100%;
  margin-top: 2px;
  min-height: 48px;
  font-size: 15px;
}
.timer-bar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  z-index: 55;
  background: #241a05;
  border-bottom: 2px solid var(--accent);
  color: var(--accent);
  padding: 14px 16px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}
.timer-bar[hidden] { display: none; }

/* --- Dashboard (B13) --- */
.muted { color: var(--dim); font-size: 15px; }
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.stat {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.stat-v {
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-l {
  font-size: 12.5px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.punch-wrap { overflow-x: auto; }
.punch {
  display: grid;
  grid-template-columns: 18px repeat(12, 13px);
  grid-auto-rows: 13px;
  gap: 3px;
  margin-top: 10px;
  justify-content: start;
}
.p-lab {
  color: var(--dim);
  font-size: 10.5px;
  line-height: 13px;
  text-align: center;
}
.p-cell {
  background: #20242f;
  border-radius: 3px;
}
.p-cell.on { background: var(--accent); }
.p-cell.fut { background: transparent; border: 1px solid var(--line); border-radius: 3px; }
.ex-select {
  width: 100%;
  min-height: 48px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  padding: 0 12px;
  margin-top: 10px;
}
.chart-box {
  height: 240px;
  margin-top: 12px;
  position: relative;
}

/* --- B15 — Affaticamento: body map (body-muscles) --- */
.bm-views { display: flex; gap: 8px; margin: 12px 0; }
.bm-view-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--dim);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.bm-view-btn.on {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
#body-map { display: flex; justify-content: center; }
#body-map svg { max-height: 62vh; }
.bm-info { min-height: 1.5em; margin-top: 6px; }
/* Legenda "Riposo → Massimo" (RIC §4): stessa scala della libreria
   (grigio #94a3b8 → giallo → arancio → rosso scuro). */
.bm-legend { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.bm-legend-label { font-size: 0.8rem; color: var(--dim); white-space: nowrap; }
.bm-legend-bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #94a3b8 0%, #fde047 20%, #f97316 60%, #7f1d1d 100%);
}
.bm-note { font-size: 0.8rem; line-height: 1.4; }
/* Tap = selezione: glow (filtro url(#glow) della libreria) + pulse */
#body-map .body-chart-muscle[aria-label*=" (selected)"] {
  animation: bm-pulse 1.2s ease-in-out infinite;
}
@keyframes bm-pulse {
  0%, 100% { fill-opacity: 1; }
  50% { fill-opacity: 0.4; }
}
