/* ==========================================================================
   Skoolio — design system
   Motion: regole di Emil Kowalski (emilkowalski/skills): ease-out per entrate/uscite,
   ease-in-out per movimenti sullo schermo, drawer iOS per i pannelli, solo transform/opacity,
   niente animazioni su azioni ripetute, prefers-reduced-motion/transparency rispettati.
   Materiale: "liquid glass" solo per la chrome (barre, menu, pannelli), non per ogni card.
   ========================================================================== */

:root {
  color-scheme: dark;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-press: 160ms;
  --dur-fast: 200ms;
  --dur-base: 250ms;
  --dur-sheet: 500ms;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 30px;
  --r-pill: 999px;

  --sidebar-w: 260px;
  --content-max: 1120px;
  --gutter: clamp(16px, 4vw, 40px);
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Colore principale (personalizzabile: data-accent su <html>). Predefinito: rosso. */
  --acc-d: #ff453a;
  --acc-l: #e0262f;

  /* Tema scuro (predefinito): grigi di sistema iOS, non nero puro */
  --bg: #1c1c1e;
  --bg-elev: #2c2c2e;
  --text: #f5f5f7;
  --text-2: rgb(235 235 245 / 0.64);
  --text-3: rgb(235 235 245 / 0.38);
  --hairline: rgb(255 255 255 / 0.08);
  --hairline-strong: rgb(255 255 255 / 0.14);
  --fill: rgb(118 118 128 / 0.2);
  --fill-2: rgb(118 118 128 / 0.28);
  --fill-3: rgb(118 118 128 / 0.38);
  --card: #2c2c2e;
  --card-hover: #333336;
  --accent: var(--acc-d);
  --accent-strong: color-mix(in srgb, var(--accent) 82%, white);
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);
  --blue: #0a84ff;
  --violet: #bf5af2;
  --good: #30d158;
  --great: #30d158;
  --ok: #ffd60a;
  --six: #c5d93a;
  --bad: #ff453a;
  --good-soft: rgb(48 209 88 / 0.16);
  --ok-soft: rgb(255 214 10 / 0.16);
  --bad-soft: rgb(255 69 58 / 0.16);

  --glass-bg: rgb(44 44 46 / 0.55);
  --glass-bg-strong: rgb(44 44 46 / 0.78);
  --glass-border: rgb(255 255 255 / 0.1);
  --glass-hi: rgb(255 255 255 / 0.16);
  --glass-lo: rgb(0 0 0 / 0.25);
  --glass-shadow: 0 12px 40px rgb(0 0 0 / 0.4), 0 2px 8px rgb(0 0 0 / 0.22);
  --glass-blur: blur(24px) saturate(180%);
  --scrim: rgb(0 0 0 / 0.5);
  --shadow-card: none;

  --aurora-1: color-mix(in srgb, var(--accent) 22%, transparent);
  --aurora-2: color-mix(in srgb, var(--accent) 9%, transparent);
  --aurora-3: rgb(255 159 10 / 0.07);
}

