/* Bonaccia – stile.
   Giorno: bruma verde-grigia con acqua profonda. Notte: blu petrolio con acqua chiara. */

:root {
  --bg: #E8EEEB;
  --surf: #F4F8F6;
  --surf2: #DCE6E2;
  --ink: #1D2A31;
  --ink2: #48595F;
  --line: #C3D1CC;
  --deep: #2D5B60;
  --on-deep: #FFFFFF;
  --sage: #9FC2B2;
  --zone: #A8CBBB;
  --dusk: #6E6C9E;
  --warm: #C98A66;
  --warn: #9C4F2A;
  --shadow-field: 0 0 0 1px rgba(45,91,96,.10);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --tabs-h: 64px;
  --mini-h: 58px;
}

[data-theme="night"] {
  --bg: #111C23;
  --surf: #192832;
  --surf2: #223641;
  --ink: #DCE7E5;
  --ink2: #9DB1B3;
  --line: #2E4350;
  --deep: #8CC4B6;
  --on-deep: #0E1A20;
  --sage: #3E7468;
  --zone: #3F7B6D;
  --dusk: #A5A3DA;
  --warm: #D69770;
  --warn: #E8A982;
  --shadow-field: 0 0 0 1px rgba(140,196,182,.10);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top);
  transition: background-color .4s, color .4s;
}

.skip { position: absolute; left: -999px; top: 0; background: var(--deep); color: var(--on-deep); padding: 10px 14px; z-index: 100; border-radius: 0 0 10px 0; }
.skip:focus { left: 0; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.005em; line-height: 1.2; margin: 0; }
h1 { font-size: 2rem; margin: 0 0 .35rem; }
h2 { font-size: 1.3rem; margin: 2rem 0 .5rem; }
.panel h2 { margin-top: 0; }
p { margin: 0 0 .9rem; max-width: 36em; }
ul { margin: 0 0 .9rem; padding-left: 1.2rem; max-width: 36em; }
li { margin-bottom: .35rem; }
em { font-style: italic; }
a { color: var(--deep); }
:focus-visible { outline: 3px solid var(--dusk); outline-offset: 3px; border-radius: 8px; }

/* ---- struttura ---- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px 6px;
  max-width: 600px; margin: 0 auto;
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-family: var(--serif); font-size: 1.25rem; font-weight: 600; }
.brand svg { color: var(--deep); }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: transparent; border: 0; color: var(--ink2); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surf2); }

main { max-width: 600px; margin: 0 auto; padding: 8px 18px calc(var(--tabs-h) + var(--mini-h) + 40px + env(safe-area-inset-bottom)); outline: none; }
.view[hidden] { display: none; }
.lede { font-family: var(--serif); font-size: 1.15rem; color: var(--ink2); margin-bottom: 1.4rem; }
.sub { color: var(--ink2); font-size: .98rem; }
.hint { color: var(--ink2); font-size: .94rem; min-height: 1.2em; margin: .5rem 0 0; }
.warn { color: var(--warn); font-size: .98rem; }
.fine { color: var(--ink2); font-size: .88rem; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.link { display: inline-block; margin-top: .2rem; }
.grp { margin: 1rem 0 0; font-weight: 600; color: var(--ink); }

/* ---- pannelli: nessuna ombra, differenza di tono ---- */
.panel { background: var(--surf); border-radius: 22px 22px 22px 8px; padding: 20px 20px 18px; margin: 1.1rem 0; }
.panel.soft { background: transparent; border: 1px solid var(--line); border-radius: 8px 22px 22px 22px; }
.panel.night-panel { background: var(--surf2); }
.panel summary { list-style: none; cursor: pointer; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary h2 { margin: 0; display: inline; }
.panel summary::after { content: "+"; float: right; font-size: 1.5rem; line-height: 1; color: var(--ink2); }
.panel[open] summary::after { content: "−"; }
.panel details { margin: 0; }

/* ---- bottoni ---- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--deep); color: var(--on-deep);
  font: inherit; font-weight: 600; font-size: 1.02rem;
  padding: 14px 22px; min-height: 48px; border-radius: 999px;
  transition: transform .15s, background-color .25s;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: transparent; color: var(--deep); box-shadow: inset 0 0 0 2px var(--deep); }
.btn.btn-night { background: var(--dusk); color: #fff; margin-top: .6rem; }
[data-theme="night"] .btn.btn-night { color: #14131f; }
.btn[disabled] { opacity: .5; cursor: default; }
.linkbtn { background: none; border: 0; padding: 12px 0; font: inherit; color: var(--ink2); text-decoration: underline; cursor: pointer; min-height: 44px; }
.linkbtn.danger { color: var(--warn); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: .8rem; }

.actions { display: grid; gap: 12px; margin: 1.4rem 0 1rem; }
.act {
  appearance: none; border: 0; cursor: pointer; text-align: left;
  background: var(--surf); color: var(--ink); font: inherit;
  padding: 18px 20px; border-radius: 22px 22px 22px 8px; min-height: 76px;
  display: flex; flex-direction: column; gap: 3px;
  transition: transform .15s;
}
.act:active { transform: scale(.985); }
.act strong { font-family: var(--serif); font-size: 1.22rem; font-weight: 600; }
.act span { color: var(--ink2); font-size: .95rem; }
.act-calm { background: var(--deep); color: var(--on-deep); }
.act-calm span { color: inherit; opacity: .85; }

/* ---- scale e cursori ---- */
.checkin { background: var(--surf); border-radius: 22px 22px 22px 8px; padding: 20px; }
.checkin label, .field label { display: block; font-weight: 600; margin-bottom: 8px; }
.scale { display: flex; align-items: center; gap: 14px; }
.scale output { min-width: 2ch; font-family: var(--serif); font-size: 1.6rem; text-align: right; color: var(--deep); }
.scale-ends { display: flex; justify-content: space-between; color: var(--ink2); font-size: .85rem; margin: 2px 52px 14px 0; }
.field { margin-bottom: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 36px; background: transparent; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 28px; height: 28px; margin-top: -11px;
  border-radius: 50%; background: var(--deep); border: 4px solid var(--surf);
  box-shadow: 0 0 0 1px var(--deep);
}
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--deep); border: 4px solid var(--surf); }

