:root {
  --bg: #0c0c0c;
  --fg: #ececec;
  --muted: #8a8a8a;
  --line: #ffffff24;
  --panel: #0e0e0ef0;
  --chip: rgba(255, 255, 255, 0.07);
  --chip-on: #ececec;
  --chip-on-fg: #0c0c0c;
  --ease: cubic-bezier(0.22, 0.9, 0.24, 1);
  --move: 1100ms;
}
[data-theme="light"] {
  --bg: #f1efea;
  --fg: #141414;
  --muted: #6d6a64;
  --line: rgba(0, 0, 0, 0.14);
  --panel: rgba(241, 239, 234, 0.95);
  --chip: rgba(0, 0, 0, 0.06);
  --chip-on: #141414;
  --chip-on-fg: #f1efea;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 11px/1.4 "JetBrains Mono", ui-monospace, monospace;
  font-variant-ligatures: none; /* "->" resta "->", senza diventare una freccia */
  letter-spacing: 0.02em;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  text-transform: uppercase;
}

/* ── Stage & tiles ───────────────────────────────────────── */
#stage {
  position: fixed;
  inset: 0;
  contain: strict;
}
/* Ogni tile ha una dimensione fissa e viene spostata/ridimensionata solo con
   transform (translate + scale): così l'animazione resta sulla GPU ed è fluida. */
.tile {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  transition:
    transform var(--move) var(--ease),
    opacity 500ms ease;
  z-index: 1;
}
#stage.moving .tile { will-change: transform; }
.tile .float { width: 100%; height: 100%; }
.tile .inner {
  width: 100%;
  height: 100%;
  overflow: hidden;
  transition: transform 380ms var(--ease);
  transform-origin: var(--ox, 50%) var(--oy, 50%);
  cursor: zoom-in;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 500ms ease;
  user-select: none;
  -webkit-user-drag: none;
}
.tile img.loaded { opacity: 1; }

.tile:hover { z-index: 50; }
.tile:hover .inner { transform: scale(var(--hover-scale, 2.4)); }

/* Immagini escluse dal filtro */
.tile.dim {
  opacity: 0.15;
  pointer-events: none;
}

/* Immagini nella nuvola */
.tile.in-cloud { z-index: 20; }
.tile.in-cloud .inner { box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); }
#stage.dense .tile.in-cloud .inner { box-shadow: none; }
.tile.in-cloud .float {
  animation: drift var(--dur, 7s) ease-in-out var(--delay, 0s) infinite alternate;
}
.tile.in-cloud:hover .float { animation-play-state: paused; }
@keyframes drift {
  0%   { transform: translate(0, 0) rotate(var(--rot, 0deg)); }
  50%  { transform: translate(var(--dx, 6px), var(--dy, -8px)) rotate(calc(var(--rot, 0deg) * -0.5)); }
  100% { transform: translate(calc(var(--dx, 6px) * -0.6), calc(var(--dy, -8px) * 0.7)) rotate(var(--rot, 0deg)); }
}

/* ── Barra ───────────────────────────────────────────────── */
#panel {
  position: fixed;
  left: 50%;
  bottom: 16px;
  width: min(980px, calc(100% - 32px));
  display: flex;
  flex-direction: column-reverse;
  background: var(--panel);
  border: 1px solid var(--line);
  transform: translateX(-50%);
  z-index: 70;
}
.panel-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  column-gap: 8px;
  min-height: 40px;
  padding: 0 6px;
}
#title {
  white-space: nowrap; /* il titolo sta sempre su una riga */
  padding: 8px 10px;
  font-weight: 600;
  text-align: left;
}
#title::after { content: " +"; opacity: 0.5; }
body.about-open #title::after { content: " ×"; }
#title:hover { opacity: 0.6; }
.panel-bar button { padding: 8px 10px; white-space: nowrap; }
.panel-bar button:hover { opacity: 0.6; }
.panel-bar button:disabled { opacity: 0.4; cursor: default; }
.panel-bar button.on { background: var(--chip-on); color: var(--chip-on-fg); }
.panel-bar button.on:hover { opacity: 1; }
.panel-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; }
#activeCount:not(:empty)::before { content: "· "; }

#filters {
  max-height: min(55vh, 480px);
  overflow-y: auto;
  padding: 10px 16px 16px;
  border-bottom: 1px solid var(--line);
  transition: max-height 400ms var(--ease), padding 400ms var(--ease), opacity 300ms ease;
}
#panel.closed #filters {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-bottom-color: transparent;
  opacity: 0;
  pointer-events: none;
}
.group { padding: 8px 0; }
.group + .group { border-top: 1px solid var(--line); }
.group h3 {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 400;
  color: var(--muted);
  text-transform: uppercase;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: left;
  padding: 5px 9px;
  background: var(--chip);
  border: 1px solid transparent;
  text-transform: none;
  transition: background 200ms, color 200ms, opacity 200ms;
}
.chip:hover { border-color: var(--line); }
.chip .n { color: var(--muted); margin-left: 6px; font-size: 10px; }
.chip.on { background: var(--chip-on); color: var(--chip-on-fg); }
.chip.on .n { color: inherit; opacity: 0.6; }
.chip.empty { opacity: 0.35; }
/* tag previsti ma non ancora assegnati a nessuna immagine */
.chip.zero { opacity: 0.4; }
.frow {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
}
.frow-label {
  flex: 0 0 84px;
  padding: 5px 0;
  color: var(--muted);
  text-align: left;
  text-transform: none;
}
.frow-label::before { content: "○ "; }
.frow-label:hover { color: var(--fg); }
.frow.on .frow-label { color: var(--fg); font-weight: 600; }
.frow.on .frow-label::before { content: "● "; }
/* i punti di vista sono attivi solo per il focus scelto */
.frow:not(.on) .chip[data-side] { opacity: 0.45; }

