/* ==========================================================================
   Scaffale — Design System editoriale mobile-first (Blocco 3)
   Font locali OFL (Fraunces, Literata, Inter). Nessuna risorsa esterna.
   Struttura dei token semantici, preferenza di sistema `prefers-color-scheme`,
   `prefers-contrast` e `forced-colors` ispirati a `tema-chiaro-scuro.css`
   (Manuale della bellezza e della funzionalità – by MrEGLD, licenza MIT).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tipografia locale (@font-face OFL) con metriche armonizzate anti-CLS
   -------------------------------------------------------------------------- */
@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  size-adjust: 100%;
  ascent-override: 94%;
  descent-override: 24%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-Italic-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
  size-adjust: 100%;
  ascent-override: 94%;
  descent-override: 24%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Literata";
  src: url("fonts/Literata-Variable.ttf") format("truetype");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
  size-adjust: 100%;
  ascent-override: 96%;
  descent-override: 25%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Literata";
  src: url("fonts/Literata-Italic-Variable.ttf") format("truetype");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
  size-adjust: 100%;
  ascent-override: 96%;
  descent-override: 25%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  size-adjust: 100%;
  ascent-override: 90%;
  descent-override: 22%;
  line-gap-override: 0%;
}

/* --------------------------------------------------------------------------
   2. Design Tokens — Palette semantica, spazi 4/8, tipi fluidi, bersagli
   -------------------------------------------------------------------------- */
/* TOKENS:START */
:root {
  color-scheme: light dark;

  /* Ruoli colore — Tema Carta (predefinito chiaro: avorio + petrolio + terracotta) */
  --color-bg: #f7f4ee;
  --color-bg-subtle: #ede7db;
  --color-bg-stage: #f2ede3;
  --color-surface: #fffdf9;
  --color-surface-elevated: #ffffff;
  --color-surface-hover: #f3eee4;
  --color-surface-glass: rgb(255 253 249 / 0.9);
  --color-backdrop: rgb(12 20 26 / 0.48);

  --color-text: #18232b;
  --color-text-secondary: #394854;
  --color-text-muted: #53626e;

  --color-primary: #0f4c5c;
  --color-primary-hover: #0a3946;
  --color-primary-active: #072c36;
  --color-primary-soft: #e2f0f3;
  --color-primary-border: #8ebbc7;
  --color-on-primary: #ffffff;

  --color-accent: #a14320;
  --color-accent-text: #973d1c;
  --color-accent-hover: #803216;
  --color-accent-soft: #faece5;
  --color-accent-border: #e3b29d;
  --color-on-accent: #ffffff;

  --color-amber: #7d5310;
  --color-amber-soft: #faf0da;
  --color-amber-border: #d9ba7b;

  --color-border: #d8d0c3;
  --color-border-control: #6f685d;
  --color-focus: #0f4c5c;
  --color-focus-ring: rgb(15 76 92 / 0.22);

  --color-mark-bg: #fce09b;
  --color-mark-text: #18232b;

  --color-docente-bg: #e8f0f6;
  --color-docente-border: #7ea3be;
  --color-docente-text: #12364f;

  --color-error-bg: #fdecec;
  --color-error-border: #c97272;
  --color-error-text: #8b1e1e;
  --color-error-solid: #8b1e1e;
  --color-on-error: #ffffff;

  --color-success-bg: #e4f2eb;
  --color-success-border: #6ba78a;
  --color-success-text: #134a34;

  --color-skeleton: #e4ddd0;
  --color-skeleton-shine: #f2ece1;

  --color-area-turismo-bg: #e6f0f3;
  --color-area-economia-bg: #f6ebe5;
  --color-area-commerciale-bg: #f4eedf;

  /* Token colore Post-it (6 colori, Tema Carta) */
  --color-note-giallo-bg: #fdf1c0;
  --color-note-giallo-text: #2e2100;
  --color-note-giallo-border: #875f00;

  --color-note-rosa-bg: #fbe5ec;
  --color-note-rosa-text: #3b0f20;
  --color-note-rosa-border: #a1365a;

  --color-note-verde-bg: #e2f2e6;
  --color-note-verde-text: #0f2e1a;
  --color-note-verde-border: #236e43;

  --color-note-azzurro-bg: #e0eef8;
  --color-note-azzurro-text: #0d293e;
  --color-note-azzurro-border: #1d6696;

  --color-note-lilla-bg: #eee6f8;
  --color-note-lilla-text: #281542;
  --color-note-lilla-border: #68429e;

  --color-note-arancio-bg: #fce8d2;
  --color-note-arancio-text: #3c1c05;
  --color-note-arancio-border: #a34b12;

  /* Famiglie tipografiche */
  --font-display: "Fraunces", Georgia, "Liberation Serif", serif;
  --font-serif: "Literata", Georgia, "Palatino Linotype", "Liberation Serif", serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  /* Scala tipografica corta e fluida (minimi e massimi in rem) */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1.04rem + 0.4vw, 1.3125rem);
  --text-xl: clamp(1.375rem, 1.2rem + 0.75vw, 1.75rem);
  --text-2xl: clamp(1.75rem, 1.4rem + 1.4vw, 2.5rem);

  --leading-tight: 1.18;
  --leading-base: 1.55;
  --measure-ui: 66ch;

  /* Preferenze dinamiche del lettore (aggiornate da app.js, misura 60–72ch) */
  --reader-font: var(--font-serif);
  --reader-size: 1.1875rem;
  --reader-leading: 1.7;
  --reader-measure: 66ch;

  /* Scala di spaziatura 4 / 8 px in rem */
  --space-1: 0.25rem;   /*  4px */
  --space-2: 0.5rem;    /*  8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.5rem;    /* 24px */
  --space-6: 2rem;      /* 32px */
  --space-7: 3rem;      /* 48px */
  --space-8: 4rem;      /* 64px */
  --space-9: 6rem;      /* 96px */
  --space-fluid-page: clamp(1rem, 0.6rem + 1.8vw, 2rem);
  --space-fluid-card: clamp(1.25rem, 0.95rem + 1.4vw, 2.25rem);

  /* Misure minime dei bersagli tattili (WCAG 2.5.8 + Apple HIG / Material) */
  --touch-min: 1.5rem;        /* 24px pavimento WCAG 2.2 AA */
  --touch-target: 2.75rem;    /* 44px comandi principali */
  --touch-target-lg: 3rem;    /* 48px barra inferiore e CTA mobile */

  /* Raggi */
  --radius-xs: 0.375rem;
  --radius-sm: 0.625rem;
  --radius-md: 0.875rem;
  --radius-lg: 1.125rem;
  --radius-xl: 1.375rem;
  --radius-pill: 999px;

  /* Ombre */
  --shadow-xs: 0 1px 2px rgb(24 35 43 / 0.06);
  --shadow-sm: 0 1px 2px rgb(24 35 43 / 0.06), 0 4px 12px rgb(24 35 43 / 0.05);
  --shadow-md: 0 2px 6px rgb(24 35 43 / 0.07), 0 12px 28px rgb(24 35 43 / 0.08);
  --shadow-lg: 0 6px 14px rgb(24 35 43 / 0.08), 0 20px 44px rgb(24 35 43 / 0.12);
  --shadow-cover: 0 2px 4px rgb(15 29 38 / 0.14), 0 10px 22px rgb(15 29 38 / 0.18), -3px 0 8px rgb(15 29 38 / 0.08);
  --shadow-float: 0 4px 12px rgb(24 35 43 / 0.08), 0 16px 36px rgb(24 35 43 / 0.12);

  /* Durate e curve */
  --dur-fast: 140ms;
  --dur-base: 220ms;
  --dur-slow: 320ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  /* Geometria shell */
  --sidebar-w: 16.5rem;
  --topbar-h: 4rem;
  --bottom-nav-h: 4.25rem;
}

html[data-tema="carta"] {
  color-scheme: light;
}

