/* =====================================================================
   La biblioteca di Anita — design system
   Neutro e pulito: le copertine sono le protagoniste, un solo colore
   d'accento, gerarchia chiara, target tattili ampi, tema chiaro/scuro.
   ===================================================================== */
:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #f1f1f4;
  --surface-3: #e9e9ee;
  --ink: #17171c;
  --ink-2: #3f3f48;
  --muted: #6c6c78;
  --line: #e4e4ea;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-ink: #ffffff;
  --accent-soft: #eef0ff;
  --accent-soft-ink: #3730a3;
  --success: #15803d; --success-soft: #e8f6ee;
  --warning: #b45309; --warning-soft: #fdf3e2;
  --danger: #dc2626;  --danger-soft: #fdecec;
  --info: #0369a1;    --info-soft: #e6f3fb;
  --star: #f59e0b;
  --wood-1: #8b5e3c; --wood-2: #5e3d24;
  --radius-lg: 16px; --radius: 12px; --radius-sm: 8px;
  --shadow-xs: 0 1px 2px rgba(16, 16, 24, .05);
  --shadow-sm: 0 1px 2px rgba(16, 16, 24, .06), 0 1px 3px rgba(16, 16, 24, .06);
  --shadow: 0 4px 12px -2px rgba(16, 16, 24, .08), 0 2px 4px -2px rgba(16, 16, 24, .05);
  --shadow-lg: 0 20px 40px -12px rgba(16, 16, 24, .25);
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --sidebar: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d11; --surface: #16161b; --surface-2: #1d1d24; --surface-3: #26262e;
    --ink: #f3f3f6; --ink-2: #d0d0d8; --muted: #9a9aa8; --line: #2a2a33;
    --accent: #818cf8; --accent-hover: #a5b4fc; --accent-ink: #0d0d11; --accent-soft: rgba(129, 140, 248, .14); --accent-soft-ink: #c7d2fe;
    --success: #4ade80; --success-soft: rgba(74, 222, 128, .12); --warning: #fbbf24; --warning-soft: rgba(251, 191, 36, .12);
    --danger: #f87171; --danger-soft: rgba(248, 113, 113, .12); --info: #38bdf8; --info-soft: rgba(56, 189, 248, .12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 4px 14px -4px rgba(0, 0, 0, .5); --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d11; --surface: #16161b; --surface-2: #1d1d24; --surface-3: #26262e;
  --ink: #f3f3f6; --ink-2: #d0d0d8; --muted: #9a9aa8; --line: #2a2a33;
  --accent: #818cf8; --accent-hover: #a5b4fc; --accent-ink: #0d0d11; --accent-soft: rgba(129, 140, 248, .14); --accent-soft-ink: #c7d2fe;
  --success: #4ade80; --success-soft: rgba(74, 222, 128, .12); --warning: #fbbf24; --warning-soft: rgba(251, 191, 36, .12);
  --danger: #f87171; --danger-soft: rgba(248, 113, 113, .12); --info: #38bdf8; --info-soft: rgba(56, 189, 248, .12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 4px 14px -4px rgba(0, 0, 0, .5); --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { max-width: 100%; overflow-x: clip; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01";
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; letter-spacing: -.02em; font-weight: 700; }
h1 { font-size: clamp(1.5rem, 2.6vw, 1.9rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: max(16px, 1rem); } /* evita lo zoom automatico di iOS */
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Struttura: sidebar (desktop) / barra in basso (mobile) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); flex: 1; min-width: 0; text-decoration: none !important; }
.brand img { width: 32px; height: 32px; border-radius: 8px; flex: none; }
.brand b { font-size: 1rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand b em { font-style: normal; color: var(--accent); }
.nav { display: flex; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; text-decoration: none; white-space: nowrap; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-soft-ink); font-weight: 600; }
.nav .ico { display: flex; }
.me { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none !important; border-radius: var(--radius-sm); padding: 4px; }
.me:hover { background: var(--surface-2); }
.me .who { font-weight: 600; font-size: .9rem; display: none; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: .85rem;
}
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 120px; animation: fade-up .3s var(--ease) both; }
main.no-anim, main.no-anim * { animation: none !important; }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } }

@media (min-width: 1024px) {
  .topbar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar); flex-direction: column; align-items: stretch; gap: 20px;
    padding: 20px 14px; border-bottom: 0; border-right: 1px solid var(--line); background: var(--surface);
  }
  .brand { flex: none; padding: 0 6px; }
  .nav { flex-direction: column; gap: 2px; }
  .nav a { padding: 9px 12px; }
  .me { margin-top: auto; padding: 8px; }
  .me .who { display: block; }
  main { margin-left: var(--sidebar); padding: 32px 40px 64px; max-width: none; }
  main > * { max-width: 1160px; margin-left: auto; margin-right: auto; }
}
@media (max-width: 1023px) {
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; justify-content: space-around;
    background: color-mix(in srgb, var(--surface) 96%, transparent); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .nav a { flex: 1; flex-direction: column; gap: 3px; padding: 6px 2px; font-size: .7rem; border-radius: 10px; min-height: 52px; justify-content: center; }
  .nav a.active { background: none; color: var(--accent); }
  .nav a.active .ico { background: var(--accent-soft); border-radius: 999px; }
  .nav .ico { padding: 3px 14px; transition: background .2s; }
}

/* ---------- Componenti ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); padding: 20px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 14px; }
.spacer { flex: 1; min-width: 0; }
.row > .spacer:has(input) { flex: 1 1 200px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: .92rem; cursor: pointer; text-decoration: none !important; white-space: nowrap;
  box-shadow: var(--shadow-xs); transition: background .15s, border-color .15s, box-shadow .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 2px rgba(79, 70, 229, .3); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.magic { background: var(--accent-soft); border-color: transparent; color: var(--accent-soft-ink); box-shadow: none; }
.btn.magic:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: .85rem; }
.btn .spin { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

label.field, div.field { display: block; font-size: .85rem; font-weight: 500; color: var(--ink-2); }
label.field > span, div.field > span { display: block; margin-bottom: 6px; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=email], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-xs); transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--muted) 45%, var(--line)); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
select { appearance: none; cursor: pointer; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236c6c78' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.grid-form .wide { grid-column: 1 / -1; }
.check { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }

.alert { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-soft-ink); font-size: .92rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warning-soft); color: var(--warning); }
.alert a { color: inherit; text-decoration: underline; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); text-decoration: none !important; white-space: nowrap;
}
.badge.read { background: var(--success-soft); color: var(--success); }
.badge.reading { background: var(--warning-soft); color: var(--warning); }
.badge.loan { background: var(--info-soft); color: var(--info); }
a.badge:hover { background: var(--surface-3); }
.stars { display: inline-flex; color: var(--star); letter-spacing: 1px; }
.stars button { background: none; border: 0; padding: 2px; font-size: 1.45rem; line-height: 1; cursor: pointer; color: var(--surface-3); transition: transform .15s, color .15s; }
.stars button.on { color: var(--star); }
.stars button:hover { transform: scale(1.15); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 6px 14px;
  font-size: .85rem; font-weight: 500; cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: color-mix(in srgb, var(--muted) 45%, var(--line)); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-2); }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: .85rem; cursor: pointer; min-height: 34px; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- Home ---------- */