/* Focus: le immagini del punto di vista non evidenziato si attenuano */
.tile.in-cloud.faded { opacity: 0.25; }
.tile.in-cloud.hl { z-index: 25; }
#emptyMsg {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-transform: uppercase;
  z-index: 40;
  pointer-events: none;
}
#emptyMsg[hidden] { display: none; }

.vs { align-self: center; padding: 0 2px; color: var(--muted); }

@media (max-width: 720px) {
  .panel-bar { padding: 4px 6px; }
  #title { width: 100%; padding: 6px 10px 0; }
}

/* ── Tooltip ─────────────────────────────────────────────── */
#tip {
  position: fixed;
  left: 0;
  top: 0;
  max-width: min(320px, calc(100vw - 16px));
  padding: 6px 8px;
  overflow-wrap: anywhere;
  background: var(--fg);
  color: var(--bg);
  pointer-events: none;
  z-index: 80;
  opacity: 0;
  transition: opacity 150ms;
}
#tip.show { opacity: 1; }
#tip b { display: block; font-weight: 600; }
#tip span { opacity: 0.7; }

/* ── Lightbox ────────────────────────────────────────────── */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  visibility: hidden;
}
#lightbox.open { visibility: visible; }
.lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 12, 12, 0.9);
  opacity: 0;
  transition: opacity 450ms ease;
}
[data-theme="light"] .lb-backdrop { background: rgba(241, 239, 234, 0.92); }
#lightbox.show .lb-backdrop { opacity: 1; }
#lightbox { cursor: zoom-out; }
.lb-frame {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  overflow: hidden;
  will-change: transform;
}
.lb-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.lb-high { opacity: 0; transition: opacity 500ms ease; }
.lb-high.loaded { opacity: 1; }
.lb-caption {
  position: absolute;
  overflow-y: auto;
  overflow-wrap: anywhere;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 250ms ease, transform 250ms ease;
  cursor: default;
}
#lightbox.show .lb-caption {
  opacity: 1;
  transform: none;
  transition: opacity 400ms ease 300ms, transform 400ms var(--ease) 300ms;
}
.lb-title { margin: 0 0 6px; font-size: 13px; font-weight: 600; text-transform: uppercase; }
.lb-meta, .lb-note { margin: 0 0 10px; color: var(--muted); }
.lb-meta:empty, .lb-note:empty { display: none; }
.lb-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.lb-close {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 26px;
  line-height: 1;
  opacity: 0;
  transition: opacity 300ms ease;
}
#lightbox.show .lb-close { opacity: 1; }

/* ── About ───────────────────────────────────────────────── */
#about {
  position: fixed;
  inset: 0;
  z-index: 65;
  overflow-y: auto;
  background: #0c0c0cf0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 450ms ease, visibility 0s linear 450ms;
}
[data-theme="light"] #about { background: #f1efeaf2; }
body.about-open #about {
  opacity: 1;
  visibility: visible;
  transition: opacity 450ms ease;
}
.about-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 10vh 16px 120px;
  transform: translateY(16px);
  transition: transform 600ms var(--ease);
  cursor: default;
}
body.about-open .about-inner { transform: none; }
.about-kicker, .about-credits {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
}
.about-credits { text-align: center; }
#aboutTitle {
  white-space: nowrap; /* sempre su una riga: sotto i 900px il corpo segue la larghezza */
  margin: 8px 0 32px;
  font-size: min(4.6vw, 44px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.about-cols {
  display: grid;
  grid-template-columns: 1fr;
  gap: 32px;
  margin-bottom: 40px;
}
.about-lead {
  margin: 0;
  font-size: clamp(15px, 1.7vw, 20px);
  line-height: 1.45;
}
.about-cols h2 {
  margin: 0 0 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.about-cols p { margin: 0 0 12px; font-size: 13px; line-height: 1.6; }
.about-cols .about-lead { font-size: clamp(15px, 1.7vw, 20px); line-height: 1.45; }

/* Desktop: tutto in una schermata, tre colonne affiancate sopra la barra.
   Le dimensioni seguono l'altezza della finestra, così il testo non viene tagliato. */
@media (min-width: 900px) {
  #about { display: flex; }
  .about-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    min-height: calc(100% - 76px); /* spazio lasciato alla barra */
    padding: clamp(16px, 5vh, 64px) 40px;
  }
  #aboutTitle { margin: 6px 0 clamp(20px, 4vh, 44px); font-size: clamp(26px, min(3.6vw, 5.5vh), 52px); }
  .about-cols {
    grid-template-columns: 0.8fr 1.4fr 1fr;
    gap: clamp(24px, 3vw, 48px);
    margin-bottom: clamp(20px, 4vh, 40px);
  }
  .about-cols h2 { margin-bottom: clamp(8px, 1.2vh, 12px); }
  .about-cols p { font-size: clamp(10px, min(1vw, 1.65vh), 14px); line-height: 1.55; margin-bottom: clamp(6px, 1.2vh, 12px); }
  .about-cols .about-lead {
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: clamp(14px, min(1.45vw, 2.4vh), 22px);
    line-height: 1.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root { --move: 0ms; }
  .tile.in-cloud .float { animation: none; }
}