/* Tema Chiaro (carta neutra luminosa) */
html[data-tema="chiaro"] {
  color-scheme: light;

  --color-bg: #f5f7f8;
  --color-bg-subtle: #e9eef2;
  --color-bg-stage: #edf2f5;
  --color-surface: #ffffff;
  --color-surface-elevated: #ffffff;
  --color-surface-hover: #f1f5f7;
  --color-surface-glass: rgb(255 255 255 / 0.92);

  --color-text: #131c24;
  --color-text-secondary: #34434f;
  --color-text-muted: #4f5e6a;

  --color-primary: #0d4b5b;
  --color-primary-hover: #083744;
  --color-primary-active: #062a34;
  --color-primary-soft: #e2f1f5;
  --color-primary-border: #8db9c6;
  --color-on-primary: #ffffff;

  --color-accent: #9d3f1c;
  --color-accent-text: #923918;
  --color-accent-hover: #7c3014;
  --color-accent-soft: #fbece6;
  --color-accent-border: #e5b3a0;
  --color-on-accent: #ffffff;

  --color-amber: #7d5310;
  --color-amber-soft: #faf0da;
  --color-amber-border: #d9ba7b;

  --color-border: #cfd8df;
  --color-border-control: #63707a;
  --color-focus: #0d4b5b;
  --color-focus-ring: rgb(13 75 91 / 0.22);

  --color-mark-bg: #fce09b;
  --color-mark-text: #131c24;

  --color-docente-bg: #e8f0f6;
  --color-docente-border: #7ea3be;
  --color-docente-text: #12364f;

  --color-error-bg: #fdecec;
  --color-error-border: #c97272;
  --color-error-text: #8b1e1e;
  --color-error-solid: #8b1e1e;
  --color-on-error: #ffffff;

  --color-success-bg: #e4f2eb;
  --color-success-border: #6ba78a;
  --color-success-text: #134a34;

  --color-skeleton: #dfe6eb;
  --color-skeleton-shine: #eef3f6;

  --color-area-turismo-bg: #e8f2f5;
  --color-area-economia-bg: #f8ece6;
  --color-area-commerciale-bg: #f6f0e1;

  /* Token colore Post-it (6 colori, Tema Chiaro) */
  --color-note-giallo-bg: #fff6cc;
  --color-note-giallo-text: #2c1f00;
  --color-note-giallo-border: #8c6400;

  --color-note-rosa-bg: #fee8ef;
  --color-note-rosa-text: #3a0e1f;
  --color-note-rosa-border: #a63a5f;

  --color-note-verde-bg: #e3f7ea;
  --color-note-verde-text: #0e2c19;
  --color-note-verde-border: #267347;

  --color-note-azzurro-bg: #e1f2fd;
  --color-note-azzurro-text: #0c273b;
  --color-note-azzurro-border: #1e6a9c;

  --color-note-lilla-bg: #f1e9fe;
  --color-note-lilla-text: #261440;
  --color-note-lilla-border: #6c45a3;

  --color-note-arancio-bg: #feeeda;
  --color-note-arancio-text: #3a1a04;
  --color-note-arancio-border: #a84f14;
}

/* Preferenza di sistema scura quando l'utente non ha scelto Carta o Chiaro */
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="carta"]):not([data-tema="chiaro"]) {
    color-scheme: dark;

    --color-bg: #12171b;
    --color-bg-subtle: #0d1216;
    --color-bg-stage: #171f25;
    --color-surface: #1a2228;
    --color-surface-elevated: #212b33;
    --color-surface-hover: #25313a;
    --color-surface-glass: rgb(26 34 40 / 0.9);
    --color-backdrop: rgb(4 8 11 / 0.64);

    --color-text: #eef2f5;
    --color-text-secondary: #c9d4dc;
    --color-text-muted: #9fb0bc;

    --color-primary: #68c2d5;
    --color-primary-hover: #81d0e0;
    --color-primary-active: #51b0c4;
    --color-primary-soft: #142f39;
    --color-primary-border: #326678;
    --color-on-primary: #071a21;

    --color-accent: #ea9470;
    --color-accent-text: #f1a484;
    --color-accent-hover: #f5b69b;
    --color-accent-soft: #362019;
    --color-accent-border: #6b3e2e;
    --color-on-accent: #210e07;

    --color-amber: #e4ba6c;
    --color-amber-soft: #302614;
    --color-amber-border: #634d26;

    --color-border: #2c3943;
    --color-border-control: #8a9aa6;
    --color-focus: #68c2d5;
    --color-focus-ring: rgb(104 194 213 / 0.28);

    --color-mark-bg: #6e5013;
    --color-mark-text: #fff6de;

    --color-docente-bg: #152834;
    --color-docente-border: #3c6f8d;
    --color-docente-text: #c2e2f6;

    --color-error-bg: #36181a;
    --color-error-border: #9a4a4e;
    --color-error-text: #f7b5b5;
    --color-error-solid: #f0a3a3;
    --color-on-error: #360d0d;

    --color-success-bg: #142e24;
    --color-success-border: #35755b;
    --color-success-text: #9bd8bc;

    --color-skeleton: #25313b;
    --color-skeleton-shine: #2f3e4a;

    --color-area-turismo-bg: #152a32;
    --color-area-economia-bg: #2d1f1b;
    --color-area-commerciale-bg: #2a2417;

    /* Token colore Post-it (6 colori, Auto dark) */
    --color-note-giallo-bg: #332a10;
    --color-note-giallo-text: #fceeb8;
    --color-note-giallo-border: #d6ad3e;

    --color-note-rosa-bg: #381a26;
    --color-note-rosa-text: #ffd6e4;
    --color-note-rosa-border: #df7fa3;

    --color-note-verde-bg: #152e20;
    --color-note-verde-text: #ccf0d8;
    --color-note-verde-border: #5eb582;

    --color-note-azzurro-bg: #14293a;
    --color-note-azzurro-text: #cde8fc;
    --color-note-azzurro-border: #64addb;

    --color-note-lilla-bg: #261c3a;
    --color-note-lilla-text: #e6d8fc;
    --color-note-lilla-border: #a686db;

    --color-note-arancio-bg: #382112;
    --color-note-arancio-text: #ffe0c2;
    --color-note-arancio-border: #de8a4b;

    --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.35);
    --shadow-sm: 0 2px 6px rgb(0 0 0 / 0.35), 0 6px 16px rgb(0 0 0 / 0.28);
    --shadow-md: 0 4px 12px rgb(0 0 0 / 0.4), 0 14px 32px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 8px 20px rgb(0 0 0 / 0.45), 0 24px 48px rgb(0 0 0 / 0.42);
    --shadow-cover: 0 4px 10px rgb(0 0 0 / 0.45), 0 14px 28px rgb(0 0 0 / 0.45);
    --shadow-float: 0 6px 18px rgb(0 0 0 / 0.45), 0 20px 44px rgb(0 0 0 / 0.45);
  }
}

/* Tema Scuro esplicito (vince sulla preferenza di sistema) */
html[data-tema="scuro"] {
  color-scheme: dark;

  --color-bg: #12171b;
  --color-bg-subtle: #0d1216;
  --color-bg-stage: #171f25;
  --color-surface: #1a2228;
  --color-surface-elevated: #212b33;
  --color-surface-hover: #25313a;
  --color-surface-glass: rgb(26 34 40 / 0.9);
  --color-backdrop: rgb(4 8 11 / 0.64);

  --color-text: #eef2f5;
  --color-text-secondary: #c9d4dc;
  --color-text-muted: #9fb0bc;

  --color-primary: #68c2d5;
  --color-primary-hover: #81d0e0;
  --color-primary-active: #51b0c4;
  --color-primary-soft: #142f39;
  --color-primary-border: #326678;
  --color-on-primary: #071a21;

  --color-accent: #ea9470;
  --color-accent-text: #f1a484;
  --color-accent-hover: #f5b69b;
  --color-accent-soft: #362019;
  --color-accent-border: #6b3e2e;
  --color-on-accent: #210e07;

  --color-amber: #e4ba6c;
  --color-amber-soft: #302614;
  --color-amber-border: #634d26;

  --color-border: #2c3943;
  --color-border-control: #8a9aa6;
  --color-focus: #68c2d5;
  --color-focus-ring: rgb(104 194 213 / 0.28);

  --color-mark-bg: #6e5013;
  --color-mark-text: #fff6de;

  --color-docente-bg: #152834;
  --color-docente-border: #3c6f8d;
  --color-docente-text: #c2e2f6;

  --color-error-bg: #36181a;
  --color-error-border: #9a4a4e;
  --color-error-text: #f7b5b5;
  --color-error-solid: #f0a3a3;
  --color-on-error: #360d0d;

  --color-success-bg: #142e24;
  --color-success-border: #35755b;
  --color-success-text: #9bd8bc;

  --color-skeleton: #25313b;
  --color-skeleton-shine: #2f3e4a;

  --color-area-turismo-bg: #152a32;
  --color-area-economia-bg: #2d1f1b;
  --color-area-commerciale-bg: #2a2417;

  /* Token colore Post-it (6 colori, Tema Scuro) */
  --color-note-giallo-bg: #332a10;
  --color-note-giallo-text: #fceeb8;
  --color-note-giallo-border: #d6ad3e;

  --color-note-rosa-bg: #381a26;
  --color-note-rosa-text: #ffd6e4;
  --color-note-rosa-border: #df7fa3;

  --color-note-verde-bg: #152e20;
  --color-note-verde-text: #ccf0d8;
  --color-note-verde-border: #5eb582;

  --color-note-azzurro-bg: #14293a;
  --color-note-azzurro-text: #cde8fc;
  --color-note-azzurro-border: #64addb;

  --color-note-lilla-bg: #261c3a;
  --color-note-lilla-text: #e6d8fc;
  --color-note-lilla-border: #a686db;

  --color-note-arancio-bg: #382112;
  --color-note-arancio-text: #ffe0c2;
  --color-note-arancio-border: #de8a4b;

  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.35);
  --shadow-sm: 0 2px 6px rgb(0 0 0 / 0.35), 0 6px 16px rgb(0 0 0 / 0.28);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.4), 0 14px 32px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 8px 20px rgb(0 0 0 / 0.45), 0 24px 48px rgb(0 0 0 / 0.42);
  --shadow-cover: 0 4px 10px rgb(0 0 0 / 0.45), 0 14px 28px rgb(0 0 0 / 0.45);
  --shadow-float: 0 6px 18px rgb(0 0 0 / 0.45), 0 20px 44px rgb(0 0 0 / 0.45);
}

