:root {
  --bg: #f3f3f7;
  --surface: #ffffff;
  --surface-2: #f1f1f6;
  --seg-on: #ffffff;
  --text: #14141b;
  --muted: #6c6c7a;
  --faint: #9c9cab;
  --line: rgba(20, 20, 50, .08);
  --line-strong: rgba(20, 20, 50, .16);
  --accent: #5b4cf0;
  --accent-2: #a24cf0;
  --accent-soft: #eeecfe;
  --btn: #5b4cf0;
  --hero-1: #5b4cf0;
  --hero-2: #a24cf0;
  --danger: #e5484d;
  --danger-soft: #fdeded;
  --ok: #2b9a66;
  --ok-soft: #e6f6ee;
  --warn: #d9590b;
  --warn-soft: #fff0e5;
  --shadow: 0 1px 2px rgba(20, 20, 50, .04), 0 6px 20px rgba(20, 20, 50, .06);
  --radius: 20px;
  /* tinte per materie e avatar (la tonalità --h la imposta l'HTML) */
  --tint-fg-l: 40%;
  --tint-bg-s: 80%;
  --tint-bg-l: 94%;
  color-scheme: light;
}
/* Tema scuro: automatico (segue il telefono) se non si è scelto "Chiaro", oppure scelto a mano */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e13;
    --surface: #18181f;
    --surface-2: #22222b;
    --seg-on: #34343f;
    --text: #f2f2f7;
    --muted: #9d9dab;
    --faint: #6b6b78;
    --line: rgba(255, 255, 255, .07);
    --line-strong: rgba(255, 255, 255, .16);
    --accent: #8b80ff;
    --accent-2: #c07cff;
    --accent-soft: rgba(139, 128, 255, .16);
    --btn: #6352f2;
    --hero-1: #4f40e0;
    --hero-2: #8a3fd6;
    --danger: #ff6b6f;
    --danger-soft: rgba(255, 107, 111, .14);
    --ok: #4cc38a;
    --ok-soft: rgba(76, 195, 138, .14);
    --warn: #ff9a52;
    --warn-soft: rgba(255, 154, 82, .14);
    --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 6px 20px rgba(0, 0, 0, .3);
    --tint-fg-l: 78%;
    --tint-bg-s: 35%;
    --tint-bg-l: 22%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e13;
  --surface: #18181f;
  --surface-2: #22222b;
  --seg-on: #34343f;
  --text: #f2f2f7;
  --muted: #9d9dab;
  --faint: #6b6b78;
  --line: rgba(255, 255, 255, .07);
  --line-strong: rgba(255, 255, 255, .16);
  --accent: #8b80ff;
  --accent-2: #c07cff;
  --accent-soft: rgba(139, 128, 255, .16);
  --btn: #6352f2;
  --hero-1: #4f40e0;
  --hero-2: #8a3fd6;
  --danger: #ff6b6f;
  --danger-soft: rgba(255, 107, 111, .14);
  --ok: #4cc38a;
  --ok-soft: rgba(76, 195, 138, .14);
  --warn: #ff9a52;
  --warn-soft: rgba(255, 154, 82, .14);
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 6px 20px rgba(0, 0, 0, .3);
  --tint-fg-l: 78%;
  --tint-bg-s: 35%;
  --tint-bg-l: 22%;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; border: 0; cursor: pointer; color: inherit; background: none; padding: 0; }
