:root {
  --bg: #f6ece1;
  --card: #fffaf4;
  --ink: #3d2621;
  --ink-soft: #7a5d55;
  --accent: #8a3f36;
  --accent-soft: #e7b8a8;
  --rose: #f1d3c6;
  --gold: #e3b46a;
  --line: #ead9ca;
  --ok: #6f8f5f;
  --shadow: 0 6px 24px rgba(122, 63, 54, .10);
  --radius: 18px;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Nunito Sans', 'Segoe UI', Roboto, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #241815; --card: #2f201c; --ink: #f4e6db; --ink-soft: #cdb3a8;
    --accent: #f0a796; --accent-soft: #6b3b33; --rose: #4a2c26; --line: #47312b;
    --shadow: 0 6px 24px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #241815; --card: #2f201c; --ink: #f4e6db; --ink-soft: #cdb3a8;
  --accent: #f0a796; --accent-soft: #6b3b33; --rose: #4a2c26; --line: #47312b;
  --shadow: 0 6px 24px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.55 var(--sans);
  padding-bottom: calc(150px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.55rem; }
h3 { font-size: 1.25rem; }
p { margin: 0 0 .9em; }
.muted { color: var(--ink-soft); font-size: .93rem; }
.small { font-size: .85rem; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.brand { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.topbar-link {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line); color: var(--ink-soft); text-decoration: none; font-weight: 700;
}

main { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; outline: none; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); margin: 0 0 16px;
}
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.hero {
  position: relative; overflow: hidden; border-radius: var(--radius);
  min-height: 230px; margin: 0 0 16px; display: flex; align-items: flex-end;
  background: var(--rose) center 70% / cover no-repeat;
  box-shadow: var(--shadow);
}
.hero-text {
  width: 100%; padding: 18px;
  background: linear-gradient(to top, color-mix(in srgb, var(--card) 96%, transparent) 55%, transparent);
}
.hero-text h1 { margin-bottom: .15em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 999px; border: 0;
  background: var(--accent); color: #fff; font: 700 1rem var(--sans);
  text-decoration: none; cursor: pointer;
}
:root[data-theme="dark"] .btn, .btn { -webkit-tap-highlight-color: transparent; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn { color: #2a1714; } }
:root[data-theme="dark"] .btn { color: #2a1714; }
.btn.secondary { background: transparent; color: var(--accent); border: 1.5px solid var(--accent-soft); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 16px; }
.tile {
  background: var(--card); border-radius: var(--radius); padding: 16px; min-height: 104px;
  box-shadow: var(--shadow); text-decoration: none; color: var(--ink);
  display: flex; flex-direction: column; justify-content: space-between;
}
.tile strong { font-family: var(--serif); font-size: 1.2rem; }
.tile span { color: var(--ink-soft); font-size: .85rem; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a, .list button.item {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 14px 2px;
  color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; text-align: left; cursor: pointer;
}
.list .num {
  flex: 0 0 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--rose); color: var(--accent); font-weight: 700; font-size: .9rem;
}
.list .grow { flex: 1; min-width: 0; }
.list .meta { color: var(--ink-soft); font-size: .85rem; }
.chev { color: var(--ink-soft); }

.tag { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }

textarea, input[type="text"], input[type="time"], input[type="date"] {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  background: var(--bg); color: var(--ink); font: 1rem/1.5 var(--sans);
}
textarea { min-height: 130px; resize: vertical; }
textarea:focus, input:focus { outline: 2px solid var(--accent-soft); border-color: transparent; }
.saved { font-size: .8rem; color: var(--ok); min-height: 1.2em; }
.question { font-family: var(--serif); font-size: 1.2rem; margin: 0 0 8px; }

/* Test */
.scale { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.scale button {
  min-height: 52px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg);
  color: var(--ink); font: 600 .78rem/1.2 var(--sans); cursor: pointer; padding: 4px;
}
.scale button b { display: block; font-size: 1.05rem; }
.scale button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 16px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 26px 1fr; gap: 8px; align-items: center; font-size: .8rem; }
.bar-pair { display: grid; gap: 3px; }
.bar { height: 9px; border-radius: 99px; background: var(--accent-soft); }
.bar.after { background: var(--accent); }
.legend { display: flex; gap: 16px; font-size: .8rem; color: var(--ink-soft); margin: 4px 0 12px; }
.legend i { display: inline-block; width: 12px; height: 9px; border-radius: 99px; margin-right: 6px; vertical-align: middle; }
.score { font-family: var(--serif); font-size: 3rem; line-height: 1; color: var(--accent); }

/* Piano */
.days { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 12px 0; }
.day {
  aspect-ratio: 1; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card);
  display: grid; place-items: center; font-weight: 700; color: var(--ink-soft); cursor: pointer; font-size: .95rem;
}
.day.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.day.today { border-color: var(--accent); color: var(--accent); }
.day.done.today { color: #fff; }
.check {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.check input { width: 22px; height: 22px; accent-color: var(--accent); margin-top: 2px; flex: 0 0 auto; }

/* Player guidato */
.player { text-align: center; }
.breath {
  width: 170px; height: 170px; margin: 16px auto 20px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff6ec, var(--accent-soft) 60%, var(--rose));
  display: grid; place-items: center; color: var(--accent); font-weight: 700; font-size: .95rem;
  transform: scale(.72); transition: transform 4s ease-in-out;
}
.breath.in { transform: scale(1); transition-duration: 4s; }
.breath.out { transform: scale(.72); transition-duration: 6s; }
.step-text { font-family: var(--serif); font-size: 1.45rem; line-height: 1.35; min-height: 7.5em; margin: 0 0 16px; }
.timebar { height: 4px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 8px 0 16px; }
.timebar > i { display: block; height: 100%; width: 0; background: var(--accent); }
audio { width: 100%; margin: 8px 0; }

details { border-top: 1px solid var(--line); padding: 10px 0; }
details summary { cursor: pointer; font-weight: 700; color: var(--ink); }
details p { margin-top: 8px; }

.notice { background: var(--rose); border-radius: 14px; padding: 12px 14px; font-size: .92rem; margin: 0 0 16px; }

.sos-button {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 6;
  bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--card); color: var(--accent); border: 1.5px solid var(--accent-soft);
  border-radius: 999px; padding: 10px 18px; font-weight: 700; font-size: .92rem; text-decoration: none;
  box-shadow: var(--shadow); white-space: nowrap;
}
body.on-sos .sos-button { display: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
  font-size: .72rem; font-weight: 700; color: var(--ink-soft); text-decoration: none;
}
.tabbar .ico { font-size: 1.25rem; line-height: 1; }
.tabbar a.active { color: var(--accent); }

.sos-wrap .card { text-align: left; }
.phone { font-size: 1.2rem; font-weight: 700; }

@media (min-width: 700px) { body { font-size: 18px; } .grid { grid-template-columns: repeat(3, 1fr); } }
@media (prefers-reduced-motion: reduce) { .breath, .breath.in, .breath.out { transition: none; } }
