/* MusclePlan — design tokens (stessi nomi e valori delle variabili Figma) */
:root {
  /* Primitivi */
  --navy-900: #101820; --navy-800: #18232E; --navy-700: #22303D; --navy-600: #2F4050;
  --navy-400: #6B7C8C; --navy-200: #B6C0C9; --navy-100: #E3E8EC;
  --yellow-900: #3A2C06; --yellow-600: #E59F00; --yellow-500: #FFB612; --yellow-400: #FFC947;
  --green-500: #3DDC97; --red-500: #FF5A5F; --white: #FFFFFF;

  /* Semantici */
  --color-bg-app: var(--navy-900);
  --color-bg-surface: var(--navy-800);
  --color-bg-surface-raised: var(--navy-700);
  --color-bg-accent: var(--yellow-500);
  --color-bg-accent-pressed: var(--yellow-600);
  --color-bg-accent-subtle: var(--yellow-900);
  --color-bg-success: var(--green-500);
  --color-bg-disabled: var(--navy-700);
  --color-text-primary: var(--white);
  --color-text-secondary: var(--navy-200);
  --color-text-muted: var(--navy-400);
  --color-text-on-accent: var(--navy-900);
  --color-text-accent: var(--yellow-500);
  --color-text-success: var(--green-500);
  --color-text-danger: var(--red-500);
  --color-text-disabled: var(--navy-400);
  --color-border-default: var(--navy-600);
  --color-border-focus: var(--yellow-500);

  --space-xs: 4px; --space-sm: 8px; --space-md: 12px; --space-lg: 16px;
  --space-xl: 24px; --space-2xl: 32px; --space-3xl: 48px;
  --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px; --radius-xl: 24px; --radius-full: 999px;

  --font-display: 'Barlow Condensed', 'Roboto Condensed', 'Arial Narrow', system-ui, sans-serif;
  --font-body: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--color-bg-app); color-scheme: dark; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--color-bg-app);
  color: var(--color-text-primary);
  font: 400 16px/24px var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, p, dl, dd, ul { margin: 0; padding: 0; }
button { font-family: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* Struttura */
#app { max-width: 520px; margin: 0 auto; }
.view {
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
  padding: env(safe-area-inset-top) 20px 0;
}
.view__main { flex: 1; padding-bottom: var(--space-xl); }
.top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); min-height: 72px; }
.top__title { flex: 1; text-align: center; font: 700 22px/26px var(--font-display); }
.top__spacer { width: 48px; flex: none; }
.bar {
  position: sticky; bottom: 0; display: flex; gap: var(--space-md);
  margin: 0 -20px; padding: var(--space-lg) 20px calc(var(--space-lg) + env(safe-area-inset-bottom));
  background: var(--color-bg-app); border-top: 1px solid var(--color-border-default);
}

/* Testi */
.h1 { font: 700 36px/40px var(--font-display); }
.lead { margin-top: var(--space-sm); color: var(--color-text-secondary); font-size: 18px; line-height: 26px; }

/* Brand */
.brand { display: flex; align-items: center; gap: var(--space-md); }
.brand__mark { width: 40px; height: 40px; color: var(--color-bg-accent); }
.brand__name { font: 700 28px/32px var(--font-display); }

/* Pulsanti */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; padding: 0 var(--space-xl); border: 0; border-radius: var(--radius-lg);
  font: 700 20px/24px var(--font-display); letter-spacing: 0.02em; cursor: pointer; background: none;
  transition: background-color .12s, transform .12s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.bar .btn { flex: 1; padding: 0 var(--space-lg); }
.btn--primary { background: var(--color-bg-accent); color: var(--color-text-on-accent); }
.btn--primary:active:not(:disabled) { background: var(--color-bg-accent-pressed); }
.btn--secondary { background: var(--color-bg-surface-raised); border: 1px solid var(--color-border-default); }
.btn--ghost { color: var(--color-text-accent); }
.btn--danger { color: var(--color-text-danger); border: 1px solid var(--color-border-default); }
.btn--danger-solid { background: var(--color-text-danger); color: var(--color-text-on-accent); }
.btn--sm { min-height: 44px; padding: 0 var(--space-lg); font-size: 18px; border-radius: var(--radius-md); }
.btn--xl { min-height: 72px; font-size: 28px; border-radius: var(--radius-xl); }
.btn:disabled { background: var(--color-bg-disabled); color: var(--color-text-disabled); border-color: transparent; cursor: not-allowed; }

.icon-btn {
  display: grid; place-items: center; width: 48px; height: 48px; flex: none;
  border: 1px solid var(--color-border-default); border-radius: var(--radius-full);
  background: var(--color-bg-surface); cursor: pointer;
}
.icon-btn:active { background: var(--color-bg-surface-raised); }