/* Contrasto aumentato dal sistema */
@media (prefers-contrast: more) {
  :root {
    --color-text-muted: var(--color-text);
    --color-border: var(--color-border-control);
    --color-border-control: var(--color-text);
  }
}
/* TOKENS:END */

/* --------------------------------------------------------------------------
   3. Reset, accessibilità e focus non coperto (Mobile first: 320px+)
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 100%;
  line-height: var(--leading-base);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  scroll-padding-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + var(--space-4));
  scroll-padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + var(--space-5));
  scrollbar-color: var(--color-border-control) transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-size: var(--text-base);
  background: var(--color-bg);
  color: var(--color-text);
  overflow-x: clip;
}

body[data-page="lettore"] {
  background: var(--color-bg-subtle);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-control) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border-control);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}

img,
svg {
  max-width: 100%;
  display: block;
}

a {
  color: var(--color-primary);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
  transition: color var(--dur-fast) var(--ease-out);
}

a:hover {
  color: var(--color-primary-hover);
}

/* Focus sempre visibile e mai coperto dalle barre fisse (WCAG 2.4.7 + 2.4.11) */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
  box-shadow: 0 0 0 6px var(--color-focus-ring);
}

a,
button,
input,
select,
summary,
[tabindex] {
  scroll-margin-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + var(--space-5));
  scroll-margin-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + var(--space-5));
}

.skip-link {
  position: fixed;
  left: -9999px;
  top: max(var(--space-3), env(safe-area-inset-top));
  min-height: var(--touch-target);
  display: inline-flex;
  align-items: center;
  background: var(--color-primary);
  color: var(--color-on-primary);
  padding: var(--space-2) var(--space-5);
  font-weight: 700;
  font-size: var(--text-sm);
  z-index: 1000;
  text-decoration: none;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
}

.skip-link:focus,
.skip-link:focus-visible {
  left: max(var(--space-4), env(safe-area-inset-left));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   4. App Shell — Mobile first (cassetto laterale + barra inferiore + topbar)
   -------------------------------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100dvh;
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: min(18rem, 86vw);
  height: 100dvh;
  background: var(--color-bg-subtle);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: max(var(--space-5), env(safe-area-inset-top)) var(--space-4) max(var(--space-5), env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left));
  gap: var(--space-5);
  overflow-y: auto;
  z-index: 60;
  transform: translateX(-105%);
  transition: transform var(--dur-base) var(--ease-out);
  box-shadow: var(--shadow-lg);
}

.app-sidebar.is-open {
  transform: translateX(0);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-backdrop);
  backdrop-filter: blur(2px);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out);
}

.sidebar-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0 var(--space-1);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-target);
  text-decoration: none;
  color: var(--color-text);
  min-width: 0;
}

.brand:hover {
  color: var(--color-text);
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 1.25rem;
  height: 1.25rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

.brand-tag {
  display: none;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.sidebar-close-btn {
  appearance: none;
  display: inline-grid;
  place-items: center;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  border: 1.5px solid var(--color-border-control);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sidebar-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-group__label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  padding: 0 var(--space-3) var(--space-1);
}

.main-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.nav-link svg {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.nav-link:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

.nav-link[aria-current="page"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

.nav-link--soon {
  color: var(--color-text-muted);
}

.nav-link--soon:hover {
  color: var(--color-text);
}

.pill-soon {
  margin-left: auto;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  border: 1px solid var(--color-border-control);
  color: var(--color-text-muted);
}

.nav-link[aria-current="page"] .pill-soon {
  background: var(--color-primary-active);
  border-color: var(--color-on-primary);
  color: var(--color-on-primary);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Selettore tema con Automatico (segui il sistema) + Carta / Chiaro / Scuro */
.theme-quick {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.theme-quick__label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.theme-quick__pills {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-1);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-sm);
  padding: var(--space-1);
}

.theme-quick__btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-secondary);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-1);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.theme-quick__btn--auto {
  grid-column: 1 / -1;
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-2);
}

.theme-quick__btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.theme-quick__btn[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.sidebar-note {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
  margin: 0;
}

/* Area principale */
.app-workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}

/* Barra superiore (Topbar) */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--color-surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  padding-top: env(safe-area-inset-top, 0px);
}

.header-inner {
  min-height: var(--topbar-h);
  max-width: 84rem;
  margin: 0 auto;
  padding: var(--space-2) max(var(--space-4), env(safe-area-inset-right)) var(--space-2) max(var(--space-4), env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.menu-toggle-btn {
  appearance: none;
  display: inline-grid;
  place-items: center;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  border: 1.5px solid var(--color-border-control);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease-out);
}

.menu-toggle-btn:hover {
  background: var(--color-surface-hover);
}

.topbar-brand {
  display: inline-flex;
}

/* Ricerca rapida topbar (nascosta su telefono piccolo, visibile da 768px) */
.topbar-search {
  display: none;
  flex: 1 1 16rem;
  max-width: 28rem;
  align-items: center;
  gap: var(--space-2);
}

.topbar-search__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.topbar-search__wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.topbar-search__icon {
  position: absolute;
  left: var(--space-3);
  width: 1rem;
  height: 1rem;
  color: var(--color-text-muted);
  pointer-events: none;
}

.topbar-search__input {
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-4) var(--space-2) 2.5rem;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--color-border-control);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
}

.topbar-search__input::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Commutatore Studente / Docente */
.role-switch {
  display: inline-flex;
  align-items: center;
  background: var(--color-bg-subtle);
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-pill);
  padding: 2px;
  gap: 2px;
}

.role-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.role-btn:hover {
  color: var(--color-text);
}

.role-btn[aria-pressed="true"] {
  background: var(--color-surface-elevated);
  color: var(--color-text);
  box-shadow: var(--shadow-xs);
}

.role-btn[data-role="docente"][aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.role-banner {
  background: var(--color-docente-bg);
  border-top: 1px solid var(--color-docente-border);
  color: var(--color-docente-text);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-4);
  text-align: center;
}

.role-banner[hidden] {
  display: none;
}

/* Barra di avanzamento lettura (GPU scaleX, zero layout shift) */
.reading-progress {
  position: relative;
  height: 4px;
  width: 100%;
  background: var(--color-border);
  overflow: hidden;
}

.reading-progress__fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: var(--color-primary);
  transition: transform 120ms linear;
}

/* --------------------------------------------------------------------------
   5. Componenti di sistema (bottoni, campi, badge, 4 stati, scheletri)
   -------------------------------------------------------------------------- */
.page-main {
  flex: 1;
  width: 100%;
  max-width: 76rem;
  margin: 0 auto;
  padding: var(--space-5) max(var(--space-fluid-page), env(safe-area-inset-right)) var(--space-7) max(var(--space-fluid-page), env(safe-area-inset-left));
}

.page-main--narrow {
  max-width: 52rem;
}

/* Unica animazione di carattere sobria, solo opacità (zero layout shift) */
.page-reveal {
  animation: quietFade var(--dur-slow) var(--ease-out) both;
}

/* Gerarchia bottoni: 1 primario per schermata + secondari + testuali */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--color-border-control);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.btn svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.btn:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-primary);
  color: var(--color-text);
}

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: var(--color-on-primary);
}

.btn-secondary {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-border);
  color: var(--color-primary);
}

.btn-secondary:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-primary);
  color: var(--color-primary-hover);
}

