:root {
  --bg: #fbf8f1;
  --surface: #ffffff;
  --text: #2a2a26;
  --muted: #6b6b66;
  --border: #e3ddcf;
  --primary: #4d6a3a;
  --primary-soft: #6b8c4f;
  --gold: #c4a25f;
  --danger: #c8102e;
  --success: #2a6a3a;
  --radius: 14px;
  --shadow: 0 4px 14px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
  /* niente più bottom-nav fissa: basta un piccolo respiro in fondo */
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
img, video { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

.app-header {
  text-align: center;
  padding: 20px 16px 12px;
}
.app-header .app-logo {
  width: clamp(96px, 26vw, 140px);
  height: auto;
  margin: 0 auto 6px;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.app-header h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 6vw, 1.9rem);
  margin: 0 0 4px;
  color: var(--primary);
  font-weight: 600;
}
.app-header .subtitle {
  margin: 0;
  font-size: .85rem;
  color: var(--muted);
  letter-spacing: .03em;
}

.app-main {
  padding: 12px 14px;
  max-width: 760px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.upload-action {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--primary) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 18%, transparent);
  margin-bottom: 10px;
  cursor: pointer;
  transition: background .2s, transform .12s;
  user-select: none;
}
.upload-action:last-of-type { margin-bottom: 0; }
.upload-action:active { transform: scale(.985); background: color-mix(in srgb, var(--primary) 14%, transparent); }
.upload-action .action-ic { font-size: 1.9rem; line-height: 1; flex: 0 0 auto; }
.upload-action .action-text { display: flex; flex-direction: column; }
.upload-action .action-title { font-weight: 600; font-size: 1rem; }
.upload-action .action-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }

.hidden-input {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.uploader-row { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.uploader-label { display: block; font-size: .82rem; margin-bottom: 6px; color: var(--muted); }
.uploader-label .opt { color: #aaa; font-size: .74rem; }
.uploader-row input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 1rem;
}
.uploader-row input:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent);
  outline-offset: 1px;
}

.queue .queue-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.queue h2 { font-size: .95rem; margin: 0; font-weight: 600; }
.queue h2 .queue-count { color: var(--muted); font-weight: 400; font-size: .85rem; }
.queue-list { list-style: none; padding: 0; margin: 0 0 12px; }
.queue-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}
.queue-list li:last-child { border-bottom: 0; }
.queue-thumb {
  width: 50px; height: 50px;
  background: #eee;
  border-radius: 8px;
  flex: 0 0 auto;
  object-fit: cover;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}
.queue-info { flex: 1; min-width: 0; }
.queue-name {
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.queue-size { font-size: .72rem; color: var(--muted); }
.queue-progress {
  width: 100%;
  height: 4px;
  background: #eee;
  border-radius: 999px;
  margin-top: 5px;
  overflow: hidden;
}
.queue-progress > span {
  display: block;
  height: 100%;
  background: var(--primary);
  width: 0;
  transition: width .25s;
}
.queue-state {
  font-size: .7rem;
  padding: 4px 9px;
  border-radius: 999px;
  flex: 0 0 auto;
  font-weight: 600;
  letter-spacing: .02em;
}
.queue-state.pending { background: #f0eee5; color: #8a8a82; }
.queue-state.uploading { background: #fff3d6; color: #8a6b1a; }
.queue-state.done { background: #d5edd9; color: var(--success); }
.queue-state.error { background: #fbdbe0; color: var(--danger); }

.primary-btn {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: .03em;
  transition: background .15s, transform .1s;
}
.primary-btn:active { background: var(--primary-soft); transform: scale(.99); }
.primary-btn:disabled { background: #b8b8b0; cursor: not-allowed; }

.link-btn {
  background: none;
  border: 0;
  color: var(--primary);
  font-size: .82rem;
  padding: 6px 8px;
  border-radius: 6px;
}
.link-btn:hover { background: color-mix(in srgb, var(--primary) 10%, transparent); }

.status {
  padding: 12px 14px;
  border-radius: 10px;
  text-align: center;
  font-size: .92rem;
  margin-bottom: 14px;
}
.status.success { background: #d5edd9; color: var(--success); }
.status.error { background: #fbdbe0; color: var(--danger); }
.status.info { background: #e9eef5; color: #34527a; }

.footnote {
  text-align: center;
  font-size: .76rem;
  color: var(--muted);
  margin: 18px 8px;
}

.ios-tip {
  margin: 2px 0 12px;
  padding: 9px 12px;
  background: #f6f1e3;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.5;
}

.filters { padding: 12px; }
.filter-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.filter-tab {
  flex: 1;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: .85rem;
  font-weight: 500;
  color: var(--text);
  transition: background .15s, color .15s, border-color .15s;
}
.filter-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.date-filters { display: flex; gap: 8px; align-items: end; }
.date-field { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.date-field span { font-size: .7rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.date-field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: .85rem;
  min-width: 0;
  color: var(--text);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
@media (min-width: 480px) { .gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; } }
@media (min-width: 720px) { .gallery-grid { grid-template-columns: repeat(4, 1fr); } }

.gallery-item {
  position: relative;
  aspect-ratio: 1;
  background: #ddd;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s;
}
.gallery-item:active { transform: scale(.97); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item .video-badge {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,.65);
  color: white;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .04em;
  backdrop-filter: blur(4px);
  z-index: 2;
}
.gallery-item .video-thumb-fallback {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #2a2a26 0%, #3a3a32 100%);
}
.gallery-item.is-video::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0) 40%, rgba(0,0,0,.35) 100%);
  pointer-events: none;
  z-index: 1;
}
.gallery-item .play-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 2.4rem;
  text-shadow: 0 2px 8px rgba(0,0,0,.55);
  pointer-events: none;
  z-index: 2;
  line-height: 1;
}
.gallery-item .play-overlay i { filter: drop-shadow(0 0 6px rgba(0,0,0,.4)); }
.gallery-item .item-meta {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 8px 6px;
  font-size: .7rem;
  color: white;
  background: linear-gradient(to top, rgba(0,0,0,.55), transparent);
  display: flex;
  justify-content: space-between;
  gap: 4px;
}
.gallery-item .item-meta .uploader-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.5;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.94);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 16px env(safe-area-inset-bottom);
}
.lightbox[hidden] { display: none; }
.lightbox-close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  background: rgba(255,255,255,.18);
  color: white;
  border: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 3;
}
.lightbox-counter {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  color: white;
  font-size: .82rem;
  font-weight: 500;
  background: rgba(255,255,255,.18);
  padding: 7px 14px;
  border-radius: 999px;
  letter-spacing: .03em;
  z-index: 3;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,.18);
  color: white;
  border: 0;
  width: 48px; height: 48px;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, opacity .2s;
  z-index: 3;
  padding: 0;
}
.lightbox-nav.prev { left: 10px; }
.lightbox-nav.next { right: 10px; }
.lightbox-nav:disabled { opacity: 0; pointer-events: none; }
.lightbox-nav:hover:not(:disabled),
.lightbox-nav:active:not(:disabled) { background: rgba(255,255,255,.32); }
@media (max-width: 640px) {
  .lightbox-nav { display: none; }
}
.lightbox-viewport {
  flex: 1 1 auto;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  position: relative;
  min-height: 0;
}
.lightbox-track {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  transition: transform .28s cubic-bezier(.22,.61,.36,1);
  touch-action: pan-y;
  will-change: transform;
}
.lightbox-track.dragging {
  transition: none;
}
.lightbox-slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  box-sizing: border-box;
  overflow: hidden;
}
.media-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  overflow: hidden;
  max-width: 100%;
  max-height: 75vh;
}
.media-wrapper.is-loading {
  width: min(86vw, 640px);
  aspect-ratio: 4 / 3;
  background: #0e0e0c;
}
.media-wrapper.is-loading::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.08) 50%, transparent 70%);
  background-size: 220% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
  z-index: 1;
  pointer-events: none;
}
.media-wrapper > img,
.media-wrapper > video {
  max-width: 100%;
  max-height: 75vh;
  width: auto;
  height: auto;
  object-fit: contain;
  position: relative;
  z-index: 2;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 1;
  transition: opacity .25s ease-out;
}
.media-wrapper > img {
  touch-action: none;
  transform-origin: center center;
  will-change: transform;
  -webkit-touch-callout: none;
}
.media-wrapper.is-loading > * { opacity: 0; }
.media-wrapper.is-error {
  width: min(86vw, 400px);
  aspect-ratio: 4 / 3;
  background: #1a1a18;
}
.media-wrapper.is-error::after {
  content: 'Impossibile caricare';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.55);
  font-size: .9rem;
  z-index: 2;
}
@keyframes shimmer {
  0%   { background-position: 220% 0; }
  100% { background-position: -220% 0; }
}