:root[data-accent="orange"] { --acc-d: #ff9f0a; --acc-l: #d46f00; }
:root[data-accent="pink"] { --acc-d: #ff375f; --acc-l: #e0244e; }
:root[data-accent="purple"] { --acc-d: #bf5af2; --acc-l: #9b3fd1; }
:root[data-accent="blue"] { --acc-d: #0a84ff; --acc-l: #0071e3; }
:root[data-accent="teal"] { --acc-d: #40c8e0; --acc-l: #0a8fa8; }
:root[data-accent="green"] { --acc-d: #30d158; --acc-l: #1f9d47; }
:root[data-accent="graphite"] { --acc-d: #98989d; --acc-l: #5b5b60; }

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --text: #1d1d1f;
  --text-2: rgb(60 60 67 / 0.68);
  --text-3: rgb(60 60 67 / 0.42);
  --hairline: rgb(60 60 67 / 0.12);
  --hairline-strong: rgb(60 60 67 / 0.2);
  --fill: rgb(118 118 128 / 0.1);
  --fill-2: rgb(118 118 128 / 0.16);
  --fill-3: rgb(118 118 128 / 0.24);
  --card: #ffffff;
  --card-hover: #fafafa;
  --accent: var(--acc-l);
  --accent-strong: color-mix(in srgb, var(--accent) 85%, black);
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 11%, transparent);
  --blue: #0071e3;
  --violet: #9b3fd1;
  --good: #1f9d47;
  --great: #1f9d47;
  --ok: #b38200;
  --six: #7c8f00;
  --bad: #e0262f;
  --good-soft: rgb(31 157 71 / 0.11);
  --ok-soft: rgb(255 204 0 / 0.2);
  --bad-soft: rgb(224 38 47 / 0.1);
  --glass-bg: rgb(255 255 255 / 0.62);
  --glass-bg-strong: rgb(255 255 255 / 0.84);
  --glass-border: rgb(255 255 255 / 0.75);
  --glass-hi: rgb(255 255 255 / 0.9);
  --glass-lo: rgb(0 0 0 / 0.05);
  --glass-shadow: 0 12px 40px rgb(0 0 0 / 0.12), 0 1px 3px rgb(0 0 0 / 0.06);
  --scrim: rgb(0 0 0 / 0.25);
  --shadow-card: 0 1px 2px rgb(0 0 0 / 0.04), 0 6px 20px rgb(0 0 0 / 0.04);
  --aurora-1: color-mix(in srgb, var(--accent) 12%, transparent);
  --aurora-2: color-mix(in srgb, var(--accent) 5%, transparent);
  --aurora-3: rgb(255 159 10 / 0.05);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  background: var(--bg);
  scrollbar-gutter: stable;
}
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11";
}
h1, h2, h3, h4, p, ol, ul, figure { margin: 0; }
ol, ul { padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
::selection { background: var(--accent-soft); }
[hidden] { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Sfondo "aurora": dà al vetro qualcosa da rifrangere. Statico (niente loop infiniti). */
.aurora {
  position: fixed;
  inset: -20vmax;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(42vmax 34vmax at 12% 8%, var(--aurora-1), transparent 70%),
    radial-gradient(38vmax 30vmax at 88% 6%, var(--aurora-2), transparent 70%),
    radial-gradient(46vmax 36vmax at 70% 96%, var(--aurora-3), transparent 72%);
  filter: saturate(120%);
}

/* ---------- tipografia ---------- */
.large-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 1.35rem + 2.2vw, 2.9rem);
  font-weight: 700;
  letter-spacing: -0.028em;
  line-height: 1.05;
  text-wrap: balance;
}
.title-1 { font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; letter-spacing: -0.022em; line-height: 1.1; }
.title-2 { font-family: var(--font-display); font-size: 1.3rem; font-weight: 650; letter-spacing: -0.018em; line-height: 1.2; }
.title-3 { font-size: 1.0625rem; font-weight: 620; letter-spacing: -0.01em; line-height: 1.3; }
.body-2 { font-size: 0.9375rem; color: var(--text-2); line-height: 1.5; }
.caption { font-size: 0.8125rem; color: var(--text-2); line-height: 1.4; }
.overline { font-size: 0.72rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.gradient-text {
  background: linear-gradient(100deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 60%, #ff9f0a) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- materiale vetro ---------- */
.glass {
  position: relative;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--glass-hi), inset 0 -1px 0 var(--glass-lo), var(--glass-shadow);
}
/* Riflesso speculare sul bordo (anello mascherato). */
.glass::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(140deg, rgb(255 255 255 / 0.55), transparent 32%, transparent 68%, rgb(255 255 255 / 0.18));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
  opacity: 0.7;
}
:root[data-theme="light"] .glass::before { opacity: 1; }
.glass-strong { background: var(--glass-bg-strong); }
/* Rifrazione "liquida" (filtro SVG di distorsione): solo Chromium su computer. Sui telefoni il filtro va
   ricalcolato a ogni frame in cui sotto la tab bar si muove qualcosa (scorrimento, apertura di una
   sezione) e su schermi ad alta densità fa perdere frame: lì resta il vetro sfocato normale. */
@media (hover: hover) and (pointer: fine) {
  .engine-chromium .glass-liquid {
    -webkit-backdrop-filter: url(#liquid-glass) blur(14px) saturate(190%);
    backdrop-filter: url(#liquid-glass) blur(14px) saturate(190%);
  }
}

.card {
  position: relative;
  background: var(--card);
  border: 1px solid transparent;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: 20px; }
@media (min-width: 720px) { .card-pad { padding: 24px; } }

@media (prefers-reduced-transparency: reduce) {
  .glass, .glass-strong, .engine-chromium .glass-liquid {
    background: var(--bg-elev);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .aurora { opacity: 0.4; }
}
@media (prefers-contrast: more) {
  :root { --hairline: rgb(255 255 255 / 0.22); --text-2: rgb(240 244 248 / 0.85); }
  :root[data-theme="light"] { --hairline: rgb(0 0 0 / 0.25); --text-2: rgb(0 0 0 / 0.78); }
}

/* ---------- pulsanti ---------- */
.btn {
  --btn-bg: var(--fill-2);
  --btn-fg: var(--text);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--r-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 600;
  font-size: 0.9375rem;
  letter-spacing: -0.005em;
  white-space: nowrap;
  user-select: none;
  touch-action: manipulation;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-fast) ease, opacity var(--dur-fast) ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { --btn-bg: var(--accent); --btn-fg: var(--accent-ink); }
.btn-lg { min-height: 54px; padding: 0 26px; font-size: 1.0625rem; }
.btn-ghost { --btn-bg: transparent; color: var(--accent); }
.btn-danger { --btn-bg: var(--bad-soft); --btn-fg: var(--bad); }
.btn-block { width: 100%; }
.btn-icon { width: 40px; min-height: 40px; padding: 0; border-radius: 50%; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { --btn-bg: var(--fill-3); }
  .btn-primary:hover { --btn-bg: var(--accent-strong); }
  .btn-ghost:hover { --btn-bg: var(--accent-soft); }
}
/* Hit area minima 44px anche per i pulsanti piccoli. */
.hit { position: relative; }
.hit::after { content: ""; position: absolute; inset: -8px; }

.pressable { transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-fast) ease; touch-action: manipulation; }
.pressable:active { transform: scale(0.98); }

/* ---------- controlli ---------- */
.segmented {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--fill);
  isolation: isolate;
}
.segmented button {
  position: relative;
  z-index: 1;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-2);
  transition: color var(--dur-fast) ease;
  touch-action: manipulation;
}
.segmented button[aria-pressed="true"] { color: var(--text); }
.segmented .seg-indicator {
  position: absolute;
  z-index: 0;
  top: 3px;
  bottom: 3px;
  left: 0;
  border-radius: var(--r-pill);
  background: var(--bg-elev);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.18), inset 0 1px 0 rgb(255 255 255 / 0.08);
  transition: transform var(--dur-base) var(--ease-in-out), width var(--dur-base) var(--ease-in-out);
}
:root:not([data-theme="light"]) .segmented .seg-indicator { background: rgb(255 255 255 / 0.14); }

.field {
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--fill);
  font-size: 16px; /* niente zoom su iOS */
  outline: none;
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field::placeholder { color: var(--text-3); }

.switch {
  position: relative;
  width: 51px;
  height: 31px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--fill-3);
  transition: background-color var(--dur-fast) ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgb(0 0 0 / 0.2);
  transition: transform var(--dur-base) var(--ease-out);
}
.switch[aria-checked="true"] { background: var(--good); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  background: var(--fill);
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.chip-accent { background: var(--accent-soft); color: var(--accent); }
.chip-good { background: var(--good-soft); color: var(--good); }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

/* Pastiglia voto */
.grade {
  --g: var(--text-2);
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  white-space: nowrap;
  border-radius: 14px;
  background: color-mix(in srgb, var(--g) 16%, transparent);
  color: var(--g);
  font-weight: 700;
  font-size: 1.0625rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.grade-sm { width: 34px; height: 30px; border-radius: 10px; font-size: 0.9rem; }
/* Medie (7,62): larghezza secondo il contenuto, minimo quella di un voto. */
.grade.grade-avg { width: auto; min-width: 44px; padding: 0 8px; }
.grade.grade-sm.grade-avg { min-width: 34px; padding: 0 6px; }
.g-great { --g: var(--great); }
.g-good { --g: var(--good); }
.g-ok { --g: var(--six); }
.g-bad { --g: var(--bad); }
.g-none { --g: var(--blue); }

/* Voto "rosso fuoco" (sotto il 4): piccole fiamme che escono da DIETRO il bordo superiore, larghe
   esattamente quanto la pastiglia. Ogni lingua ondeggia per conto suo (animazione CSS dentro l'SVG,
   scripts/generate_fire.py). Ordine dei livelli nel contesto isolato del voto:
   ::after fiamme (z -2) → ::before faccia piena (z -1, ne copre la base) → numero.
   Sotto il 3 (.g-devil) spuntano anche le corna da demone. */
.grade.g-fire {
  --fire: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 40 27%22%3E%3Cstyle%3E.f%7Btransform-box:fill-box%3Btransform-origin:50%25 100%25%3Banimation:k 1.6s ease-in-out infinite alternate%7D.l%7Bfill:%23ff913d%3Banimation-duration:1.3s%3Banimation-delay:-.7s%7D.r%7Bfill:%23ff8535%3Banimation-duration:1.5s%3Banimation-delay:-.3s%7D.m%7Bfill:%23ffb044%3Banimation-duration:1.75s%3Banimation-delay:-.9s%7D.i%7Bfill:%23ffdc78%3Banimation-duration:1.2s%3Banimation-delay:-.4s%7D%40keyframes k%7B0%25%7Btransform:scaleY(.91) skewX(-2deg)%7D50%25%7Btransform:scaleY(1.03) skewX(1deg)%7D100%25%7Btransform:scaleY(.96) skewX(2deg)%7D%7D%40media (prefers-reduced-motion:reduce)%7B.f%7Banimation:none%7D%7D%3C/style%3E%3Cpath class=%22f l%22 d=%22M1 27 C0 21 2 18 6 12 C6 16 9 17 9 20 C12 16 11 14 11 12 C17 19 17 23 15 27 Z%22/%3E%3Cpath class=%22f r%22 d=%22M25 27 C23 23 24 19 29 14 C29 18 31 19 32 20 C34 17 34 15 34 12 C39 19 40 23 39 27 Z%22/%3E%3Cpath class=%22f m%22 d=%22M12 27 C9 22 12 17 17 11 C20 7 20 4 20 2 C28 10 26 16 25 19 C29 15 29 13 28 10 C36 19 32 24 29 27 Z%22/%3E%3Cpath class=%22f i%22 d=%22M17 27 C15 23 17 20 20 16 C21 19 21 21 22 22 C24 19 24 17 24 16 C29 22 27 26 26 27 Z%22/%3E%3C/svg%3E");
  position: relative;
  isolation: isolate;
  overflow: visible;
  background: none;
  color: #fff;
  font-weight: 800;
}
.grade.g-devil { --fire: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 40 27%22%3E%3Cstyle%3E.f%7Btransform-box:fill-box%3Btransform-origin:50%25 100%25%3Banimation:k 1.6s ease-in-out infinite alternate%7D.l%7Bfill:%23ff913d%3Banimation-duration:1.3s%3Banimation-delay:-.7s%7D.r%7Bfill:%23ff8535%3Banimation-duration:1.5s%3Banimation-delay:-.3s%7D.m%7Bfill:%23ffb044%3Banimation-duration:1.75s%3Banimation-delay:-.9s%7D.i%7Bfill:%23ffdc78%3Banimation-duration:1.2s%3Banimation-delay:-.4s%7D%40keyframes k%7B0%25%7Btransform:scaleY(.91) skewX(-2deg)%7D50%25%7Btransform:scaleY(1.03) skewX(1deg)%7D100%25%7Btransform:scaleY(.96) skewX(2deg)%7D%7D%40media (prefers-reduced-motion:reduce)%7B.f%7Banimation:none%7D%7D%3C/style%3E%3Cpath class=%22f l%22 d=%22M1 27 C0 21 2 18 6 12 C6 16 9 17 9 20 C12 16 11 14 11 12 C17 19 17 23 15 27 Z%22/%3E%3Cpath class=%22f r%22 d=%22M25 27 C23 23 24 19 29 14 C29 18 31 19 32 20 C34 17 34 15 34 12 C39 19 40 23 39 27 Z%22/%3E%3Cpath class=%22f m%22 d=%22M12 27 C9 22 12 17 17 11 C20 7 20 4 20 2 C28 10 26 16 25 19 C29 15 29 13 28 10 C36 19 32 24 29 27 Z%22/%3E%3Cpath class=%22f i%22 d=%22M17 27 C15 23 17 20 20 16 C21 19 21 21 22 22 C24 19 24 17 24 16 C29 22 27 26 26 27 Z%22/%3E%3Cpath d=%22M6 26 C5 19 4 12 1 6 C7 9 11 15 13 26 Z%22 fill=%22%23c8161f%22 stroke=%22%234a0309%22 stroke-width=%221.1%22 stroke-linejoin=%22round%22/%3E%3Cpath d=%22M34 26 C35 19 36 12 39 6 C33 9 29 15 27 26 Z%22 fill=%22%23c8161f%22 stroke=%22%234a0309%22 stroke-width=%221.1%22 stroke-linejoin=%22round%22/%3E%3Cpath d=%22M7.5 21 C7 16 5.5 12 3.5 9%22 fill=%22none%22 stroke=%22%23ff7a6b%22 stroke-width=%221%22 stroke-linecap=%22round%22/%3E%3Cpath d=%22M32.5 21 C33 16 34.5 12 36.5 9%22 fill=%22none%22 stroke=%22%23ff7a6b%22 stroke-width=%221%22 stroke-linecap=%22round%22/%3E%3C/svg%3E"); }
.grade.g-fire::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(160deg, #d74b35, #b92f25);
  box-shadow: 0 3px 10px rgb(181 48 35 / 0.15);
}
.grade.g-devil::before { background: linear-gradient(160deg, #cf2b2b, #9c111a); }
.grade.g-fire::after {
  content: "";
  position: absolute;
  z-index: -2;
  left: 0;
  right: 0;
  bottom: 86%;
  aspect-ratio: 40 / 27;
  background: var(--fire) center bottom / 100% 100% no-repeat;
  pointer-events: none;
}

/* Dal 9 in su: pastiglia piena con un riflesso che la attraversa ogni tanto (solo transform). */
.grade.g-top {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  color: #fff;
  background: linear-gradient(160deg, color-mix(in srgb, var(--good) 82%, #fff) 0%, var(--good) 55%, color-mix(in srgb, var(--good) 75%, #000) 100%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.35), 0 6px 16px -8px color-mix(in srgb, var(--good) 80%, transparent);
  text-shadow: 0 1px 0 rgb(0 60 20 / 0.35);
}
.grade.g-top::after {
  content: "";
  position: absolute;
  inset: -20% auto -20% 0;
  width: 45%;
  z-index: -1;
  background: linear-gradient(100deg, transparent 0%, rgb(255 255 255 / 0.55) 50%, transparent 100%);
  transform: translateX(-140%) skewX(-18deg);
  animation: g-top-shine 4.2s cubic-bezier(0.77, 0, 0.175, 1) 1s infinite;
  will-change: transform;
  pointer-events: none;
}
@keyframes g-top-shine {
  0% { transform: translateX(-140%) skewX(-18deg); }
  28%, 100% { transform: translateX(330%) skewX(-18deg); }
}
@media (prefers-reduced-motion: reduce) { .grade.g-top::after { animation: none; opacity: 0; } }

/* Dettaglio voto */
.gd-hero {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 34px 12px 22px;
  text-align: center;
  isolation: isolate;
}
.gd-hero .gd-big {
  width: 96px;
  height: 96px;
  padding: 0;
  border-radius: 30px;
  font-size: 2.6rem;
  letter-spacing: -0.04em;
  animation: gd-in 520ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.gd-hero.is-low .gd-big.g-fire { margin-top: 40px; }
.gd-copy { display: grid; gap: 4px; animation: gd-copy-in 480ms cubic-bezier(0.23, 1, 0.32, 1) 90ms both; }
.gd-copy .body-2 { color: var(--text-2); }
.gd-glow {
  position: absolute;
  z-index: -2;
  left: 50%;
  top: 30px;
  width: 220px;
  height: 220px;
  margin-left: -110px;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--g, var(--accent)) 30%, transparent), transparent);
  opacity: 0.6;
  pointer-events: none;
}
.gd-hero:has(.g-good) .gd-glow { --g: var(--good); }
.gd-hero:has(.g-ok) .gd-glow { --g: var(--ok); }
.gd-hero:has(.g-bad) .gd-glow { --g: var(--bad); }
@keyframes gd-in { from { opacity: 0; transform: scale(0.82); } to { opacity: 1; transform: none; } }
@keyframes gd-copy-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Celebrazione (≥ 9): il voto cade dall'alto e rimbalza, raggi che ruotano, alone che pulsa, coriandoli. */
.gd-hero.is-top { padding-top: 46px; padding-bottom: 28px; }
.gd-hero.is-top .gd-big {
  width: 112px;
  height: 112px;
  border-radius: 34px;
  font-size: 3.1rem;
  animation: gd-pop 900ms linear both;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.4), 0 18px 40px -14px color-mix(in srgb, var(--good) 90%, transparent);
}
.gd-hero.is-top .gd-glow {
  top: 18px;
  width: 260px;
  height: 260px;
  margin-left: -130px;
  animation: gd-glow 2.4s cubic-bezier(0.77, 0, 0.175, 1) 600ms infinite alternate;
  will-change: transform, opacity;
}
.gd-rays {
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 102px;
  width: 360px;
  height: 360px;
  margin: -180px 0 0 -180px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--good) 28%, transparent) 0deg 9deg, transparent 9deg 24deg);
  -webkit-mask: radial-gradient(closest-side, #000 22%, transparent 100%);
  mask: radial-gradient(closest-side, #000 22%, transparent 100%);
  opacity: 0;
  animation: gd-rays-in 700ms cubic-bezier(0.23, 1, 0.32, 1) 220ms forwards, gd-spin 14s linear infinite;
  will-change: transform, opacity;
  pointer-events: none;
}
.gd-confetti { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 5; border-radius: inherit; pointer-events: none; }
.gd-hero.is-top .gd-copy .title-2 {
  background: linear-gradient(90deg, var(--good), #ffd60a, var(--good));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
/* Rimbalzo "a molla" scritto a mano: caduta, schiacciamento, due rimbalzi smorzati. */
@keyframes gd-pop {
  0% { opacity: 0; transform: translateY(-70px) scale(0.4) rotate(-14deg); }
  22% { opacity: 1; transform: translateY(0) scale(1.08, 0.9) rotate(4deg); }
  38% { transform: translateY(-14px) scale(0.96, 1.06) rotate(-2deg); }
  54% { transform: translateY(0) scale(1.04, 0.97) rotate(1deg); }
  70% { transform: translateY(-4px) scale(0.99, 1.01); }
  84% { transform: translateY(0) scale(1.01, 0.995); }
  100% { opacity: 1; transform: none; }
}
@keyframes gd-glow { from { transform: scale(0.9); opacity: 0.55; } to { transform: scale(1.12); opacity: 0.9; } }
@keyframes gd-rays-in { to { opacity: 1; } }
@keyframes gd-spin { to { transform: rotate(360deg); } }
.gd-hero.is-still .gd-big, .gd-hero.is-still .gd-copy { animation: gd-fade 300ms ease both; }
.gd-hero.is-still .gd-rays { animation: gd-rays-in 300ms ease forwards; }
.gd-hero.is-still .gd-glow { animation: none; }
@keyframes gd-fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .gd-hero .gd-big, .gd-copy { animation: gd-fade 300ms ease both !important; }
  .gd-rays { animation: gd-rays-in 300ms ease forwards !important; }
  .gd-glow { animation: none !important; }
}
.gd-note { font-style: italic; color: var(--text-2); margin-bottom: 12px; }
.gd-recover { margin-bottom: 12px; display: grid; gap: 6px; }
.gd-recover .title-3 { display: flex; align-items: center; gap: 8px; }
.gd-recover .title-3 svg { width: 18px; height: 18px; color: var(--accent); }
.gd-facts .row-trail { font-weight: 600; }

/* Anello media */
.ring { position: relative; display: grid; place-items: center; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-track { stroke: var(--fill-2); }
.ring .ring-value { transition: stroke-dashoffset 900ms var(--ease-out); }
.ring .ring-label { position: absolute; text-align: center; }
.ring .ring-num { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1; }

/* ---------- liste stile iOS ---------- */
.list { border-radius: var(--r-lg); overflow: hidden; }
.list.card { padding: 0; }
.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  padding: 12px 18px;
  width: 100%;
  text-align: left;
  transition: background-color var(--dur-fast) ease;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 18px; right: 0; height: 1px; background: var(--hairline); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 560; letter-spacing: -0.005em; overflow-wrap: anywhere; }
.row-sub { font-size: 0.84rem; color: var(--text-2); margin-top: 2px; overflow-wrap: anywhere; }
.row .row-trail { flex: none; color: var(--text-3); font-size: 0.9rem; display: flex; align-items: center; gap: 8px; }
.row .chev { width: 14px; height: 14px; color: var(--text-3); flex: none; }
button.row:active, a.row:active { background: var(--fill); }
@media (hover: hover) and (pointer: fine) { button.row:hover, a.row:hover { background: var(--fill); } }
.row-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); }
.row-icon svg { width: 18px; height: 18px; }

/* ---------- layout app ---------- */
.app { min-height: 100dvh; }
.sidebar {
  position: fixed;
  z-index: 30;
  top: 12px;
  bottom: 12px;
  left: 12px;
  width: calc(var(--sidebar-w) - 12px);
  display: none;
  flex-direction: column;
  border-radius: 26px;
  padding: 18px 12px;
}
.sidebar nav { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; margin: 0 -4px; padding: 0 4px; }
.sidebar nav::-webkit-scrollbar { display: none; }
@media (max-height: 820px) { .nav-item { min-height: 36px; } .nav-group { margin-top: 4px; } .nav-group-label { padding-top: 6px; } }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand .logo-img { height: 34px; width: auto; }
/* Logo: scritta bianca sul tema scuro, quasi nera sul chiaro. */
.logo-on-light { display: none; }
:root[data-theme="light"] .logo-on-dark { display: none; }
:root[data-theme="light"] .logo-on-light { display: block; }
.nav-group { margin-top: 10px; }
.nav-group-label { padding: 8px 12px 6px; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  color: var(--text-2);
  font-weight: 560;
  font-size: 0.94rem;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item[aria-current="page"] { background: var(--fill-2); color: var(--text); }
.nav-item[aria-current="page"] svg { color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .nav-item:hover { background: var(--fill); color: var(--text); } }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 0.72rem; font-weight: 700; display: grid; place-items: center; }
.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--hairline); }

.main {
  position: relative;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 8px) var(--gutter) calc(var(--tabbar-h) + var(--safe-bottom) + 40px);
}
.page { max-width: var(--content-max); margin: 0 auto; }

/* Barra compatta (compare scorrendo: il titolo grande "si rimpicciolisce" nella barra) */
.topbar {
  position: fixed;
  z-index: 25;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--safe-top) + 52px);
  padding: var(--safe-top) var(--gutter) 0;
  display: flex;
  align-items: center;
  gap: 12px;
  border-width: 0 0 1px;
  border-radius: 0;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.topbar::before { display: none; }
.topbar.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.topbar-title { flex: 1; min-width: 0; text-align: center; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-side { width: 96px; display: flex; }
.topbar-side.end { justify-content: flex-end; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 28px 0 22px; }
.page-header .eyebrow { margin-bottom: 8px; }
.page-header .subtitle { margin-top: 8px; max-width: 60ch; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Tab bar flottante (mobile) */
.tabbar {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 12px);
  width: min(calc(100% - 24px), 460px);
  height: var(--tabbar-h);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px;
  border-radius: 32px;
}
.tab {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 24px;
  color: var(--text-2);
  font-size: 0.66rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  transition: color var(--dur-fast) ease, transform var(--dur-press) var(--ease-out);
  touch-action: manipulation;
}
.tab:active { transform: scale(0.94); }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab-indicator {
  position: absolute;
  z-index: 0;
  top: 6px;
  bottom: 6px;
  left: 6px;
  width: calc((100% - 12px) / 5);
  border-radius: 26px;
  background: var(--fill-2);
  transition: transform 420ms var(--ease-drawer);
}
.tab .tab-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 0.65rem; font-weight: 700; display: grid; place-items: center; }

@media (min-width: 1024px) {
  .sidebar { display: flex; }
  .tabbar { display: none; }
  .main { margin-left: var(--sidebar-w); padding: 12px var(--gutter) 64px; }
  .topbar { left: calc(var(--sidebar-w) + 12px); right: 12px; top: 12px; height: 52px; padding: 0 20px; border-radius: 18px; border-width: 1px; }
}

/* ---------- griglie ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.hstack { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section { margin-top: 32px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding: 0 4px; }

/* ---------- pannelli (sheet), menu, toast ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}
.scrim.is-open { opacity: 1; }
.sheet {
  position: fixed;
  z-index: 61;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(100dvh - var(--safe-top) - 24px);
  display: flex;
  flex-direction: column;
  border-radius: 30px 30px 0 0;
  padding-bottom: var(--safe-bottom);
  transform: translateY(100%);
  transition: transform var(--dur-sheet) var(--ease-drawer);
  touch-action: pan-y;
}
.sheet.is-open { transform: translateY(0); }
.sheet { will-change: transform; }
/* Sui telefoni i pannelli sono pieni, non di vetro: una sfocatura dello sfondo grande quanto il pannello
   va ricalcolata a ogni frame mentre sale (e mentre scorri dentro), e su schermi ad alta densità
   come quello del Galaxy S24 Ultra faceva scattare l'apertura di "Altro". Lo sfondo è già oscurato. */
@media (pointer: coarse) {
  .sheet.glass, .menu.glass {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--bg-elev);
  }
  .sheet.glass::before { display: none; }
}
.sheet-grabber { flex: none; display: grid; place-items: center; height: 22px; cursor: grab; }
.sheet-grabber::before { content: ""; width: 38px; height: 5px; border-radius: 3px; background: var(--fill-3); }
.sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 20px 12px; }
.sheet-body { flex: 1; overflow: auto; overscroll-behavior: contain; padding: 0 20px 24px; }
@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(560px, calc(100% - 48px));
    max-height: min(760px, calc(100dvh - 64px));
    border-radius: 30px;
    padding-bottom: 0;
    transform: translate(-50%, -50%) scale(0.96);
    opacity: 0;
    transition: transform var(--dur-base) var(--ease-out), opacity var(--dur-base) var(--ease-out);
  }
  .sheet.is-open { transform: translate(-50%, -50%); opacity: 1; }
  .sheet.sheet-wide { width: min(760px, calc(100% - 48px)); }
  .sheet-grabber { display: none; }
  .sheet-head { padding-top: 22px; }
}

