:root {
  --fondo: #000;
  --fondo-2: #0a1422;
  --linea: #13304a;
  --ciano: #4fd8ff;
  --ciano-tenue: #4fd8ff33;
  --oro: #ffb547;
  --rosso: #ff5f6d;
  --verde: #4dffa6;
  --testo: #d8ecf7;
  --testo-tenue: #7c98ad;
  --carattere: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* la scena in movimento (spazio.js) sta dietro a tutto */
#spazio { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.accesso, .hud { position: relative; z-index: 1; }

html, body { height: 100%; }
body {
  margin: 0;
  background: #000;
  color: var(--testo);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ─── accesso ─────────────────────────────────────────── */
.accesso { height: 100%; display: grid; place-items: center; padding: 16px; }
.pannello {
  width: min(360px, 100%); padding: 32px 24px; display: grid; gap: 14px; justify-items: center;
  background: #0a1422bb; backdrop-filter: blur(8px); border: 1px solid var(--linea); border-radius: 16px;
}
.pannello h1 { margin: 0; font: 600 20px var(--carattere); letter-spacing: .35em; color: var(--ciano); }
.pannello input, .pannello button { width: 100%; }
input[type=password], input[type=text] {
  background: var(--fondo-2); border: 1px solid var(--linea); border-radius: 10px; padding: 11px 14px; outline: none;
}
input:focus { border-color: var(--ciano); box-shadow: 0 0 0 3px var(--ciano-tenue); }
button:not(.icona):not(.secondario):not(.reattore) {
  background: var(--ciano); color: #031018; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600;
}
.secondario { background: transparent; border: 1px solid var(--linea); border-radius: 10px; padding: 9px 14px; }
.secondario:hover { border-color: var(--ciano); }
.errore { color: var(--rosso); min-height: 1.5em; margin: 0; font-size: 13px; }

/* ─── HUD ─────────────────────────────────────────────── */
.hud {
  height: 100%; display: grid; grid-template-rows: auto auto 1fr auto auto;
  max-width: 880px; margin: 0 auto; padding: 0 16px max(12px, env(safe-area-inset-bottom));
}
.barra { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 4px; }
.marchio { font: 600 14px var(--carattere); letter-spacing: .4em; color: var(--ciano); text-shadow: 0 0 12px var(--ciano-tenue); }
.ora { font: 13px var(--carattere); color: var(--testo-tenue); }
.icona { background: transparent; border: 1px solid var(--linea); border-radius: 50%; width: 40px; height: 40px; flex: none; }
.icona:hover { border-color: var(--ciano); }

.centro { display: grid; justify-items: center; padding: 8px 0 4px; }
.costellazione { position: relative; width: 100%; height: 300px; display: grid; place-items: center; }
/* Le etichette degli agenti: la posizione in orbita la calcola spazio.js. */
.nodo {
  position: absolute; left: 0; top: 0; transform-origin: 50% 0;
  display: grid; justify-items: center; font: 11px var(--carattere); color: var(--testo-tenue);
  text-shadow: 0 0 6px #04080f, 0 0 2px #04080f; pointer-events: none; will-change: transform;
  transition: color .3s;
}
.nodo b { font-weight: 500; letter-spacing: .12em; text-transform: uppercase; }
.nodo small { font-size: 10px; color: var(--ciano); opacity: .85; max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nodo.attivo { color: #e9fbff; text-shadow: 0 0 10px var(--ciano), 0 0 2px #04080f; }

/* il reattore */
.reattore {
  position: relative; width: 132px; height: 132px; border-radius: 50%; border: 0; padding: 0;
  background: radial-gradient(circle, #e9fbff 0 9%, #7fe6ff 14%, #1b6f95 30%, #08263a 52%, transparent 70%);
  box-shadow: 0 0 40px #4fd8ff55, inset 0 0 30px #4fd8ff44;
  transform: scale(var(--scala, 1));
  transition: box-shadow .3s;
  z-index: 2;
}
.reattore span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid transparent; }
.reattore span:nth-child(1) { inset: 6px; border-top-color: var(--ciano); border-bottom-color: var(--ciano); animation: gira 6s linear infinite; }
.reattore span:nth-child(2) { inset: 18px; border-left-color: #4fd8ffaa; border-right-color: #4fd8ffaa; animation: gira 9s linear infinite reverse; }
.reattore span:nth-child(3) { inset: -8px; border: 1px dashed #4fd8ff44; animation: gira 30s linear infinite; }
.reattore.piccolo { width: 64px; height: 64px; transform: none; }
@keyframes gira { to { transform: rotate(360deg); } }
@keyframes pulsa { 50% { box-shadow: 0 0 80px #4fd8ffaa, inset 0 0 40px #4fd8ff88; } }
body.pensa .reattore span:nth-child(1) { animation-duration: 1.2s; }
body.pensa .reattore span:nth-child(2) { animation-duration: 1.8s; }
body.ascolta .reattore { box-shadow: 0 0 60px #ffb54788, inset 0 0 30px #ffb54766; }
body.ascolta .reattore span:nth-child(1) { border-top-color: var(--oro); border-bottom-color: var(--oro); }
body.parla .reattore { animation: pulsa .9s ease-in-out infinite; }

.stato { margin: 6px 0 0; font: 12px var(--carattere); letter-spacing: .2em; text-transform: uppercase; color: var(--ciano); }
.ascolto { margin: 2px 0 0; min-height: 1.4em; font-size: 13px; color: var(--oro); text-align: center; }

/* ─── conversazione ───────────────────────────────────── */
.registro { overflow-y: auto; padding: 8px 2px 12px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.voce { max-width: 86%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.voce.utente { align-self: flex-end; background: #13304acc; border-bottom-right-radius: 4px; backdrop-filter: blur(6px); }
.voce.jarvis { align-self: flex-start; background: #0a1625cc; border: 1px solid var(--linea); border-bottom-left-radius: 4px; backdrop-filter: blur(6px); }
.voce.jarvis::before { content: "JARVIS"; display: block; font: 10px var(--carattere); letter-spacing: .25em; color: var(--ciano); margin-bottom: 2px; }
.voce.sistema { align-self: center; font: 11px var(--carattere); color: var(--testo-tenue); padding: 2px; }
.voce.automatico { opacity: .7; font-style: italic; }
.voce a { color: var(--ciano); }
.voce .attivita { display: block; font: 11px var(--carattere); color: var(--testo-tenue); margin-top: 4px; }

.comandi { display: flex; gap: 8px; align-items: center; padding-top: 6px; }
.comandi input { flex: 1; min-width: 0; }
#microfono.attivo { border-color: var(--oro); box-shadow: 0 0 14px #ffb54777; }
.scorciatoie { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 0 4px; }
.scorciatoie button { background: transparent !important; color: var(--testo-tenue) !important; border: 1px solid var(--linea) !important; border-radius: 999px !important; padding: 4px 12px !important; font-size: 12px; font-weight: 400 !important; }
.scorciatoie button:hover { color: var(--ciano) !important; border-color: var(--ciano) !important; }

/* ─── pannello laterale ───────────────────────────────── */
.laterale {
  position: fixed; inset: 0 0 0 auto; width: min(360px, 100%); padding: 16px; overflow-y: auto;
  background: #070e18f2; border-left: 1px solid var(--linea); backdrop-filter: blur(8px); z-index: 5;
  display: flex; flex-direction: column; gap: 10px;
}
.laterale header { display: flex; justify-content: space-between; align-items: center; }
.laterale h2 { font: 600 12px var(--carattere); letter-spacing: .2em; text-transform: uppercase; color: var(--ciano); margin: 12px 0 0; }
.collegamenti { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.collegamenti li { border: 1px solid var(--linea); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; }
.collegamenti b { font-weight: 600; }
.collegamenti small { color: var(--testo-tenue); }
.spia { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--testo-tenue); }
.spia.ok { background: var(--verde); box-shadow: 0 0 8px var(--verde); }
.spia.ko { background: var(--rosso); }
.riga { display: flex; gap: 8px; align-items: center; }
.riga select { flex: 1; min-width: 0; background: var(--fondo-2); border: 1px solid var(--linea); border-radius: 8px; padding: 6px; }
.avviso { border: 1px solid var(--oro); border-radius: 10px; padding: 12px; font-size: 14px; }
.avviso code { font: 600 18px var(--carattere); color: var(--oro); letter-spacing: .1em; }

/* ─── conferma ────────────────────────────────────────── */
.conferma {
  width: min(520px, calc(100% - 32px)); background: var(--fondo-2); color: var(--testo);
  border: 1px solid var(--oro); border-radius: 16px; padding: 20px; box-shadow: 0 0 60px #ffb54733;
}
.conferma::backdrop { background: #000a; }
.conferma h2 { margin: 0 0 10px; font: 600 13px var(--carattere); letter-spacing: .2em; text-transform: uppercase; color: var(--oro); }
.conferma pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 50vh; overflow: auto; font: 13px/1.5 var(--carattere); background: #04080f; padding: 12px; border-radius: 10px; margin: 0; }
.conferma .azioni { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

@media (max-width: 520px) {
  .ora { display: none; }
  .costellazione { height: 250px; }
  .reattore:not(.piccolo) { width: 112px; height: 112px; }
  .voce { max-width: 94%; }
}
@media (max-height: 640px) {
  .costellazione { height: 210px; }
}

/* ─── accensione ──────────────────────────────────────── */
.accensione {
  position: fixed; inset: 0; z-index: 4; display: grid; place-content: center; justify-items: center; gap: 22px;
  background: radial-gradient(circle at 50% 45%, #000a 0%, #000e 60%);
}
.accensione p { margin: 0; font: 12px var(--carattere); letter-spacing: .4em; text-transform: uppercase; color: var(--ciano); opacity: .8; }
.reattore.grande { width: 168px; height: 168px; filter: brightness(.45) saturate(.6); animation: attesa 2.6s ease-in-out infinite; }
.reattore.grande:hover { filter: brightness(.8); }
@keyframes attesa { 50% { filter: brightness(.75) saturate(.9); box-shadow: 0 0 70px #4fd8ff66, inset 0 0 30px #4fd8ff44; } }
.nota { color: var(--testo-tenue); }
#sigla-file { min-width: 0; font-size: 12px; }

/* schermo spento: resta solo lo spazio */
html.spento .hud > *, html.spento .nodo { opacity: 0; }
/* accensione: il reattore si illumina, poi compare il resto, un pezzo alla volta */
html.avvio #reattore { animation: accendi 2.4s cubic-bezier(.2, .8, .2, 1) both; }
html.avvio .hud > * { animation: compari .9s ease-out both; }
html.avvio .hud > .barra { animation-delay: 1.4s; }
html.avvio .hud > .centro { animation-delay: .1s; }
html.avvio .hud > .registro { animation-delay: 1.8s; }
html.avvio .hud > .comandi { animation-delay: 2.1s; }
html.avvio .hud > .scorciatoie { animation-delay: 2.3s; }
@keyframes accendi {
  0% { transform: scale(.2); filter: brightness(.2); }
  55% { transform: scale(1.18); filter: brightness(2); }
  100% { transform: scale(1); filter: none; }
}
@keyframes compari { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  html.avvio #reattore, html.avvio .hud > *, .reattore.grande { animation: none; }
}

.dispositivi { font-size: 13px; color: var(--testo-tenue); }
.dispositivi p { margin: 0 0 8px; }
.dispositivi ul { margin: 0 0 10px; padding-left: 18px; }
.dispositivi a { color: var(--ciano); overflow-wrap: anywhere; }
