/* Base = modalità lettura (funziona anche senza JavaScript).
   La classe .game su <html> attiva la mappa 3D; .reading torna alla lettura. */
:root {
  --ink: #26314a;
  --paper: #fffdf6;
  --chip: #f3efe2;
  --active: #ffd43b;
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(#8fd6f5, #b9ecc0) fixed;
}

body { margin: 0; min-height: 100vh; }

canvas { position: fixed; inset: 0; display: none; }
#world { z-index: 0; touch-action: none; }
#sky { z-index: 30; pointer-events: none; }
.game canvas { display: block; }
.game body { overflow: hidden; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* Caricamento */
.loading { display: none; }
.js:not(.ready) .loading {
  display: grid; place-items: center; position: fixed; inset: 0; z-index: 50;
  font-weight: 900; font-size: 1.4rem; color: #fff;
  text-shadow: 0 3px 0 var(--ink);
}
.js:not(.ready) .topbar, .js:not(.ready) main { visibility: hidden; }

/* Barra in alto */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  padding: 12px 16px;
}
.game .topbar { position: fixed; left: 0; right: 0; }

.brand {
  margin: 0; font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 900; letter-spacing: .02em;
  color: #fff;
  text-shadow: 0 4px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink),
    2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink);
}

nav {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 2px 2px 6px; margin: -2px 0 -6px;
}
nav::-webkit-scrollbar { display: none; }

nav a, #read-toggle, .close {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; min-height: 40px;
  border: 3px solid var(--ink); border-radius: 12px;
  background: var(--paper); color: var(--ink);
  font: 800 .95rem var(--font); text-decoration: none;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer; transition: transform .08s, box-shadow .08s;
}
nav a:active, #read-toggle:active, .close:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
nav a[aria-current] { background: var(--active); }
#read-toggle { display: none; margin-left: auto; }
.game #read-toggle { display: inline-flex; }
#read-toggle[aria-pressed="true"] { background: var(--active); }

:focus-visible { outline: 3px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 6px var(--ink); }

/* Schede */
main {
  position: relative; z-index: 10;
  display: grid; gap: 22px;
  max-width: 720px; margin: 16px auto 0; padding: 0 16px 32px;
}

.card {
  background: var(--paper);
  border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: 0 6px 0 var(--ink);
  padding: 0 20px 18px;
}
.card > header {
  display: flex; align-items: center; gap: 10px;
  margin: 0 -20px 14px; padding: 10px 14px 10px 20px;
  background: var(--zone); border-bottom: 3px solid var(--ink); border-radius: 15px 15px 0 0;
}
.card h2 { margin: 0; font-size: 1.3rem; font-weight: 900; line-height: 1.15; }
.badge { font-size: 1.6rem; line-height: 1; }
.card p { margin: 0 0 12px; line-height: 1.55; }
.card a { color: inherit; font-weight: 800; }

.close { display: none; margin-left: auto; padding: 4px 10px; min-height: 36px; font-size: .9rem; }

.facts {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  list-style: none; padding: 0; margin: 14px 0 0;
}
.facts li {
  background: var(--chip); border: 2px solid var(--ink); border-radius: 12px;
  padding: 8px 6px; text-align: center; font-size: .78rem; font-weight: 700; line-height: 1.2;
}
.facts b { display: block; font-size: 1.2rem; font-weight: 900; }
.contact { margin: 14px 0 0 !important; font-size: .95rem; }

.site-footer {
  text-align: center; font-size: .9rem; font-weight: 700; line-height: 1.5;
  padding: 8px 12px 16px;
}
.site-footer p { margin: 0 0 6px; }
.site-footer a { color: inherit; }

/* Suggerimento comandi */
.hint { display: none; }
.hint .touch { display: none; }
@media (pointer: coarse) {
  .hint .keys { display: none; }
  .hint .touch { display: inline; }
}
.game:not(.reading) .hint:not(.gone) {
  display: block; position: fixed; z-index: 15; left: 16px; bottom: 16px; margin: 0;
  padding: 8px 14px; border: 3px solid var(--ink); border-radius: 12px;
  background: var(--paper); box-shadow: 0 4px 0 var(--ink);
  font-weight: 800; font-size: .9rem;
}

/* Modalità gioco: una scheda alla volta */
.game main {
  position: fixed; margin: 0; padding: 0;
  top: 84px; right: 16px; width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 110px);
  display: block;
}
.game .card { display: none; max-height: inherit; overflow-y: auto; }
.game .card.active { display: block; animation: pop .35s cubic-bezier(.3, 1.5, .5, 1); }
.game .close { display: inline-flex; }
.game:not(.reading) .site-footer { display: none; }

@keyframes pop {
  from { transform: translateY(16px) scale(.92); opacity: 0; }
}

/* Modalità lettura sopra la mappa */
.game.reading main {
  inset: 0; width: auto; max-height: none; overflow-y: auto;
  display: grid; grid-template-columns: min(720px, 100%); justify-content: center; gap: 22px;
  padding: 130px 16px 32px;
  background: rgba(143, 214, 245, .6); backdrop-filter: blur(6px);
}
.game.reading .card { display: block; max-height: none; overflow: visible; animation: none; }
.game.reading .close, .game.reading #sky { display: none; }

@media (max-width: 899px) {
  .topbar { padding: 10px 12px; }
  nav { order: 3; width: 100%; }
  .game main {
    top: auto; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto; max-height: 44vh;
  }
  .game .card { font-size: .95rem; }
  .game:not(.reading) .hint:not(.gone) { top: 118px; bottom: auto; left: 12px; }
  .game.reading main { padding-top: 124px; }
}

@media (max-width: 340px) {
  .facts { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