.btn-text {
  background: transparent;
  border-color: transparent;
  color: var(--color-primary);
  box-shadow: none;
  padding-inline: var(--space-3);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.btn-text:hover {
  background: var(--color-primary-soft);
  border-color: transparent;
  color: var(--color-primary-hover);
}

.btn-small {
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.01em;
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.badge--primary {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border-color: var(--color-primary-border);
}

.badge--accent {
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
  border-color: var(--color-accent-border);
}

.badge--amber {
  background: var(--color-amber-soft);
  color: var(--color-amber);
  border-color: var(--color-amber-border);
}

.badge--docente {
  background: var(--color-docente-bg);
  color: var(--color-docente-text);
  border-color: var(--color-docente-border);
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Campi con etichette visibili e bordi >= 3:1 */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field-label,
.field label {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text);
  display: block;
}

.input,
.select {
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 1rem; /* >= 16px evita lo zoom automatico su iOS */
  transition: border-color var(--dur-fast) var(--ease-out);
}

.input::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

.input:hover,
.select:hover {
  border-color: var(--color-primary);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.breadcrumb a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-min);
  color: var(--color-primary);
  font-weight: 600;
}

/* Stati (vuoto, caricamento / scheletri, errore, successo) */
.state-box,
.notice-card {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-fluid-card);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.state-box h2,
.state-box h3,
.notice-card h2,
.notice-card h3 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0;
  color: var(--color-text);
}

.state-box p,
.notice-card p {
  margin: 0;
  max-width: var(--measure-ui);
  color: var(--color-text-secondary);
}

.state-box__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.state-box__icon {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.state-box__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.state-box--error {
  background: var(--color-error-bg);
  border-color: var(--color-error-border);
  color: var(--color-error-text);
}

.state-box--error h2,
.state-box--error h3,
.state-box--error p {
  color: var(--color-error-text);
}

.state-box--empty {
  border-style: dashed;
  border-color: var(--color-border-control);
}

.state-box--success {
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
  color: var(--color-success-text);
}

.state-box--success h2,
.state-box--success p {
  color: var(--color-success-text);
}

.notice-card--restricted {
  border-color: var(--color-docente-border);
  background: var(--color-docente-bg);
  color: var(--color-docente-text);
  max-width: var(--measure-ui);
  margin: var(--space-5) auto;
}

.notice-card--restricted h1,
.notice-card--restricted p {
  color: var(--color-docente-text);
}

/* Scheletri di caricamento con dimensioni riservate (zero CLS) */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-skeleton) 25%,
    var(--color-skeleton-shine) 50%,
    var(--color-skeleton) 75%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-xs);
  animation: skeletonPulse 1.4s ease-in-out infinite;
}

.skeleton-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 29rem;
}

.skeleton-card__stage {
  height: 16rem;
  background: var(--color-bg-stage);
  display: grid;
  place-items: center;
}

.skeleton-card__cover {
  width: 9.25rem;
  aspect-ratio: 360 / 500;
  border-radius: var(--radius-sm);
}

.skeleton-card__body {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.skeleton-line {
  height: 1rem;
  width: 100%;
}

.skeleton-line--title {
  height: 1.5rem;
  width: 78%;
}

.skeleton-line--short {
  width: 48%;
}

.skeleton-row {
  min-height: 4.5rem;
  border-radius: var(--radius-md);
  width: 100%;
}

.skeleton-prose {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 28rem;
}

/* --------------------------------------------------------------------------
   6. Home / Libreria (web/index.html)
   -------------------------------------------------------------------------- */
.library-hero {
  position: relative;
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-fluid-card);
  margin-bottom: var(--space-7);
  box-shadow: var(--shadow-sm);
}

.library-hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-accent-text);
  margin-bottom: var(--space-2);
}

.library-hero h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: -0.025em;
  margin: 0 0 var(--space-3);
  max-width: 24ch;
  color: var(--color-text);
}

.library-hero__sub {
  margin: 0 0 var(--space-5);
  color: var(--color-text-secondary);
  font-size: var(--text-base);
  max-width: var(--measure-ui);
}

.hero-search-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 44rem;
}

.hero-search-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.hero-search-bar__field {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.hero-search-bar__icon {
  position: absolute;
  left: var(--space-4);
  width: 1.125rem;
  height: 1.125rem;
  color: var(--color-text-muted);
  pointer-events: none;
}

.hero-search-bar__input {
  width: 100%;
  min-height: var(--touch-target-lg);
  padding: var(--space-3) var(--space-4) var(--space-3) 2.75rem;
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface-elevated);
  color: var(--color-text);
  font: inherit;
  font-size: 1rem;
}

.hero-search-bar__input::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}

.hero-search-bar .btn-primary {
  width: 100%;
  min-height: var(--touch-target-lg);
}

/* Sezione «Continua a leggere» */
.shelf-section {
  margin-bottom: var(--space-7);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
}

.section-head h2 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--color-text);
}

.section-head__meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.continue-track {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  padding: var(--space-1) 2px var(--space-3);
  scroll-snap-type: x proximity;
}

.continue-card {
  flex: 0 0 auto;
  width: min(21rem, 84vw);
  scroll-snap-align: start;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.continue-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  color: var(--color-text);
}

.continue-card__cover {
  width: 4rem;
  height: auto;
  aspect-ratio: 360 / 500;
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-cover);
  flex-shrink: 0;
}

.continue-card__body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.continue-card__kicker {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-accent-text);
}

.continue-card__title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.continue-card__chap {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.continue-card__cta {
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-primary);
}

/* Stato vuoto «Continua a leggere» */
.continue-empty {
  background: var(--color-surface);
  border: 1.5px dashed var(--color-border-control);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.continue-empty__text h3 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0 0 var(--space-1);
}

.continue-empty__text p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  max-width: var(--measure-ui);
}

.continue-suggestions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
}

.suggestion-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch-target-lg);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  border: 1.5px solid var(--color-border);
  text-decoration: none;
  color: var(--color-text);
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.suggestion-chip:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-primary);
  color: var(--color-text);
}

.suggestion-chip__cover {
  width: 2.5rem;
  height: auto;
  aspect-ratio: 360 / 500;
  border-radius: 4px;
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
}

.suggestion-chip__meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.suggestion-chip__area {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.suggestion-chip__title {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Barra filtri a pillola (bersagli >= 44px) */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.filter-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.filter-pill {
  appearance: none;
  min-height: var(--touch-target);
  border: 1.5px solid var(--color-border-control);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}

.filter-pill:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

.filter-pill[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}

.filter-select-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.filter-select-wrap label {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text);
}

.filter-select-wrap .select {
  min-width: 11.5rem;
}

.library-status {
  margin: 0 0 var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Griglia volumi */
.book-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
}

.book-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}

.book-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.book-card__stage {
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: var(--color-area-economia-bg);
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
}

.book-card[data-indirizzo="Turismo"] .book-card__stage {
  background: var(--color-area-turismo-bg);
}

.book-card[data-indirizzo="IP servizi commerciali"] .book-card__stage {
  background: var(--color-area-commerciale-bg);
}

.book-card__cover {
  width: 8.75rem;
  height: auto;
  aspect-ratio: 360 / 500;
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-cover);
}

.book-card__body {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
}

.book-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.book-card__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.26;
  letter-spacing: -0.015em;
  margin: 0;
}

.book-card__title a {
  color: var(--color-text);
  text-decoration: none;
}

.book-card__title a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.book-card__desc {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.55;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card__resume {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  background: var(--color-accent-soft);
  border: 1px solid var(--color-accent-border);
  color: var(--color-accent-text);
}

.book-card__resume svg {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
}

.book-card__resume strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-card__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-top: var(--space-3);
  margin-top: auto;
  border-top: 1px solid var(--color-border);
}

.book-card__counts {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
}

.book-card__btns {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

/* --------------------------------------------------------------------------
   7. Scheda volume (web/libro.html)
   -------------------------------------------------------------------------- */
.book-hero {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-fluid-card);
  margin-bottom: var(--space-7);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  align-items: center;
}

.book-hero__cover-wrap {
  background: var(--color-bg-stage);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: grid;
  place-items: center;
  border: 1px solid var(--color-border);
}

.book-hero__cover-wrap[data-indirizzo="Turismo"] {
  background: var(--color-area-turismo-bg);
}

.book-hero__cover-wrap[data-indirizzo="Economia aziendale biennio"] {
  background: var(--color-area-economia-bg);
}

.book-hero__cover-wrap[data-indirizzo="IP servizi commerciali"] {
  background: var(--color-area-commerciale-bg);
}

.book-hero__cover {
  width: 100%;
  max-width: 11.25rem;
  height: auto;
  aspect-ratio: 360 / 500;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-cover);
}

.book-hero__info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.book-hero h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  margin: 0;
}

.book-hero__desc {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--text-base);
  line-height: 1.65;
  max-width: var(--measure-ui);
}

.book-hero__stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-1) 0;
}

.book-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-2);
}