button:disabled { opacity: .5; cursor: default; }
svg.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Struttura ---------- */
.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 4px 18px; }
.top h1 { font-size: 32px; line-height: 1.1; font-weight: 800; letter-spacing: -.025em; margin: 0; }
.top p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); flex: none;
}
.icon-btn.plain { background: transparent; color: var(--faint); }
.section-title {
  font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); margin: 26px 4px 10px; display: flex; justify-content: space-between; align-items: center;
}
.section-title:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Barra in basso ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tabbar-inner { display: flex; width: 100%; max-width: 560px; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 4px; color: var(--faint); font-size: 11px; font-weight: 600; position: relative;
  transition: color .15s;
}
.tab svg.i { width: 26px; height: 26px; }
.tab.active { color: var(--accent); }
.tab .badge {
  position: absolute; top: 1px; left: calc(50% + 7px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; border: 2px solid var(--surface);
}

/* ---------- Card ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.group { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 58px; width: 100%; text-align: left; color: inherit; text-decoration: none; }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); }
.row-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.row-icon svg.i { width: 20px; height: 20px; }
.row.danger { color: var(--danger); }

/* Hero: prossima interrogazione */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--hero-1), var(--hero-2));
  color: #fff; border-radius: 26px; padding: 20px 20px 18px; margin-bottom: 8px;
  box-shadow: 0 14px 34px -14px color-mix(in srgb, var(--hero-1) 75%, transparent);
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
}
.hero .label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.hero .big { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 2px; line-height: 1.15; }
.hero .date { font-size: 16px; opacity: .95; }
.hero .pills { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.hero .pill { background: rgba(255, 255, 255, .2); border-radius: 99px; padding: 5px 11px; font-size: 13px; font-weight: 600; }
.hero.calm { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.hero.calm::after { background: var(--accent-soft); }
.hero.calm .label { color: var(--muted); opacity: 1; }
.agenda { margin: 20px 4px 22px; }
.agenda-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 6px; }
.agenda-head h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.agenda-head .small { font-size: 12px; }
.agenda-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.agenda-row + .agenda-row { border-top: 1px solid var(--line); }
.agenda-row .grow { min-width: 0; }
.agenda-row .title { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.agenda-row .pill-btn { flex-shrink: 0; }
.agenda p { margin: 12px 0 0; }
.update-item { align-items: flex-start; }
.update-item p { margin: 5px 0; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.update-item.new { border-left: 3px solid var(--accent); }
.update-new { display: inline-block; font-size: 10px; color: var(--accent); background: var(--accent-soft); padding: 2px 6px; border-radius: 5px; vertical-align: middle; }

/* Filtri per materia */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 18px -16px 4px; padding: 2px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 14px; border-radius: 99px; font-size: 14px; font-weight: 600;
  background: var(--surface); color: var(--muted); box-shadow: var(--shadow);
}
.chip.on { background: var(--text); color: var(--bg); }

/* Timeline */
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 10px; }
.day-head b { font-size: 16px; }
.rel { font-size: 13px; font-weight: 600; color: var(--muted); }
.rel.soon { color: var(--accent); }

.tag {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 8px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
  color: hsl(var(--h, 250) 65% var(--tint-fg-l)); background: hsl(var(--h, 250) var(--tint-bg-s) var(--tint-bg-l));
}
.ev-head { display: flex; align-items: flex-start; gap: 10px; }
.ev-head .grow { flex: 1; min-width: 0; }
.ev-title { font-weight: 700; font-size: 17px; margin-top: 8px; }
.ev-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }

.test-icon { width: 44px; height: 44px; border-radius: 14px; background: var(--warn-soft); color: var(--warn); }

