:root {
  --vuoto: #020a12;
  --ciano: #3fe8ff;
  --blu: #1f8bff;
  --ghiaccio: #d9f6ff;
  --tenue: rgba(63, 232, 255, 0.18);
  --velo: rgba(8, 28, 44, 0.55);
  --allarme: #ff5d73;
  --carattere: "Chakra Petch", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--vuoto);
  color: var(--ghiaccio);
  font-family: var(--carattere);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Dentro la finestra trasparente dell'app per Mac lo sfondo lascia vedere la scrivania */
html.trasparente, html.trasparente body { background: transparent; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 45% at 50% 38%, rgba(31, 139, 255, 0.16), transparent 70%),
    repeating-linear-gradient(0deg, rgba(63, 232, 255, 0.035) 0 1px, transparent 1px 4px);
}
html.trasparente body::before { background: radial-gradient(60% 45% at 50% 38%, rgba(2, 10, 18, 0.72), transparent 72%); }

.schermo {
  position: relative;
  min-height: 100dvh;
  max-width: 44rem;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.5rem;
}

/* --- intestazione --- */
.testata {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.nome {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ciano);
  text-shadow: 0 0 18px rgba(63, 232, 255, 0.55);
}
.stato { font-size: 0.85rem; font-weight: 300; color: rgba(217, 246, 255, 0.7); }
.testata button { margin-left: 0.25rem; }

/* --- nucleo --- */
.scena { display: grid; place-items: center; min-height: 0; }
.nucleo {
  position: relative;
  width: min(78vw, 46vh, 24rem);
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}
.nucleo:focus-visible { outline: 2px solid var(--ciano); outline-offset: 6px; }
.nucleo canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.anello {
  position: absolute;
  border-radius: 50%;
  border: 1px solid transparent;
  animation: giro linear infinite;
}
.anello.a { inset: 4%;  border-top-color: var(--ciano); border-bottom-color: var(--tenue); animation-duration: 18s; }
.anello.b { inset: 13%; border-left-color: var(--blu); border-right-color: var(--tenue); animation-duration: 11s; animation-direction: reverse; }
.anello.c { inset: 22%; border: 1px dashed var(--tenue); animation-duration: 40s; }
.cuore {
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #eaffff 0%, var(--ciano) 22%, rgba(31, 139, 255, 0.55) 55%, transparent 72%);
  box-shadow: 0 0 60px 8px rgba(63, 232, 255, 0.35), inset 0 0 30px rgba(255, 255, 255, 0.35);
  animation: respiro 4.5s ease-in-out infinite;
}
.nucleo[data-stato="ascolto"] .cuore { animation-duration: 1.1s; box-shadow: 0 0 90px 18px rgba(63, 232, 255, 0.6), inset 0 0 30px #fff; }
.nucleo[data-stato="pensiero"] .anello.a { animation-duration: 2.2s; }
.nucleo[data-stato="pensiero"] .anello.b { animation-duration: 1.4s; }
.nucleo[data-stato="pensiero"] .cuore { filter: hue-rotate(-28deg); animation-duration: 0.9s; }
.nucleo[data-stato="errore"] .cuore { background: radial-gradient(circle, #fff 0%, var(--allarme) 30%, transparent 70%); box-shadow: 0 0 60px 8px rgba(255, 93, 115, 0.4); }

@keyframes giro { to { transform: rotate(360deg); } }
@keyframes respiro { 0%, 100% { transform: scale(0.94); opacity: 0.85; } 50% { transform: scale(1.05); opacity: 1; } }

/* --- dialogo --- */
.dialogo { display: grid; gap: 0.75rem; }
.scambio {
  min-height: 4.5rem;
  max-height: 30vh;
  overflow-y: auto;
  padding: 0.85rem 1rem;
  border-left: 2px solid var(--ciano);
  background: linear-gradient(90deg, var(--velo), transparent);
  backdrop-filter: blur(6px);
}
.scambio .domanda { margin: 0 0 0.35rem; font-size: 0.85rem; font-weight: 300; color: rgba(217, 246, 255, 0.6); }
.scambio .risposta { margin: 0; font-size: 1.02rem; line-height: 1.5; max-width: 62ch; white-space: pre-wrap; }
.scambio .risposta.errore { color: var(--allarme); }

.rapide { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.15rem; scrollbar-width: none; }
.rapide::-webkit-scrollbar { display: none; }

button, input { font: inherit; color: inherit; }
.tasto {
  flex: none;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--tenue);
  background: rgba(63, 232, 255, 0.06);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.tasto:hover, .tasto[aria-pressed="true"] { background: rgba(63, 232, 255, 0.2); border-color: var(--ciano); }
.tasto:focus-visible, .campo input:focus-visible { outline: 2px solid var(--ciano); outline-offset: 2px; }
.tasto:disabled { opacity: 0.4; cursor: default; }

.campo { display: flex; gap: 0.5rem; }
.campo input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--tenue);
  background: rgba(2, 10, 18, 0.6);
}
.campo input::placeholder { color: rgba(217, 246, 255, 0.4); }

.opzioni { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; font-size: 0.85rem; }

/* --- pannelli (primo accesso, collegamento telefono) --- */
.pannello {
  align-self: center;
  justify-self: center;
  width: min(100%, 26rem);
  padding: 1.5rem;
  border: 1px solid var(--tenue);
  background: var(--velo);
  backdrop-filter: blur(10px);
  display: grid;
  gap: 0.9rem;
}
.pannello h1 { margin: 0; font-size: 1.25rem; font-weight: 500; }
.pannello p { margin: 0; line-height: 1.5; color: rgba(217, 246, 255, 0.8); max-width: 48ch; }
.qr { background: #fff; padding: 0.75rem; justify-self: center; line-height: 0; }
.qr img { width: min(60vw, 15rem); height: auto; image-rendering: pixelated; }

@media (prefers-reduced-motion: reduce) {
  .anello, .cuore { animation: none; }
}

/* --- finestra per Mac: pannello di vetro sopra la scrivania, trascinabile dall'intestazione --- */
html.trasparente .schermo {
  min-height: 100vh;
  padding: 0.9rem;
  background: rgba(2, 10, 18, 0.62);
  border: 1px solid var(--tenue);
  border-radius: 18px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
html.trasparente .testata { cursor: grab; user-select: none; -webkit-user-select: none; align-items: center; }
html.trasparente .stato { margin-left: auto; }
.chiudi { border: 0; background: none; font-size: 1.3rem; line-height: 1; padding: 0 0.25rem; cursor: pointer; color: rgba(217, 246, 255, 0.7); }
.chiudi:hover { color: var(--allarme); }

/* formato piccolo: solo il nucleo, da tenere in un angolo dello schermo */
.schermo.compatta { padding: 0.45rem 0.55rem 0.6rem; gap: 0; grid-template-rows: auto 1fr; }
.schermo.compatta .dialogo, .schermo.compatta .stato { display: none; }
.schermo.compatta .nome { font-size: 0.68rem; letter-spacing: 0.22em; margin-right: auto; }
.schermo.compatta .testata { cursor: default; }
.schermo.compatta .nucleo { width: min(84vw, 80vh); }
.schermo.compatta .cuore { box-shadow: 0 0 26px 4px rgba(63, 232, 255, 0.35), inset 0 0 14px rgba(255, 255, 255, 0.35); }
