/* Pectora: gesso e petrolio, con l'ambra come segnale. Il motivo ricorrente è la spalliera. */
:root {
  --bg: #edf1f0;
  --surface: #ffffff;
  --ink: #10262e;
  --ink-2: #4a6068;
  --line: #d0dad9;
  --petrol: #0e5a66;
  --petrol-ink: #ffffff;
  --air: #d3e9e6;
  --signal: #f4b63f;
  --signal-ink: #a86c00;
  --alert: #b3371f;
  --r-s: 8px;
  --r-m: 14px;
  --r-l: 26px;
  --font-d: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-b: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1b20;
    --surface: #11292f;
    --ink: #e7f0ee;
    --ink-2: #9db3b5;
    --line: #25434b;
    --petrol: #6fcdd1;
    --petrol-ink: #06242a;
    --air: #17404a;
    --signal-ink: #f4b63f;
    --alert: #ff8d76;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1.0625rem/1.5 var(--font-b);
}
h1, h2, h3 { font-family: var(--font-d); line-height: 1.12; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.9rem, 7.5vw, 2.5rem); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.3rem; font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: 1.0625rem; font-weight: 650; }
p { margin: 0; }
p + p { margin-top: 0.7em; }
a { color: inherit; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
small, .small { font-size: 0.875rem; }
.muted { color: var(--ink-2); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--signal-ink); outline-offset: 2px; border-radius: 4px; }
#view:focus { outline: none; }

#app { max-width: 34rem; margin: 0 auto; padding: 20px 20px calc(92px + env(safe-area-inset-bottom)); }

/* Testata di pagina */
.page-head { padding: 12px 0 22px; }
.brand { display: flex; align-items: baseline; gap: 10px; margin-bottom: 18px; font: 750 1.25rem/1 var(--font-d); letter-spacing: -0.01em; }
.brand span { font: 400 0.875rem/1.2 var(--font-b); letter-spacing: 0; color: var(--ink-2); }
.page-head .date { color: var(--ink-2); margin-bottom: 6px; }
.page-head .lede { margin-top: 10px; color: var(--ink-2); max-width: 30em; }
.back { display: inline-block; padding: 10px 0; font-family: var(--font-d); font-weight: 600; }
.block { padding: 24px 0; border-top: 1px solid var(--line); }
.block > h2 { margin-bottom: 12px; }
.block > h2 + p { margin-bottom: 14px; }
.stack > * + * { margin-top: 12px; }
.note { color: var(--ink-2); font-size: 0.9375rem; }
.callout { background: var(--air); border-radius: var(--r-m); padding: 14px 16px; }
.callout.warn { background: transparent; border: 1.5px solid var(--alert); }

/* Pulsanti */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0.7rem 1.15rem;
  border: 1.5px solid var(--ink); border-radius: var(--r-m);
  background: transparent; color: var(--ink);
  font: 600 1rem/1.1 var(--font-d); text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--petrol); border-color: var(--petrol); color: var(--petrol-ink); }
.btn.quiet { border-color: transparent; padding-inline: 0.2rem; min-height: 44px; text-decoration: underline; text-underline-offset: 3px; font-weight: 500; }
.btn.danger { border-color: var(--alert); color: var(--alert); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* Scelta a segmenti */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); margin: 0; padding: 0; border: 1.5px solid var(--ink); border-radius: var(--r-m); overflow: hidden; min-width: 0; }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.seg label { display: block; cursor: pointer; }
.seg label + label { border-left: 1.5px solid var(--ink); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; padding: 6px 3px; text-align: center; font: 600 0.8125rem/1.15 var(--font-d); overflow-wrap: break-word; hyphens: auto; min-width: 0; }
@media (min-width: 440px) { .seg span { font-size: 0.9375rem; } }
.seg span small { font: 400 0.75rem/1 var(--font-b); opacity: 0.8; }
.seg input:checked + span { background: var(--ink); color: var(--bg); }
.seg input:focus-visible + span { outline: 3px solid var(--signal-ink); outline-offset: -4px; }

/* La spalliera */
.ladder { display: flex; flex-direction: column-reverse; justify-content: space-evenly; gap: 10px; width: 104px; padding: 14px 0; border-inline: 7px solid var(--ink); border-radius: 3px; }
.rung { flex: 0 0 auto; height: 16px; background: var(--line); }
.rung.on { background: var(--signal); }
.ladder.mini { width: 26px; gap: 3px; padding: 4px 0; border-inline-width: 2.5px; margin: 0 auto; }
.ladder.mini .rung { height: 5px; }