.people { margin: 12px -4px 0; }
.person { display: flex; align-items: center; gap: 12px; padding: 7px 4px; border-radius: 12px; }
.person .name { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person.me { background: var(--accent-soft); padding-left: 8px; padding-right: 8px; margin: 2px 0; }
.person.me .name { font-weight: 700; }
.you { font-size: 11px; font-weight: 800; letter-spacing: .04em; color: var(--accent); text-transform: uppercase; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; letter-spacing: .02em;
  color: hsl(var(--h) 60% var(--tint-fg-l)); background: hsl(var(--h) var(--tint-bg-s) var(--tint-bg-l));
}
.avatar.lg { width: 76px; height: 76px; font-size: 28px; }

.pill-btn {
  flex: none; display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 12px; border-radius: 99px;
  font-size: 13.5px; font-weight: 650; background: var(--accent-soft); color: var(--accent);
}
.pill-btn svg.i { width: 16px; height: 16px; stroke-width: 2.4; }
.pill-btn.grey { background: var(--surface-2); color: var(--muted); }

/* ---------- Scambi ---------- */
.swap-top { display: flex; align-items: center; gap: 12px; }
.swap-top .grow { flex: 1; min-width: 0; }
.swap-dates {
  display: flex; align-items: center; gap: 10px; margin: 14px 0; padding: 12px; border-radius: 14px; background: var(--surface-2);
}
.swap-dates > div { flex: 1; min-width: 0; }
.swap-dates span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.swap-dates b { display: block; font-size: 15px; }
.swap-dates .to b { color: var(--accent); }
.swap-dates svg.i { color: var(--faint); }
.status { font-size: 12.5px; font-weight: 700; padding: 3px 9px; border-radius: 8px; white-space: nowrap; }
.status.accepted { color: var(--ok); background: var(--ok-soft); }
.status.rejected { color: var(--danger); background: var(--danger-soft); }
.status.pending { color: var(--accent); background: var(--accent-soft); }
.status.cancelled, .status.expired { color: var(--muted); background: var(--surface-2); }

/* ---------- Bottoni e form ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 50px; padding: 0 20px; border-radius: 15px;
  background: var(--btn); color: #fff; font-weight: 650; font-size: 16px;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.soft-danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { height: 40px; border-radius: 12px; font-size: 15px; width: auto; }
.btns { display: flex; gap: 10px; }
.btns .btn { flex: 1; }
.link-btn { color: var(--accent); font-weight: 600; font-size: 15px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 4px; }
input, select, textarea {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 16px; -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239c9cab' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 18px; padding-right: 40px;
}
textarea { height: auto; min-height: 180px; padding: 12px 14px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
input[type=date] { min-height: 50px; }
.date-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.date-row input { flex: 1; }
.date-row .num { width: 26px; text-align: center; font-weight: 700; color: var(--faint); font-size: 14px; }

.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; height: 38px; border-radius: 11px; font-weight: 650; font-size: 15px; color: var(--muted); }
.seg button.on { background: var(--seg-on); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.subj-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.subj-list .tag { height: 32px; padding: 0 6px 0 12px; font-size: 14px; border-radius: 10px; }
.subj-list .tag button { width: 22px; height: 22px; display: grid; place-items: center; opacity: .7; }
.subj-list .tag svg.i { width: 14px; height: 14px; stroke-width: 2.6; }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; }
.inline-add .btn { width: auto; flex: none; }
.hint { font-size: 13.5px; color: var(--muted); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 4px 0 14px; }

.code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace; font-weight: 700; font-size: 14px; letter-spacing: .08em;
  padding: 5px 9px; border-radius: 8px; background: var(--surface-2); color: var(--text);
}
.search { position: relative; margin-bottom: 12px; }
.search input { padding-left: 42px; background: var(--surface); box-shadow: var(--shadow); border-color: transparent; }
.search svg.i { position: absolute; left: 14px; top: 14px; color: var(--faint); width: 20px; height: 20px; }

.switch { width: 51px; height: 31px; border-radius: 16px; background: var(--line-strong); position: relative; flex: none; transition: background .2s; }
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .2s;
}
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(20px); }

.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; border-radius: 16px;
  background: var(--accent-soft); color: var(--text); margin-bottom: 14px; width: 100%; text-align: left;
}
.banner .row-icon { background: var(--btn); color: #fff; }
a.banner { text-decoration: none; }
.banner .grow { flex: 1; font-size: 14px; }
.banner b { display: block; font-size: 15px; }

.empty { text-align: center; padding: 44px 24px; color: var(--muted); }
.empty .em { font-size: 46px; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

.profile { text-align: center; margin: 10px 0 8px; }
.profile .avatar { margin: 0 auto 10px; }
.profile h2 { margin: 0; font-size: 22px; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
  background:
    radial-gradient(110% 60% at 0% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    radial-gradient(90% 60% at 100% 100%, color-mix(in srgb, var(--accent-2) 18%, transparent), transparent 70%),
    var(--bg);
}
.login-box { width: 100%; max-width: 380px; margin: 0 auto; }
.login .logo { width: 76px; height: 76px; border-radius: 20px; box-shadow: 0 12px 30px -10px rgba(91, 76, 240, .6); }
.login h1 { font-size: 34px; font-weight: 800; letter-spacing: -.03em; margin: 22px 0 6px; line-height: 1.1; }
.login p { color: var(--muted); margin: 0 0 26px; }
.code-input {
  height: 64px; text-align: center; font-size: 26px; font-weight: 700; letter-spacing: .3em; text-transform: uppercase;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace; background: var(--surface); margin-bottom: 12px;
}
.login .switch-link { display: block; margin: 22px auto 0; }

/* ---------- Sheet e toast ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .42);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .32s cubic-bezier(.2, .9, .3, 1);
}
.overlay.closing { animation: fade .2s ease reverse forwards; }
.overlay.closing .sheet { animation: down .2s ease forwards; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 0 auto 16px; }
.sheet h2 { font-size: 21px; margin: 0 0 6px; letter-spacing: -.01em; }
.sheet > p { color: var(--muted); margin: 0 0 18px; }
.sheet .group { box-shadow: none; background: var(--surface-2); margin-bottom: 14px; }
.sheet .btns { margin-top: 6px; }
.steps { margin: 0 0 18px; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: center; padding: 10px 0; }
.steps li::before {
  content: counter(s); width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 14px;
}
.steps svg.i { display: inline; vertical-align: -5px; color: var(--accent); width: 20px; height: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); z-index: 60;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-weight: 600; font-size: 15px; max-width: calc(100% - 32px); text-align: center;
  transition: opacity .2s, transform .25s cubic-bezier(.2, .9, .3, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* Stato della connessione e aggiornamenti dell'app */
.netbar {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 8px); z-index: 55;
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s;
}
.netbar.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.netbar > * {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); cursor: default;
}
.netbar button { cursor: pointer; }
.netbar svg.i { width: 16px; height: 16px; color: var(--muted); }
.netbar b { color: var(--accent); }
.netbar .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }
/* Barra "Annulla" dopo un sorteggio o uno spostamento */
.undobar {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); z-index: 61; width: min(528px, calc(100% - 32px));
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px; box-shadow: var(--shadow);
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s cubic-bezier(.2, .9, .3, 1);
}
.undobar.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.undobar button {
  display: inline-flex; align-items: center; gap: 6px; flex: none; font: inherit; font-weight: 700; cursor: pointer;
  padding: 8px 12px; border-radius: 10px; border: 0; background: color-mix(in srgb, var(--bg) 16%, transparent); color: var(--bg);
}
.undobar svg.i { width: 18px; height: 18px; }
body.net-on .page { padding-top: calc(env(safe-area-inset-top) + 58px); transition: padding-top .2s; }