.hero { margin-bottom: 28px; }
.hero h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); margin-bottom: 4px; }
.hero .sub { color: var(--muted); margin-bottom: 18px; }
.hero .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.hero-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 720px) { .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.hero-stat { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-xs); }
.hero-stat .tile { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent-soft-ink); }
.hero-stat:nth-child(2) .tile { background: var(--success-soft); color: var(--success); }
.hero-stat:nth-child(3) .tile { background: var(--warning-soft); color: var(--warning); }
.hero-stat:nth-child(4) .tile { background: var(--info-soft); color: var(--info); }
.hero-stat .n { font-size: 1.45rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.hero-stat .l { font-size: .8rem; color: var(--muted); }
.btn.dice .die { display: inline-block; transition: transform .4s var(--ease); }
.btn.dice:hover .die { transform: rotate(180deg); }
.btn.dice.rolling .die { animation: spin .4s linear infinite; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 28px 0 14px; }
.section-title h2 { margin: 0; }
.carousel { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 16px; overflow-x: auto; padding: 4px 2px 12px; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.carousel > * { scroll-snap-align: start; }

/* ---------- Libreria ---------- */
.toolbar { display: grid; gap: 12px; margin-bottom: 20px; }
.searchbox { position: relative; }
.searchbox input { padding-left: 42px; min-height: 46px; border-radius: 12px; }
.searchbox::before {
  content: ""; position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); pointer-events: none; opacity: .7;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236c6c78' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat center / contain;
}
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.toolbar .row { justify-content: space-between; }

.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 28px 20px; }
@media (max-width: 520px) {
  .books { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 12px; }
  .book-card { gap: 7px; }
  .book-card .t { font-size: .8rem; }
  .book-card .a { font-size: .72rem; }
  .book-card .meta .badge { font-size: .65rem; padding: 1px 6px; }
  .gen { padding: 12% 10%; }
  .gen .gt { font-size: .72rem; }
  .gen .ga { font-size: .6rem; }
}
.book-card { display: flex; flex-direction: column; gap: 10px; color: inherit; text-decoration: none !important; border-radius: var(--radius-sm); }
.book-card.enter { animation: fade-up .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 25ms); }
.cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 6px; overflow: hidden; background: var(--surface-2);
  box-shadow: 0 1px 2px rgba(16, 16, 24, .12), 0 8px 18px -8px rgba(16, 16, 24, .35); transition: transform .25s var(--ease), box-shadow .25s var(--ease);
}
.cover::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); pointer-events: none; }
.book-card:hover .cover { transform: translateY(-4px); box-shadow: 0 2px 4px rgba(16, 16, 24, .12), 0 18px 30px -10px rgba(16, 16, 24, .4); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .4s; }
.cover img.loaded { opacity: 1; }
.cover .tag { position: absolute; top: 8px; left: 8px; z-index: 2; box-shadow: var(--shadow-sm); }
.gen {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; padding: 14% 12%;
  color: #fff; background: var(--c, #4f46e5);
  background-image: linear-gradient(160deg, rgba(255, 255, 255, .18), transparent 45%), linear-gradient(0deg, rgba(0, 0, 0, .22), transparent 50%);
}
.gen .gt { font-family: var(--serif); font-weight: 700; font-size: clamp(.85rem, 1vw + .45rem, 1.1rem); line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.gen .orn { width: 24px; height: 2px; background: rgba(255, 255, 255, .7); margin-top: 10px; border-radius: 2px; }
.gen .ga { font-size: .72rem; font-weight: 600; opacity: .9; }
.detail .gen .gt { font-size: 1.5rem; }
.book-card .t { font-weight: 600; font-size: .92rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card .a { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-card .meta { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.mini-stars { color: var(--star); font-size: .75rem; letter-spacing: 1px; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; width: 0; height: 100%; background: var(--accent); border-radius: inherit; transition: width .4s var(--ease); }
.progress.big { height: 8px; }

.books.list { grid-template-columns: 1fr; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.books.list .book-card { flex-direction: row; align-items: center; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); border-radius: 0; }
.books.list .book-card:last-child { border-bottom: 0; }
.books.list .book-card:hover { background: var(--surface-2); }
.books.list .cover { width: 40px; flex: none; border-radius: 4px; }
.books.list .book-card:hover .cover { transform: none; }
.books.list .gen { padding: 10%; }
.books.list .gen .gt { font-size: .42rem; -webkit-line-clamp: 3; }
.books.list .gen .ga, .books.list .gen .orn, .books.list .cover .tag { display: none; }
.books.list .info { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) auto; gap: 4px 16px; align-items: center; }
.books.list .t { -webkit-line-clamp: 1; }
.books.list .meta { margin: 0; }
@media (max-width: 640px) { .books.list .info { grid-template-columns: 1fr; } }

/* Scaffale */
.shelves { display: grid; gap: 28px; }
.shelf h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.shelf-row {
  display: flex; align-items: flex-end; gap: 3px; padding: 18px 16px 0; min-height: 230px; overflow-x: auto; scrollbar-width: thin;
  background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0;
}
.shelf-board { height: 12px; border-radius: 0 0 6px 6px; background: linear-gradient(180deg, var(--wood-1), var(--wood-2)); box-shadow: 0 6px 12px -6px rgba(0, 0, 0, .4); }
.spine {
  flex: none; width: var(--w, 32px); height: var(--h, 190px); background: var(--c); color: #fff; text-decoration: none !important;
  border-radius: 3px 3px 1px 1px; position: relative; display: flex; align-items: center; justify-content: center; padding: 10px 0;
  background-image: linear-gradient(90deg, rgba(0, 0, 0, .18), rgba(255, 255, 255, .12) 35%, rgba(0, 0, 0, .12));
  transition: transform .25s var(--ease); animation: fade-up .4s var(--ease) both; animation-delay: calc(var(--i, 0) * 15ms);
}
.spine span { writing-mode: vertical-rl; transform: rotate(180deg); font-size: .76rem; font-weight: 600; max-height: calc(var(--h, 190px) - 24px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spine:hover, .spine:focus-visible { transform: translateY(-10px); z-index: 2; }
.spine.lean { transform: rotate(-3deg); margin-left: 6px; }
.spine .dot { position: absolute; top: -5px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--info); border: 2px solid var(--surface); }

/* Caricamento, vuoti */
.skel { border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-card .skel:first-child { aspect-ratio: 2 / 3; border-radius: 6px; }
.skel-card .skel + .skel { height: 12px; margin-top: 10px; width: 80%; }
.skel-card .skel + .skel + .skel { width: 50%; }
.empty { text-align: center; padding: 56px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.empty .big { font-size: 2.6rem; margin-bottom: 6px; }
.sentinel { height: 1px; }
.loading-more { display: flex; justify-content: center; align-items: center; gap: 8px; padding: 20px; color: var(--muted); }

/* ---------- Scheda libro ---------- */
.backdrop { position: relative; overflow: hidden; padding: 28px; margin-bottom: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); }
.backdrop .bg { position: absolute; inset: -60px -60px auto; height: 260px; background-size: cover; background-position: center; filter: blur(50px) saturate(1.3); opacity: .22; }
.backdrop .bg.tint { opacity: .12; filter: none; }
.backdrop > :not(.bg) { position: relative; }
.detail { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px; align-items: start; }
@media (max-width: 720px) { .detail { grid-template-columns: 1fr; gap: 20px; } .detail > .cover, .detail > div > .cover { width: 100%; max-width: 170px; margin: 0 auto; } .backdrop { padding: 18px; } }
.detail h1 { font-size: clamp(1.5rem, 3vw, 2rem); margin-bottom: 2px; }
.detail .byline { font-size: 1.05rem; color: var(--muted); margin: 0 0 12px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1px; margin: 0; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.facts div { background: var(--surface); padding: 10px 14px; }
.facts dt { font-size: .75rem; color: var(--muted); font-weight: 500; }
.facts dd { margin: 2px 0 0; font-weight: 600; font-size: .92rem; word-break: break-word; }
.prose { white-space: pre-line; line-height: 1.65; color: var(--ink-2); max-width: 72ch; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.list-item { display: flex; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .thumb { width: 40px; flex: none; text-decoration: none !important; }
.list-item .thumb .gen { padding: 10%; }
.list-item .thumb .gen .gt { font-size: .42rem; }
.list-item .thumb .gen .ga, .list-item .thumb .gen .orn { display: none; }
.overdue { color: var(--danger); font-weight: 600; }
.loan-ring { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 1.1rem; flex: none; background: var(--info-soft); }
.loan-ring.late { background: var(--danger-soft); }
details summary { cursor: pointer; color: var(--muted); font-weight: 500; }

/* ---------- Statistiche ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { position: relative; padding: 16px; animation: fade-up .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 40ms); }
.kpi .ico { position: absolute; right: 14px; top: 14px; font-size: 1.2rem; opacity: .8; }
.kpi .n { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.bars { display: grid; gap: 10px; }
.bar { display: grid; grid-template-columns: minmax(80px, 38%) 1fr 32px; gap: 10px; align-items: center; font-size: .88rem; }
.bar .track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar .fill { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .8s var(--ease); }
.bar .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar b { text-align: right; font-variant-numeric: tabular-nums; }
.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; transform: rotate(-90deg); }
.donut circle { fill: none; stroke-width: 16; transition: stroke-dasharray 1s var(--ease); }
.legend { display: grid; gap: 8px; font-size: .9rem; }
.legend span { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }
.medals { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.medal { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); opacity: .55; }
.medal.on { opacity: 1; border-color: color-mix(in srgb, var(--star) 45%, var(--line)); background: color-mix(in srgb, var(--star) 7%, var(--surface)); }
.medal-ico { font-size: 1.6rem; margin-bottom: 4px; }
.medal strong { font-size: .9rem; }

/* ---------- Varie ---------- */
.loc-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); }
.loc-picker { width: 100%; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(10, 10, 14, .55); backdrop-filter: blur(4px); animation: fade .2s both; }
@keyframes fade { from { opacity: 0; } }
.modal .box { width: min(480px, 100%); background: var(--surface); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-lg); animation: fade-up .25s var(--ease) both; }
.modal video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); background: #000; display: block; }
.scan-frame { position: relative; }
.scan-frame::after { content: ""; position: absolute; left: 12%; right: 12%; top: 50%; height: 2px; background: #ef4444; box-shadow: 0 0 10px #ef4444; animation: scan 1.8s ease-in-out infinite; }
@keyframes scan { 0%, 100% { transform: translateY(-50px); } 50% { transform: translateY(50px); } }
.scan-frame.batch video { width: 100%; aspect-ratio: 16 / 9; max-height: 42vh; object-fit: cover; border-radius: var(--radius); background: #000; display: block; }
.suggest { max-height: 360px; overflow: auto; border-radius: var(--radius); }
.suggest button { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 8px; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.suggest button:hover { background: var(--surface-2); }
.suggest img, .suggest .ph { width: 36px; height: 54px; object-fit: cover; border-radius: 4px; background: var(--surface-2); flex: none; }
.batch-list { margin-top: 16px; padding: 4px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.batch-list:empty { display: none; }
.batch-item { animation: fade-up .3s var(--ease) both; }
.batch-item.removed { opacity: .55; }
.batch-item.flash { animation: flash .9s ease; }
@keyframes flash { 30% { background: var(--accent-soft); } }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 200;
  max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 12px; background: var(--ink); color: var(--surface);
  font-weight: 500; font-size: .92rem; box-shadow: var(--shadow-lg); text-align: center; animation: toast-in .25s var(--ease) both;
}
.toast.out { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); } }
@media (min-width: 1024px) { .toast { bottom: 28px; left: calc(50% + var(--sidebar) / 2); } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 8px; height: 12px; border-radius: 2px; animation: fall var(--d) cubic-bezier(.25, .6, .5, 1) var(--delay) forwards; }
.confetti i.emo { width: auto; height: auto; font-size: 20px; font-style: normal; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }

/* ---------- Accesso ---------- */
.login { max-width: 400px; margin: 0 auto; padding: 12vh 16px 40px; }
.login .logo { width: 56px; height: 56px; border-radius: 14px; display: block; margin: 0 auto 16px; box-shadow: var(--shadow); }
.login h1 { text-align: center; font-size: 1.6rem; }
.login h1 em { font-style: normal; color: var(--accent); }
.login .tagline { text-align: center; color: var(--muted); margin-bottom: 24px; }
.login .card { padding: 24px; box-shadow: var(--shadow); }
.login .btn.primary { width: 100%; min-height: 44px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* =====================================================================
   Ottimizzazioni mobile e app installata (PWA, in particolare iOS)
   ===================================================================== */
html { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
a, button, .chip, .seg button, label.btn { touch-action: manipulation; -webkit-touch-callout: none; }
.nav, .btn, .chip, .seg, .hero-stat { -webkit-user-select: none; user-select: none; }
a.hero-stat { color: inherit; text-decoration: none !important; transition: border-color .15s, transform .1s; }
a.hero-stat:active { transform: scale(.98); }
.btn.back { padding-left: 6px; margin-left: -6px; color: var(--accent); }
.settings-link { color: inherit; text-decoration: none !important; padding: 14px 18px; }
.settings-link:active { background: var(--surface-2); }

/* Invito all'installazione */
.install-card { margin: 0 0 18px; border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%); }
.install-card .app-ico { width: 44px; height: 44px; border-radius: 11px; box-shadow: var(--shadow-sm); }
.install-card > * + * { margin-top: 12px; }
.install-card > .row { flex-wrap: nowrap; align-items: flex-start; }
.install-card > .row > .row { flex-wrap: nowrap; min-width: 0; }
.steps { margin: 12px 0 0; padding-left: 22px; display: grid; gap: 8px; font-size: .92rem; }
.kbd { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: .85rem; vertical-align: middle; }
.kbd svg.i { width: 15px; height: 15px; color: var(--accent); }

@media (max-width: 1023px) {
  /* Barra in alto compatta che rispetta notch e Dynamic Island */
  .topbar { padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); background: var(--surface); }
  .brand img { width: 30px; height: 30px; }
  main { padding: 18px max(16px, env(safe-area-inset-left)) calc(96px + env(safe-area-inset-bottom)); }

  /* Barra in basso: 5 voci, "Aggiungi" al centro in evidenza, Statistiche dentro "Altro" */
  .nav { padding-left: max(4px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right)); }
  /* Home, Libri, Aggiungi (al centro), Prestiti, Altro. Desideri è una scheda dentro Libri,
     Statistiche si apre da Home e da Altro. */
  .nav a[href="#/"] { order: 1; }
  .nav a[href="#/libri"] { order: 2; }
  .nav a[href="#/aggiungi"] { order: 3; }
  .nav a[href="#/prestiti"] { order: 4; }
  .nav a[href="#/impostazioni"] { order: 5; }
  .nav a[href="#/statistiche"], .nav a[href="#/desideri"] { display: none; }
  .nav a.active-parent { color: var(--ink); }
  .nav a.active-parent .ico { background: color-mix(in srgb, currentColor 14%, transparent); }
  .nav a[href="#/aggiungi"] .ico {
    width: 46px; height: 46px; padding: 0; margin-top: -18px; border-radius: 16px; display: grid; place-items: center;
    background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 16px -4px color-mix(in srgb, var(--accent) 70%, transparent);
  }
  .nav a[href="#/aggiungi"] .ico svg.i { width: 24px; height: 24px; stroke-width: 2.2; }
  .nav a[href="#/aggiungi"].active .ico { background: var(--accent-hover); }
  .nav a:active .ico { transform: scale(.92); }

  /* Elementi più comodi da toccare */
  .chip { min-height: 36px; padding: 7px 14px; }
  .seg button { min-height: 38px; padding: 7px 12px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .stars button { font-size: 1.7rem; padding: 4px; }

  /* Filtri tutti visibili, senza scorrimento orizzontale: due per riga, l'ordinamento sotto a tutta larghezza */
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .filters select { min-height: 44px; border-radius: 14px; padding: 8px 32px 8px 12px; background-position: right 10px center; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
  .filters select:last-child { grid-column: 1 / -1; }
  /* Stati di lettura: quattro pulsanti che si dividono la riga */
  .toolbar .chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .toolbar .chip { padding: 7px 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .toolbar .row { flex-wrap: nowrap; }
  .toolbar .seg { margin-left: auto; }

  /* Home */
  .hero .actions .btn.primary { flex: 1 1 100%; }
  .hero .actions .btn:not(.primary) { flex: 1 1 0; }
  .hero-stats { gap: 10px; }
  .hero-stat { padding: 12px; gap: 10px; }
  .hero-stat .tile { width: 36px; height: 36px; }
  .carousel { grid-auto-columns: 112px; margin: 0 -16px; padding: 4px 16px 12px; scroll-padding: 0 16px; }

  /* Finestre e scanner: pannello dal basso, a tutta larghezza */
  .modal { align-items: flex-end; padding: 0; }
  .modal .box { width: 100%; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: sheet-up .3s var(--ease) both; }
  .modal video { aspect-ratio: 3 / 4; max-height: 58vh; }
  .modal .row .btn { flex: 1; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }

  /* Scheda libro e moduli */
  .facts { grid-template-columns: 1fr 1fr; }
  .grid-form { grid-template-columns: 1fr 1fr; gap: 12px; }
  .grid-form > .field:has(textarea), .grid-form > label.field:first-child { grid-column: 1 / -1; }
  .two { grid-template-columns: 1fr; }
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@media (max-width: 380px) { .grid-form { grid-template-columns: 1fr; } }

/* Nell'app installata niente invito all'installazione e niente rimbalzo dello sfondo */
@media (display-mode: standalone) {
  .install-card { display: none; }
  body { overscroll-behavior: none; }
}

/* ---------- Schede Biblioteca / Desideri ---------- */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 16px; border-radius: 14px; background: var(--surface-2); }
.tabs a {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; border-radius: 11px;
  color: var(--muted); font-weight: 700; text-decoration: none !important; transition: background .2s, color .2s;
}
.tabs a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.tabs svg.i { width: 18px; height: 18px; }
.page-head .btn { flex: none; }

/* ---------- Home in una schermata ---------- */
.home-shelf { margin-top: 4px; }
.home-shelf .section-title { margin: 18px 0 10px; }
.link-more { font-weight: 700; font-size: .9rem; }
.home-books { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (min-width: 1024px) { .home-books { grid-template-columns: repeat(3, minmax(0, 170px)); gap: 22px; } }
@media (max-width: 1023px) {
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 1.45rem; }
  /* Home: tutto entra nello schermo, niente scorrimenti */
  .hero { margin-bottom: 0; }
  .hero .sub { margin-bottom: 14px; }
  .hero .actions { margin-bottom: 14px; }
  .hero-stats { gap: 8px; }
  .hero-stat { padding: 10px 12px; }
  .hero-stat .n { font-size: 1.25rem; }
  .home-books .book-card .meta { display: none; }
  .home-books .cover { max-height: 24vh; }
  .install-card { margin: 14px 0 0; }
}
@media (max-width: 1023px) and (max-height: 720px) {
  .hero h1 { font-size: 1.3rem; }
  .hero .sub { display: none; }
  .home-books .cover { max-height: 19vh; }
}

/* Home su iPhone 15 Pro / Pro Max: contatori su una riga, così tutto sta nello schermo
   anche in Safari con le barre visibili (circa 740 punti di altezza utile). */
@media (max-width: 1023px) {
  .hero-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .hero-stat { flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px; padding: 10px 4px; border-radius: 14px; }
  .hero-stat .tile { display: none; }
  .hero-stat .n { font-size: 1.35rem; }
  .hero-stat .l { font-size: .72rem; line-height: 1.2; }
  .home-books .cover { max-height: min(24vh, 200px); }
}
@media (min-width: 420px) and (max-width: 1023px) {
  .home-books { gap: 16px; }
}
@media (max-width: 1023px) {
  /* Lo spazio in fondo coincide con l'altezza della barra in basso (circa 74 punti + area sicura) */
  main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .hero .sub { margin-bottom: 12px; }
}
/* Invito all'installazione nella Home: una sola riga */
.install-bar { display: flex; align-items: center; gap: 10px; margin: 12px 0 0; padding: 8px 8px 8px 10px; border-radius: 16px; font-size: .9rem; border: 1px solid var(--line); }
.install-bar .app-ico { width: 30px; height: 30px; border-radius: 8px; }
.install-bar .spacer { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.install-bar .btn.small { min-height: 34px; }
.install-bar > * + * { margin-top: 0; }
.hero .install-bar { margin: 4px 0 12px; background: rgba(255, 255, 255, .75); border-color: rgba(255, 255, 255, .9); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero .install-bar { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .1); } }
:root[data-theme="dark"] .hero .install-bar { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .1); }