/* Home: lista esercizi */
.ex-list { list-style: none; display: flex; flex-direction: column; gap: var(--space-md); margin-top: var(--space-xl); }
.ex {
  display: grid; grid-template-columns: 36px 1fr 24px; align-items: center; gap: var(--space-md);
  width: 100%; padding: var(--space-lg); text-align: left; cursor: pointer;
  background: var(--color-bg-surface); border: 1px solid var(--color-border-default); border-radius: var(--radius-lg);
}
.ex:active { background: var(--color-bg-surface-raised); }
.ex__n { font: 700 30px/1 var(--font-display); color: var(--color-text-accent); }
.ex__name { display: block; font: 600 22px/26px var(--font-display); overflow-wrap: anywhere; }
.ex__stats { display: flex; flex-wrap: wrap; gap: 2px var(--space-lg); margin-top: 6px; color: var(--color-text-secondary); font-size: 14px; line-height: 20px; }
.ex__stats b { color: var(--color-text-primary); font-size: 16px; font-weight: 600; }
.ex__go { color: var(--color-text-muted); }
.ex-add {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 64px;
  background: none; border: 2px dashed var(--color-border-default); border-radius: var(--radius-lg);
  color: var(--color-text-accent); font: 700 20px/24px var(--font-display); letter-spacing: .02em; cursor: pointer;
}
.ex-add:active { background: var(--color-bg-surface); }
.empty { padding-top: var(--space-2xl); }
.install {
  display: flex; flex-direction: column; gap: var(--space-md); margin-bottom: var(--space-xl); padding: var(--space-lg);
  background: var(--color-bg-accent-subtle); border: 1px solid var(--color-border-default); border-radius: var(--radius-lg);
}
.install__title { font: 700 22px/26px var(--font-display); }
.install__text { color: var(--color-text-secondary); font-size: 15px; line-height: 22px; }
.install__actions { display: flex; gap: var(--space-sm); }
.install__actions .btn { flex: 1; min-height: 48px; padding: 0 var(--space-md); font-size: 18px; }
.view__main--home { display: flex; flex-direction: column; }
.foot { margin-top: auto; padding-top: var(--space-2xl); text-align: center; color: var(--color-text-muted); font-size: 12px; line-height: 16px; }

/* Editor */
.form { display: flex; flex-direction: column; gap: 20px; padding-top: var(--space-sm); }
.field { display: flex; flex-direction: column; gap: var(--space-sm); }
.field__label { color: var(--color-text-secondary); font-weight: 500; font-size: 15px; }
.field__hint { color: var(--color-text-muted); font-size: 14px; line-height: 20px; }
.field__error { color: var(--color-text-danger); font-size: 14px; line-height: 20px; }
.input {
  width: 100%; padding: 14px var(--space-lg); background: var(--color-bg-surface); color: var(--color-text-primary);
  border: 1px solid var(--color-border-default); border-radius: var(--radius-md); font: 500 20px/28px var(--font-body);
}
.input[aria-invalid="true"] { border-color: var(--color-text-danger); }
.input::placeholder { color: var(--color-text-muted); }
.input:focus-visible { outline: 3px solid var(--color-border-focus); outline-offset: 1px; }
.stepper {
  display: grid; grid-template-columns: 64px 1fr 64px; align-items: stretch; overflow: hidden;
  background: var(--color-bg-surface); border: 1px solid var(--color-border-default); border-radius: var(--radius-lg);
}
.stepper:focus-within { border-color: var(--color-border-focus); }
.stepper button { display: grid; place-items: center; height: 64px; border: 0; background: var(--color-bg-surface-raised); cursor: pointer; }
.stepper button:active { background: var(--color-bg-accent); color: var(--color-text-on-accent); }
.stepper__input {
  width: 100%; min-width: 0; border: 0; background: transparent; color: var(--color-text-primary); text-align: center;
  font: 700 34px/1 var(--font-display); font-variant-numeric: tabular-nums;
}
.stepper__input:focus-visible { outline: none; }
.manage { display: flex; flex-direction: column; gap: var(--space-md); margin-top: var(--space-sm); padding-top: var(--space-xl); border-top: 1px solid var(--color-border-default); }
.manage__order { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm) var(--space-md); }
.manage__pos { flex-basis: 100%; color: var(--color-text-secondary); font-size: 15px; }
.manage__order .btn { flex: 1; }