.loading { display: grid; place-items: center; height: 60vh; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }

@keyframes up { from { transform: translateY(100%); } }
@keyframes down { to { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- Preferenze, programma, assenze ---------- */
.pref-list { margin-top: 10px; }
.pref-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.pref-row .grow { flex: 1; min-width: 0; }
.pref-row .title { font-weight: 600; }
.pref-row .sub { font-size: 13px; color: var(--muted); }
.tri { display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--surface-2); flex: none; }
.tri button { width: 42px; height: 34px; border-radius: 9px; font-size: 16px; color: var(--muted); transition: background .15s; }
.tri button.on { background: var(--seg-on); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); color: var(--text); }
.tri button.on.want { background: var(--ok-soft); }
.tri button.on.avoid { background: var(--danger-soft); }

.prog-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: var(--surface-2);
}
.prog-btn > svg.i { width: 20px; height: 20px; color: var(--accent); }
.prog-btn > svg.i:last-child { color: var(--faint); width: 18px; height: 18px; }
.prog-btn .grow { flex: 1; min-width: 0; }
.prog-btn b { display: block; font-size: 14px; }
.prog-btn .grow span { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.program-text.code-line { font: 13px/1.45 ui-monospace, Menlo, Consolas, monospace; word-break: break-all; user-select: all; }
.program-text { white-space: pre-wrap; background: var(--surface-2); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; line-height: 1.5; }

.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; display: block; background: var(--surface-2); }
.thumb { position: relative; aspect-ratio: 1; border-radius: 12px; background: var(--surface-2); }
.thumb button {
  position: absolute; top: 5px; right: 5px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(0, 0, 0, .6); color: #fff; display: grid; place-items: center;
}
.thumb button svg.i { width: 14px; height: 14px; stroke-width: 2.6; }
.thumb.loading { display: grid; place-items: center; }
.add-photo {
  aspect-ratio: 1; border-radius: 12px; border: 2px dashed var(--line-strong); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--muted); font-size: 13px; font-weight: 600;
}