input[type="text"], input[type="time"], input[type="number"], textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px;
}
textarea { resize: vertical; margin-bottom: 10px; }
::placeholder { color: var(--ink2); opacity: .75; }

.check { display: flex; gap: 12px; align-items: flex-start; margin: .9rem 0; cursor: pointer; font-size: .98rem; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--deep); flex: none; }

/* ---- chip e segmenti ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: .6rem 0; }
.chip {
  appearance: none; font: inherit; font-size: .98rem; cursor: pointer;
  background: var(--bg); color: var(--ink); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 9px 15px; min-height: 44px;
  transition: background-color .2s, border-color .2s;
}
.chip[aria-checked="true"], .chip[aria-pressed="true"] { background: var(--deep); color: var(--on-deep); border-color: var(--deep); }
.chips-field { border: 0; padding: 0; margin: 0 0 12px; }
.chips-field legend { font-weight: 600; padding: 0; margin-bottom: 2px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: .8rem 0; background: var(--bg); border-radius: 14px; padding: 4px; border: 1.5px solid var(--line); }
.seg button { appearance: none; border: 0; font: inherit; font-size: .9rem; color: var(--ink2); background: transparent; padding: 10px 8px; border-radius: 10px; cursor: pointer; min-height: 46px; }
.seg button[aria-checked="true"] { background: var(--deep); color: var(--on-deep); font-weight: 600; }

/* ---- campo del suono: l’elemento memorabile ---- */
.field-wrap { position: relative; width: min(78vw, 320px); aspect-ratio: 1; margin: 1.4rem auto .6rem; }
.field-wrap canvas { width: 100%; height: 100%; display: block; border-radius: 50%; box-shadow: var(--shadow-field); }
.play {
  position: absolute; inset: 31%; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--deep); color: var(--on-deep);
  display: grid; place-items: center; transition: transform .2s;
}
.play:active { transform: scale(.96); }
.play .i-pause, .mini-btn .i-pause { display: none; }
.is-playing .play .i-play, .is-playing .mini-btn .i-play { display: none; }
.is-playing .play .i-pause, .is-playing .mini-btn .i-pause { display: block; }
.now { text-align: center; color: var(--ink2); margin: 0 auto 1.4rem; max-width: 22em; min-height: 1.5em; }

.level { margin-bottom: 1rem; }
.level > label { font-weight: 600; display: block; }
.zonebar { position: relative; height: 40px; margin-top: 6px; }
.zonebar input { position: relative; z-index: 2; height: 40px; }
.zone {
  position: absolute; z-index: 1; top: 8px; height: 24px; border-radius: 12px;
  background: var(--zone);
  left: calc(14px + (100% - 28px) * var(--lo, 0));
  width: calc((100% - 28px) * (var(--hi, 0) - var(--lo, 0)));
}
.zone-caption { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; color: var(--ink2); margin: 0 4px; }
.zone-caption #zone-mid { color: var(--deep); font-weight: 600; }

/* ---- atmosfere, mixer, liste ---- */
.presets { display: grid; gap: 10px; }
.preset {
  appearance: none; text-align: left; font: inherit; cursor: pointer;
  background: var(--surf); color: var(--ink); border: 2px solid transparent;
  border-radius: 18px 18px 18px 6px; padding: 14px 16px; min-height: 64px;
}
.preset strong { font-family: var(--serif); font-size: 1.1rem; display: block; }
.preset span { color: var(--ink2); font-size: .92rem; display: block; margin-top: 2px; }
.preset[aria-pressed="true"] { border-color: var(--deep); }

