html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #050818;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
}

canvas {
  position: fixed;
  left: 0;
  top: 0;
  display: block;
  touch-action: none;
}

#start {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2vh;
  cursor: pointer;
  touch-action: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(5, 8, 24, 0.15), rgba(5, 8, 24, 0.72));
  transition: opacity 0.9s ease, visibility 0.9s;
}

#start.gone {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#start .title {
  font-size: min(22vw, 30vh);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  background: linear-gradient(100deg, #7dffb0, #5fe3ff 35%, #b48cff 65%, #ff8fd0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 28px rgba(120, 255, 200, 0.45));
  animation: breathe 3.2s ease-in-out infinite;
}

#start .sub {
  font-size: min(4.2vw, 5.5vh);
  font-weight: 600;
  color: #eaf6ff;
  text-shadow: 0 0 18px rgba(130, 220, 255, 0.8);
  animation: nudge 1.6s ease-in-out infinite;
  text-align: center;
  padding: 0 4vw;
}

@keyframes breathe {
  50% { transform: scale(1.04); filter: drop-shadow(0 0 44px rgba(190, 140, 255, 0.6)); }
}

@keyframes nudge {
  50% { transform: translateY(-0.8vh); opacity: 0.75; }
}

#backstage {
  position: fixed;
  left: 50%;
  bottom: 28%;
  transform: translateX(-50%);
  margin: 0;
  padding: 14px 18px;
  max-width: 94vw;
  box-sizing: border-box;
  overflow: hidden;
  font: 12px/1.55 ui-monospace, "SF Mono", Menlo, monospace;
  color: #d8f3ff;
  background: rgba(4, 8, 22, 0.72);
  border: 1px solid rgba(140, 220, 255, 0.35);
  border-radius: 12px;
  pointer-events: none;
  white-space: pre;
}

/* --- guida per i grandi ---------------------------------------------------- */

#help {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.6em;
  height: 40px;
  min-width: 40px;
  margin: 0;
  padding: 0 4px;
  border: 0;
  background: none;
  color: #eaf6ff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.25s ease;
  touch-action: manipulation;
}

#help .mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid rgba(215, 240, 255, 0.75);
  background: rgba(8, 14, 40, 0.5);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
}

#help .label { display: none; text-shadow: 0 0 14px rgba(130, 220, 255, 0.7); }
#help:hover, #help:focus-visible { opacity: 1; }
#help:focus-visible { outline: none; }
#help:focus-visible .mark { box-shadow: 0 0 0 3px rgba(125, 255, 176, 0.7); }

/* Prima di cominciare (quando chi legge è un adulto) l'ingresso è in chiaro. */
#start:not(.gone) ~ #help { opacity: 0.95; padding-left: 12px; }
#start:not(.gone) ~ #help .label { display: inline; }

#mode {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 0.45em;
  height: 40px;
  margin: 0;
  padding: 0 12px 0 5px;
  border: 0;
  border-radius: 999px;
  background: rgba(8, 14, 40, 0.42);
  color: #eaf6ff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  opacity: 0.82;
  touch-action: manipulation;
}

#mode .mark {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #fff8d0, #ffc24a 58%, #f08a2a);
  box-shadow: 0 0 12px rgba(255, 190, 70, 0.55);
}

#mode .label { text-shadow: 0 0 14px rgba(130, 220, 255, 0.7); }
#mode:hover, #mode:focus-visible { opacity: 1; }
#mode:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(125, 255, 176, 0.7); }
#mode:active { transform: scale(0.96); }
#mode[aria-pressed="true"] { opacity: 1; background: rgba(180, 200, 255, 0.16); }
#mode[aria-pressed="true"] .mark {
  background: radial-gradient(circle at 38% 32%, #fffdf6, #d7e2ff 46%, #9aa6d4);
  box-shadow: 0 0 12px rgba(190, 210, 255, 0.45);
}
#start:not(.gone) ~ #mode { opacity: 1; }

#guide {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: #eaf6ff;
  overflow: hidden;
  /* Testo lungo: un carattere normale si legge meglio di quello tondo e grasso dei titoli. */
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(14.5px, 0.3vw + 0.55vh + 6.5px, 19px);
  font-weight: 400;
  line-height: 1.45;
  -webkit-user-select: text;
  user-select: text;
}

