/* --------------------------------------------------------------------
   Asteroids - foglio di stile
   I colori arrivano dal tema attivo tramite variabili CSS (vedi themes.js).
   -------------------------------------------------------------------- */

:root {
  --bg: #000;
  --fg: #fff;
  --dim: rgba(255, 255, 255, 0.55);
  --accent: #fff;
  --accent-2: #fff;
  --panel: rgba(0, 0, 0, 0.82);
  --border: rgba(255, 255, 255, 0.55);
  --glow: 0 0 6px rgba(255, 255, 255, 0.45);
  --btn-bg: rgba(255, 255, 255, 0.06);
  --btn-bg-active: rgba(255, 255, 255, 0.28);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font: ui-monospace, "SF Mono", "Menlo", "Consolas", "DejaVu Sans Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  /* Niente zoom, selezione o scroll elastico: e' un gioco, non una pagina. */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ------------------------------ Barra alta ------------------------- */

#topbar {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  right: calc(var(--safe-right) + 12px);
  display: flex;
  gap: 8px;
  z-index: 20;
}

.chip {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--fg);
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0.55;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.chip:hover, .chip:focus-visible { opacity: 1; outline: none; box-shadow: var(--glow); }
.chip:active { background: var(--btn-bg-active); }

/* Icone disegnate in CSS: niente immagini da caricare. */
.icon-pause {
  width: 12px; height: 14px;
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor;
}
body.is-paused .icon-pause {
  width: 0; height: 0;
  border: 8px solid transparent;
  border-left: 13px solid currentColor;
  border-right: 0;
  transform: translateX(2px);
}
.icon-theme {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: linear-gradient(90deg, currentColor 0 50%, transparent 50% 100%);
}
.icon-sound {
  width: 16px; height: 16px;
  position: relative;
}
.icon-sound::before {
  content: "";
  position: absolute; left: 0; top: 4px;
  width: 6px; height: 8px;
  background: currentColor;
  clip-path: polygon(0 0, 55% 0, 100% -35%, 100% 135%, 55% 100%, 0 100%);
}
.icon-sound::after {
  content: "";
  position: absolute; left: 8px; top: 3px;
  width: 7px; height: 10px;
  border-right: 2px solid currentColor;
  border-radius: 0 50% 50% 0 / 0 50% 50% 0;
}
body.is-muted .icon-sound::after {
  border: none;
  left: 7px; top: 3px;
  width: 10px; height: 10px;
  background:
    linear-gradient(45deg, transparent 44%, currentColor 44% 56%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, currentColor 44% 56%, transparent 56%);
}

/* --------------------------- Comandi touch ------------------------- */

#touch {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: none;
  pointer-events: none;
}
body.touch-visible #touch { display: block; }
body.menu-open #touch { display: none; }

/* Meta' sinistra dello schermo: area del joystick fluttuante. */
.stick-zone {
  position: absolute;
  left: 0;
  top: 84px;
  width: 50%;
  bottom: 0;
  pointer-events: auto;
  touch-action: none;
}

.stick {
  --stick-size: 148px;
  position: absolute;
  width: var(--stick-size);
  height: var(--stick-size);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.stick[hidden] { display: none; }

.stick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--btn-bg);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0.8;
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44%;
  height: 44%;
  margin: -22% 0 0 -22%;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--btn-bg-active);
  box-shadow: var(--glow);
  will-change: transform;
}

/* Suggerimento mostrato finche' il joystick non viene usato la prima volta. */
.stick-hint {
  position: absolute;
  left: 50%;
  bottom: 20%;
  width: 128px;
  height: 128px;
  margin: 0 0 -64px -64px;
  border-radius: 50%;
  border: 1.5px dashed var(--border);
  display: grid;
  place-items: center;
  opacity: 0.4;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  pointer-events: none;
  animation: breathe 2.6s ease-in-out infinite;
}
.stick-hint.is-used { display: none; }
.stick-hint span { max-width: 80px; line-height: 1.4; }

