/* ---------------------------------------------------------------- base */
:root {
  --r-sm: 12px; --r-md: 16px; --r-lg: 22px;
  --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 1rem/1.5 var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
/* bagliori di sfondo: gradienti fissi con i colori del tema, nessun filtro (leggero sulla webview) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(95% 55% at 100% -8%, color-mix(in srgb, var(--accent) var(--glow), transparent), transparent 75%),
    radial-gradient(80% 50% at -18% 46%, color-mix(in srgb, var(--period) var(--glow-2), transparent), transparent 75%),
    radial-gradient(95% 52% at 90% 112%, color-mix(in srgb, var(--accent-2) var(--glow-2), transparent), transparent 75%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.icon { display: inline-flex; flex: none; }
.icon svg { display: block; }

/* -------------------------------------------------------------- layout */
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; overflow-x: clip; }
.page { animation: enter .28s var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .25rem;
  padding: calc(env(safe-area-inset-top) + .5rem) .75rem .5rem;
  transition: background .2s;
}
/* sfondo sfocato solo quando la pagina scorre: a riposo i bagliori passano senza bordi */
body.scrolled .topbar {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.topbar h1 { flex: 1; font-size: 1.125rem; font-weight: 650; letter-spacing: -.01em; }
.topbar.home { padding-top: calc(env(safe-area-inset-top) + 1rem); align-items: flex-end; }
.topbar.home .greet { flex: 1; min-width: 0; padding-left: .25rem; }
.greet .eyebrow { font-size: .8125rem; color: var(--muted); }
.greet .eyebrow::first-letter { text-transform: uppercase; }
.greet h1 { font-size: 1.75rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }

.content {
  display: flex; flex-direction: column; gap: 1rem;
  padding: .5rem 1rem calc(3.5rem + env(safe-area-inset-bottom));
}

.icon-btn {
  width: var(--tap); height: var(--tap); border: 0; border-radius: 50%;
  display: grid; place-items: center; background: transparent; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.filled { background: var(--surface); border: 1px solid var(--border); }

/* ------------------------------------------------------------- card */
.card {
  background: color-mix(in srgb, var(--surface) 84%, transparent); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 1rem;
}
.card-title { display: flex; align-items: center; gap: .625rem; font-weight: 650; }
.card-title .grow { flex: 1; }
a.card, button.card { display: block; width: 100%; text-align: left; text-decoration: none; color: inherit; }
a.card:active, button.card:active { background: var(--surface-2); transform: scale(.992); }
.tile-icon {
  width: 2.5rem; height: 2.5rem; border-radius: var(--r-sm); display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
}
.tile-icon.period { background: color-mix(in srgb, var(--period) 16%, transparent); color: var(--period); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.tile { display: flex; flex-direction: column; gap: .75rem; min-height: 9.5rem; }
.tile .tile-body { margin-top: auto; }
.tile h2 { font-size: 1rem; font-weight: 650; line-height: 1.25; }
.tile p { font-size: .8125rem; color: var(--muted); margin-top: .125rem; }
.big-number { font-size: 2rem; font-weight: 750; letter-spacing: -.02em; line-height: 1; }

/* ---------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 3rem; padding: 0 1.25rem; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-weight: 600; text-decoration: none; text-align: center; line-height: 1.2;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 2.25rem; padding: 0 .875rem; font-size: .875rem; border-radius: var(--r-sm); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: .75rem; }
.btn-row .btn { flex: 1; }
.btn-row .btn.wide { flex: 2; }

/* ---------------------------------------------------- status (home) */
.status { display: flex; align-items: center; gap: 1rem; }
.status .txt { flex: 1; min-width: 0; }
.status h2 { font-size: 1.0625rem; font-weight: 650; line-height: 1.3; }
.status p { font-size: .875rem; color: var(--muted); margin-top: .125rem; }
.status.alert { border-color: color-mix(in srgb, var(--period) 60%, var(--border)); background: color-mix(in srgb, var(--period) 9%, var(--surface)); flex-direction: column; align-items: stretch; }
.status.alert .btn-row { margin-top: .25rem; }
.ring { position: relative; width: 4.5rem; height: 4.5rem; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: var(--period); stroke-linecap: round; transition: stroke-dashoffset .8s var(--ease); }
.ring .num { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.05; }
.ring .num b { font-size: 1.5rem; font-weight: 750; }
.ring .num small { font-size: .625rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ------------------------------------------------------ month grid */
.month-head { display: flex; align-items: center; gap: .25rem; }
.month-head h2 { flex: 1; text-align: center; font-size: 1.0625rem; font-weight: 650; text-transform: capitalize; }
.dow, .days { display: grid; grid-template-columns: repeat(7, 1fr); }
.dow span { text-align: center; font-size: .6875rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: .5rem 0; }
.day {
  position: relative; display: grid; place-items: center; height: 3rem; padding: 0;
  border: 0; background: transparent; font-size: .9375rem;
}
.day .n { position: relative; z-index: 1; width: 2.5rem; height: 2.5rem; border-radius: 50%; display: grid; place-items: center; }
.day.period::before {
  content: ""; position: absolute; top: .3125rem; bottom: .3125rem; left: .125rem; right: .125rem;
  background: color-mix(in srgb, var(--period) 20%, transparent); border-radius: 999px;
}
.day.period.join-l::before { left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.day.period.join-r::before { right: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.day.period .n { background: var(--period); color: #fff; font-weight: 700; }
.day.start .n { box-shadow: 0 0 0 3px color-mix(in srgb, var(--period) 35%, transparent); }
.day.predicted .n { border: 2px dashed var(--period); color: var(--period); font-weight: 650; }
.day.today .n { font-weight: 800; }
.day.today:not(.period) .n { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); }
.day.future { color: var(--muted); }
.day.future:not(.predicted) { opacity: .5; }
.day.empty { pointer-events: none; }
.day:not(.empty):not(.future):active .n { background: var(--surface-2); }
.day.period:active .n { background: var(--period); filter: brightness(.9); }

/* mini calendario nella home */
.mini .dow span { padding: .125rem 0 .25rem; font-size: .5625rem; }
.mini .day { height: 1.75rem; font-size: .6875rem; pointer-events: none; }
.mini .day .n { width: 1.5rem; height: 1.5rem; }
.mini .day.period::before { top: .1875rem; bottom: .1875rem; }
.mini .day.start .n, .mini .day.predicted .n { box-shadow: none; }
.mini .day.predicted .n { border-width: 1.5px; }

.legend { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; font-size: .8125rem; color: var(--muted); }
.legend i { display: inline-block; width: .875rem; height: .875rem; border-radius: 50%; vertical-align: -.125rem; margin-right: .375rem; }
.legend .l-period { background: var(--period); }
.legend .l-pred { border: 2px dashed var(--period); }
.legend .l-today { box-shadow: inset 0 0 0 1.5px var(--accent); }

/* ------------------------------------------------------------ lists */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.stat { padding: .875rem .75rem; text-align: center; }
.stat b { display: block; font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.stat small { display: block; margin-top: .25rem; line-height: 1.25; font-size: .6875rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.entry { display: flex; flex-direction: column; gap: .75rem; }
.entry-head { display: flex; align-items: center; gap: .75rem; }
.entry-date { flex: 1; min-width: 0; }
.entry-date b { display: block; font-size: 1.0625rem; font-weight: 650; }
.entry-date span { font-size: .8125rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  display: inline-flex; align-items: center; gap: .375rem; padding: .25rem .625rem;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: .8125rem; color: var(--muted);
}
.chip b { color: var(--text); font-weight: 650; }
.note-preview {
  font-size: .875rem; color: var(--muted); padding: .625rem .75rem; border-radius: var(--r-sm);
  background: var(--surface-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.empty-state { display: flex; flex-direction: column; align-items: center; gap: .75rem; text-align: center; padding: 3rem 1.5rem; }
.empty-state .tile-icon { width: 4rem; height: 4rem; border-radius: 50%; }
.empty-state h2 { font-size: 1.125rem; font-weight: 650; }
.empty-state p { color: var(--muted); font-size: .9375rem; max-width: 20rem; }

/* ----------------------------------------------------------- config */
.section-label { font-size: .75rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .5rem .25rem 0; }
.rows { padding: 0; overflow: hidden; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .875rem; padding: .875rem 1rem; min-height: 3.5rem; }
.row + .row { border-top: 1px solid var(--border); }
.row .grow { flex: 1 1 9rem; min-width: 0; }
.row > .field, .row > .select { flex: 1 1 100%; }
.row .grow b { display: block; font-weight: 600; }
.row .grow small { color: var(--muted); font-size: .8125rem; }
.field, .select {
  min-height: 2.75rem; padding: 0 .75rem; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
textarea.field { width: 100%; padding: .75rem; min-height: 8rem; resize: vertical; line-height: 1.45; }
.badge { font-size: .6875rem; font-weight: 650; padding: .125rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.themes { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; padding: 1rem; }
.theme {
  position: relative; padding: .5rem; border-radius: var(--r-md); text-align: left;
  border: 2px solid var(--border); background: var(--surface);
}
.theme[aria-pressed="true"] { border-color: var(--accent); }
.theme .preview { height: 3.5rem; border-radius: var(--r-sm); padding: .5rem; display: flex; flex-direction: column; gap: .3125rem; justify-content: center; }
.theme .preview i { display: block; height: .5rem; border-radius: 99px; }
.theme .preview .a { width: 60%; }
.theme .preview .b { width: 85%; opacity: .9; }
.theme .preview .dots { display: flex; gap: .25rem; }
.theme .preview .dots u { width: .625rem; height: .625rem; border-radius: 50%; }
.theme .label { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .25rem .125rem; font-weight: 600; font-size: .9375rem; line-height: 1.25; }
.theme .label small { display: block; color: var(--muted); font-weight: 400; font-size: .75rem; }
.theme .check { color: var(--accent); opacity: 0; }
.theme[aria-pressed="true"] .check { opacity: 1; }

/* ------------------------------------------------- sheet / toast */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .5); animation: fade .2s ease both; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-width: 560px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 26px 26px 0 0; padding: .5rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  max-height: 88vh; max-height: 88dvh; overflow-y: auto; animation: rise .3s var(--ease) both;
  display: flex; flex-direction: column; gap: 1rem;
}
.sheet .grab { width: 2.5rem; height: .3125rem; border-radius: 99px; background: var(--border); margin: 0 auto; flex: none; }
.sheet h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em; }
.sheet .sub { color: var(--muted); font-size: .9375rem; margin-top: .125rem; }
.sheet.closing { animation: sink .2s ease both; }
.scrim.closing { animation: fade .2s ease reverse both; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }
@keyframes sink { to { transform: translateY(100%); } }

.toast {
  position: fixed; left: 50%; bottom: calc(2.75rem + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%); max-width: calc(100vw - 2rem);
  padding: .75rem 1.125rem; border-radius: var(--r-md); font-size: .9375rem; font-weight: 550;
  background: var(--text); color: var(--bg); box-shadow: 0 8px 24px rgb(0 0 0 / .3);
  animation: toast-in .3s var(--ease) both;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

/* --------------------------------------------------------- skeleton */
.skeleton { border-radius: var(--r-lg); min-height: 6rem; background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

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

.sheet h2::first-letter { text-transform: uppercase; }

/* ------------------------------------------------------------ form */
.form { display: flex; flex-direction: column; gap: 1.125rem; }
.form-field { display: flex; flex-direction: column; gap: .375rem; }
.form-label { font-size: .8125rem; font-weight: 600; color: var(--muted); }
.form .field { width: 100%; }
.weekdays { display: flex; justify-content: space-between; gap: .25rem; }
.day-toggle {
  width: 2.75rem; height: 2.75rem; border-radius: 50%; padding: 0; font-weight: 650; font-size: .875rem;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.day-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.times { display: flex; flex-direction: column; gap: .5rem; }
.time-row { display: flex; align-items: center; gap: .5rem; }
.time-row .field { flex: 1; }
.add-time { align-self: flex-start; }
.switch-row { flex-direction: row; align-items: center; justify-content: space-between; }
.switch {
  position: relative; width: 3.25rem; height: 2rem; border-radius: 999px; padding: 0; flex: none;
  border: 1px solid var(--border); background: var(--surface-2); transition: background .2s;
}
.switch i { position: absolute; top: .1875rem; left: .1875rem; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--muted); transition: transform .2s var(--ease), background .2s; }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"] i { transform: translateX(1.25rem); background: var(--on-accent); }
.paused { opacity: .65; }
button.card.entry { font: inherit; }

.brand-my { color: var(--accent); }

/* entrata direzionale quando si passa da una sezione all'altra (swipe o tocco) */
.page.slide-next { animation: slide-next .32s var(--ease) both; }
.page.slide-prev { animation: slide-prev .32s var(--ease) both; }
@keyframes slide-next { from { opacity: 0; transform: translateX(32px); } }
@keyframes slide-prev { from { opacity: 0; transform: translateX(-32px); } }

/* ---- swipe con la pagina che segue il dito ---- */
#app { touch-action: pan-y pinch-zoom; }
body.dragging { user-select: none; -webkit-user-select: none; }
body.dragging .page { will-change: transform; }
.page.neighbor { position: fixed; top: 0; height: 100vh; height: 100dvh; overflow: hidden; }
.page.animating { transition: transform .26s cubic-bezier(.2, .8, .2, 1); }

/* ---- puntini di posizione tra le sezioni ---- */
.pager {
  position: fixed; left: 0; right: 0; bottom: calc(.75rem + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; justify-content: center; gap: .5rem; pointer-events: none; transition: opacity .2s;
}
.pager.hidden { opacity: 0; }
.pager i {
  width: .4375rem; height: .4375rem; border-radius: 99px;
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  transition: width .28s var(--ease), background .28s;
}
.pager i.on { width: 1.375rem; background: var(--accent); }