.menu {
  position: fixed;
  z-index: 70;
  min-width: 220px;
  padding: 6px;
  border-radius: 20px;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.menu.is-open { opacity: 1; transform: none; }
.menu-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; min-height: 42px; padding: 0 14px; border-radius: 14px; font-weight: 560; text-align: left; }
.menu-item[aria-checked="true"] { color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .menu-item:hover { background: var(--fill); } }

.toaster { position: fixed; z-index: 90; left: 50%; bottom: calc(var(--safe-bottom) + var(--tabbar-h) + 24px); transform: translateX(-50%); width: min(420px, calc(100% - 32px)); pointer-events: none; }
@media (min-width: 1024px) { .toaster { bottom: 24px; left: calc(50% + var(--sidebar-w) / 2); } }
.toast {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 12px 16px;
  border-radius: 20px;
  font-weight: 560;
  pointer-events: auto;
  transform: translateY(calc(var(--offset, 0px) * -1)) scale(var(--scale, 1));
  transition: transform 400ms var(--ease-out), opacity 400ms var(--ease-out);
}
.toast[data-mounted="false"] { opacity: 0; transform: translateY(100%); }
.toast[data-removed="true"] { opacity: 0; transform: translateY(100%); }
.toast .dot { background: var(--good); }
.toast.is-error .dot { background: var(--bad); }