.mixer { background: var(--surf); border-radius: 22px 22px 22px 8px; padding: 6px 18px; }
.mix-row { padding: 14px 0; border-bottom: 1px solid var(--line); }
.mix-row:last-child { border-bottom: 0; }
.mix-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mix-head span { font-weight: 600; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; z-index: 2; }
.switch i { position: absolute; inset: 0; border-radius: 16px; background: var(--line); transition: background-color .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--surf); transition: transform .2s; }
.switch input:checked + i { background: var(--deep); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 3px solid var(--dusk); outline-offset: 3px; }
.mix-extra { margin-top: 6px; }
.mix-extra .lbl { display: flex; justify-content: space-between; font-size: .88rem; color: var(--ink2); margin-top: 6px; }

.inline-form { display: flex; gap: 10px; align-items: center; }
.inline-form .btn { flex: none; }
.mymixes { display: grid; gap: 8px; margin-top: .8rem; }
.mymix { display: flex; align-items: center; gap: 8px; background: var(--surf); border-radius: 14px; padding: 4px 6px 4px 6px; }
.mymix .name { flex: 1; text-align: left; background: none; border: 0; font: inherit; color: var(--ink); padding: 12px; cursor: pointer; min-height: 48px; font-weight: 600; }
.mymix .del { background: none; border: 0; color: var(--ink2); cursor: pointer; min-width: 44px; min-height: 44px; font-size: 1.3rem; }

.list { display: grid; gap: 10px; }
.item {
  appearance: none; text-align: left; font: inherit; cursor: pointer; width: 100%;
  background: var(--surf); color: var(--ink); border: 0;
  border-radius: 18px 18px 18px 6px; padding: 14px 16px; min-height: 64px;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
}
.item strong { font-family: var(--serif); font-size: 1.12rem; font-weight: 600; }
.item small { color: var(--deep); font-weight: 600; font-size: .88rem; grid-row: 1; grid-column: 2; }
.item span { grid-column: 1 / -1; color: var(--ink2); font-size: .94rem; }

.checklist { list-style: none; padding: 0; margin: 0 0 .6rem; }
.checklist li { margin: 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist label { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; cursor: pointer; font-size: .98rem; }
.checklist input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--deep); flex: none; }
.plain { padding-left: 1.1rem; }

.notes { display: grid; gap: 8px; margin: .8rem 0; }
.note { border-left: 3px solid var(--sage); padding: 4px 0 4px 12px; font-size: .95rem; }
.note small { display: block; color: var(--ink2); }
.note button { background: none; border: 0; color: var(--ink2); cursor: pointer; text-decoration: underline; font: inherit; font-size: .85rem; padding: 6px 0; }

/* ---- grafico ---- */
#chart svg { width: 100%; height: auto; display: block; }
#chart .grid { stroke: var(--line); stroke-width: 1; }
#chart .axis { fill: var(--ink2); font-size: 11px; font-family: var(--sans); }
#chart .l-ann { stroke: var(--deep); fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
#chart .l-loud { stroke: var(--dusk); fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 5; }
#chart .dot-ann { fill: var(--deep); }
#chart .dot-loud { fill: var(--dusk); }
.legend { display: flex; gap: 18px; font-size: .88rem; color: var(--ink2); margin: 4px 0 8px; }
.legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; background: var(--deep); }
.legend i.dusk { background: var(--dusk); }
.empty { color: var(--ink2); font-size: .98rem; }
.ins { margin: 12px 0 0; font-size: .96rem; }
.ins li { margin-bottom: .45rem; }

/* ---- accordion Capire ---- */
.acc details { border-bottom: 1px solid var(--line); }
.acc summary { list-style: none; cursor: pointer; padding: 18px 0; font-family: var(--serif); font-size: 1.15rem; font-weight: 600; display: flex; justify-content: space-between; gap: 12px; min-height: 56px; align-items: center; }
.acc summary::-webkit-details-marker { display: none; }
.acc summary::after { content: "+"; font-size: 1.5rem; color: var(--ink2); }
.acc details[open] summary::after { content: "−"; }
.acc .body { padding: 0 0 12px; }
.acc .body p, .acc .body ul { font-size: 1rem; }

