/* ───────── Stile ispirato all'app TV di Apple ───────── */
:root {
  color-scheme: dark;
  --bg: #000;
  --bg-2: #111113;
  --sidebar: #1c1c1e;
  --surface: #2c2c2e;
  --surface-2: #3a3a3c;
  --text: #fff;
  --muted: rgba(235, 235, 245, 0.6);
  --faint: rgba(235, 235, 245, 0.3);
  --sep: rgba(84, 84, 88, 0.55);
  --accent: #0a84ff;
  --accent-press: #0071e3;
  --danger: #ff453a;
  --fav: #ff375f;
  --radius: 12px;
  --sidebar-w: 260px;
  --gutter: clamp(16px, 3vw, 28px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
img { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ic { width: 20px; height: 20px; flex: none; }

/* ───────── Pulsanti ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px; border-radius: 12px;
  font-weight: 600; font-size: 15px; transition: transform .15s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-press); }
.btn.secondary { background: var(--surface); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger-btn { background: var(--danger); }
.small-btn { height: 36px; padding: 0 16px; font-size: 14px; }
.link { color: var(--accent); font-size: 14px; padding: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-grid; place-items: center; color: var(--text);
  transition: background .15s, transform .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.icon-btn:active { transform: scale(.92); }
.glass { background: rgba(60, 60, 67, .55); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6); }
.glass:hover { background: rgba(90, 90, 96, .7); }
.danger { color: var(--danger); }
[aria-disabled="true"] { opacity: .35; pointer-events: none; }

/* ───────── Splash ───────── */
.splash { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--text); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── Login ───────── */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto; }
.login-bg {
  position: fixed; inset: -20%;
  background:
    radial-gradient(40% 50% at 20% 30%, rgba(255, 55, 140, .55), transparent 70%),
    radial-gradient(45% 55% at 80% 25%, rgba(10, 132, 255, .55), transparent 70%),
    radial-gradient(50% 60% at 55% 85%, rgba(255, 159, 10, .40), transparent 70%),
    #000;
  filter: blur(40px);
  animation: drift 22s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(4%, -3%, 0) rotate(8deg) scale(1.08); } }
.login-card {
  position: relative; width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  padding: 36px 28px 26px; border-radius: 26px;
  background: rgba(28, 28, 30, .72);
  backdrop-filter: blur(40px) saturate(1.8); -webkit-backdrop-filter: blur(40px) saturate(1.8);
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 4px; border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #3aa0ff, #0a5fff);
  box-shadow: 0 10px 30px rgba(10,132,255,.45);
}
.login-logo .ic { width: 36px; height: 36px; fill: #fff; stroke: #fff; }
.login-card h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 8px; }
.login-card input, .field input, .dialog input, .search-box input {
  width: 100%; height: 48px; padding: 0 16px; border-radius: 12px;
  background: rgba(118, 118, 128, .24); border: 1px solid transparent; outline: none;
  transition: border-color .15s, background .15s;
}
.login-card input:focus, .field input:focus, .dialog input:focus { border-color: var(--accent); background: rgba(118,118,128,.32); }
.login-card .btn { width: 100%; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0 !important; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--sep); }
.demo-note { font-size: 12px; color: #ffd60a; background: rgba(255,214,10,.1); padding: 10px; border-radius: 10px; margin: 6px 0 0 !important; }

/* ───────── Layout app ───────── */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--sidebar);
  display: flex; flex-direction: column; position: relative; z-index: 30;
  padding-top: env(safe-area-inset-top);
}
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 22px 12px 12px; scrollbar-width: none; }
.sidebar-scroll::-webkit-scrollbar { display: none; }
.brand { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 6px 10px 14px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; height: 38px; padding: 0 10px;
  border-radius: 10px; font-size: 15px; transition: background .12s;
}
.nav a .ic { color: var(--accent); }
.nav a span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a em { font-style: normal; font-size: 13px; color: var(--muted); }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: var(--accent); }
.nav a.active .ic, .nav a.active em { color: #fff; }
.nav-empty { padding: 4px 10px; margin: 0; }
.nav-section { margin-top: 18px; }
.section-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; font-size: 17px; font-weight: 700;
}
.section-head .ic { color: var(--accent); transition: transform .2s; width: 18px; }
.nav-section.collapsed .nav { display: none; }
.nav-section.collapsed .section-head .ic { transform: rotate(-90deg); }