.chapter-group {
  margin-bottom: var(--space-7);
}

.chapter-group__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.chapter-group h2 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0;
}

.chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.chapter-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.chapter-item:hover {
  border-color: var(--color-primary);
}

.chapter-item--docente {
  background: var(--color-docente-bg);
  border-color: var(--color-docente-border);
}

.chapter-item__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.chapter-item__title-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.chapter-item__num {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  background: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: 700;
  flex-shrink: 0;
}

.chapter-item--docente .chapter-item__num {
  background: var(--color-surface);
  color: var(--color-docente-text);
}

.chapter-item__link {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-target);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
}

.chapter-item__link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.chapter-item__badges {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

.chapter-item__sub {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px dashed var(--color-border);
}

.chapter-item__sub summary {
  cursor: pointer;
  min-height: var(--touch-target);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.chapter-item__sub summary::-webkit-details-marker {
  display: none;
}

.chapter-item__sub summary::before {
  content: "▸";
  display: inline-block;
  transition: transform var(--dur-fast) var(--ease-out);
}

.chapter-item__sub[open] summary::before {
  transform: rotate(90deg);
}

.chapter-item__sub summary:hover {
  color: var(--color-primary);
}

.sub-sections {
  list-style: none;
  margin: var(--space-2) 0 0;
  padding: var(--space-2) 0 0 var(--space-4);
  border-left: 2px solid var(--color-primary-border);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: var(--space-2) var(--space-5);
  font-size: var(--text-sm);
}

.sub-sections a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-min);
  color: var(--color-text-secondary);
  text-decoration: none;
}

.sub-sections a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   8. Lettore a testo liquido (web/lettore.html) — Ritmo editoriale + Indice docs
   -------------------------------------------------------------------------- */
.reader-float-wrap {
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 4px);
  z-index: 35;
  padding: var(--space-2) max(var(--space-3), env(safe-area-inset-right)) 0 max(var(--space-3), env(safe-area-inset-left));
  pointer-events: none;
}

.reader-float-bar {
  pointer-events: auto;
  max-width: 72rem;
  margin: 0 auto;
  background: var(--color-surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.reader-bar__book {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  flex: 1 1 12rem;
}

.reader-bar__mini-cover {
  width: 1.875rem;
  height: auto;
  aspect-ratio: 360 / 500;
  border-radius: 4px;
  box-shadow: var(--shadow-xs);
  outline: 1px solid var(--color-border);
  flex-shrink: 0;
}

.reader-bar__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-bar__title:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

/* Su telefono i controlli principali del lettore stanno nella barra inferiore */
.reader-bar__controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.reader-bar__desktop-only {
  display: none;
}

.tool-btn {
  appearance: none;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--color-text-secondary);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}

.tool-btn svg {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

.tool-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.tool-btn[aria-expanded="true"],
.tool-btn.is-active {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-border);
  color: var(--color-primary);
}

.tool-btn--icon {
  padding: var(--space-2);
}

.tool-btn[aria-disabled="true"],
.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar-divider {
  display: none;
  width: 1px;
  height: 1.5rem;
  background: var(--color-border);
  margin: 0 var(--space-1);
}

/* Pannelli a scomparsa */
.reader-panel-dock {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 max(var(--space-3), env(safe-area-inset-right)) 0 max(var(--space-3), env(safe-area-inset-left));
}

.reader-panel {
  margin-top: var(--space-3);
  background: var(--color-surface-elevated);
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-lg);
}

.reader-panel[hidden] {
  display: none;
}

.prefs-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-5);
  align-items: end;
}

.pref-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.pref-group__label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-md);
  padding: 3px;
  background: var(--color-bg);
  gap: 3px;
}

.segmented button {
  appearance: none;
  min-height: var(--touch-target);
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xs);
  cursor: pointer;
}

.segmented button:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
}

.segmented button[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.size-stepper {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-bg);
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-md);
  padding: 2px;
}

.size-value {
  min-width: 3.5rem;
  text-align: center;
  font-size: var(--text-sm);
  font-weight: 700;
}

/* Workspace lettore */
.reader-shell {
  flex: 1;
  width: 100%;
  max-width: 88rem;
  margin: 0 auto;
  padding: var(--space-4) max(var(--space-3), env(safe-area-inset-right)) var(--space-7) max(var(--space-3), env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.reader-shell.toc-collapsed .reader-toc {
  display: none;
}

/* Indice laterale in stile documentazione (gruppi, attivo nitido, avanzamento) */
.reader-toc {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-4);
  max-height: 26rem;
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}

.reader-toc__head {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-bottom: var(--space-4);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.reader-toc__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.reader-toc h2 {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin: 0;
}

.toc-progress-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-primary);
}

.toc-progress-bar {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-bg-subtle);
  overflow: hidden;
}

.toc-progress-bar__fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: var(--color-primary);
  transition: transform 150ms ease-out;
}

.toc-chapters {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.toc-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.toc-group__title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  padding: 0 var(--space-2) var(--space-1);
}

.toc-group__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc-chap-link {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: var(--touch-target);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  line-height: 1.35;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.toc-chap-link:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.toc-chap-link[aria-current="page"] {
  background: var(--color-primary-soft);
  border-left-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 700;
}

.toc-chap-type {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 600;
}

.toc-sections {
  list-style: none;
  margin: var(--space-2) 0 var(--space-3) var(--space-3);
  padding: var(--space-1) 0 var(--space-1) var(--space-3);
  border-left: 2px solid var(--color-primary-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.toc-sections a {
  display: flex;
  align-items: center;
  min-height: var(--touch-min);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-xs);
}

.toc-sections a:hover,
.toc-sections a.is-active,
.toc-sections a[aria-current="location"] {
  color: var(--color-primary);
  background: var(--color-primary-soft);
  font-weight: 700;
}

.toc-sections .toc-h3 {
  padding-left: var(--space-3);
}

/* Foglio pagina centrato con ritmo verticale arioso (ispirazione editoriale) */
.reader-content-wrap {
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.reader-sheet {
  position: relative;
  width: 100%;
  max-width: calc(var(--reader-measure) + clamp(2rem, 8vw, 7rem));
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: clamp(1.5rem, 4vw, 3.75rem) clamp(1.25rem, 4.5vw, 4rem);
  box-shadow: var(--shadow-md);
}

.reader-prose {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: var(--reader-leading);
  max-width: var(--reader-measure);
  margin: 0 auto;
  color: var(--color-text);
  overflow-wrap: break-word;
  hyphens: auto;
}

.reader-prose h1 {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 1.4rem + 1.3vw, 2.35rem);
  font-weight: 700;
  line-height: 1.16;
  letter-spacing: -0.025em;
  margin: 0 0 1.25em;
  padding-bottom: 0.55em;
  border-bottom: 2px solid var(--color-primary-border);
  color: var(--color-text);
  hyphens: none;
}

.reader-prose h2 {
  font-family: var(--font-display);
  font-size: 1.42em;
  font-weight: 700;
  line-height: 1.24;
  letter-spacing: -0.015em;
  margin: 2.35em 0 0.75em;
  color: var(--color-primary);
  scroll-margin-top: calc(var(--topbar-h) + 5.5rem);
  hyphens: none;
}

.reader-prose h3 {
  font-family: var(--font-display);
  font-size: 1.16em;
  font-weight: 700;
  line-height: 1.32;
  margin: 1.75em 0 0.55em;
  color: var(--color-text);
  scroll-margin-top: calc(var(--topbar-h) + 5.5rem);
  hyphens: none;
}

.reader-prose p {
  margin: 0 0 1.2em;
}

.reader-prose ul,
.reader-prose ol {
  margin: 0 0 1.3em;
  padding-left: 1.5em;
}

.reader-prose li {
  margin-bottom: 0.5em;
}

.reader-prose strong {
  font-weight: 700;
  color: var(--color-text);
}

.reader-prose blockquote {
  margin: 1.75em 0;
  padding: 1.1em 1.35em;
  border-left: 4px solid var(--color-primary);
  background: var(--color-bg);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--color-text-secondary);
}

.reader-prose .callout {
  padding: 1.15em 1.35em;
  border-radius: var(--radius-md);
  margin: 1.65em 0;
}

.reader-prose .callout-glossario {
  background: var(--color-primary-soft);
  border: 1px solid var(--color-primary-border);
  border-left: 4px solid var(--color-primary);
}

.reader-prose .callout-glossario strong:first-child {
  color: var(--color-primary);
}

.reader-prose .callout-focus {
  background: var(--color-accent-soft);
  border: 1px solid var(--color-accent-border);
  border-left: 4px solid var(--color-accent);
}

.reader-prose .callout-focus strong:first-child {
  color: var(--color-accent-text);
}

.reader-prose pre {
  font-family: var(--font-mono);
  font-size: 0.84em;
  line-height: 1.55;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1em 1.25em;
  overflow-x: auto;
  hyphens: none;
}

.reader-prose code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--color-bg-subtle);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  hyphens: none;
}

