/* Registro Peso — creatina · stile condiviso da index.html. Tema scuro di base, chiaro se il sistema lo chiede. */
:root {
  color-scheme: dark light;
  --bg: #15181B;
  --surface: #1D2124;
  --surface-2: #262B2F;
  --text: #ECEAE4;
  --text-dim: #9AA0A0;
  --accent: #C6822C;
  --accent-ink: #15181B;
  --accent-soft: rgba(198,130,44,0.16);
  --good: #7A9B76;
  --good-soft: rgba(122,155,118,0.16);
  --red: #E0645B;
  --line-thigh: #5C86A8;
  --line-chest: #A6657A;
  --border: #33383C;
  --band: rgba(198,130,44,0.10);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F3F1EC; --surface: #FFFFFF; --surface-2: #EDEAE2; --text: #1C1E1B; --text-dim: #6B6F6A;
    --accent: #A8631E; --accent-ink: #FFFFFF; --accent-soft: rgba(168,99,30,0.10);
    --good: #4C7048; --good-soft: rgba(76,112,72,0.10); --red: #B3362E;
    --line-thigh: #3E6483; --line-chest: #8B4A5E; --border: #DBD7CC; --band: rgba(168,99,30,0.07);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F3F1EC; --surface: #FFFFFF; --surface-2: #EDEAE2; --text: #1C1E1B; --text-dim: #6B6F6A;
  --accent: #A8631E; --accent-ink: #FFFFFF; --accent-soft: rgba(168,99,30,0.10);
  --good: #4C7048; --good-soft: rgba(76,112,72,0.10); --red: #B3362E;
  --line-thigh: #3E6483; --line-chest: #8B4A5E; --border: #DBD7CC; --band: rgba(168,99,30,0.07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

/* ---------- Barra in alto e menu ---------- */
.topbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-family: 'Oswald', 'Arial Narrow', sans-serif; font-weight: 600; font-size: 18px; letter-spacing: .01em; }
.topbar .brand img { width: 28px; height: 28px; border-radius: 7px; display: block; }
.icon-btn {
  margin-left: auto; align-self: auto;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  width: 40px; height: 40px; padding: 0; border-radius: 10px; font-size: 20px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.menu-dropdown {
  position: fixed; top: calc(56px + env(safe-area-inset-top, 0px)); right: 12px; z-index: 25;
  min-width: 240px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 6px;
  box-shadow: 0 14px 34px rgba(0,0,0,.35); display: none;
}
.menu-dropdown.show { display: block; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; align-self: auto;
  background: none; color: var(--text); border: 0; padding: 12px; border-radius: 8px;
  text-align: left; font-size: 15px; font-weight: 500; text-decoration: none;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); filter: none; }
.menu-item .em { width: 22px; text-align: center; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }

.lic-banner {
  display: none; margin: 14px 20px 0; max-width: 600px; margin-left: auto; margin-right: auto;
  background: var(--accent-soft); border: 1px solid var(--accent); color: var(--text);
  border-radius: 10px; padding: 10px 14px; font-size: 13.5px; cursor: pointer;
}

/* ---------- Pagina ---------- */
.wrap { max-width: 640px; margin: 0 auto; padding: 24px 20px calc(60px + env(safe-area-inset-bottom, 0px)); }
h1 {
  font-family: 'Oswald', 'Arial Narrow', sans-serif; font-weight: 600;
  font-size: clamp(28px, 7vw, 38px); letter-spacing: 0.01em; margin: 0 0 6px; line-height: 1.05;
}
.subtitle { color: var(--text-dim); font-size: 15px; margin: 0 0 28px; max-width: 46ch; line-height: 1.5; }