.storage { padding: 10px 22px; }
.storage-bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.storage-bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .4s; }
.storage-bar span.warn { background: #ff9f0a; }
.storage p { margin: 6px 0 0; }

.user-wrap { position: relative; border-top: 1px solid var(--sep); padding-bottom: env(safe-area-inset-bottom); }
.user { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 18px; text-align: left; }
.user:hover { background: rgba(255,255,255,.04); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; overflow: hidden;
  display: grid; place-items: center; font-weight: 600; font-size: 14px;
  background: linear-gradient(160deg, #8e8e93, #48484a);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu {
  position: absolute; bottom: calc(100% + 6px); left: 12px; right: 12px;
  background: var(--surface); border-radius: 14px; padding: 8px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.user-menu p { margin: 4px 8px 8px; overflow: hidden; text-overflow: ellipsis; }
.user-menu button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 10px 8px; border-radius: 8px; color: var(--danger); }
.user-menu button:hover { background: rgba(255,255,255,.06); }

.main { flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; position: relative; background: var(--bg-2); }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 0 var(--gutter); pointer-events: none;
}
.topbar > * { pointer-events: auto; margin-top: calc(14px + env(safe-area-inset-top)); }
.menu-btn { visibility: hidden; }
.scrim { display: none; }

/* ───────── Hero (carosello) ───────── */
.hero { position: relative; height: clamp(320px, 62vh, 620px); overflow: hidden; background: #000; }
.page-title { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-title.on-hero { position: absolute; z-index: 3; top: calc(22px + env(safe-area-inset-top)); left: var(--gutter); text-shadow: 0 2px 12px rgba(0,0,0,.4); }
.hero-slide { position: absolute; inset: 0; opacity: 0; transition: opacity .9s ease; pointer-events: none; }
.hero-slide.active { opacity: 1; pointer-events: auto; }
.hero-slide img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.06); transition: transform 7s ease-out; }
.hero-slide.active img { transform: scale(1); }
.hero-shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(to top, var(--bg-2) 0%, rgba(17,17,19,.65) 22%, transparent 55%),
    linear-gradient(to right, rgba(0,0,0,.55), transparent 55%),
    linear-gradient(to bottom, rgba(0,0,0,.45), transparent 22%);
}
.hero-info { position: absolute; left: var(--gutter); right: var(--gutter); bottom: 54px; max-width: 560px; }
.hero-title { margin: 0; font-size: clamp(30px, 5vw, 56px); font-weight: 800; letter-spacing: -.03em; line-height: 1.02; text-shadow: 0 4px 30px rgba(0,0,0,.4); overflow-wrap: anywhere; }
.hero-sub { margin: 10px 0 16px; color: rgba(255,255,255,.8); font-size: 14px; }
.hero-btn { background: rgba(255,255,255,.92); color: #000; height: 40px; }
.hero-btn:hover { background: #fff; }
.hero-btn .ic { width: 16px; height: 16px; }
.hero-dots { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; gap: 7px; z-index: 3; }
.hero-dots button { width: 7px; height: 7px; border-radius: 4px; background: rgba(255,255,255,.4); transition: width .3s, background .3s; }
.hero-dots button.active { width: 20px; background: #fff; }

/* ───────── File orizzontali ───────── */
.rows { padding: 8px 0 48px; }
.row { margin-top: 18px; }
.row-head { display: inline-flex; align-items: center; gap: 4px; padding: 0 var(--gutter); margin-bottom: 10px; }
.row-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.row-head .ic { color: var(--muted); width: 18px; }
.row-head:hover .ic { color: var(--text); }
.row-wrap { position: relative; }
.row-scroll {
  display: grid; grid-auto-flow: column; grid-auto-columns: clamp(200px, 22vw, 300px); gap: 14px;
  overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 var(--gutter);
  padding: 4px var(--gutter) 8px; scrollbar-width: none;
}
.row-scroll::-webkit-scrollbar { display: none; }
.row-scroll > * { scroll-snap-align: start; }
.row-scroll.ranked { grid-auto-columns: clamp(230px, 25vw, 340px); }
.row-arrow {
  position: absolute; top: 0; bottom: 52px; width: var(--gutter); min-width: 34px; z-index: 2;
  display: grid; place-items: center; opacity: 0; transition: opacity .2s;
  background: linear-gradient(to right, rgba(17,17,19,.9), transparent);
}
.row-arrow.right { right: 0; background: linear-gradient(to left, rgba(17,17,19,.9), transparent); }
.row-arrow.left { left: 0; }
.row-arrow .ic { width: 26px; height: 26px; }
@media (hover: hover) { .row-wrap:hover .row-arrow { opacity: 1; } }

/* ───────── Card ───────── */
.card { display: block; width: 100%; text-align: left; min-width: 0; }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-ph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--faint); }
.thumb-ph .ic { width: 34px; height: 34px; }
.card:hover .thumb, .card:focus-visible .thumb { transform: scale(1.04); box-shadow: 0 18px 40px rgba(0,0,0,.55); }
.card:focus-visible { outline: none; }
.card:focus-visible .thumb { outline: 3px solid #fff; outline-offset: 2px; }
.badge {
  position: absolute; left: 8px; bottom: 8px; display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px 3px 6px; border-radius: 7px; font-size: 12px; font-weight: 600;
  background: rgba(0,0,0,.55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.badge .ic { width: 12px; height: 12px; }
.fav-dot { position: absolute; right: 8px; top: 8px; color: var(--fav); filter: drop-shadow(0 1px 4px rgba(0,0,0,.5)); }
.fav-dot .ic { width: 18px; height: 18px; }
.card-meta { display: flex; flex-direction: column; padding: 8px 2px 0; min-width: 0; }
.card-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 12px; color: var(--muted); }

/* Classifica numerata stile "Top Chart" */
.ranked-item { position: relative; }
.rank {
  position: absolute; left: 2px; bottom: 0; font-size: 24px; font-weight: 600; color: var(--muted); line-height: 38px;
}
.ranked .ranked-item .card-meta { padding-left: 26px; }

/* ───────── Pagine a griglia ───────── */
.page { padding: calc(22px + env(safe-area-inset-top)) var(--gutter) 60px; }
.page-head { margin: 0 0 22px; padding-left: 52px; min-height: 38px; }
.page-head p { margin: 4px 0 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 22px 16px; }
.sub-title { font-size: 20px; margin: 28px 0 12px; }

.search-box {
  display: flex; align-items: center; gap: 10px; padding: 0 14px; margin-bottom: 22px;
  background: rgba(118,118,128,.24); border-radius: 12px; max-width: 640px;
}
.search-box .ic { color: var(--muted); }
.search-box input { background: transparent; padding: 0; border: 0; height: 46px; font-size: 17px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 12px; background: var(--surface); }
.chip:hover { background: var(--surface-2); }
.chip .ic { color: var(--accent); width: 18px; }
.chip em { font-style: normal; color: var(--muted); font-size: 13px; }

.empty { text-align: center; max-width: 420px; margin: 12vh auto 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty-icon { width: 84px; height: 84px; border-radius: 24px; display: grid; place-items: center; background: var(--surface); color: var(--accent); margin-bottom: 10px; }
.empty-icon .ic { width: 44px; height: 44px; }
.empty h2 { margin: 0; font-size: 22px; }
.empty p { margin: 0 0 16px; }

/* ───────── Pannello caricamento ───────── */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; animation: fade .2s; }
.sheet {
  width: min(560px, 100%); max-height: min(720px, 100%); overflow: auto;
  background: var(--sidebar); border-radius: 22px; padding: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: pop .25s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.dropzone {
  border: 2px dashed var(--surface-2); border-radius: 16px; padding: 28px 16px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: border-color .15s, background .15s;
}
.dropzone p { margin: 0; }
.dropzone.over { border-color: var(--accent); background: rgba(10,132,255,.08); }
.dz-icon { color: var(--accent); margin-bottom: 6px; }
.dz-icon .ic { width: 38px; height: 38px; }
.dropzone .btn { margin-top: 8px; }
.queue { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 8px; }
.queue li { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: var(--surface); border-radius: 12px; }
.q-icon { color: var(--accent); }
.q-body { flex: 1; min-width: 0; }
.q-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-bar { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.q-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.queue li.done .q-bar span { background: #30d158; }
.queue li.done .q-icon { color: #30d158; }
.queue li.failed .q-sub { color: var(--danger); }
.queue li.failed .q-bar { display: none; }

/* ───────── Visualizzatore ───────── */
.no-scroll .main { overflow: hidden; }
.lightbox { position: fixed; inset: 0; z-index: 50; background: #000; animation: fade .2s; outline: none; }
.lb-top {
  position: absolute; z-index: 3; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 30px;
  background: linear-gradient(to bottom, rgba(0,0,0,.7), transparent);
}
.lb-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lb-title strong, .lb-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-actions { display: flex; gap: 8px; }
#lb-fav.on { color: var(--fav); }
.lb-stage { position: absolute; inset: 0; display: grid; place-items: center; }
.lb-stage > img, .lb-stage > video { grid-area: 1 / 1; max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; }
.lb-stage .lb-full { opacity: 0; transition: opacity .3s; }
.lb-stage.loaded .lb-full { opacity: 1; }
.lb-stage.loaded .lb-low { visibility: hidden; transition: visibility 0s .3s; }
.lb-low { filter: blur(6px); }
.lb-demo { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }
.lb-demo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: .6; }
.lb-demo p { position: relative; background: rgba(0,0,0,.6); padding: 10px 16px; border-radius: 12px; }
.lb-nav { position: absolute; z-index: 3; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; }
.lb-nav.prev { left: 16px; }
.lb-nav.next { right: 16px; }
.lb-nav .ic { width: 24px; height: 24px; }
.lb-panel {
  position: absolute; z-index: 4; right: 16px; top: calc(76px + env(safe-area-inset-top)); width: 300px; max-width: calc(100% - 32px);
  padding: 18px; border-radius: 18px; background: rgba(44,44,46,.82);
  backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px); animation: pop .2s;
}
.lb-panel h3 { margin: 0 0 12px; font-size: 17px; }
.lb-panel dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; font-size: 14px; }
.lb-panel dt { color: var(--muted); }
.lb-panel dd { margin: 0; overflow-wrap: anywhere; }

/* ───────── Dialog / Toast ───────── */
.dialog {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(380px, calc(100% - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.dialog::backdrop { background: rgba(0,0,0,.5); }
.dialog form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dialog h3 { margin: 0; font-size: 18px; }
.dialog p { margin: 0; }
.dialog input { background: rgba(118,118,128,.24); }
.dialog-actions { display: flex; gap: 10px; margin-top: 6px; }
.dialog-actions .btn { flex: 1; }
.toast {
  position: fixed; z-index: 100; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 12px 18px; border-radius: 14px; background: rgba(58,58,60,.95); font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: opacity .25s, transform .25s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ───────── Responsive ───────── */
@media (min-width: 901px) {
  .page-head { padding-left: 0; }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 84vw);
    transform: translateX(-100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
    box-shadow: 20px 0 60px rgba(0,0,0,.5);
  }
  .sidebar-open .sidebar { transform: none; }
  .sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.5); animation: fade .2s; }
  .menu-btn { visibility: visible; }
  .page-title.on-hero { left: calc(var(--gutter) + 50px); top: calc(16px + env(safe-area-inset-top)); }
  .page-title { font-size: 26px; }
  .row-scroll { grid-auto-columns: 62vw; gap: 12px; }
  .row-scroll.ranked { grid-auto-columns: 68vw; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 10px; }
  .lb-nav { display: none; }
  .lb-actions { gap: 4px; }
  .lb-actions .icon-btn { width: 34px; height: 34px; }
  .lb-actions .ic { width: 18px; height: 18px; }
  .hero { height: 58vh; min-height: 340px; }
  .hero-info { bottom: 48px; }
}
@media (max-width: 520px) {
  .lb-title { display: none; }
  .lb-top { justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
