/* ============================================================
   DITHER MORPH — base del design system + stili di progetto
   ============================================================ */

/* --- Tokens ------------------------------------------------- */
:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --color-bg:        var(--c-bg);
  --color-sidebar:   var(--c-sidebar);
  --color-border:    var(--c-border);
  --color-border-md: var(--c-track);
  --color-border-lg: var(--c-muted);
  --color-text-muted:   var(--c-muted);
  --color-text-sub:     var(--c-sec);
  --color-text:         var(--c-primary);
  --color-accent:       var(--c-white);
}

/* --- Reset -------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }

/* --- Scrollbar ---------------------------------------------- */
.custom-scrollbar::-webkit-scrollbar { width: 4px; height: 4px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: var(--color-border-md); border-radius: 2px; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--color-border-lg); }
.custom-scrollbar { scrollbar-width: thin; scrollbar-color: var(--color-border-md) transparent; }

/* --- Focus -------------------------------------------------- */
:focus-visible { outline: 2px solid var(--color-text-sub); outline-offset: 2px; border-radius: 4px; }
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible) { outline: none; }

/* --- Select ------------------------------------------------- */
select { -webkit-appearance: none; appearance: none; }

/* --- Range slider ------------------------------------------ */
input[type="range"] { -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; }

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  height: 12px; width: 12px; border-radius: 50%;
  background: var(--color-accent); cursor: pointer; margin-top: -5px;
}
input[type="range"]::-webkit-slider-runnable-track {
  width: 100%; height: 2px; cursor: pointer; background: var(--color-border-md);
}
input[type="range"]::-moz-range-track {
  width: 100%; height: 2px; cursor: pointer; background: var(--color-border-md); border: 0;
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--color-accent); border: 0; cursor: pointer;
}
input[type="range"]:disabled { opacity: 0.3; cursor: not-allowed; }

/* --- Color input ------------------------------------------- */
.color-input {
  -webkit-appearance: none; appearance: none;
  width: 28px; height: 28px;
  border: 1px solid var(--color-border-md); border-radius: 4px;
  padding: 0; cursor: pointer; background: none; flex-shrink: 0;
}
.color-input::-webkit-color-swatch-wrapper { padding: 2px; }
.color-input::-webkit-color-swatch { border: none; border-radius: 2px; }
.color-input::-moz-color-swatch { border: none; border-radius: 2px; }

/* --- Toast -------------------------------------------------- */
#toast {
  opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateY(0); }
/* errore: con l'accento bianco un toast "colorato" sparirebbe, quindi lo inverto */
#toast.err { background: var(--color-text); border-color: var(--color-text); color: var(--color-bg); }

/* --- Canvas container -------------------------------------- */
#canvasWrap { cursor: default; max-width: 100%; max-height: 100%; display: flex; }
#canvasWrap canvas {
  display: block; max-width: 100%; max-height: 100%;
  image-rendering: pixelated; cursor: grab; touch-action: none;
}
#canvasWrap canvas.drag { cursor: grabbing; }

/* ============================================================
   PROJECT-SPECIFIC — DITHER MORPH
   ============================================================ */

/* --- Testo di servizio ------------------------------------- */
.note { color: var(--color-text-muted); font-size: 12px; line-height: 1.5; }
kbd { border: 1px solid var(--color-border-md); border-radius: 3px; padding: 0 4px;
      color: var(--color-text); font-size: 11px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
#stat.err { color: var(--color-text); }

/* --- Righe disattivate (gate() in script.js) ---------------- */
/* niente pointer-events:none: bloccherebbe anche il tooltip che spiega
   perche la riga e spenta. Il blocco vero lo fa l'attributo disabled. */
.off { opacity: .3; cursor: not-allowed; }
.off input, .off select, .off button, .off textarea, .off label { cursor: not-allowed; }

/* --- Select / textarea ------------------------------------- */
.sel, .ta {
  width: 100%; background: var(--color-bg); color: var(--color-text);
  border: 1px solid var(--color-border-md); border-radius: 6px;
  font-size: 12px; font-family: inherit; padding: 7px 9px;
  transition: border-color .2s ease;
}
.sel:hover, .ta:hover { border-color: var(--color-border-lg); }
.sel {
  padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%),
                    linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.ta { line-height: 1.5; resize: vertical; min-height: 56px; display: block; }
.ta::placeholder { color: var(--color-text-muted); }

/* --- Bottoni ------------------------------------------------ */
/* stato .solid lo commuta script.js sul bottone di registrazione */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--color-border-md); border-radius: 6px;
  background: transparent; color: var(--color-text);
  font-family: inherit; font-size: 14px; font-weight: 500;
  padding: 8px 12px; cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}
