
/* ============================================================
   BASE PAGE
   ============================================================ */

html, body {
  margin: 0;
  padding: 0;
  padding-top: var(--safe-top, 24px);
  overflow-x: hidden;
  max-width: 100%;
  touch-action: pan-y pinch-zoom;
  background: #ffffff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #1a1a1a;
  min-height: 100vh;
}


/* Impedisce selezione testo e highlight blu Android */
* {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Variabile di zoom globale */
:root {
  --zoom: 1;
}

/* ============================================================
   GRIGLIA ICONE
   ============================================================ */

.folder {
  display: grid;
  grid-template-columns: repeat(
    auto-fill,
    minmax(calc(85px * var(--zoom)), 1fr)
  );
  gap: calc(16px * var(--zoom));
  padding: 0 24px 24px 24px;
  justify-items: start;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;

  transition: grid-template-columns 0.15s ease-out,
              gap 0.15s ease-out;
}

/* Contenitore icona — versione glass */
.app-icon {
  text-align: center;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  transition: transform 0.18s ease, filter 0.18s ease;

  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  border-radius: calc(20px * var(--zoom));
  padding: calc(6px * var(--zoom));
  box-sizing: border-box;
  overflow: hidden;
}

/* Icona PNG */
.app-icon img {
  width: calc(78px * var(--zoom));
  height: calc(78px * var(--zoom));
  border-radius: calc(16px * var(--zoom));
  background: transparent;
  pointer-events: none;

  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.12),
    0 8px 24px rgba(0, 0, 0, 0.08);

  display: block;
}

/* Etichetta */
.app-icon span {
  display: block;
  margin-top: calc(6px * var(--zoom));
  font-size: calc(11px * var(--zoom));
  color: #3a3a3a;
  font-weight: 500;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  transition: font-size 0.18s ease-out,
              margin-top 0.18s ease-out;
}

/* ============================================================
   WIGGLE MODE
   ============================================================ */

@keyframes wiggle {
  0%   { transform: rotate(-2deg) scale(1.02); }
  50%  { transform: rotate( 2deg) scale(0.98); }
  100% { transform: rotate(-2deg) scale(1.02); }
}

.edit-mode .app-icon:not(.dragging) img {
  animation: wiggle 0.25s ease-in-out infinite;
}

.app-icon.dragging {
  opacity: 0.9;
  z-index: 1000;
}

.app-icon.placeholder {
  opacity: 0;
  visibility: hidden;
}

/* ============================================================
   MENU CONTESTUALE — ANDROID MATERIAL + RESPONSIVE ALLO ZOOM
   ============================================================ */

#context-menu {
  position: fixed;
  background: #ffffff;
  border-radius: calc(14px * var(--zoom));
  min-width: calc(180px * var(--zoom));
  padding: calc(8px * var(--zoom)) 0;
  z-index: 2000;
  isolation: isolate;

  box-shadow:
    0 calc(6px * var(--zoom)) calc(20px * var(--zoom)) rgba(0,0,0,0.18),
    0 calc(2px * var(--zoom)) calc(6px * var(--zoom)) rgba(0,0,0,0.12);

  opacity: 0;
  transform: scale(0.85);
  transform-origin: top center;
  transition: opacity 120ms ease, transform 120ms ease, visibility 0s linear 120ms;
  visibility: hidden;
  pointer-events: none;
}

#context-menu:not(.hidden) {
  opacity: 1;
  transform: scale(1);
  visibility: visible;
  pointer-events: auto;
  transition: opacity 120ms ease, transform 120ms ease;
}

/* Pulsanti del menù */
#context-menu button {
  width: 100%;
  padding: calc(14px * var(--zoom)) calc(18px * var(--zoom));
  font-size: calc(15px * var(--zoom));
  color: #222;
  display: flex;
  align-items: center;
  gap: calc(12px * var(--zoom));
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background: none;
  border: none;

  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Ripple effect */
#context-menu button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.08);
  opacity: 0;
  transition: opacity 150ms;
}

#context-menu button:active::after {
  opacity: 1;
}

/* Separatore tra voci */
#context-menu button + button {
  border-top: 1px solid rgba(0,0,0,0.08);
}

/* Voce "Rimuovi" in rosso */
#context-menu button:last-child {
  color: #d11a2a;
}

/* ============================================================
   PAGINA INIZIALE
   ============================================================ */

#setup-page {
  position: fixed;
  inset: 0;
  background: #f5f5f7;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 9999;
}

#setup-page.hidden {
  display: none;
}

#setup-page input {
  padding: 12px;
  font-size: 16px;
  border-radius: 8px;
  border: 1px solid #ccc;
}

#setup-page button {
  padding: 14px;
  font-size: 16px;
  border-radius: 8px;
  background: #007aff;
  color: white;
  border: none;
}

#cfg-refresh {
  display: none;
}