@keyframes breathe {
  0%, 100% { opacity: 0.22; transform: scale(0.96); }
  50% { opacity: 0.5; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .stick-hint { animation: none; opacity: 0.35; }
}

/* Pulsanti a destra: fuoco e iperspazio. */
.pad {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 14px);
  display: grid;
  gap: 10px;
  pointer-events: none;
}
.pad-right {
  right: calc(var(--safe-right) + 14px);
  justify-items: end;
  grid-template-areas:
    "hyper"
    "fire";
}

.tbtn {
  pointer-events: auto;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--border);
  background: var(--btn-bg);
  color: var(--fg);
  border-radius: 50%;
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: 0.08em;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0.72;
  transition: background 0.08s linear, transform 0.08s ease;
  touch-action: none;
}
.tbtn.is-pressed {
  background: var(--btn-bg-active);
  transform: scale(0.94);
  opacity: 1;
  box-shadow: var(--glow);
}
.tbtn .label { font-size: 13px; }

.tbtn-fire { grid-area: fire; width: 104px; height: 104px; }
.tbtn-hyper {
  grid-area: hyper;
  width: 104px; height: 50px;
  border-radius: 26px;
  font-size: 12px;
}

/* Schermi molto bassi (telefono in orizzontale): comandi piu' compatti. */
@media (max-height: 460px) {
  .stick { --stick-size: 116px; }
  .stick-hint { width: 100px; height: 100px; margin-bottom: -50px; margin-left: -50px; }
  .stick-zone { top: 64px; }
  .tbtn-fire { width: 86px; height: 86px; }
  .tbtn-hyper { width: 86px; height: 42px; }
}

/* ------------------------- Avviso in sovrimpressione --------------- */

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 22px);
  transform: translate(-50%, 12px);
  z-index: 40;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--fg);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  box-shadow: var(--glow);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
#toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: opacity 0.25s ease; }
}

/* ------------------------------ Schermate -------------------------- */

#overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px)
           calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px);
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.9));
}
body.menu-open #overlay { display: grid; }

.screen {
  width: min(620px, 100%);
  margin: auto;
  padding: 26px 22px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--glow);
  animation: pop 0.22s ease-out;
}
.screen[hidden] { display: none; }

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
}

.title {
  margin: 0 0 6px;
  font-size: clamp(34px, 11vw, 62px);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--fg);
  text-shadow: var(--glow);
}
.title.small { font-size: clamp(26px, 7vw, 40px); }
[data-theme="synthwave"] .title {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 22px rgba(255, 47, 185, 0.45);
}
/* Tema d'atmosfera: fosforo ambrato e un'interfaccia che ha visto di
   meglio. Il titolo sfarfalla appena, come un tubo che sta cedendo. */
[data-theme="dread"] .title {
  color: var(--accent);
  text-shadow: 0 0 10px rgba(255, 176, 0, 0.35), 1px 0 0 rgba(224, 59, 47, 0.35),
    -1px 0 0 rgba(143, 227, 106, 0.25);
  animation: dread-flicker 6s steps(1) infinite;
}
[data-theme="dread"] .screen {
  border-style: solid;
  box-shadow: var(--glow), inset 0 0 60px rgba(0, 0, 0, 0.65);
}
[data-theme="dread"] .opt-val,
[data-theme="dread"] .help h2 {
  text-shadow: 0 0 6px rgba(255, 176, 0, 0.4);
}

@keyframes dread-flicker {
  0%, 34%, 36%, 61%, 63%, 100% { opacity: 1; }
  35%, 62% { opacity: 0.55; }
  62.5% { opacity: 0.85; }
}
@media (prefers-reduced-motion: reduce) {
  [data-theme="dread"] .title { animation: none; }
}

