/* Bit, l'assistente del sito (assets/js/assistente.js).
   CSS normale, non Tailwind: non serve ricompilare main.css. */

:root {
  --bit-bg: #f5f5f4;
  --bit-surface: #e7e5e4;
  --bit-text: #0c0a09;
  --bit-muted: #57534e;
  --bit-border: #a8a29e;
  --bit-accent: #0c0a09;
  --bit-accent-text: #fafaf9;
  --bit-mark: #d97706;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bit-bg: #1c1917;
    --bit-surface: #292524;
    --bit-text: #fafaf9;
    --bit-muted: #a8a29e;
    --bit-border: #44403c;
    --bit-accent: #fafaf9;
    --bit-accent-text: #0c0a09;
    --bit-mark: #f59e0b;
  }
}

/* ── Gattino ─────────────────────────────────────────────── */

/* Livello fisso grande quanto lo schermo: il gatto vicino ai bordi non allarga la pagina. */
.bit-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 80;
  pointer-events: none;
}

.bit-cat {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: none; /* solo i pixel disegnati sono cliccabili */
  opacity: 0;
  will-change: transform;
}

.bit-cat.bit-ready {
  opacity: 1;
  transition: opacity 0.4s;
}

.bit-cat:focus-visible {
  outline: 3px solid var(--bit-mark);
  outline-offset: 4px;
  border-radius: 6px;
}

.bit-sprite {
  display: block;
}

.bit-sprite rect {
  pointer-events: auto;
}

.bit-cat[data-dir="-1"] .bit-sprite {
  transform: scaleX(-1);
}

.bit-f,
.bit-hat {
  display: none;
}

.bit-cat[data-frame="walk1"] .bit-f-walk1,
.bit-cat[data-frame="walk2"] .bit-f-walk2,
.bit-cat[data-frame="sit"] .bit-f-sit,
.bit-cat[data-frame="play"] .bit-f-play,
.bit-cat[data-frame="sleep"] .bit-f-sleep,
.bit-cat[data-frame="ride"] .bit-f-ride {
  display: inline;
}

.bit-cat[data-skin="witch"] .bit-hat {
  display: inline;
}

/* Su telefono (o con "riduci movimento") resta seduto in un angolo. */
.bit-cat.bit-docked {
  position: fixed;
  top: auto;
  left: 12px;
  bottom: 12px;
  transform: none !important;
  pointer-events: auto;
  z-index: 95;
}

.bit-cat.bit-docked .bit-sprite rect {
  pointer-events: none;
}

/* Su telefono, con il gatto fermo nell'angolo, il pulsante "Prendi una Moneta" non si mostra. */
html.bit-moneta-nascosta #btn-container {
  display: none !important;
}

/* Con il dito i pixel sono un bersaglio troppo piccolo: si tocca tutto il riquadro del gatto. */
@media (hover: none), (pointer: coarse) {
  .bit-cat {
    pointer-events: auto;
  }
}

/* Colori: arancione tigrato, e gatto nero con cappello ad Halloween. */
.bit-cat {
  --bit-outline: #141414;
  --bit-fur: #f2b16a;
  --bit-stripe: #d9813a;
  --bit-patch: #d9813a;
  --bit-chest: #ffffff;
  --bit-eye: #2a1608;
  --bit-nose: #f39ab0;
}

.bit-cat[data-skin="witch"] {
  --bit-outline: #0a0a0a;
  --bit-fur: #2e2e33;
  --bit-stripe: #26262b;
  --bit-patch: #26262b;
  --bit-chest: #2e2e33;
  --bit-eye: #f59e0b;
  --bit-nose: #4a4a50;
  --bit-hat: #45306e;
  --bit-band: #e8761c;
  --bit-broom: #9a5b2c;
  --bit-straw: #e8b64c;
  --bit-straw-shade: #b9832a;
}