.person.absent .name, .person.absent .avatar { opacity: .5; }
.notice { display: flex; gap: 12px; align-items: center; font-size: 14.5px; }
.notice > svg.i { color: var(--danger); width: 26px; height: 26px; }
.role-badge { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; color: var(--warn); background: var(--warn-soft); flex: none; }
.role-badge svg.i { width: 15px; height: 15px; }

input[type=checkbox] {
  -webkit-appearance: none; appearance: none; flex: none; margin: 0; padding: 0;
  width: 24px; height: 24px; min-height: 0; border-radius: 8px;
  border: 2px solid var(--line-strong); background: var(--surface);
}
input[type=checkbox]:checked {
  border-color: var(--btn);
  background: var(--btn) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.check-row { cursor: pointer; }

/* ---------- Guida del primo accesso ---------- */
.guide {
  position: fixed; inset: 0; z-index: 70; background: var(--bg);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 10px) 0 calc(env(safe-area-inset-bottom) + 18px);
  animation: fade .25s ease;
}
.guide.closing { animation: fade .2s ease reverse forwards; }
.guide-top { display: flex; justify-content: space-between; align-items: center; min-height: 44px; padding: 0 20px; width: 100%; max-width: 560px; margin: 0 auto; }
.guide-top .step { font-size: 12.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.slides { flex: 1; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
.slides::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; scroll-snap-align: center; display: flex; align-items: center; overflow-y: auto; padding: 8px 28px; }
.slide-inner { width: 100%; max-width: 440px; margin: 0 auto; }
.art {
  width: 104px; height: 104px; border-radius: 32px; display: grid; place-items: center; font-size: 54px; margin-bottom: 26px;
  background: linear-gradient(135deg, var(--accent-soft), color-mix(in srgb, var(--accent-2) 16%, var(--surface)));
}
.slide h2 { font-size: 29px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 10px; }
.slide p { font-size: 17px; line-height: 1.5; color: var(--muted); margin: 0; }
.slide p b { color: var(--text); }
.demo { margin-top: 22px; padding: 12px 14px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); pointer-events: none; }
.demo.bare { padding: 0; background: none; box-shadow: none; }
.fake-notif {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); box-shadow: var(--shadow);
}
.fake-notif img { width: 38px; height: 38px; border-radius: 10px; }
.fake-notif .grow { flex: 1; min-width: 0; }
.fake-notif b { display: block; font-size: 15px; }
.fake-notif span { font-size: 13px; color: var(--muted); }
.dots { display: flex; justify-content: center; gap: 7px; margin: 12px 0 18px; }
.dots span { width: 7px; height: 7px; border-radius: 4px; background: var(--line-strong); transition: width .25s, background .25s; }
.dots span.on { width: 22px; background: var(--accent); }
.guide-btns { display: flex; gap: 10px; width: 100%; max-width: 560px; margin: 0 auto; padding: 0 20px; }
.guide-btns .btn { flex: 1; }