.today { display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: stretch; padding-bottom: 26px; }
.today .ladder { min-height: 200px; }
.today-main { display: flex; flex-direction: column; gap: 14px; justify-content: space-between; min-width: 0; }
@media (max-width: 380px) { .today { gap: 16px; } .today .ladder { width: 78px; } }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.week .d { display: block; font: 600 0.8125rem/1 var(--font-d); color: var(--ink-2); margin-bottom: 8px; }
.week .is-today .d { color: var(--ink); text-decoration: underline; text-decoration-thickness: 2.5px; text-underline-offset: 4px; text-decoration-color: var(--signal); }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0; }
.facts > div { display: flex; flex-direction: column; justify-content: space-between; gap: 4px; }
.facts dt { color: var(--ink-2); font-size: 0.875rem; line-height: 1.25; }
.facts dd { margin: 2px 0 0; font: 700 1.9rem/1 var(--font-d); font-variant-numeric: tabular-nums; }

.level { display: grid; gap: 8px; }
.level-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.level-top strong { font: 700 1.3rem/1 var(--font-d); }
.meter { height: 10px; background: var(--line); border-radius: 2px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--petrol); }

.badges { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.badges li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; font-size: 0.9375rem; line-height: 1.3; }
.badges .mark { width: 22px; height: 22px; margin-top: 1px; border: 2px solid var(--ink-2); border-radius: 3px; }
.badges .got .mark { background: var(--signal); border-color: var(--signal); }
.badges li:not(.got) { color: var(--ink-2); }
.badges strong { display: block; font-family: var(--font-d); }

/* Esercizi */
.fig { width: 100%; height: auto; color: var(--ink); }
.fig .body { fill: none; stroke: currentColor; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.fig .head { fill: currentColor; }
.fig .prop { fill: none; stroke: var(--petrol); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.fig .propf { fill: var(--petrol); }
.fig .sig { fill: none; stroke: var(--signal-ink); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.fig .gnd { stroke: var(--line); stroke-width: 2; stroke-linecap: round; }
.fig .ghost { stroke: currentColor; stroke-width: 6; stroke-linecap: round; stroke-dasharray: 2 10; opacity: 0.45; }
.fig-frame { background: var(--surface); border-radius: var(--r-l); padding: 10px 14px; }

.steps > li { padding: 24px 0; border-top: 1px solid var(--line); }
.steps .step-n { color: var(--ink-2); font: 600 0.9375rem/1 var(--font-d); margin-bottom: 6px; }
.steps h2 + p { margin-top: 8px; color: var(--ink-2); }
.ex-list { margin-top: 12px; }
.ex-row { display: grid; grid-template-columns: 84px 1fr; gap: 14px; align-items: center; padding: 10px 0; text-decoration: none; border-top: 1px solid var(--line); }
.ex-row strong { display: block; font: 650 1.0625rem/1.2 var(--font-d); }
.ex-row span span { color: var(--ink-2); font-size: 0.9375rem; }
.howto { counter-reset: s; }
.howto li { counter-increment: s; display: grid; grid-template-columns: 1.6rem 1fr; padding: 7px 0; }
.howto li::before { content: counter(s); font: 700 1rem/1.5 var(--font-d); color: var(--petrol); }
.plain li { padding: 4px 0 4px 1.1rem; position: relative; }
.plain li::before { content: ""; position: absolute; left: 0; top: 0.8em; width: 9px; height: 3px; background: var(--signal-ink); }

/* Guida */
details { border-top: 1px solid var(--line); }
details:last-of-type { border-bottom: 1px solid var(--line); }
summary { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 16px 0; cursor: pointer; list-style: none; font: 650 1.125rem/1.2 var(--font-d); }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; font-weight: 400; font-size: 1.5rem; line-height: 0.8; color: var(--petrol); }
details[open] summary::after { content: "\2212"; }
details .body { padding: 0 0 18px; max-width: 34em; }

/* Moduli */
label.f, .f { display: block; }
.f > span, .f-label { display: block; font-size: 0.9375rem; margin-bottom: 5px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="time"], select, textarea {
  width: 100%; min-height: 48px; padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--ink-2); border-radius: var(--r-s);
  background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: grid; grid-template-columns: 24px 1fr; gap: 10px; align-items: start; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--petrol); }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; }
.switch-row input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--petrol); flex: none; }
.switch-row input[type="number"], .switch-row select { width: 6.5rem; flex: none; }
.times { display: flex; flex-wrap: wrap; gap: 8px; }
.times input { width: 7rem; }

/* Calendario e grafici */
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cal-head strong { font: 650 1.0625rem/1 var(--font-d); text-transform: capitalize; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: 0.75rem; color: var(--ink-2); padding-bottom: 2px; }
.cal .c { aspect-ratio: 1; display: grid; place-items: center; border-radius: var(--r-s); background: var(--surface); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.cal .c.l1 { background: var(--air); }
.cal .c.l2 { background: var(--petrol); color: var(--petrol-ink); }
.cal .c.l3 { background: var(--signal); color: #10262e; font-weight: 700; }
.cal .c.now { outline: 2px solid var(--ink); outline-offset: -2px; }
.cal .c.out { background: transparent; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 0.8125rem; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart { width: 100%; height: auto; }
.chart .ln { fill: none; stroke: var(--petrol); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--surface); stroke: var(--petrol); stroke-width: 3; }
.chart .ax { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--ink-2); font: 400 11px var(--font-b); }
.rows li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }

/* Comunità */
.post { padding: 18px 0; border-top: 1px solid var(--line); }
.post-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 8px; }
.post-head strong { font: 650 1.0625rem/1.2 var(--font-d); }
.tag { display: inline-block; padding: 2px 9px; border: 1.5px solid var(--ink-2); border-radius: 99px; font-size: 0.8125rem; line-height: 1.3; }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.post-photos { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 12px; }
.post-photos img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: var(--r-m); background: var(--line); }
.ai-box { margin-top: 12px; background: var(--air); border-radius: var(--r-m); padding: 12px 14px; font-size: 0.9375rem; }
.ai-box h3 { margin-bottom: 4px; }
.post-actions { display: flex; flex-wrap: wrap; gap: 2px 18px; margin-top: 6px; }
.post-actions .btn.quiet[aria-pressed="true"] { font-weight: 700; text-decoration-color: var(--signal-ink); text-decoration-thickness: 3px; }
.comments { margin-top: 8px; padding-left: 14px; border-left: 3px solid var(--line); }
.comments li { padding: 8px 0; }
.comments form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }

/* Barra delle sezioni */
.tabs {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(5, 1fr);
  width: 100%; max-width: 34rem; padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line); z-index: 5;
}
.tabs a { position: relative; padding: 18px 2px 16px; text-align: center; text-decoration: none; color: var(--ink-2); font: 600 0.8125rem/1 var(--font-d); }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"]::before { content: ""; position: absolute; top: -1px; left: 50%; width: 30px; height: 5px; margin-left: -15px; background: var(--signal); }
@media (min-width: 420px) { .tabs a { font-size: 0.9375rem; } }

/* Avvisi e finestre */
#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; width: max-content; max-width: min(30rem, calc(100vw - 32px)); pointer-events: none; }
#toast p { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: var(--r-m); font-size: 0.9375rem; }
dialog { width: min(30rem, calc(100vw - 28px)); max-height: calc(100dvh - 28px); border: 0; border-radius: var(--r-l); padding: 26px 22px; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(8, 24, 29, 0.72); }
dialog h1 { font-size: 1.75rem; margin-bottom: 14px; }

/* Sessione guidata: sempre su fondo petrolio scuro */
#overlay { position: fixed; inset: 0; z-index: 30; overflow: auto; }
.pl {
  --bg: #0b2a31; --surface: #123a43; --ink: #eaf3f1; --ink-2: #9dbabc; --line: #25525c;
  --petrol: #7fd3d6; --petrol-ink: #06242a; --air: #1b4650; --signal-ink: #f4b63f;
  min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; gap: 12px;
  background: var(--bg); color: var(--ink);
  padding: calc(14px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
}
.pl-in { width: 100%; max-width: 32rem; margin: 0 auto; }
.pl-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pl-top .btn { min-height: 44px; padding: 0.4rem 0.9rem; font-size: 0.9375rem; }
.pl-count { color: var(--ink-2); font-size: 0.9375rem; }
.pl-body { display: flex; flex-direction: column; justify-content: center; gap: 18px; }
.pl-ex { color: var(--ink-2); font: 600 1rem/1.2 var(--font-d); }
.pl-phase { font: 700 clamp(2rem, 9vw, 2.75rem)/1.05 var(--font-d); letter-spacing: -0.02em; }
.pl-stage { display: flex; align-items: center; justify-content: center; gap: 30px; padding: 8px 0; }
.pl-stage .ladder { width: 150px; min-height: 250px; border-inline-width: 9px; gap: 9px; }
.pl-stage .ladder .rung { flex: 1 1 0; height: auto; min-height: 8px; }
.pl-stage .ladder.drain .rung.on { background: var(--petrol); }
.pl-num { font: 800 clamp(5rem, 26vw, 7.5rem)/0.9 var(--font-d); font-variant-numeric: tabular-nums; min-width: 1.2em; text-align: center; }
.pl-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--ink-2); }
.pl-meta strong { color: var(--ink); }
.pl-fig { max-width: 300px; margin: 0 auto; width: 100%; }
.pl-fig.small { max-width: 150px; margin: 0; }
.pl-ctl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pl-ctl.one { grid-template-columns: 1fr; }
.pl .btn.primary { background: var(--signal); border-color: var(--signal); color: #10262e; }
.pl .seg input:checked + span { background: var(--ink); color: var(--bg); }
.pl h1 { font-size: clamp(1.9rem, 8vw, 2.4rem); }
.pl textarea { background: var(--surface); }

@media (prefers-reduced-motion: no-preference) {
  .rung { transition: background-color 0.18s linear; }
  .meter > span { transition: width 0.4s ease; }
}