/* ---------- stati ---------- */
.skeleton { background: var(--fill); border-radius: 12px; }
.skeleton-line { height: 14px; border-radius: 7px; background: var(--fill); }
.empty { display: grid; place-items: center; text-align: center; gap: 10px; padding: 48px 20px; color: var(--text-2); }
.empty svg { width: 44px; height: 44px; color: var(--text-3); }
.empty .title-3 { color: var(--text); }
.error-box { border-color: color-mix(in srgb, var(--bad) 30%, transparent); }

/* ---------- motion ---------- */
/* Entrata della vista: breve, una volta per navigazione. */
.view-enter { animation: view-in 320ms var(--ease-out) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } }
.stagger > * { animation: rise 360ms var(--ease-out) both; animation-delay: calc(min(var(--i, 0), 8) * 40ms); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

::view-transition-old(root) { animation: vt-out 160ms var(--ease-out) both; }
::view-transition-new(root) { animation: vt-in 260ms var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }
.sidebar, .tabbar, .topbar { view-transition-name: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; }
  .sheet, .menu, .toast, .topbar, .tab-indicator, .seg-indicator, .switch::after, .ring .ring-value { transition-property: opacity !important; transition-duration: 200ms !important; }
  .btn:active, .pressable:active, .tab:active { transform: none; }
}