/* ---------- Foto profilo ---------- */
.avatar { overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar .spinner { width: 24px; height: 24px; }
.avatar-edit { position: relative; display: block; width: 76px; margin: 0 auto 10px; border-radius: 50%; }
.profile .avatar-edit .avatar { margin: 0; }
.avatar-edit .cam {
  position: absolute; right: -4px; bottom: -4px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; background: var(--btn); color: #fff; border: 3px solid var(--bg);
}
.avatar-edit .cam svg.i { width: 15px; height: 15px; }

/* Telefoni piccoli: guida più compatta, così tutto sta nello schermo */
@media (max-height: 720px) {
  .art { width: 72px; height: 72px; border-radius: 22px; font-size: 38px; margin-bottom: 16px; }
  .slide h2 { font-size: 24px; margin-bottom: 8px; }
  .slide p { font-size: 15.5px; line-height: 1.45; }
  .demo { margin-top: 14px; }
  .dots { margin: 8px 0 12px; }
}

.role-badge.rep { color: var(--accent); background: var(--accent-soft); }
.seg.three button { font-size: 13.5px; padding: 0 2px; }

/* Pulsante "Aggiungi ai Promemoria" */
.ev-actions { display: flex; gap: 8px; margin-top: 10px; }
.hero button.pill { display: inline-flex; align-items: center; gap: 5px; color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.hero button.pill svg.i { width: 15px; height: 15px; }

/* ---------- Orario ---------- */
.date-row select.h { width: 112px; flex: none; padding-right: 30px; background-position: right 10px center; }
.tt-row { gap: 10px; min-height: 54px; padding: 8px 14px; }
.tt-row select, .tt-row input { flex: 1; width: auto; height: 40px; min-height: 40px; border-radius: 11px; }
.tt-row select.eh { flex: none; width: 200px; }
.tt-n { width: 44px; flex: none; font-weight: 800; display: flex; flex-direction: column; line-height: 1.15; }
.tt-n small { font-weight: 600; font-size: 12px; color: var(--muted); }
#tt-tabs button { font-size: 14px; }
#f-hour, #r-hour { width: 100%; }

/* ---------- Persone fissate prima del sorteggio ---------- */
.locks, .seats-box { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.locks-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.locks-head b { font-size: 14px; }
.lock-tag { font-size: 13px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 6px 10px; border-radius: 10px; white-space: nowrap; }
input[type=radio] {
  -webkit-appearance: none; appearance: none; flex: none; margin: 0; padding: 0;
  width: 24px; height: 24px; min-height: 0; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface);
}
input[type=radio]:checked { border: 7px solid var(--btn); }

/* ---------- Preferenze: icone e anteprima ---------- */
.tri button { display: grid; place-items: center; }
.tri button svg.i { width: 18px; height: 18px; }
.tri button.on.want { background: var(--ok-soft); color: var(--ok); }
.tri button.on.avoid { background: var(--danger-soft); color: var(--danger); }
.lock-tag { display: inline-flex; align-items: center; gap: 5px; }
.lock-tag svg.i, .lock-date svg.i { width: 14px; height: 14px; }
.lock-date { display: inline-flex; align-items: center; gap: 4px; }
.pref-sum { display: inline-flex; align-items: center; gap: 10px; margin-top: 4px; font-size: 13px; font-weight: 650; color: var(--muted); text-align: left; }
.pref-sum .c { display: inline-flex; align-items: center; gap: 3px; }
.pref-sum .c svg.i { width: 15px; height: 15px; }
.pref-sum .c.up { color: var(--ok); }
.pref-sum .c.down { color: var(--danger); }
.pref-sum .c.lk { color: var(--accent); }
.stack { display: inline-flex; align-items: center; }
.stack .avatar, .stack .more { width: 22px; height: 22px; font-size: 9px; border: 2px solid var(--surface); margin-left: -6px; }
.stack > :first-child { margin-left: 0; }
.stack .more { display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.avatar.mini { width: 26px; height: 26px; font-size: 10px; }
.pref-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px 10px; flex-wrap: wrap; margin-top: 10px; }
.ico { display: inline-grid; place-items: center; vertical-align: -4px; width: 22px; height: 22px; border-radius: 7px; background: var(--surface-2); color: var(--text); }
.ico.ok { background: var(--ok-soft); color: var(--ok); }
.ico.danger { background: var(--danger-soft); color: var(--danger); }
.ico svg.i { width: 15px; height: 15px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend svg.i { width: 15px; height: 15px; }
.legend .want { color: var(--ok); } .legend .avoid { color: var(--danger); } .legend .lock { color: var(--accent); }
.matrix-wrap { overflow-x: auto; margin: 0 -20px 14px; padding: 0 20px; }
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; }
.matrix th { padding: 0 2px 8px; min-width: 46px; text-align: center; font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.matrix th b { display: block; font-size: 17px; color: var(--text); text-transform: none; }
.matrix td { padding: 6px 2px; border-top: 1px solid var(--line); text-align: center; vertical-align: middle; }
.matrix td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; padding-right: 10px; }
.matrix .who { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 14px; }
.matrix td svg.i { width: 18px; height: 18px; }
.matrix td.want { color: var(--ok); }
.matrix td.avoid { color: var(--danger); }
.matrix td.lock { color: var(--accent); }
.matrix td i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); }
.matrix tr.none .who span { color: var(--faint); }
.matrix tr.me .who span { font-weight: 700; }