#guide[open] {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: guide-in 0.22s ease-out;
}

#guide::backdrop {
  background: rgba(3, 6, 20, 0.62);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

@keyframes guide-in {
  from { opacity: 0; transform: translateY(1.2vh) scale(0.985); }
}

#guide .panel {
  display: flex;
  flex-direction: column;
  width: min(100em, 94vw);
  max-height: min(92vh, 92dvh);
  box-sizing: border-box;
  border-radius: 1.4em;
  border: 1px solid rgba(140, 220, 255, 0.35);
  background: linear-gradient(165deg, rgba(22, 30, 78, 0.97), rgba(8, 12, 36, 0.98) 70%);
  box-shadow: 0 0 70px rgba(120, 255, 200, 0.16), 0 24px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

#guide header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  padding: 0.8em 1.1em 0.7em 1.5em;
  border-bottom: 1px solid rgba(140, 220, 255, 0.18);
}

#guide h2 {
  margin: 0;
  font-size: 1.6em;
  font-weight: 800;
  line-height: 1.15;
  width: fit-content;
  background: linear-gradient(100deg, #7dffb0, #5fe3ff 35%, #b48cff 65%, #ff8fd0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#guide header p { margin: 0.15em 0 0; color: #b9cdf0; }
#guide header > div:first-child { min-width: 10em; flex: 1 1 12em; }

#guide .langs {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35em;
  margin-left: auto;
}

#guide .langs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.82em;
  font-weight: 700;
  line-height: 1.2;
  min-height: 36px;
  padding: 0.4em 0.75em;
  border-radius: 999px;
  border: 1px solid rgba(215, 240, 255, 0.4);
  background: rgba(255, 255, 255, 0.06);
  color: #d7e6ff;
  cursor: pointer;
  touch-action: manipulation;
}

#guide .langs button[aria-pressed="true"] {
  color: #062016;
  background: linear-gradient(180deg, #d8ffe9, #7dffb0);
  border-color: transparent;
}

#guide .langs button:hover { background: rgba(255, 255, 255, 0.14); }
#guide .langs button[aria-pressed="true"]:hover { background: linear-gradient(180deg, #d8ffe9, #7dffb0); }
#guide .langs button:focus-visible { outline: 3px solid rgba(125, 255, 176, 0.8); outline-offset: 2px; }

#guide-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.75em;
  height: 2.75em;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(215, 240, 255, 0.55);
  background: rgba(255, 255, 255, 0.07);
  color: #eaf6ff;
  cursor: pointer;
  touch-action: manipulation;
}

#guide-close svg { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
#guide-close:hover { background: rgba(255, 255, 255, 0.16); }
#guide-close:focus-visible { outline: 3px solid rgba(125, 255, 176, 0.8); outline-offset: 2px; }

/* Il fondo sfuma: si capisce che sotto c'è altro da leggere. */
#guide .body {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 1em 1.5em 2.6em;
  outline: none;
  scrollbar-color: rgba(160, 220, 255, 0.4) transparent;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 2.2em), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 2.2em), transparent);
}

#guide .lead { margin: 0 0 1em; color: #d5e6ff; }

#guide .cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22em, 1fr));
  grid-auto-flow: dense;
  gap: 0.9em;
}

#guide .card {
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  min-width: 0;
  overflow-wrap: break-word;
  padding: 1em;
  border-radius: 1.1em;
  border: 1px solid rgba(160, 220, 255, 0.16);
  background: rgba(255, 255, 255, 0.055);
}

#guide .card.wide { grid-column: span 2; }

#guide h2, #guide h3 { font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif; }
#guide h3 { margin: 0 0 0.2em; font-size: 1.2em; font-weight: 800; color: #9ff5d0; line-height: 1.2; }
#guide p { margin: 0; }
#guide ul { margin: 0; padding: 0; list-style: none; }
#guide b { color: #ffffff; font-weight: 700; }

#guide .tech {
  margin-top: auto;
  font-size: max(12px, 0.84em);
  color: #9fb4de;
  padding-top: 0.6em;
  border-top: 1px dashed rgba(160, 220, 255, 0.2);
}