.reader-prose pre code {
  background: none;
  padding: 0;
}

.reader-prose hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2.4em 0;
}

/* Tabelle leggibili con scorrimento orizzontale sicuro */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 1.75em 0;
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  -webkit-overflow-scrolling: touch;
}

.reader-prose table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.84em;
  line-height: 1.5;
  hyphens: none;
}

.reader-prose th,
.reader-prose td {
  padding: 0.7em 0.9em;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}

.reader-prose th:last-child,
.reader-prose td:last-child {
  border-right: none;
}

.reader-prose tr:last-child td {
  border-bottom: none;
}

.reader-prose thead th {
  background: var(--color-bg-subtle);
  font-weight: 700;
  color: var(--color-text);
  border-bottom: 1.5px solid var(--color-border-control);
}

.reader-prose tbody tr:nth-child(even) {
  background: var(--color-bg);
}

.reader-prose mark,
.search-snippet mark {
  background: var(--color-mark-bg);
  color: var(--color-mark-text);
  padding: 0.08em 0.25em;
  border-radius: 4px;
  font-weight: 700;
}

/* Navigazione tra capitoli a fondo foglio */
.chapter-pager {
  width: 100%;
  max-width: calc(var(--reader-measure) + clamp(2rem, 8vw, 7rem));
  margin: var(--space-5) auto 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}

.pager-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-1);
  min-height: var(--touch-target-lg);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border-control);
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}

.pager-card:hover {
  border-color: var(--color-primary);
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.pager-card--next {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}

.pager-card--next:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: var(--color-on-primary);
}

.pager-card__dir {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pager-card__title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1.3;
}

/* Toast glossario contestuale */
.glossary-toast {
  position: fixed;
  right: max(var(--space-4), env(safe-area-inset-right));
  bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + var(--space-3));
  max-width: min(26rem, calc(100vw - 2rem));
  background: var(--color-surface-elevated);
  border: 1.5px solid var(--color-primary-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-lg);
  z-index: 65;
}

.glossary-toast[hidden] {
  display: none;
}

.glossary-toast__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.glossary-toast__term {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--color-primary);
}

.glossary-toast__def {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.55;
}

.glossary-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: var(--space-3);
  margin-top: var(--space-4);
  max-height: 19rem;
  overflow-y: auto;
  padding-right: var(--space-1);
}

.glossary-item {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.glossary-item strong {
  display: block;
  margin-bottom: var(--space-1);
  font-family: var(--font-display);
  color: var(--color-primary);
  font-size: var(--text-base);
}

/* --------------------------------------------------------------------------
   9. Ricerca globale (web/ricerca.html)
   -------------------------------------------------------------------------- */
.search-hero {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-fluid-card);
  margin-bottom: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.search-hero h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-2);
}

.search-hero > p {
  margin: 0 0 var(--space-5);
  color: var(--color-text-secondary);
  max-width: var(--measure-ui);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  align-items: end;
  margin-bottom: var(--space-5);
}

.search-form__input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-form__input-wrap svg {
  position: absolute;
  left: var(--space-4);
  width: 1.125rem;
  height: 1.125rem;
  color: var(--color-text-muted);
  pointer-events: none;
}

.search-form__input-wrap .input {
  padding-left: 2.75rem;
}

.search-examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.chip-btn {
  appearance: none;
  min-height: var(--touch-target);
  border: 1.5px solid var(--color-border-control);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.chip-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.search-empty-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.search-tip-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}

.search-tip-card h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0 0 var(--space-2);
}

.search-tip-card p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.55;
}

.search-group {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.search-group__header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.search-group__book {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.search-group__cover {
  width: 2.75rem;
  height: auto;
  aspect-ratio: 360 / 500;
  border-radius: 5px;
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
}

.search-group__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0 0 var(--space-1);
}

.search-group__title a {
  color: var(--color-text);
  text-decoration: none;
}

.search-group__title a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.search-hits {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.search-hit-item {
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.search-hit-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch-min);
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--color-primary);
}

.search-hit-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: var(--space-2) 0;
}

.search-snippet {
  margin: var(--space-2) 0 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.55;
}

/* --------------------------------------------------------------------------
   10. Pagine «prossimamente» (tutor, classi, verifiche, impara-giocando)
   -------------------------------------------------------------------------- */
.soon-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-fluid-card);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-6);
}

.soon-card__hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  align-items: center;
  margin-bottom: var(--space-6);
}

.soon-illustration {
  width: 100%;
  max-width: 12.5rem;
  height: auto;
  aspect-ratio: 220 / 190;
  margin: 0 auto;
}

.soon-card h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  margin: var(--space-3) 0;
}

.soon-card__lead {
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--color-text-secondary);
  max-width: var(--measure-ui);
  margin: 0;
}

.soon-previews {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.soon-preview-item {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.soon-preview-item h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0 0 var(--space-2);
  color: var(--color-text);
}

.soon-preview-item p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.55;
}

.soon-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.soon-ready {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.soon-ready__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.soon-ready__head h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0;
}

/* --------------------------------------------------------------------------
   11. Piè di pagina e barra inferiore smartphone (zona del pollice + safe area)
   -------------------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: var(--space-5) max(var(--space-fluid-page), env(safe-area-inset-right)) calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + var(--space-5)) max(var(--space-fluid-page), env(safe-area-inset-left));
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.footer-inner {
  max-width: 76rem;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.mobile-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  background: var(--color-surface-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1.5px solid var(--color-border);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) max(var(--space-2), env(safe-area-inset-right)) max(var(--space-2), env(safe-area-inset-bottom)) max(var(--space-2), env(safe-area-inset-left));
  z-index: 45;
}

.mobile-bottom-nav--reader {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.mobile-bottom-nav--reader .mobile-bottom-nav__item {
  padding: var(--space-1) 2px;
  white-space: nowrap;
}

.mobile-bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--touch-target-lg);
  text-decoration: none;
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid transparent;
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.mobile-bottom-nav__item svg {
  width: 1.25rem;
  height: 1.25rem;
}

.mobile-bottom-nav__item[aria-current="page"],
.mobile-bottom-nav__item[aria-expanded="true"],
.mobile-bottom-nav__item[aria-pressed="true"] {
  color: var(--color-primary);
  background: var(--color-primary-soft);
  border-color: var(--color-primary-border);
}

.mobile-bottom-nav__item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   12. Animazioni (solo opacità / GPU, zero layout shift)
   -------------------------------------------------------------------------- */
@keyframes quietFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes skeletonPulse {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* --------------------------------------------------------------------------
   13. Breakpoint progressivi Mobile First (min-width: 480, 768, 960, 1280)
   -------------------------------------------------------------------------- */
@media (min-width: 480px) {
  .brand-tag {
    display: block;
  }

  .role-btn {
    font-size: var(--text-sm);
    padding: var(--space-2) var(--space-4);
  }

  .hero-search-bar {
    flex-direction: row;
    align-items: stretch;
  }

  .hero-search-bar .btn-primary {
    width: auto;
  }

  .book-card__cover {
    width: 9.25rem;
  }

  .continue-suggestions,
  .search-empty-grid,
  .soon-previews {
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  }
}

@media (min-width: 768px) {
  html {
    scroll-padding-bottom: var(--space-6);
  }

  .topbar-search {
    display: flex;
  }

  .mobile-bottom-nav {
    display: none;
  }

  .site-footer {
    padding-bottom: var(--space-5);
  }

  .glossary-toast {
    bottom: var(--space-5);
  }

  .filter-row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
  }

  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-6);
  }

  .book-hero {
    grid-template-columns: 14rem minmax(0, 1fr);
    gap: var(--space-6);
  }

  .book-hero__cover {
    max-width: 12rem;
  }

  .soon-card__hero {
    grid-template-columns: 12.5rem minmax(0, 1fr);
    gap: var(--space-6);
  }

  .search-form {
    grid-template-columns: minmax(0, 1.5fr) minmax(12rem, 0.85fr) auto;
  }

  .chapter-pager {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pager-card--next {
    text-align: right;
  }

  .reader-float-bar {
    border-radius: var(--radius-pill);
    padding: var(--space-2) var(--space-4);
  }

  .reader-bar__desktop-only {
    display: inline-flex;
  }

  .toolbar-divider {
    display: inline-block;
  }

  .reader-sheet {
    border-radius: var(--radius-xl);
  }
}