/* ---- mini-player ---- */
.mini {
  position: fixed; left: 12px; right: 12px; z-index: 30; max-width: 576px; margin: 0 auto;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 8px);
  height: var(--mini-h); background: var(--deep); color: var(--on-deep);
  border-radius: 999px; display: flex; align-items: center; gap: 6px; padding: 0 6px 0 6px;
}
.mini[hidden] { display: none; }
.mini-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; padding: 0 0 0 14px; height: 100%; }
.mini-dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex: none; animation: soft 3.6s ease-in-out infinite; }
.mini-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.mini-text strong { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-text small { opacity: .85; font-size: .8rem; }
.mini-btn { width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: inherit; display: grid; place-items: center; cursor: pointer; flex: none; }
[data-theme="night"] .mini-btn { background: rgba(0,0,0,.18); }
@keyframes soft { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* ---- barra delle schede ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surf); border-top: 1px solid var(--line);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--ink2); text-decoration: none; font-size: .74rem; min-height: 56px; position: relative; }
.tabs a[aria-current="page"] { color: var(--deep); font-weight: 700; }
.tabs a[aria-current="page"]::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--deep); }

/* ---- finestra sovrapposta ---- */
.sheet { position: fixed; inset: 0; z-index: 60; background: rgba(15,25,30,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 28px 28px 0 0; padding: 24px 22px calc(28px + env(safe-area-inset-bottom)); outline: none;
}
.sheet-card.full { min-height: 80vh; display: flex; flex-direction: column; }
.sheet-card.full > div { flex: 1; display: flex; flex-direction: column; }
.sheet-card.full .sheet-actions { margin-top: auto; padding-top: 1.2rem; }
.sheet-card.full .breath-wrap .sheet-actions { justify-content: center; }
.sheet-card h2 { margin-top: 0; }
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 1rem; }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 14px 0; }
.progress i { display: block; height: 100%; width: 0; background: var(--deep); transition: width .8s linear; }
.step-text { font-family: var(--serif); font-size: 1.5rem; line-height: 1.4; margin: 1.2rem 0; min-height: 6.5em; }
.cal-big { font-family: var(--serif); font-size: 3rem; text-align: center; margin: 1rem 0; color: var(--deep); }

/* respiro */
.breath-stage { flex: 1; display: grid; place-items: center; min-height: 300px; }
.breath-orb {
  width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--sage), var(--deep) 75%);
  transform: scale(.55); opacity: .85;
  display: grid; place-items: center; color: var(--on-deep);
  font-family: var(--serif); font-size: 1.4rem;
}
.breath-label { text-align: center; font-family: var(--serif); font-size: 2rem; margin-top: .4rem; }
.breath-left { text-align: center; color: var(--ink2); }

/* ---- schermo nero per la notte ---- */
.sheet.dark { background: #000; }
.sheet-card.dark { background: #000; color: #6f8187; }
.sheet-card.dark .btn.secondary { color: #6f8187; box-shadow: inset 0 0 0 2px #26343a; }
.sheet-card.dark .breath-orb { background: radial-gradient(circle at 40% 35%, #2c4a54, #12262c 75%); color: #6f8187; }
.sheet-card.dark .breath-left, .sheet-card.dark .breath-label { color: #5b6d73; }

.night {
  position: fixed; inset: 0; z-index: 55; background: #000; color: #7d8f93;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center;
}
.night[hidden] { display: none; }
.night-title { font-family: var(--serif); font-size: 1.6rem; margin: 0; color: #62747a; }
.night-sub { margin: 0 0 18px; color: #4d5c61; }
.night-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.night button { font: inherit; color: #6f8187; background: #0b0f11; border: 1px solid #1c272b; border-radius: 999px; padding: 14px 20px; min-height: 52px; cursor: pointer; }
.night .night-title, .night .night-sub { max-width: 20em; }
.night.dark-breath .breath-orb { background: radial-gradient(circle at 40% 35%, #2a4650, #12262c 75%); }

@media (min-width: 700px) {
  body { font-size: 19px; }
  .tabs { max-width: 600px; margin: 0 auto; border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}

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

/* gruppi di atmosfere */
.grp-h { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; margin: 1.1rem 0 .1rem; color: var(--ink2); }
.grp-h:first-child { margin-top: .2rem; }

/* rumori: sezione chiusa */
.rumori { margin-top: 1.4rem; border-top: 1px solid var(--line); padding-top: .4rem; }
.rumori summary { cursor: pointer; list-style: none; font-family: var(--serif); font-size: 1.05rem; font-weight: 600; color: var(--ink2); padding: 12px 0; min-height: 48px; display: flex; justify-content: space-between; align-items: center; }
.rumori summary::-webkit-details-marker { display: none; }
.rumori summary::after { content: "+"; font-size: 1.4rem; }
.rumori[open] summary::after { content: "−"; }
.rumori .preset { margin-bottom: 10px; display: block; width: 100%; }

/* versione e data dell'ultimo aggiornamento */
.version { text-align: center; color: var(--ink2); font-size: .88rem; margin: 2rem 0 .4rem; line-height: 1.6; }
.version .love { display: block; font-family: var(--serif); font-size: 1rem; margin-top: .2rem; }
.version .heart { color: var(--warm); }