.queue-error {
  font-size: .72rem;
  color: var(--danger);
  margin-top: 4px;
  line-height: 1.3;
}
.lightbox-meta {
  color: rgba(255,255,255,.85);
  font-size: .82rem;
  margin-top: 18px;
  text-align: center;
  max-width: 480px;
}
.lightbox-meta > div { margin-bottom: 4px; }
.lightbox-meta .download-link {
  display: inline-block;
  color: white;
  text-decoration: none;
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px;
  margin-top: 10px;
  font-size: .85rem;
  font-weight: 500;
}
.lightbox-meta .download-link:active { background: rgba(255,255,255,.12); }

.install-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--primary);
  color: white;
  font-size: .88rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.install-banner[hidden] { display: none; }
.install-text { display: flex; align-items: center; gap: 8px; min-width: 0; }
.install-text i { font-size: 1.1rem; flex: 0 0 auto; }
.install-text span { overflow: hidden; text-overflow: ellipsis; }
.install-actions { display: flex; gap: 4px; align-items: center; flex: 0 0 auto; }
.install-btn {
  background: var(--gold);
  color: #2a2a26;
  border: 0;
  padding: 7px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: .82rem;
  letter-spacing: .02em;
}
.install-btn:active { background: #b58e4d; }
.install-dismiss {
  background: transparent;
  border: 0;
  color: white;
  padding: 6px 10px;
  font-size: 1rem;
  opacity: .8;
  cursor: pointer;
}
.install-dismiss:active { opacity: 1; }

.install-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  animation: fadeIn .2s ease-out;
}
.install-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 22px 22px 18px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 -4px 30px rgba(0,0,0,.2);
  animation: slideUp .25s ease-out;
}
.install-card h3 {
  margin: 0 0 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  color: var(--primary);
}
.install-card ol {
  margin: 0 0 18px;
  padding-left: 22px;
  font-size: .92rem;
  line-height: 1.65;
  color: var(--text);
}
.install-card ol li { margin-bottom: 8px; }
.install-card ol li strong { color: var(--primary); }
.install-card ol li i { color: #007aff; margin: 0 2px; }
.install-card .close-modal { margin-top: 4px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
  box-shadow: 0 -2px 8px rgba(0,0,0,.04);
}
.nav-link {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  text-decoration: none;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 500;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  letter-spacing: .02em;
}
.nav-link .nav-ic { font-size: 1.3rem; line-height: 1; }
.nav-link.active { color: var(--primary); }
.nav-link.active .nav-ic { transform: scale(1.05); }