/* ---------- campanella notifiche ---------- */
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-right: 6px; }
.brand-row .brand { padding-bottom: 18px; }
.bell-btn, .bell-float { position: relative; display: grid; place-items: center; color: var(--text-2); transition: transform var(--dur-press) var(--ease-out), color var(--dur-fast) ease; }
.bell-btn { width: 36px; height: 36px; margin-bottom: 18px; border-radius: 50%; }
.bell-btn:active, .bell-float:active { transform: scale(0.94); }
.bell-btn svg, .bell-float svg { width: 21px; height: 21px; }
@media (hover: hover) and (pointer: fine) { .bell-btn:hover { color: var(--text); background: var(--fill); } }
.bell-float { position: fixed; z-index: 26; top: calc(var(--safe-top) + 10px); right: 14px; width: 42px; height: 42px; border-radius: 50%; color: var(--text); }
.bell-badge { position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 0.64rem; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--bg); }
@media (min-width: 1024px) { .bell-float { display: none; } }
/* La barra compatta (scroll) occupa la stessa zona: la campanella resta sopra, a destra. */
.topbar .topbar-side.end { padding-right: 48px; }
@media (min-width: 1024px) { .topbar .topbar-side.end { padding-right: 0; } }

/* ---------- icone attive: due toni come gli SF Symbols ---------- */
.tab[aria-current="page"] svg,
.nav-item[aria-current="page"] svg { fill: currentColor; fill-opacity: 0.2; stroke-width: 1.9; }

/* ---------- personalizzazione ---------- */
.no-aurora .aurora { display: none; }
.density-compact { --gutter: clamp(12px, 3vw, 28px); }
.density-compact .card-pad { padding: 14px; }
.density-compact .row { min-height: 48px; padding-top: 9px; padding-bottom: 9px; }
.density-compact .page-header { padding: 18px 0 14px; }
.density-compact .large-title { font-size: clamp(1.7rem, 1.2rem + 2vw, 2.4rem); }
.density-compact .grid, .density-compact .stack, .density-compact .home-grid { gap: 10px; }
/* Mobile: come la barra di navigazione iOS, la campanella sta in una riga sopra il titolo grande. */
@media (max-width: 1023px) { .main { padding-top: calc(var(--safe-top) + 56px); } .page-header { padding-top: 4px; } }
.toast.is-clickable { cursor: pointer; }
