:root {
  --bg: #fbf3f7;
  --card: #ffffff;
  --ink: #3a2a33;
  --muted: #8a7682;
  --line: #eedbe5;
  --pink: #e98aa8;
  --pink-d: #c95a7e;
  --lilac: #b89be6;
  --ok: #3aa676;
  --radius: 16px;
  --tabs-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px); }
h1, h2, h3 { font-weight: 600; margin: 0 0 .6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; color: var(--muted); font-weight: 500; }
p { margin: .3rem 0; }

#topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: rgba(251,243,247,.92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; display: flex; align-items: center; gap: .4rem; }
.logo { color: var(--pink-d); font-size: 1.3rem; }
.status { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c9b8c1; }
.status.on .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(58,166,118,.18); }

main { padding: 14px; max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; align-items: end; }
.row > * { min-width: 0; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-size: .9rem; }
.err { color: #c0392b; font-size: .9rem; }

label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 10px; }
input, textarea, select { width: 100%; margin-top: 4px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px;
  font: inherit; color: var(--ink); background: #fff; }
textarea { resize: vertical; min-height: 84px; }
/* iPhone: data e ora hanno una larghezza minima propria che sfonda la card */
input[type=time], input[type=date] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%;
  min-height: 45px; text-align: left; }
input[type=time]::-webkit-date-and-time-value, input[type=date]::-webkit-date-and-time-value { text-align: left; }
input[type=checkbox] { width: auto; margin: 0 .5rem 0 0; transform: scale(1.25); }
input[type=range] { padding: 0; border: 0; accent-color: var(--pink-d); }

.btn { display: inline-flex; justify-content: center; align-items: center; gap: .4rem; padding: 11px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap; flex: none; }
.btn.primary { background: var(--pink-d); border-color: var(--pink-d); color: #fff; }
.btn.small { padding: 6px 10px; font-size: .85rem; border-radius: 10px; }
.btn.danger { color: #b03a48; }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }

#tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: rgba(255,255,255,.95);
  backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs button { flex: 1; height: var(--tabs-h); border: 0; background: none; font: inherit; font-size: .75rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#tabs button .ic { font-size: 1.35rem; line-height: 1; }
#tabs button.active { color: var(--pink-d); }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 10;
  max-width: 90vw; text-align: center; }

/* login */
.login { text-align: center; padding-top: 12vh; }
.login form { text-align: left; max-width: 360px; margin: 18px auto 0; }
.big-heart { font-size: 4rem; color: var(--pink-d); animation: beat 1.4s ease-in-out infinite; }
@keyframes beat { 0%,100% { transform: scale(1); } 15% { transform: scale(1.15); } 30% { transform: scale(1); } 45% { transform: scale(1.08); } }

/* effetti */
.effects { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.effects button { padding: 12px 6px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: .9rem; }
.effects button.active { border-color: var(--pink-d); background: #fdeef3; color: var(--pink-d); font-weight: 600; }

/* colore */
.swatch-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.color-name { font-weight: 600; font-size: 1.05rem; }
.spectrum { height: 18px; border-radius: 9px; margin-bottom: 2px; }
.color-range { margin-top: -26px; position: relative; }
.color-range input { -webkit-appearance: none; appearance: none; background: transparent; height: 34px; margin: 0; }
.color-range input::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; border-radius: 50%;
  background: #fff; border: 3px solid var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 10px; font: inherit; font-size: .8rem;
  display: inline-flex; align-items: center; gap: 6px; }
.chips i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* ti amo */
.love-btn { width: 100%; padding: 22px; border-radius: 22px; border: 0; color: #fff; font: inherit; font-size: 1.3rem; font-weight: 600;
  background: linear-gradient(135deg, #f08fae, #c95a7e); box-shadow: 0 8px 24px rgba(201,90,126,.35); }
.love-btn:active { transform: scale(.98); }

/* messaggi */
.msg { padding: 12px 0; border-bottom: 1px solid var(--line); }
.msg:last-child { border-bottom: 0; }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.msg .meta { font-size: .8rem; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: #f1e7ec; color: var(--muted); }
.badge.read { background: #e2f4ec; color: var(--ok); }
.badge.deliv { background: #eee9fb; color: #6c58b8; }
.counter { text-align: right; font-size: .8rem; color: var(--muted); margin-top: -6px; margin-bottom: 8px; }

/* eventi */
.event { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.event:last-child { border-bottom: 0; }
.event .when { font-size: .8rem; color: var(--muted); }

.hint { background: #fff7e6; border: 1px solid #f5dfb0; color: #8a6418; border-radius: 12px; padding: 10px 12px; font-size: .88rem; margin-bottom: 10px; }
.stat { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: .92rem; }
.stat:last-child { border-bottom: 0; }
.big-number { font-size: 2.2rem; font-weight: 700; color: var(--pink-d); line-height: 1.1; }

/* messaggio da leggere sul cuore (Giorgia) */
.msg.locked, .new-msg { display: flex; gap: 12px; align-items: center; }
.env { font-size: 1.6rem; line-height: 1; color: var(--pink-d); flex: none; animation: beat 2.2s ease-in-out infinite; }
.new-msg { background: #fdeef3; border-color: #f3c6d6; }
#tabs button { position: relative; }
#tabs button.has-new::after { content: ''; position: absolute; top: 12px; left: 50%; margin-left: 9px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--pink-d); }