@media (prefers-color-scheme: dark) {
  /* contorno chiaro, altrimenti il gatto nero sparisce sullo sfondo scuro */
  .bit-cat[data-skin="witch"] {
    --bit-outline: #8b8494;
    --bit-fur: #35303d;
    --bit-stripe: #2c2833;
    --bit-patch: #2c2833;
    --bit-chest: #35303d;
  }
}

/* Zzz mentre dorme */
.bit-zzz {
  display: none;
  position: absolute;
  bottom: 18px;
  right: 2px;
  font-family: "VT323", ui-monospace, monospace;
  font-size: 15px;
  line-height: 1;
  color: var(--bit-muted);
}

.bit-cat[data-dir="-1"] .bit-zzz {
  right: auto;
  left: 2px;
}

.bit-cat[data-frame="sleep"] .bit-zzz {
  display: block;
}

.bit-zzz span {
  position: absolute;
  bottom: 0;
  left: 0;
  opacity: 0;
  animation: bit-zzz 3s steps(6) infinite;
}

.bit-zzz span:nth-child(2) { animation-delay: 1s; }
.bit-zzz span:nth-child(3) { animation-delay: 2s; }

@keyframes bit-zzz {
  0% { opacity: 0; transform: translate(0, 0); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(10px, -22px); }
}

/* Il punto indicato da "Portami lì" */
.bit-highlight {
  outline: 3px solid var(--bit-mark);
  outline-offset: 6px;
  border-radius: 6px;
  animation: bit-pulse 0.8s ease-in-out 3;
}

@keyframes bit-pulse {
  50% { outline-offset: 2px; outline-color: transparent; }
}

/* ── Fumetto ─────────────────────────────────────────────── */

/* Bordo "a pixel": quattro ombre piene invece di border + border-radius,
   così gli angoli restano scalettati come nei giochi. */
.bit-bubble {
  --bit-ink: var(--bit-text);
  --bit-paper: var(--bit-bg);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 101; /* sopra la barra e il pulsante "Prendi una Moneta" */
  width: min(300px, calc(100vw - 24px));
  max-height: calc(100vh - 140px);
  overflow: visible;
  padding: 12px 14px 12px;
  background: var(--bit-paper);
  color: var(--bit-ink);
  box-shadow:
    0 -3px 0 0 var(--bit-ink),
    0 3px 0 0 var(--bit-ink),
    -3px 0 0 0 var(--bit-ink),
    3px 0 0 0 var(--bit-ink),
    6px 6px 0 0 rgba(0, 0, 0, 0.18);
  font-family: "Montserrat", ui-sans-serif, system-ui, sans-serif;
  animation: bit-pop 0.16s steps(3);
}

.bit-bubble[hidden] {
  display: none;
}

@keyframes bit-pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* punta del fumetto verso la testa di Bit */
.bit-tail {
  position: absolute;
  top: calc(100% + 1px);
  left: calc(var(--bit-tail-x, 50%) - 10px);
  display: block;
}

.bit-tail-ink { fill: var(--bit-ink); }
.bit-tail-fill { fill: var(--bit-paper); }

.bit-bubble-below .bit-tail {
  top: auto;
  bottom: calc(100% + 1px);
  transform: scaleY(-1);
}

.bit-bubble-notail .bit-tail {
  display: none;
}