@media (min-width: 960px) {
  /* Sidebar fissa visibile su desktop (tranne nel lettore, dove resta cassetto) */
  body:not([data-page="lettore"]) .app-shell {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  body:not([data-page="lettore"]) .app-sidebar {
    position: sticky;
    top: 0;
    width: var(--sidebar-w);
    transform: none;
    box-shadow: none;
    z-index: 30;
  }

  body:not([data-page="lettore"]) .sidebar-close-btn,
  body:not([data-page="lettore"]) .menu-toggle-btn,
  body:not([data-page="lettore"]) .topbar-brand {
    display: none;
  }

  /* Lettore: layout a due colonne stile documentazione */
  .reader-shell {
    grid-template-columns: 19rem minmax(0, 1fr);
    padding: var(--space-5) var(--space-5) var(--space-8);
    gap: var(--space-6);
  }

  .reader-shell.toc-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .reader-toc {
    position: sticky;
    top: calc(var(--topbar-h) + 5rem);
    max-height: calc(100dvh - var(--topbar-h) - 6.5rem);
  }

  body[data-page="prossimamente"] .page-main {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100dvh - 10rem);
  }
}

@media (min-width: 1280px) {
  .book-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* --------------------------------------------------------------------------
   14. Movimento ridotto e colori forzati di sistema
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .skeleton {
    animation: none !important;
  }
}

@media (forced-colors: active) {
  .btn,
  .input,
  .select,
  .book-card,
  .state-box,
  .reader-sheet,
  .reader-float-bar,
  .mobile-bottom-nav {
    border: 2px solid ButtonText;
  }

  :focus-visible {
    outline: 3px solid Highlight;
  }
}

/* Ritocchi finali v3b (21/11/2026) */
/* Bottone secondario: contorno deciso, non compete con il primario */
.btn-secondary{
  background:var(--color-surface);
  border:1.5px solid var(--color-primary);
  color:var(--color-primary);
  font-weight:650;
  box-shadow:var(--shadow-xs, none);
}
.btn-secondary:hover{background:var(--color-primary-soft);border-color:var(--color-primary-hover);color:var(--color-primary-hover)}
.btn-secondary:active{background:var(--color-primary-soft);border-color:var(--color-primary-active)}
/* Etichetta «Cerca» della barra in alto: solo per lettori di schermo */
.topbar-search__label{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
/* Sillabazione: solo manuale; automatica solo su schermi molto stretti */
.reader-prose p,.reader-prose li{hyphens:auto;-webkit-hyphens:auto}
@media (min-width:22.5rem){.reader-prose,.reader-prose p,.reader-prose li{hyphens:manual;-webkit-hyphens:manual}}

/* ==========================================================================
   15. Blocco 4 — Barra annotazione, Post-it, Le mie note, Dialogo e Modalità LIM
   ========================================================================== */

.btn-danger {
  background: var(--color-error-solid);
  border-color: var(--color-error-solid);
  color: var(--color-on-error);
  box-shadow: var(--shadow-xs);
}

.btn-danger:hover {
  background: var(--color-error-text);
  border-color: var(--color-error-text);
  color: var(--color-on-error);
}

.tool-btn[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}

.tool-btn__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.375rem;
  height: 1.375rem;
  padding: 0 var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--color-primary-soft);
  border: 1px solid var(--color-primary-border);
  color: var(--color-primary);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1;
}

.tool-btn__count[hidden] {
  display: none;
}

.tool-btn[aria-pressed="true"] .tool-btn__count {
  background: var(--color-primary-active);
  border-color: var(--color-on-primary);
  color: var(--color-on-primary);
}

/* Barra di annotazione separata (su smartphone lo strumento Post-it è nella barra inferiore) */
.reader-annotate-wrap {
  display: none;
  padding: var(--space-2) max(var(--space-3), env(safe-area-inset-right)) 0 max(var(--space-3), env(safe-area-inset-left));
}

.reader-annotate-bar {
  max-width: 72rem;
  margin: 0 auto;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-1) var(--space-3);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.reader-annotate-bar__label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  padding: 0 var(--space-2);
}

.tool-btn--annotate {
  border-color: var(--color-border-control);
  background: var(--color-bg);
  color: var(--color-text);
}

.tool-btn--annotate:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.reader-annotate-bar__hint {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  margin-left: var(--space-2);
}

.reader-annotate-bar__hint[hidden] {
  display: none;
}

/* Avviso modalità attiva (crea post-it o «Sposta qui») visibile su ogni schermo */
.annotate-mode-banner {
  margin-top: var(--space-3);
  background: var(--color-primary-soft);
  border: 1.5px solid var(--color-primary);
  color: var(--color-primary);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
}

.annotate-mode-banner[hidden] {
  display: none;
}

.notes-storage-error {
  margin-top: var(--space-3);
}

.notes-storage-error[hidden] {
  display: none;
}

/* Stato interattivo del testo durante la creazione o lo spostamento di un post-it */
.reader-prose.is-annotating,
.reader-prose.is-moving-note {
  cursor: crosshair;
}

.reader-prose.is-annotating [data-note-block-id]:hover,
.reader-prose.is-moving-note [data-note-block-id]:hover,
.reader-prose.is-annotating [data-note-block-id]:focus-visible,
.reader-prose.is-moving-note [data-note-block-id]:focus-visible {
  background: var(--color-primary-soft);
  outline: 2px dashed var(--color-primary);
  outline-offset: 4px;
  border-radius: var(--radius-xs);
}

/* Layer dei post-it ancorato al foglio di lettura */
.reader-notes-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

/* Mapping token per i 6 colori dei post-it */
.postit-card[data-color="giallo"],
.postit-pin[data-color="giallo"],
.note-color-dot[data-color="giallo"],
.postit-swatch[data-swatch="giallo"] {
  --postit-bg: var(--color-note-giallo-bg);
  --postit-text: var(--color-note-giallo-text);
  --postit-border: var(--color-note-giallo-border);
}

.postit-card[data-color="rosa"],
.postit-pin[data-color="rosa"],
.note-color-dot[data-color="rosa"],
.postit-swatch[data-swatch="rosa"] {
  --postit-bg: var(--color-note-rosa-bg);
  --postit-text: var(--color-note-rosa-text);
  --postit-border: var(--color-note-rosa-border);
}

.postit-card[data-color="verde"],
.postit-pin[data-color="verde"],
.note-color-dot[data-color="verde"],
.postit-swatch[data-swatch="verde"] {
  --postit-bg: var(--color-note-verde-bg);
  --postit-text: var(--color-note-verde-text);
  --postit-border: var(--color-note-verde-border);
}

.postit-card[data-color="azzurro"],
.postit-pin[data-color="azzurro"],
.note-color-dot[data-color="azzurro"],
.postit-swatch[data-swatch="azzurro"] {
  --postit-bg: var(--color-note-azzurro-bg);
  --postit-text: var(--color-note-azzurro-text);
  --postit-border: var(--color-note-azzurro-border);
}

.postit-card[data-color="lilla"],
.postit-pin[data-color="lilla"],
.note-color-dot[data-color="lilla"],
.postit-swatch[data-swatch="lilla"] {
  --postit-bg: var(--color-note-lilla-bg);
  --postit-text: var(--color-note-lilla-text);
  --postit-border: var(--color-note-lilla-border);
}

.postit-card[data-color="arancio"],
.postit-pin[data-color="arancio"],
.note-color-dot[data-color="arancio"],
.postit-swatch[data-swatch="arancio"] {
  --postit-bg: var(--color-note-arancio-bg);
  --postit-text: var(--color-note-arancio-text);
  --postit-border: var(--color-note-arancio-border);
}

/* Scheda Post-it espansa */
.postit-card {
  position: absolute;
  pointer-events: auto;
  width: min(19rem, calc(100% - 1rem));
  background: var(--postit-bg);
  color: var(--postit-text);
  border: 2px solid var(--postit-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  z-index: 22;
}

.postit-card:focus-within,
.postit-card.is-active {
  z-index: 28;
  box-shadow: var(--shadow-lg);
}

.postit-card.is-dragging {
  z-index: 32;
  opacity: 0.94;
}

.postit-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-bottom: 1.5px solid var(--postit-border);
}

.postit-card__drag {
  flex: 1;
  min-height: var(--touch-target);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--postit-text);
  cursor: grab;
  touch-action: none;
  user-select: none;
  border-radius: var(--radius-xs);
}

.postit-card.is-dragging .postit-card__drag {
  cursor: grabbing;
}

.postit-card__drag svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.postit-card__head-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.postit-icon-btn {
  appearance: none;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  display: inline-grid;
  place-items: center;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--postit-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.postit-icon-btn:hover {
  border-color: var(--postit-border);
  background: var(--color-surface-glass);
}

.postit-icon-btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

.postit-card__body {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.postit-card__label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--postit-text);
}