#guide canvas {
  position: static;
  display: block;
  flex: none;
  touch-action: pan-y;
  border-radius: 0.9em;
  background: radial-gradient(circle at 50% 38%, #1f2f72, #0a1030 78%);
}

#guide .pic { width: 5.4em; height: 5.4em; }
#guide .head { display: flex; gap: 0.9em; align-items: flex-start; }

#guide .states { display: grid; gap: 0.5em; }
#guide .states li { display: flex; gap: 0.75em; align-items: center; }
#guide .states canvas { width: 3.5em; height: 3.5em; border-radius: 0.7em; }

#guide .split { display: flex; gap: 1.2em; align-items: center; }

#guide .compass {
  flex: none;
  display: grid;
  grid-template: "n n n" auto "w c e" auto "s s s" auto / minmax(5.2em, 7.2em) auto minmax(5.2em, 7.2em);
  align-items: center;
  justify-items: center;
  gap: 0.4em 0.5em;
  font-size: 0.9em;
  font-weight: 600;
  line-height: 1.25;
  color: #cfe3ff;
  text-align: center;
}

#guide .compass .pic { grid-area: c; width: 6.4em; height: 6.4em; }
#guide .compass .n { grid-area: n; }
#guide .compass .s { grid-area: s; }
#guide .compass .w { grid-area: w; }
#guide .compass .e { grid-area: e; }
#guide .compass .n::before { content: "↑ "; }
#guide .compass .s::before { content: "↓ "; }
#guide .compass .w::before { content: "← "; }
#guide .compass .e::after { content: " →"; }
#guide .compass span::before, #guide .compass span::after { color: #7dffb0; font-weight: 800; }

#guide .points { margin-top: 0.5em; padding-left: 1.1em; list-style: disc; }
#guide .points li + li { margin-top: 0.3em; }
#guide .points li::marker { color: #7dffb0; }

#guide .keys { width: 100%; max-width: 44em; align-self: center; }
#guide .keys .strip { width: 100%; height: 5em; }
#guide .keys .caps { display: grid; grid-template-columns: repeat(15, 1fr); margin-top: 0.4em; justify-items: center; }
#guide .keys .caps kbd { min-width: 0; width: 1.6em; padding: 0; font-size: 0.82em; }

#guide kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.75em;
  height: 1.75em;
  padding: 0 0.3em;
  box-sizing: border-box;
  border-radius: 0.4em;
  border: 1px solid rgba(215, 240, 255, 0.5);
  border-bottom-width: 3px;
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
  font: inherit;
  font-size: 0.9em;
  font-weight: 700;
  line-height: 1;
}

#guide kbd.long { padding: 0 0.6em; }
#guide dd kbd { height: 1.5em; }

#guide .shortcuts { display: grid; gap: 0.6em; margin: 0; }
#guide .shortcuts > div { display: grid; grid-template-columns: max-content 1fr; gap: 0.7em; align-items: start; }
#guide dt { display: flex; flex-wrap: wrap; gap: 0.25em; }
#guide dd { margin: 0; }

/* Schermi stretti: una colonna sola. */
@media (max-width: 800px) {
  #guide .cards { grid-template-columns: minmax(0, 1fr); }
  #guide .card.wide { grid-column: auto; }
  #guide .split { flex-direction: column; }
  #guide .body { padding-left: 1em; padding-right: 1em; }
  #guide .langs { margin-left: 0; }
}

/* Il titolo d'ingresso non deve coprire tutta la larghezza del telefono. */
@media (max-width: 520px) {
  #start .title { font-size: min(16vw, 11vh); }
}
@media (max-height: 520px) {
  #start .title { font-size: min(12vw, 20vh); }
}

/* Sul telefono le scritte dei due pulsanti si coprono. Restano i cerchi. */
@media (max-width: 820px), (max-height: 520px) {
  #help .label,
  #start:not(.gone) ~ #help .label,
  #mode .label { display: none; }
  #mode, #help, #start:not(.gone) ~ #help {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }
  #help .mark, #mode .mark { width: 36px; height: 36px; }
}