/* Allenamento: serie */
.progress { height: 6px; border-radius: var(--radius-full); background: var(--color-bg-surface-raised); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--color-bg-accent); border-radius: var(--radius-full); transition: width .3s; }
.set { display: flex; flex-direction: column; gap: var(--space-lg); padding-top: var(--space-xl); }
.set__name { font: 700 clamp(40px, 12vw, 56px)/1 var(--font-display); overflow-wrap: anywhere; }
.set__count { font: 600 28px/1 var(--font-display); color: var(--color-text-secondary); }
.set__count b { color: var(--color-text-accent); font-size: 44px; font-weight: 800; }
.dots { display: flex; gap: var(--space-sm); }
.dot { flex: 1; height: 8px; border-radius: var(--radius-full); background: var(--color-bg-surface-raised); }
.dot.is-done { background: var(--color-bg-accent); }
.dot.is-current { background: transparent; box-shadow: inset 0 0 0 2px var(--color-border-focus); }
.target { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); margin-top: var(--space-md); }
.target__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-xs); min-height: 168px;
  padding: var(--space-xl) var(--space-sm); background: var(--color-bg-surface); border: 1px solid var(--color-border-default); border-radius: var(--radius-xl);
}
.target__num { font: 800 clamp(72px, 24vw, 104px)/.9 var(--font-display); font-variant-numeric: tabular-nums; }
.target__text { font: 700 38px/40px var(--font-display); text-align: center; }
.target__label { color: var(--color-text-secondary); font-size: 18px; }
.set__rest { color: var(--color-text-secondary); }

/* Allenamento: recupero */
.rest__main { display: flex; flex-direction: column; align-items: center; gap: var(--space-xl); padding-top: var(--space-sm); text-align: center; }
.rest__what { color: var(--color-text-secondary); font-size: 18px; line-height: 26px; }
.ring { position: relative; width: min(78vw, 320px); aspect-ratio: 1; }
.ring__svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring__track { fill: none; stroke: var(--color-bg-surface-raised); stroke-width: 12; }
.ring__bar { fill: none; stroke: var(--color-bg-accent); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .25s linear, stroke .2s; }
.is-done .ring__bar { stroke: var(--color-bg-success); }
.ring__center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-xs); }
.ring__time { font: 800 clamp(80px, 26vw, 112px)/1 var(--font-display); font-variant-numeric: tabular-nums; }
.ring__label { color: var(--color-text-secondary); font-size: 18px; }
.is-done .ring__label { color: var(--color-text-success); font-weight: 600; }
.rest__next { max-width: 34ch; color: var(--color-text-secondary); }
.rest__next b { color: var(--color-text-primary); font-weight: 600; }
.bar--rest { flex-direction: column; align-items: center; gap: var(--space-sm); }
.is-done #skip { visibility: hidden; }
.next-btn {
  display: grid; place-items: center; width: 96px; height: 96px; border: 0; border-radius: var(--radius-full); cursor: pointer;
  background: var(--color-bg-accent); color: var(--color-text-on-accent); transition: transform .12s, background-color .12s;
}
.next-btn .icon { width: 46px; height: 46px; stroke-width: 2.6; }
.next-btn:active:not(:disabled) { transform: scale(.94); background: var(--color-bg-accent-pressed); }
.next-btn:disabled { background: var(--color-bg-disabled); color: var(--color-text-disabled); cursor: not-allowed; }
.next-btn.is-ready { animation: ready .9s ease-out 1; }
@keyframes ready {
  0% { transform: scale(.9); box-shadow: 0 0 0 0 rgba(255, 182, 18, .55); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); box-shadow: 0 0 0 30px rgba(255, 182, 18, 0); }
}

/* Fine allenamento */
.done { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-xl); padding-top: var(--space-3xl); }
.done__mark { width: 96px; height: 96px; color: var(--color-bg-accent); }
.stats { width: 100%; }
.stats > div { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-lg); padding: var(--space-lg) 0; border-bottom: 1px solid var(--color-border-default); }
.stats dt { color: var(--color-text-secondary); font-size: 18px; }
.stats dd { font: 700 40px/1 var(--font-display); font-variant-numeric: tabular-nums; }

/* Dialog */
.dlg {
  width: min(92vw, 420px); padding: var(--space-xl); color: var(--color-text-primary);
  background: var(--color-bg-surface); border: 1px solid var(--color-border-default); border-radius: var(--radius-xl);
}
.dlg::backdrop { background: rgba(8, 12, 16, .72); }
.dlg__title { font: 700 28px/32px var(--font-display); }
.dlg__text { margin-top: var(--space-sm); color: var(--color-text-secondary); }
.dlg__actions { display: flex; gap: var(--space-md); margin-top: var(--space-xl); }
.dlg__actions .btn { flex: 1; padding: 0 var(--space-md); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