[data-theme="halo"] .title {
  background: linear-gradient(180deg, #eaf7ff 0%, #7fd4ff 55%, #3f8fbe 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 24px rgba(127, 212, 255, 0.4);
}

.tagline {
  margin: 0 0 20px;
  color: var(--dim);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 15px 18px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--btn-bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn:hover, .btn:focus-visible { background: var(--btn-bg-active); outline: none; box-shadow: var(--glow); }
.btn:active { transform: scale(0.985); }
.btn-primary { border-color: var(--accent); color: var(--accent); }
.btn-ghost { opacity: 0.7; font-size: 14px; padding: 11px 16px; }

.options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin: 16px 0;
}
.opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  font-family: var(--font);
  font-size: 12px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  cursor: pointer;
}
.opt:hover, .opt:focus-visible { background: var(--btn-bg); outline: none; }
.opt-key { color: var(--dim); }
.opt-val { color: var(--accent); font-weight: 700; }

.help {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 14px;
  margin: 18px 0 10px;
  text-align: left;
}
.help h2 {
  margin: 0 0 7px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}
.help ul { margin: 0; padding: 0; list-style: none; }
.help li {
  font-size: 12px;
  line-height: 1.75;
  color: var(--dim);
}
.help b { color: var(--fg); font-weight: 700; }

/* Stato del controller: acceso solo quando il browser lo vede davvero. */
.pad-status {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  color: var(--dim);
  opacity: 0.8;
}
.pad-status.is-on {
  color: var(--accent);
  opacity: 1;
}

.hint {
  margin: 0 0 4px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--dim);
  text-align: left;
  opacity: 0.85;
}

.record, .final, .credits, .newrecord {
  margin: 8px 0 0;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--dim);
  text-transform: uppercase;
}
.final { font-size: 20px; color: var(--fg); }
.final span, .record span { color: var(--accent); font-weight: 700; }
.newrecord { color: var(--accent-2); font-weight: 700; }
.newrecord[hidden] { display: none; }
.credits { margin-top: 16px; font-size: 11px; opacity: 0.55; text-transform: none; }

/* ------------------------- Versione e novita' ---------------------- */

.version {
  margin: 10px 0 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--dim);
  text-transform: uppercase;
}

/* Pulsante che si comporta come un collegamento: la versione e' anche
   la porta d'accesso alle note di rilascio. */
.linklike {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--dim);
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}
.linklike:hover,
.linklike:focus-visible {
  color: var(--accent);
  outline: none;
  background: var(--btn-bg);
}
.linklike .sep { margin: 0 8px; opacity: 0.6; }

/* Pallino acceso finche' le novita' di questa versione non sono lette. */
.news-dot {
  width: 6px;
  height: 6px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: var(--glow);
}
.news-dot[hidden] { display: none; }

.notes {
  margin: 4px 0 18px;
  max-height: min(46vh, 380px);
  overflow-y: auto;
  touch-action: pan-y;
  text-align: left;
}
.release + .release {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.release h2 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg);
}
.release h2 b { color: var(--accent); }
.release-date {
  margin: 2px 0 10px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}
.release ul { margin: 0; padding-left: 18px; }
.release li {
  margin-bottom: 7px;
  font-size: 12px;
  line-height: 1.65;
  color: var(--dim);
}


/* Viewport basse (telefono in orizzontale): schermate compatte. */
@media (max-height: 560px) {
  .screen { padding: 16px 18px; border-radius: 12px; }
  .title { font-size: clamp(24px, 6vh, 38px); letter-spacing: 0.16em; }
  .title.small { font-size: clamp(20px, 5.5vh, 30px); }
  .tagline { margin-bottom: 12px; font-size: 11px; }
  .btn { margin: 6px 0; padding: 11px 16px; font-size: 15px; }
  .options { margin: 10px 0; gap: 6px; }
  .opt { padding: 8px 11px; }
  .help { display: none; }
  .hint { display: none; }
  .credits { display: none; }
  .notes { max-height: 40vh; }
}