.bit-x {
  position: absolute;
  top: 2px;
  right: 4px;
  width: 30px;
  height: 30px;
  border: 0;
  background: none;
  color: var(--bit-muted);
  font: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.bit-x:hover {
  color: var(--bit-text);
}

.bit-asked {
  margin: 0 28px 4px 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--bit-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bit-say {
  margin: 0 24px 0 0;
  min-height: 1.1em;
  font-family: "VT323", ui-monospace, monospace;
  font-size: 22px;
  line-height: 1.1;
  cursor: default;
}

.bit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 8px;
  margin-top: 10px;
  max-height: 38vh;
  overflow-y: auto;
  padding: 3px; /* spazio per i bordi a pixel dei pulsanti */
}

.bit-actions[hidden] {
  display: none;
}

/* pulsanti a pixel */
.bit-action {
  display: inline-block;
  padding: 4px 9px 3px;
  border: 0;
  background: var(--bit-paper);
  color: var(--bit-text);
  box-shadow:
    0 -2px 0 0 var(--bit-border),
    0 2px 0 0 var(--bit-border),
    -2px 0 0 0 var(--bit-border),
    2px 0 0 0 var(--bit-border);
  font-family: "VT323", ui-monospace, monospace;
  font-size: 19px;
  line-height: 1.1;
  text-decoration: none;
  cursor: pointer;
}

.bit-action:hover {
  box-shadow:
    0 -2px 0 0 var(--bit-text),
    0 2px 0 0 var(--bit-text),
    -2px 0 0 0 var(--bit-text),
    2px 0 0 0 var(--bit-text);
}

.bit-action-go {
  background: var(--bit-mark);
  color: #1c1917;
  box-shadow:
    0 -2px 0 0 var(--bit-text),
    0 2px 0 0 var(--bit-text),
    -2px 0 0 0 var(--bit-text),
    2px 0 0 0 var(--bit-text);
}

.bit-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.bit-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 2px solid var(--bit-border);
  border-radius: 0;
  background: var(--bit-paper);
  color: var(--bit-text);
  font: inherit;
  font-size: 16px; /* niente zoom automatico su iPhone */
}

.bit-input:focus {
  outline: none;
  border-color: var(--bit-mark);
}

.bit-send {
  width: 40px;
  border: 0;
  background: var(--bit-text);
  color: var(--bit-bg);
  font-size: 18px;
  cursor: pointer;
}

.bit-stay {
  display: block;
  margin: 8px 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--bit-muted);
  font: inherit;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* "Eccolo!" dopo "Portami lì": solo la frase */
.bit-bubble-short {
  width: max-content;
  max-width: min(250px, calc(100vw - 24px));
  padding: 8px 14px;
  cursor: pointer; /* toccandolo si apre il fumetto per fare domande */
}

.bit-bubble-short .bit-x,
.bit-bubble-short .bit-form,
.bit-bubble-short .bit-stay,
.bit-bubble-short .bit-actions,
.bit-bubble-short .bit-asked {
  display: none;
}

.bit-bubble-short .bit-say {
  margin: 0;
}

/* Messaggio di Bit con pulsanti (es. i collaboratori): niente campo di testo */
.bit-bubble-rich .bit-form,
.bit-bubble-rich .bit-stay,
.bit-bubble-rich .bit-asked {
  display: none;
}

/* Chi ha collaborato: un gattino pixel e il nome */
.bit-people {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 8px;
  width: 100%;
  margin: 2px 0 6px;
  padding: 0;
  list-style: none;
}

.bit-people a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 58px;
  color: var(--bit-text);
  text-decoration: none;
}

.bit-people svg {
  display: block;
  width: 36px;
  height: 33px;
}

.bit-people a:hover svg {
  transform: translateY(-2px);
}

.bit-people span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "VT323", ui-monospace, monospace;
  font-size: 15px;
  line-height: 1;
}

.bit-people a:hover span,
.bit-people a:focus-visible span {
  text-decoration: underline;
}

.bit-people a:focus-visible {
  outline: 2px solid var(--bit-mark);
  outline-offset: 2px;
}

.bit-people-more {
  align-self: center;
  font-family: "VT323", ui-monospace, monospace;
  font-size: 15px;
  color: var(--bit-muted);
}

.bit-action:focus-visible,
.bit-send:focus-visible,
.bit-x:focus-visible,
.bit-stay:focus-visible {
  outline: 2px solid var(--bit-mark);
  outline-offset: 3px;
}

.bit-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .bit-zzz span { animation: none; opacity: 1; }
  .bit-zzz span:nth-child(2) { transform: translate(5px, -9px); }
  .bit-zzz span:nth-child(3) { transform: translate(10px, -18px); }
  .bit-highlight { animation: none; }
  .bit-bubble { animation: none; }
}