.postit-card__textarea {
  width: 100%;
  min-height: 5.5rem;
  resize: vertical;
  padding: var(--space-2) var(--space-3);
  border: 1.5px solid var(--postit-border);
  border-radius: var(--radius-sm);
  background: var(--postit-bg);
  color: var(--postit-text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.45;
}

.postit-card__textarea::placeholder {
  color: var(--postit-text);
  opacity: 0.72;
}

.postit-colors {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.postit-swatch {
  appearance: none;
  position: relative;
  width: 2rem;
  height: 2rem;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  border-radius: var(--radius-pill);
  background: var(--postit-bg);
  border: 2px solid var(--postit-border);
  color: var(--postit-text);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  font-size: var(--text-xs);
  font-weight: 800;
  padding: 0;
}

.postit-swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--postit-bg), 0 0 0 4px var(--postit-text);
}

.postit-swatch[aria-pressed="true"]::after {
  content: "✓";
  line-height: 1;
}

.postit-card__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-top: var(--space-1);
  border-top: 1px dashed var(--postit-border);
}

.postit-card__status {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--postit-text);
}

.postit-card__move-btn {
  appearance: none;
  min-height: var(--touch-target);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--postit-border);
  background: transparent;
  color: var(--postit-text);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.postit-card__move-btn:hover,
.postit-card__move-btn[aria-pressed="true"] {
  background: var(--postit-text);
  color: var(--postit-bg);
}

.postit-card__kbd-hint {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--postit-text);
  line-height: 1.35;
}

/* Post-it compresso nel margine (44x44 px, >= 24 px) */
.postit-pin {
  position: absolute;
  pointer-events: auto;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-md);
  border: 2px solid var(--postit-border);
  background: var(--postit-bg);
  color: var(--postit-text);
  box-shadow: var(--shadow-sm);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  z-index: 21;
  padding: 0;
}

.postit-pin:hover {
  box-shadow: var(--shadow-md);
}

.postit-pin svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Pannello «Le mie note» */
.notes-panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.notes-panel__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0;
  color: var(--color-text);
}

.notes-panel__meta {
  margin: var(--space-1) 0 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.notes-panel__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  max-height: 24rem;
  overflow-y: auto;
  padding-right: var(--space-1);
}

.notes-group__title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-2);
}

.notes-group__items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.note-list-btn {
  width: 100%;
  min-height: var(--touch-target);
  text-align: left;
  appearance: none;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font: inherit;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}

.note-list-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-surface-hover);
}

.note-color-dot {
  width: 1rem;
  height: 1rem;
  border-radius: var(--radius-pill);
  background: var(--postit-bg);
  border: 2px solid var(--postit-border);
  flex-shrink: 0;
  margin-top: 0.25rem;
}

.note-list-btn__content {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.note-list-btn__text {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
}

.note-list-btn__meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Contatore discreto note in libreria e scheda libro */
.book-card__notes-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  background: var(--color-note-giallo-bg);
  border: 1.5px solid var(--color-note-giallo-border);
  color: var(--color-note-giallo-text);
}

.book-card__notes-badge svg {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
}

.book-hero__notes-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--touch-min);
  font-weight: 700;
  color: var(--color-primary);
}

/* Dialogo accessibile di conferma eliminazione */
.confirm-dialog {
  padding: 0;
  border: 2px solid var(--color-border-control);
  border-radius: var(--radius-lg);
  background: var(--color-surface-elevated);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
  max-width: min(28rem, calc(100vw - 2rem));
  width: 100%;
}

.confirm-dialog::backdrop {
  background: var(--color-backdrop);
  backdrop-filter: blur(2px);
}

.confirm-dialog__box {
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.confirm-dialog__box h2 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  margin: 0;
  color: var(--color-text);
}

.confirm-dialog__box p {
  margin: 0;
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.confirm-dialog__preview {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  font-size: var(--text-sm);
  color: var(--color-text);
}

.confirm-dialog__preview[hidden] {
  display: none;
}

.confirm-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

/* Breakpoint tablet/desktop per barra di annotazione separata */
@media (min-width: 768px) {
  .reader-annotate-wrap {
    display: block;
  }

  .reader-annotate-bar {
    border-radius: var(--radius-pill);
    padding: var(--space-1) var(--space-4);
  }
}

/* ==========================================================================
   16. Modalità LIM (Lavagna Interattiva Multimediale)
   Testo 1,5x, bersagli 56 px (3.5rem), contrasto alto, sidebar nascosta,
   post-it ingranditi e leggibili da lontano.
   ========================================================================== */
html[data-lim="on"] body[data-page="lettore"] {
  --touch-target: 3.5rem;      /* 56px */
  --touch-target-lg: 3.75rem;  /* 60px */
  --color-text-muted: var(--color-text);
  --color-text-secondary: var(--color-text);
  --color-border: var(--color-border-control);
}

html[data-lim="on"] body[data-page="lettore"] :focus-visible {
  outline-width: 4px;
  outline-offset: 4px;
}

html[data-lim="on"] body[data-page="lettore"] .app-sidebar,
html[data-lim="on"] body[data-page="lettore"] .menu-toggle-btn {
  display: none;
}

html[data-lim="on"] body[data-page="lettore"] .reader-shell {
  grid-template-columns: minmax(0, 1fr);
  max-width: 100%;
}

html[data-lim="on"] body[data-page="lettore"] .reader-sheet {
  max-width: min(96%, calc(var(--reader-measure) * 1.5 + 8rem));
  border-width: 2px;
}

html[data-lim="on"] body[data-page="lettore"] .reader-prose {
  font-size: calc(var(--reader-size) * 1.5);
  max-width: min(100%, var(--reader-measure));
}

html[data-lim="on"] body[data-page="lettore"] .reader-prose h1 {
  font-size: clamp(2.4rem, 2rem + 1.8vw, 3.4rem);
}

html[data-lim="on"] body[data-page="lettore"] .reader-prose h2 {
  font-size: clamp(1.9rem, 1.6rem + 1.2vw, 2.5rem);
}

html[data-lim="on"] body[data-page="lettore"] .reader-float-bar,
html[data-lim="on"] body[data-page="lettore"] .reader-annotate-bar {
  border-width: 2px;
}

html[data-lim="on"] body[data-page="lettore"] .tool-btn {
  font-size: var(--text-base);
  padding: var(--space-2) var(--space-4);
}

html[data-lim="on"] body[data-page="lettore"] .tool-btn svg {
  width: 1.5rem;
  height: 1.5rem;
}

html[data-lim="on"] body[data-page="lettore"] .postit-card {
  width: min(26rem, calc(100% - 1rem));
  border-width: 3px;
}

html[data-lim="on"] body[data-page="lettore"] .postit-card__textarea {
  font-size: 1.25rem;
  min-height: 7rem;
}

html[data-lim="on"] body[data-page="lettore"] .postit-card__drag,
html[data-lim="on"] body[data-page="lettore"] .postit-card__label,
html[data-lim="on"] body[data-page="lettore"] .postit-card__status,
html[data-lim="on"] body[data-page="lettore"] .postit-card__move-btn {
  font-size: var(--text-base);
}

html[data-lim="on"] body[data-page="lettore"] .postit-swatch {
  width: 2.75rem;
  height: 2.75rem;
  font-size: var(--text-base);
}

html[data-lim="on"] body[data-page="lettore"] .postit-pin {
  border-width: 3px;
}

html[data-lim="on"] body[data-page="lettore"] .postit-pin svg {
  width: 1.625rem;
  height: 1.625rem;
}

@media (forced-colors: active) {
  .reader-annotate-bar,
  .postit-card,
  .postit-pin,
  .confirm-dialog,
  .note-list-btn {
    border: 2px solid ButtonText;
  }
}


/* Pagina privacy */
.privacy-doc {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: var(--space-6);
}

.privacy-doc__kicker {
  margin: 0 0 var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.privacy-doc h1 {
  margin: 0 0 var(--space-4);
  font-family: var(--font-display);
  font-weight: 650;
  line-height: 1.2;
}

.privacy-doc h2 {
  margin: var(--space-5) 0 var(--space-2);
  font-size: var(--text-lg);
  line-height: 1.3;
}

.privacy-doc p,
.privacy-doc li {
  max-width: 65ch;
  color: var(--color-text);
}

.privacy-doc ul {
  margin: 0 0 var(--space-4);
  padding-left: 1.2em;
}

.privacy-doc li + li {
  margin-top: var(--space-2);
}

.privacy-doc__actions {
  margin: var(--space-6) 0 0;
}

.site-footer a {
  color: var(--color-primary);
  font-weight: 650;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.15em;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--color-primary-hover, var(--color-primary));
}