.btn:hover { background: var(--color-border); }
.btn-primary, .btn.solid {
  background: var(--color-text); border-color: var(--color-text); color: var(--c-sidebar);
}
.btn-primary:hover, .btn.solid:hover { background: var(--color-accent); border-color: var(--color-accent); }
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }

/* --- Segmented control (stato .on gestito da bindSeg) ------- */
.seg { display: flex; border: 1px solid var(--color-border-md); border-radius: 6px; overflow: hidden; }
.seg-wrap { flex-wrap: wrap; }
.seg button {
  flex: 1 1 auto; min-width: 0;
  background: transparent; border: 0; border-right: 1px solid var(--color-border-md);
  color: var(--color-text-muted); font-family: inherit; font-size: 12px;
  padding: 7px 4px; cursor: pointer;
  transition: background-color .2s ease, color .2s ease;
}
.seg button:last-child { border-right: 0; }
.seg button:hover:not(.on) { color: var(--color-text); background: var(--c-border); }
.seg button.on { background: var(--color-text); color: var(--color-bg); }

/* --- Miniature sorgenti ------------------------------------- */
#thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
#thumbs:empty { display: none; }
.th { position: relative; width: 56px; height: 56px; border: 1px solid var(--color-border-md);
      border-radius: 4px; overflow: hidden; background: #000; }
.th img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .85; }
.th b { position: absolute; left: 0; top: 0; background: var(--color-text); color: var(--color-bg);
        font-size: 10px; padding: 1px 4px; font-weight: 400; font-variant-numeric: tabular-nums; }
.th .rm { position: absolute; right: 0; top: 0; background: var(--color-bg); color: var(--color-text);
          border: 0; padding: 2px 3px; cursor: pointer; line-height: 0;
          opacity: 0; transition: opacity .2s ease; }
.th .rm svg { width: 12px; height: 12px; }
.th:hover .rm, .th .rm:focus-visible { opacity: 1; }

/* --- Drop zone ---------------------------------------------- */
#drop {
  position: absolute; inset: 16px; border: 1px dashed var(--color-border-md); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 8px;
  color: var(--color-text-muted); text-align: center; pointer-events: none;
}
#drop.hide { display: none; }
/* senza immagini il canvas e' un rettangolo nero: resta nascosto finche' c'e' la zona di rilascio */
main:has(#drop:not(.hide)) #canvasWrap { visibility: hidden; }
#drop strong { font-size: 16px; font-weight: 600; color: var(--color-text); }
body.dragging #drop { border-color: var(--color-accent); color: var(--color-accent); display: flex; }

/* --- Transport ---------------------------------------------- */
.tbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 28px; flex: 0 0 auto;
  background: transparent; border: 1px solid var(--color-border-md); border-radius: 6px;
  color: var(--color-text); cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease;
}
.tbtn:hover { background: var(--color-border); border-color: var(--color-border-lg); }
.tbtn svg { width: 15px; height: 15px; }
.ic { display: inline-flex; }
#play .ic-play { display: none; }
#play.paused .ic-play { display: inline-flex; }
#play.paused .ic-pause { display: none; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--color-accent); flex: 0 0 auto; }
.dot.off { background: var(--color-border-md); opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  #sidebar, #toast, details i { transition: none; }
}
