:root {
  color-scheme: dark;
  --bg: #0f0a17;
  --surface: #1a1326;
  --surface2: #241a35;
  --border: #33264a;
  --fg: #f4eefc;
  --muted: #a698bd;
  --pink: #ff5fa2;
  --violet: #9b5cff;
  --grad: linear-gradient(135deg, #ff5fa2, #9b5cff);
  --danger: #ff6b7d;
  --ok: #6ee7a8;
  --radius: 16px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #2a1544 0%, transparent 60%), var(--bg);
  background-attachment: fixed;
  color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
h2 { font-size: 1.05rem; margin: 28px 0 8px; }

/* --- controlli --- */
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--violet); }
textarea { resize: vertical; min-height: 48px; }
label { display: block; margin: 16px 0 6px; font-size: .88rem; font-weight: 650; }
label .opt { font-weight: 400; color: var(--muted); margin-left: 4px; }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; }
label.check input { width: 20px; height: 20px; accent-color: var(--pink); }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 16px;
  font: inherit; font-weight: 600;
  color: var(--fg);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: transform .08s ease, opacity .2s;
}
button:active, .btn:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--grad); border: 0; color: #fff; box-shadow: 0 6px 24px -8px #ff5fa2aa; }
button.ghost { background: transparent; }
button.danger, .danger { color: var(--danger); }
button.wide { width: 100%; margin-top: 18px; }
button.small, .btn.small { padding: 8px 12px; font-size: .88rem; }
button.link { padding: 4px 0; border: 0; background: none; color: var(--pink); }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row > button { flex: 1; }
.row.stack { flex-direction: column; align-items: stretch; margin-top: 28px; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.card p { margin: 0 0 8px; }

/* --- avatar --- */
.av {
  flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 50%;
  overflow: hidden;
  background: var(--grad);
  color: #fff;
  user-select: none;
}
.av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av canvas { width: 100%; height: 100%; display: block; }
.av.sm { width: 38px; height: 38px; font-size: 1.2rem; }
.av.md { width: 52px; height: 52px; font-size: 1.6rem; }
.av.xl { width: 112px; height: 112px; font-size: 3.4rem; }
.c0 { background: linear-gradient(135deg, #ff6b9d, #c44dff); }
.c1 { background: linear-gradient(135deg, #7b5cff, #3fb5ff); }
.c2 { background: linear-gradient(135deg, #ff9a3c, #ff4f6d); }
.c3 { background: linear-gradient(135deg, #2e3350, #8a6cff); }
.c4 { background: linear-gradient(135deg, #3ccf91, #2a8d8f); }
.c5 { background: linear-gradient(135deg, #d4b07a, #6e4a2a); }
.c6 { background: linear-gradient(135deg, #ff7ad9, #4fd8f0); }
.c7 { background: linear-gradient(135deg, #4b6cf0, #b8c6ff); }

/* --- accesso --- */
.auth {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 24px; text-align: center; max-width: 420px; margin: 0 auto;
}
.logo { font-size: 4rem; width: 108px; height: 108px; display: grid; place-items: center; border-radius: 32px; background: var(--grad); box-shadow: 0 16px 48px -12px #ff5fa2; }
.brand { font-size: 2rem; font-weight: 850; letter-spacing: -.02em; margin: 22px 0 6px; }
.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.92); opacity: .7; } }

/* --- struttura app --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 18px 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar h1 { margin: 0; font-size: 1.6rem; font-weight: 850; letter-spacing: -.02em; }
.quota { font-size: .78rem; color: var(--muted); }
.tabs { max-width: 720px; margin: 0 auto; padding: 0 16px calc(var(--tabbar) + var(--safe-b) + 24px); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #150f20ee; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tabbar button {
  flex: 1; flex-direction: column; gap: 2px;
  padding: 6px 0; font-size: .72rem; font-weight: 600;
  background: none; border: 0; border-radius: 0; color: var(--muted);
}
.tabbar .ico { font-size: 1.3rem; line-height: 1; filter: grayscale(1) opacity(.7); }
.tabbar button.on { color: var(--fg); }
.tabbar button.on .ico { filter: none; }

/* --- scopri --- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; padding-top: 0; }
.chip {
  flex-shrink: 0; padding: 7px 14px; font-size: .85rem; font-weight: 600;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.chip.on { background: var(--grad); border-color: transparent; color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 12px; margin-top: 12px; }
.ccard {
  position: relative; aspect-ratio: 3 / 4; padding: 0; overflow: hidden;
  border: 0; border-radius: 18px; display: block; text-align: left; color: #fff;
}
.ccard .art { position: absolute; inset: 0; display: grid; place-items: center; font-size: 4.2rem; padding-bottom: 34%; }
.ccard .art:has(img) { padding-bottom: 0; }
.ccard .art img { width: 100%; height: 100%; object-fit: cover; }
.ccard .shade { position: absolute; inset: 0; background: linear-gradient(transparent 40%, #0009 72%, #000c); }
.ccard .meta { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 12px 12px; }
.ccard .name { font-weight: 800; font-size: 1rem; line-height: 1.2; }
.ccard .tag-line { font-size: .78rem; font-weight: 450; opacity: .85; margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ccard .badge { position: absolute; top: 10px; left: 10px; font-size: .68rem; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; background: #0007; backdrop-filter: blur(6px); }
.ccard .badge.r { left: auto; right: 10px; }
.empty { color: var(--muted); text-align: center; padding: 36px 12px; }

/* --- lista chat --- */
.chat-list, .list, .mem-list { list-style: none; margin: 0; padding: 0; }
.chat-list li { display: flex; gap: 12px; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.chat-list li:active { background: var(--surface); }
.chat-list .txt { min-width: 0; flex: 1; }
.chat-list .top { display: flex; justify-content: space-between; gap: 8px; }
.chat-list .name { font-weight: 700; }
.chat-list .when { font-size: .75rem; color: var(--muted); flex-shrink: 0; }
.chat-list .prev { font-size: .88rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- crea --- */
.avatar-edit { display: flex; gap: 16px; align-items: center; margin-top: 4px; }
.avatar-btns { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.emoji-in { width: 72px; text-align: center; font-size: 1.5rem; padding: 8px; flex-shrink: 0; }
.emoji-picks { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.emoji-picks button { padding: 6px; font-size: 1.3rem; background: none; border: 0; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 50%; padding: 0; border: 2px solid transparent; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--violet); }

/* --- profilo, ricordi --- */
.who { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; }
.mem-list li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.mem-list li .t { flex: 1; font-size: .92rem; }
.mem-list li button { padding: 6px 10px; font-size: .85rem; }
.mem-group { font-size: .8rem; font-weight: 700; color: var(--muted); padding: 14px 0 2px !important; border: 0 !important; }

/* --- amministrazione --- */
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li .info { min-width: 0; }
.list li .small { color: var(--muted); }
.list li button { padding: 6px 12px; font-size: .88rem; flex-shrink: 0; }
.list li.blocked .name { text-decoration: line-through; color: var(--muted); }
.list.log li { display: block; font-size: .86rem; }
.tag { font-size: .72rem; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); margin-left: 6px; color: var(--muted); }
.link-box { display: block; word-break: break-all; font-size: .82rem; padding: 10px; border-radius: 8px; background: var(--bg); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.kv .k { color: var(--muted); }
.ok-t { color: var(--ok); }
.bad-t { color: var(--danger); }

/* --- chat --- */
#v-chat { position: fixed; top: 0; left: 0; right: 0; height: 100%; display: flex; flex-direction: column; background: var(--bg); z-index: 20; }
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 8px 8px;
  background: #150f20f2; border-bottom: 1px solid var(--border);
}
.icon-btn { width: 40px; height: 40px; padding: 0; font-size: 1.6rem; background: none; border: 0; color: var(--fg); }
.c-title { flex: 1; min-width: 0; flex-direction: column; align-items: flex-start; gap: 0; padding: 0; background: none; border: 0; text-align: left; }
.c-title #c-name { font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.c-title .small { color: var(--ok); font-weight: 500; }
.menu {
  position: absolute; right: 10px; top: calc(56px + env(safe-area-inset-top, 0px)); z-index: 30;
  display: flex; flex-direction: column; min-width: 220px; padding: 6px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 18px 40px #000a;
}
.menu button { justify-content: flex-start; background: none; border: 0; font-weight: 500; padding: 11px 12px; }
.c-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.messages { max-width: 720px; margin: 0 auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; animation: pop .18s ease-out; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(82%, 560px);
  padding: 10px 14px; border-radius: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface2); border-bottom-left-radius: 6px;
}
.msg.user .bubble { background: var(--grad); color: #fff; border-radius: 18px; border-bottom-right-radius: 6px; }
.bubble em { color: #cbb8ea; font-style: italic; }
.msg.user .bubble em { color: #ffe3f1; }
.bubble.err { background: #3a1624; color: #ffc2cc; }
.bubble .photo { display: block; width: 100%; max-width: 320px; border-radius: 12px; margin: -2px 0 8px; cursor: zoom-in; }
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.caret::after { content: "▍"; margin-left: 1px; color: var(--pink); animation: blink .9s infinite; }
.c-actions { display: flex; gap: 8px; justify-content: center; padding: 4px 12px 0; }
.c-actions button { padding: 6px 12px; font-size: .82rem; font-weight: 600; border-radius: 999px; background: var(--surface); color: var(--muted); }
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  max-width: 720px; width: 100%; margin: 0 auto;
  padding: 8px 10px calc(10px + var(--safe-b));
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 46px;
  border-radius: 23px; padding: 12px 16px; background: var(--surface);
}
.send { width: 46px; height: 46px; padding: 0; border: 0; border-radius: 50%; background: var(--grad); color: #fff; font-size: 1.1rem; flex-shrink: 0; }
.retry { margin-top: 6px; padding: 6px 12px; font-size: .82rem; }

/* --- foglio dal basso --- */
.sheet-bg { position: fixed; inset: 0; z-index: 40; background: #0009; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 88vh; overflow-y: auto;
  max-width: 640px; margin: 0 auto;
  padding: 8px 18px calc(22px + var(--safe-b));
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 24px 24px 0 0;
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 12px; }
.hero { position: relative; height: 240px; margin: 0 -18px; overflow: hidden; display: grid; place-items: center; font-size: 6rem; }
.hero img { width: 100%; height: 100%; object-fit: cover; }
.hero .shade { position: absolute; inset: 0; background: linear-gradient(transparent 55%, var(--surface)); }
.sheet h3 { font-size: 1.5rem; font-weight: 850; margin: 8px 0 2px; letter-spacing: -.01em; }
.sheet .sub { color: var(--muted); margin: 0 0 10px; }
.sheet .section { margin-top: 14px; font-size: .92rem; white-space: pre-wrap; }
.sheet .section b { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.sheet .chips { padding-top: 4px; }
.full-img { width: 100%; border-radius: 14px; display: block; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-b) + 16px); z-index: 60;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  background: #3a1624; color: #ffd0d8; border: 1px solid #5a2236; box-shadow: 0 10px 30px #0008;
  animation: up .2s ease-out;
}
.toast.ok { background: #143024; color: #c8f7dc; border-color: #1f4a36; }
@media (min-width: 760px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
}