/* Fissaggio riservato (visibile solo al rappresentante principale) */
.person div.name { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.person div.name > span:first-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.private-tag {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  font-size: 11.5px; font-weight: 700; color: var(--muted); background: var(--surface-2); padding: 2px 7px; border-radius: 7px;
}
.private-tag svg.i { width: 13px; height: 13px; }

/* Orario: materie dello stesso professore */
.pair-add { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.pair-sel { display: flex; align-items: center; gap: 8px; }
.pair-sel select { flex: 1; min-width: 0; height: 44px; min-height: 44px; }

/* Posti per giorno */
.seats-note { margin: 2px 0 2px; line-height: 1.45; }
.seats-note b { color: var(--text); }
.pref-sum .c.seat { color: var(--muted); }
.pref-sum .c.seat.manual { color: var(--accent); }
.seat-row { gap: 10px; min-height: 60px; padding: 8px 12px 8px 14px; }
.seat-row .link-btn { font-size: inherit; padding: 0; }
.stepper { display: inline-flex; align-items: center; gap: 4px; flex: none; }
.stepper button { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); color: var(--text); font-size: 20px; font-weight: 600; line-height: 1; }
.stepper button:disabled { opacity: .35; }
.stepper span { min-width: 44px; text-align: center; font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; color: var(--muted); }
.stepper.manual span { color: var(--accent); }
.hint.bad { color: var(--danger); }

/* Storico: chi ha creato e modificato */
.edits-line { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--muted); margin: -4px 4px 14px; line-height: 1.45; }
.edits-line svg.i { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.edits-line b { color: var(--text); font-weight: 650; }

/* Giorno in cui lo studente ha già un'interrogazione */
.busy-note { margin-top: 5px; font-size: 12.5px; line-height: 1.4; color: var(--muted); }
.busy-note b { color: var(--text); font-weight: 650; }

/* Cestino */
.trash-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.trash-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 14px; background: var(--surface-2); }
.trash-item .row-icon { background: var(--surface); color: var(--muted); }
.trash-item .grow { flex: 1; min-width: 0; }
.trash-item .title { font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.trash-item .small { margin-top: 3px; line-height: 1.4; }
.trash-item .small b { color: var(--text); font-weight: 600; }
.trash-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn.danger-text { color: var(--danger); }
.trash-item .pill-btn.grey { background: var(--surface); }

/* Calendario a mese */
.month { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 8px 10px; }
.month-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 4px; }
.month-head b { font-size: 16px; }
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.month-grid .wd { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--faint); padding: 2px 0 4px; }
.md { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 0 5px; border-radius: 12px; color: var(--text); }
.md .n { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; font-size: 14.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.md.we .n { color: var(--faint); }
.md.today .n { color: var(--accent); font-weight: 800; }
.md.mine .n { box-shadow: inset 0 0 0 2px var(--accent); }
.md.lesson { background: var(--accent-soft); }
.md.active { background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--line-strong); }
/* Giorni dei sondaggi da votare: tratteggiati; verdi se li preferisco, rossi se li evito; pallino arancione = consigliato */
.md.poll { outline: 1.5px dashed var(--accent); outline-offset: -3px; }
.md.pw { background: var(--ok-soft); outline-color: var(--ok); }
.md.pw .n { color: var(--ok); font-weight: 800; }
.md.pa { background: var(--danger-soft); outline-color: var(--danger); }
.md.pa .n { color: var(--danger); font-weight: 800; }
.md.sug::after { content: ''; position: absolute; top: 5px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.md.picked .n { background: var(--accent); color: #fff; box-shadow: none; }
.md:disabled { opacity: .35; }
.mdots { display: flex; gap: 3px; height: 7px; align-items: center; }
.dot, .sq { display: inline-block; width: 7px; height: 7px; flex: none; background: hsl(var(--h, 250) 65% 55%); }
.dot { border-radius: 50%; }
.dot.open { background: transparent; box-shadow: inset 0 0 0 1.6px hsl(var(--h, 250) 65% 55%); }
.sq { border-radius: 2px; }
.month-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); margin: 10px 4px 0; }
.month-legend span { display: inline-flex; align-items: center; gap: 6px; }
.month-legend .ring { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--accent); }
.month-legend .lesson-sw { width: 14px; height: 12px; border-radius: 4px; background: var(--accent-soft); }
.pick-info { font-size: 13.5px; color: var(--muted); line-height: 1.45; margin: 10px 4px 0; min-height: 40px; }
.pick-info b { color: var(--text); }
.month-legend .sw { width: 14px; height: 12px; border-radius: 4px; }
.month-legend .sw.poll { outline: 1.5px dashed var(--accent); outline-offset: -1.5px; }
.month-legend .sw.pw { background: var(--ok-soft); box-shadow: inset 0 0 0 1.5px var(--ok); }
.month-legend .sw.pa { background: var(--danger-soft); box-shadow: inset 0 0 0 1.5px var(--danger); }
.month-legend .sw.sug { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.month-legend .sw.picked { width: 12px; border-radius: 50%; background: var(--accent); }

/* Calendario dentro il modulo di Programma */
.form-cal-hint { font-size: 13.5px; color: var(--muted); line-height: 1.45; margin: 0 2px 8px; }
.form-cal-hint b { color: var(--text); }
#form-cal .month { background: var(--surface-2); box-shadow: none; padding: 6px 4px 8px; }
#form-cal .md.active { box-shadow: none; }
#form-cal .md:not(.lesson) .n { font-weight: 500; }
#form-cal + .pick-info { margin: 8px 2px 0; min-height: 0; }
#dates:empty::before { content: 'Nessun giorno scelto: toccali sul calendario qui sopra.'; display: block; font-size: 13.5px; color: var(--faint); padding: 4px 2px 8px; }

/* Votare dal calendario a mese */
.vote-hint { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: var(--accent-soft); font-size: 14px; line-height: 1.45; margin-bottom: 4px; }
.vote-hint > svg.i { width: 20px; height: 20px; color: var(--accent); flex: none; margin-top: 1px; }
.vote-hint .grow { flex: 1; }
.vote-hint + .suggest-toggle { margin: 2px 0 10px; }
.poll-day { box-shadow: var(--shadow), inset 0 0 0 1.5px var(--accent-soft); }
.day-notes { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; font-size: 13.5px; line-height: 1.4; }
.day-notes .bad { color: var(--danger); }
.day-notes .meh { color: var(--warn); }
.day-notes .good { color: var(--ok); }
.day-notes .sug { display: flex; gap: 6px; align-items: flex-start; color: var(--text); margin-top: 4px; }
.day-notes .sug svg.i { width: 16px; height: 16px; color: var(--warn); flex: none; margin-top: 1px; }
.pref-choice { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.pref-choice button { height: 56px; border-radius: 13px; background: var(--surface-2); color: var(--muted); font-weight: 650; font-size: 13px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; white-space: nowrap; }
.pref-choice button svg.i { width: 18px; height: 18px; flex: none; }
.pref-choice button.on { background: var(--seg-on); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
.pref-choice button.on.want { background: var(--ok-soft); color: var(--ok); box-shadow: inset 0 0 0 1.5px var(--ok); }
.pref-choice button.on.avoid { background: var(--danger-soft); color: var(--danger); box-shadow: inset 0 0 0 1.5px var(--danger); }
.pref-foot-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* Consiglio sul giorno */
.suggest-toggle { display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 12px; padding: 8px 2px; text-align: left; font-weight: 600; font-size: 15px; color: var(--text); }
.suggest-toggle svg.i { width: 20px; height: 20px; color: var(--warn); flex: none; }
.suggest-toggle .grow { flex: 1; }
.suggest-box { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0 4px; padding: 12px; border-radius: 14px; background: var(--warn-soft); font-size: 14px; line-height: 1.45; }
.suggest-box > svg.i { width: 20px; height: 20px; color: var(--warn); flex: none; margin-top: 1px; }
.suggest-box .grow { flex: 1; min-width: 0; }
.suggest-box b { font-weight: 650; }
.sug-tag { display: inline-block; vertical-align: 2px; margin-left: 4px; font-size: 11px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; color: var(--warn); background: var(--warn-soft); padding: 2px 7px; border-radius: 6px; }
.ok-text { color: var(--ok); font-weight: 650; display: inline-flex; align-items: center; gap: 5px; }
.ok-text svg.i { width: 15px; height: 15px; }