.hero { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px 22px; margin-bottom: 20px; }
.hero-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px 24px; flex-wrap: wrap; }
.hero-metric { min-width: 0; flex: 0 1 auto; }
.hero-metric .label { color: var(--text-dim); font-size: 13px; margin-bottom: 4px; white-space: nowrap; }
.hero-metric .value { font-family: 'Oswald', sans-serif; font-weight: 600; font-size: clamp(30px, 9vw, 44px); line-height: 1; letter-spacing: -0.01em; white-space: nowrap; }
.hero-metric .value.positive { color: var(--accent); }
.hero-metric .unit { font-size: 18px; color: var(--text-dim); margin-left: 4px; font-family: 'Inter', sans-serif; }
.phase-note { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--text-dim); line-height: 1.55; }
.phase-note strong { color: var(--text); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; margin-bottom: 20px; }
.card h2 { font-family: 'Oswald', sans-serif; font-weight: 500; font-size: 18px; margin: 0 0 16px; letter-spacing: 0.01em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h2 { margin: 0; }

form { display: flex; flex-wrap: wrap; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 130px; }
.field.wide { flex: 1 1 100%; }
label { font-size: 12.5px; color: var(--text-dim); }
input, textarea, select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  color: var(--text); font-size: 16px; font-family: inherit; width: 100%;
  appearance: none; -webkit-appearance: none; -moz-appearance: textfield; text-align: left;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { min-height: 110px; resize: vertical; line-height: 1.4; }
input::placeholder, textarea::placeholder { color: var(--text-dim); opacity: 1; }
input[type="date"] { min-height: 42px; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }

button, .btn {
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 8px; padding: 11px 20px;
  font-size: 14.5px; font-weight: 600; cursor: pointer; font-family: 'Inter', sans-serif; align-self: flex-end;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button:disabled { opacity: .55; cursor: default; filter: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.secondary, button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger, button.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn.block { display: flex; align-items: center; justify-content: center; width: 100%; align-self: auto; margin-top: 10px; padding: 12px; }

.chip {
  align-self: auto; background: transparent; color: var(--text-dim); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.chart-wrap { width: 100%; overflow-x: auto; }
svg.chart { display: block; width: 100%; height: auto; aspect-ratio: 600 / 260; min-height: 180px; }
.legend { display: flex; gap: 8px 18px; margin-top: 10px; font-size: 12.5px; color: var(--text-dim); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dash { width: 18px; height: 0; border-top: 2px dashed var(--text); opacity: .75; display: inline-block; }
.trend-note { margin: 12px 0 0; font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.trend-note strong { color: var(--text); font-weight: 600; }

.entries { display: flex; flex-direction: column; gap: 8px; }
.entry { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font-size: 14px; }
.entry .left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.entry .date { color: var(--text-dim); font-size: 12px; }
.entry .note { color: var(--text-dim); font-size: 12.5px; font-style: italic; }
.entry .weight { font-family: 'Oswald', sans-serif; font-weight: 500; font-size: 17px; }
.entry .delta { font-size: 12.5px; margin-left: 8px; }
.entry .delta.pos { color: var(--accent); }
.entry .delta.neg { color: var(--good); }
.entry button.del { background: transparent; color: var(--text-dim); border: 1px solid var(--border); padding: 5px 10px; font-size: 12px; font-weight: 500; align-self: auto; }
.entry button.del:hover { color: var(--text); border-color: var(--text-dim); filter: none; }
.empty { color: var(--text-dim); font-size: 14px; text-align: center; padding: 24px 10px; }

.stats-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { flex: 1 1 clamp(96px, 40%, 160px); min-width: 0; background: var(--surface-2); border-radius: 10px; padding: 14px 16px; }
.stat .label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.stat .val { font-family: 'Oswald', sans-serif; font-size: clamp(17px, 5vw, 22px); font-weight: 500; white-space: nowrap; }

.section-divider { margin: 34px 0 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.section-divider h1 { font-family: 'Oswald', sans-serif; font-weight: 600; font-size: 22px; margin-bottom: 4px; }
.section-divider .subtitle { margin-bottom: 0; }

.credit { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 34px 0 0; font-size: 12.5px; color: var(--text-dim); text-align: center; }
.credit img { height: 34px; width: auto; display: block; }
.credit img.tl-light, .lic-credit img.tl-light { display: none; }
.credit a { line-height: 0; }
.tl-light { display: none; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) img.tl-light { display: block; }
  :root:not([data-theme="dark"]) img.tl-dark { display: none; }
}

/* ---------- Schede a scorrimento dal basso ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; z-index: 30; }
.sheet-backdrop.show { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-width: 560px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(22px + env(safe-area-inset-bottom, 0px)); max-height: 88vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  transform: translateY(105%); transition: transform .22s ease; visibility: hidden;
}
.sheet.show { transform: translateY(0); visibility: visible; }
.sheet h3 { margin: 0 0 4px; font-family: 'Oswald', sans-serif; font-weight: 500; font-size: 20px; }
.sheet .sub { color: var(--text-dim); font-size: 13.5px; line-height: 1.5; margin: 0 0 14px; }
.sheet h4 { margin: 18px 0 6px; font-size: 14px; font-weight: 600; }
.sheet .row { display: flex; gap: 10px; flex-wrap: wrap; }
.sheet .row .btn, .sheet .row button { flex: 1 1 140px; align-self: auto; }
.status-line { min-height: 20px; margin: 10px 0 0; font-size: 13.5px; color: var(--text-dim); line-height: 1.45; }
.code-box { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.code-box b { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 15px; letter-spacing: .5px; word-break: break-all; user-select: all; -webkit-user-select: all; }
.code-box button { align-self: auto; padding: 7px 12px; font-size: 13px; }
.note-small { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; margin: 8px 0 0; }
.sheet-close { margin-top: 16px; }

/* ---------- Licenza: schermate a tutto schermo ---------- */
#lic-overlay {
  position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; display: none;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 18px 0;
}
.lic-card { max-width: 440px; margin: 0 auto; padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }
.lic-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 8px 0 18px; font-family: 'Oswald', sans-serif; font-size: 20px; font-weight: 600; }
.lic-brand img { width: 30px; height: 30px; border-radius: 8px; }
#lic-overlay h2 { margin: 0 0 10px; font-family: 'Oswald', sans-serif; font-weight: 600; font-size: 24px; text-align: center; }
.lic-p { font-size: 15px; line-height: 1.5; margin: 0 0 12px; }
.lic-hint { color: var(--text-dim); font-size: 13px; line-height: 1.45; margin: 0 0 10px; }
.lic-l { display: block; font-size: 12px; color: var(--text-dim); margin: 14px 0 4px; }
.lic-btn {
  display: flex; align-items: center; justify-content: center; width: 100%; margin-top: 10px; padding: 13px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 600; align-self: auto;
}
.lic-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lic-btn:disabled { opacity: .55; }
.lic-msg { min-height: 20px; margin-top: 10px; font-size: 13px; color: var(--text-dim); text-align: center; }
.lic-plans { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 6px; }
.lic-plan { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.lic-plan-h { display: flex; justify-content: space-between; align-items: baseline; font-size: 17px; }
.lic-price { font-family: 'Oswald', sans-serif; font-size: 24px; font-weight: 600; color: var(--accent); }
.lic-price small { font-family: 'Inter', sans-serif; font-size: 12px; color: var(--text-dim); font-weight: 500; }
.lic-note { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.lic-plan .lic-btn { margin-top: 12px; }
.lic-code, .lic-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 12px 0; }
.lic-code span, .lic-row span { font-size: 12px; color: var(--text-dim); flex: 1 1 100%; }
.lic-code b, .lic-row b { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 15px; word-break: break-all; user-select: all; -webkit-user-select: all; }
.lic-row { margin: 8px 0; flex-wrap: nowrap; } .lic-row span { flex: 0 0 86px; }
.lic-copy { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; align-self: auto; }
.lic-paypal { flex: none; background: #0070ba; border: 1px solid #0070ba; color: #fff; border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.lic-steps { padding-left: 20px; line-height: 1.5; font-size: 14px; margin: 0 0 6px; } .lic-steps li { margin-bottom: 6px; }
.lic-welcome-plans { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lic-welcome-plans li { display: flex; align-items: flex-start; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; font-size: 12.5px; line-height: 1.4; }
.lic-welcome-plans .em { font-size: 20px; line-height: 1.3; }
.lic-code-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.lic-code-row input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, monospace; font-size: 13px; letter-spacing: .2px; padding: 10px; }
.lic-code-row .lic-copy { padding: 10px 14px; font-size: 14px; }
.lic-actions { display: flex; gap: 10px; }
.lic-actions .lic-btn { margin-top: 0; flex: 1; padding: 11px 8px; font-size: 14px; font-weight: 700; }
.lic-sticky { position: sticky; bottom: 0; z-index: 2; background: var(--bg); margin: 6px 0 0; padding: 8px 0; }
.lic-sticky .lic-msg { min-height: 0; margin: 0 0 6px; } .lic-sticky .lic-msg:empty { display: none; }
.lic-subscribe { background: linear-gradient(135deg, #ffd166, #f5a623) !important; color: #4a2e00 !important; border: none !important; }
.lic-credit { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 18px 0 4px; font-size: 12.5px; color: var(--text-dim); text-align: center; }
.lic-credit img { height: 30px; width: auto; display: block; }
.lic-credit a { line-height: 0; }

/* Il benvenuto e' una finestra ancorata in basso, sopra l'app. */
#lic-overlay.lic-sheetmode { background: rgba(0,0,0,.55); padding: 0; overflow: hidden; }
#lic-overlay.lic-sheetmode .lic-card {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0; max-height: 92vh; overflow-y: auto;
  padding: 18px 16px calc(14px + env(safe-area-inset-bottom, 0px)); -webkit-overflow-scrolling: touch;
}
.lic-sheetmode .lic-welcome-plans li, .lic-sheetmode .lic-code-row input, .lic-sheetmode #lic-name { background: var(--bg); }
.lic-sheetmode .lic-copy { background: var(--bg); }
.lic-sheetmode .lic-sticky { position: static; background: none; margin: 0; padding: 0; }
.lic-sheetmode .lic-actions { margin-top: 14px; }
#lic-overlay .lic-welcome h2 { font-size: 18px; text-align: left; margin: 0 0 12px; }
.lic-name-card { background: var(--accent-soft); border: 2px solid var(--accent); border-radius: 12px; padding: 8px 10px 7px; margin: 2px 0 12px; }
.lic-name-title { display: block; margin: 0 0 5px; font-size: 14px; font-weight: 700; color: var(--text); }
.lic-name-card #lic-name { margin: 0; padding: 9px 10px; border: 1.5px solid var(--accent); background: var(--surface); }
.lic-name-note { margin: 5px 0 0; font-size: 11.5px; line-height: 1.3; color: var(--text-dim); }
.lic-name-error { margin: 5px 0 0; font-size: 13px; font-weight: 700; color: var(--red); }
.lic-name-card.has-error { border-color: var(--red); background: rgba(224,100,91,.10); }
.lic-name-card.has-error #lic-name { border-color: var(--red); }
.lic-name-card.shake { animation: lic-shake .4s ease; }
@keyframes lic-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-7px); } 40%,80% { transform: translateX(7px); } }
@media (prefers-reduced-motion: reduce) { .lic-name-card.shake { animation: none; } .sheet { transition: none; } }

/* ---------- Tour introduttivo ---------- */
.tour-overlay { position: fixed; inset: 0; z-index: 9998; pointer-events: none; }
.tour-overlay.hidden { display: none; }
.tour-highlight { position: fixed; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0,0,0,.62); pointer-events: none; transition: all .2s ease; }
.tour-tooltip {
  position: fixed; width: min(300px, calc(100vw - 32px)); background: var(--accent); color: var(--accent-ink);
  border-radius: 12px; padding: 14px 16px; pointer-events: auto; box-shadow: 0 12px 30px rgba(0,0,0,.4);
}
.tour-progress { font-size: 12px; opacity: .75; font-weight: 600; margin-bottom: 4px; }
.tour-tooltip-title { margin: 0 0 6px; font-size: 15px; font-family: 'Oswald', sans-serif; font-weight: 600; }
.tour-tooltip-text { margin: 0; font-size: 13.5px; line-height: 1.4; white-space: pre-line; }
.tour-tooltip-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.tour-tooltip-actions-right { display: flex; gap: 8px; margin-left: auto; }
.tour-tooltip .tour-tooltip-actions button { flex: none; padding: 8px 14px; font-size: 13.5px; font-weight: 600; border-radius: 10px; border: 1px solid transparent; align-self: auto; }
.tour-tooltip .tour-next { background: var(--accent-ink); color: var(--accent); }
.tour-tooltip .tour-skip, .tour-tooltip .tour-back { background: transparent; color: var(--accent-ink); border-color: currentColor; opacity: .85; }
.tour-tooltip-actions .hidden { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: #2a2f33; color: #ECEAE4; border-radius: 10px; padding: 11px 16px; font-size: 14px; z-index: 9999;
  max-width: calc(100vw - 32px); text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
