/* Font self-hosted (OFL) — funzionano anche offline nella PWA */
@font-face { font-family: "Marcellus SC"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../assets/fonts/marcellus-sc-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Marcellus SC"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../assets/fonts/marcellus-sc-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Outfit"; font-style: normal; font-weight: 400; font-display: swap; src: url("../assets/fonts/outfit-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Outfit"; font-style: normal; font-weight: 500; font-display: swap; src: url("../assets/fonts/outfit-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Outfit"; font-style: normal; font-weight: 600 700; font-display: swap; src: url("../assets/fonts/outfit-latin-600-normal.woff2") format("woff2"); }

:root {
  --ink: #073c49;
  --frame: #188b94;
  --font-display: "Marcellus SC", "Syne", serif;
  --font-ui: "Outfit", "Sora", system-ui, sans-serif;
  --abyss: #06141a;
  --veil: #0d4f5c;
  --glow: #7fe3d2;
  --aurora: #f2c66d;
  --parchment: #f4f1e6;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Utility globale: senza questa regola input/pannelli con class="hidden" restano visibili */
.hidden { display: none !important; }
#save-file-input { display: none !important; }

html, body {
  height: 100%;
  height: 100dvh;
  min-height: 100%;
  min-height: -webkit-fill-available;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(13, 79, 92, 0.55), rgba(6, 20, 26, 0) 70%),
    radial-gradient(ellipse 40% 60% at 85% 100%, rgba(141, 107, 224, 0.16), rgba(6, 20, 26, 0) 70%),
    var(--abyss);
  color: var(--parchment);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* iOS PWA standalone: 100svh a volte collassa — forza altezza utile */
@media (display-mode: standalone) {
  html, body, #app {
    height: 100%;
    height: 100dvh;
    min-height: -webkit-fill-available;
    max-height: none;
  }
}

#app {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem;
  padding-top: max(0.6rem, var(--safe-top));
  padding-bottom: max(0.6rem, var(--safe-bottom));
}

.brand-bar { display: flex; flex-direction: column; align-items: center; gap: 0.12rem; }
.brand-mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.1rem, 3.2vw, 1.5rem);
  letter-spacing: 0.18em;
  font-weight: 400;
  color: #fff1cc;
  text-shadow: 0 0 18px rgba(242, 198, 109, 0.55);
}
.brand-sub {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--aurora);
  font-weight: 500;
}

#screen-wrap {
  position: relative;
  /* Desktop: il più grande 9:16 che entra in altezza */
  width: min(96vw, calc((100dvh - 5.5rem) * 9 / 16));
  border-radius: 6px;
  background: var(--abyss);
  box-shadow:
    0 0 0 1px rgba(242, 198, 109, 0.35),
    0 0 60px rgba(127, 227, 210, 0.12),
    0 30px 80px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

#game-stage { position: relative; width: 100%; line-height: 0; }
#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 9 / 16;
  image-rendering: auto;
  background: #66cbd2;
}
#overlay { position: absolute; inset: 0; pointer-events: none; z-index: 3; }

.name-input {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 18%;
  z-index: 8;
  height: 2.4rem;
  padding: 0.45rem 0.7rem;
  border: 2px solid #e8c547;
  border-radius: 10px;
  background: rgba(8, 20, 24, 0.92);
  color: #f2efe6;
  font-family: var(--font-ui);
  font-size: 1rem;
  text-align: center;
  outline: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.name-input.hidden { display: none; }
.name-input:focus { border-color: #7ec8c4; }

#hud-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  justify-content: center;
  font-size: 0.68rem;
  color: rgba(207, 232, 228, 0.6);
  font-weight: 500;
}
#hud-hint span { padding: 0.16rem 0.48rem; border-radius: 4px; background: rgba(13, 79, 92, 0.35); }

#touch-pad {
  display: none;
  width: min(96vw, 420px);
  height: 118px;
  padding: 0.4rem 0.55rem;
  border-radius: 14px;
  background: rgba(6, 30, 38, 0.46);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  align-items: center;
  justify-content: space-between;
}

.stick {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
}
.stick-btn {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.24);
  pointer-events: auto;
}
.stick-btn::after {
  content: "";
  position: absolute;
  inset: 11px;
  background: rgba(255,255,255,0.9);
  clip-path: polygon(50% 12%, 88% 82%, 12% 82%);
}
/* Frecce ortogonali a schermo: Su = verso l'alto dello schermo (movimento iso diagonale). */
.stick-up { top: 4px; left: 36px; }
.stick-down { bottom: 4px; left: 36px; }
.stick-down::after { transform: rotate(180deg); }
.stick-left { left: 4px; top: 36px; }
.stick-left::after { transform: rotate(-90deg); }
.stick-right { right: 4px; top: 36px; }
.stick-right::after { transform: rotate(90deg); }

.actions { display: flex; align-items: center; gap: 0.55rem; }
.pad-btn.ghost,
.pad-btn.confirm {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.94);
  font-family: var(--font-ui);
  font-weight: 650;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.pad-btn.ghost {
  min-width: 72px;
  height: 44px;
  border-radius: 999px;
  background: rgba(10, 40, 48, 0.45);
  font-size: 0.82rem;
}
.pad-btn.confirm {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(46, 168, 120, 0.58);
  font-size: 0.85rem;
}

.pad-btn,
.stick-btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  transition: transform 0.06s ease-out, filter 0.06s ease-out, box-shadow 0.06s ease-out;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.28);
}

.pad-btn:active,
.stick-btn:active,
.pad-btn.is-pressed,
.stick-btn.is-pressed {
  transform: translateY(2px) scale(0.92);
  filter: brightness(1.18);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0.2), inset 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* Pad upright: movimento già rimappato in DIRS (screen-relative). */
.stick.iso-pad .stick-btn::after {
  transform-origin: center center;
}

.pad-btn.confirm {
  box-shadow: 0 4px 0 rgba(20, 80, 55, 0.55), 0 0 12px rgba(80, 220, 160, 0.25);
}
.pad-btn.confirm.is-pressed,
.pad-btn.confirm:active {
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.35);
}

@media (max-width: 720px), (pointer: coarse) {
  html, body {
    background: var(--abyss);
    height: 100svh;
    max-height: 100svh;
    overflow: hidden;
  }
  #app {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    width: 100vw;
    height: 100svh;
    max-height: 100svh;
    padding: 0;
    padding-top: var(--safe-top);
    gap: 0;
    align-items: stretch;
    justify-items: stretch;
    overflow: hidden;
  }
  .brand-bar, #hud-hint { display: none; }

  #screen-wrap {
    width: 100%;
    min-height: 0;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    background: var(--abyss);
    display: flex;
    align-items: stretch;
    justify-content: center;
    overflow: hidden;
  }
  #game-stage {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--abyss);
    overflow: hidden;
  }
  /* Riempie lo spazio sopra i controlli: niente taglio del bordo basso */
  #game {
    display: block;
    height: 100%;
    width: auto;
    max-width: 100%;
    max-height: 100%;
    /* aspect-ratio impostato da Game.fitViewport() sullo stage reale */
    object-fit: contain;
    background: var(--abyss);
  }

  #touch-pad {
    display: flex;
    width: 100vw;
    flex-shrink: 0;
    height: calc(108px + max(0px, var(--safe-bottom)));
    padding: 0.3rem 1rem;
    padding-bottom: max(0.35rem, var(--safe-bottom));
    border-radius: 0;
    border: 0;
    border-top: 1px solid rgba(242, 198, 109, 0.28);
    background: linear-gradient(180deg, rgba(13, 40, 48, 0.98), var(--abyss));
  }
  .stick { width: 112px; height: 112px; }
  .stick-btn { width: 40px; height: 40px; }
  .stick-up { top: 4px; left: 36px; right: auto; }
  .stick-down { bottom: 4px; left: 36px; top: auto; }
  .stick-left { left: 4px; top: 36px; }
  .stick-right { right: 4px; top: 36px; bottom: auto; left: auto; }
  .pad-btn.ghost { min-width: 64px; height: 48px; font-size: 0.86rem; }
  .pad-btn.confirm { width: 76px; height: 76px; font-size: 1rem; }
}

@media (min-width: 721px) and (pointer: fine) {
  #touch-pad { display: none !important; }
}

#save-import-panel {
  position: fixed;
  left: 50%;
  bottom: max(1rem, var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 40;
  width: min(96vw, 420px);
  padding: 0.85rem;
  border-radius: 14px;
  background: rgba(6, 28, 34, 0.96);
  border: 1px solid rgba(255,255,255,0.16);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}
#save-import-panel.hidden { display: none; }
.save-import-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #e8fff8;
}
#save-code-input {
  width: 100%;
  min-height: 5.5rem;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid rgba(232, 197, 71, 0.55);
  background: rgba(0,0,0,0.45);
  color: #f2efe6;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  padding: 0.55rem;
}
.save-import-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  align-items: center;
}
.save-import-actions .pad-btn.confirm {
  width: auto;
  min-width: 96px;
  height: 44px;
  border-radius: 999px;
  padding: 0 1rem;
}

#pwa-install {
  position: fixed;
  top: max(0.65rem, var(--safe-top));
  right: 0.65rem;
  z-index: 30;
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.78rem;
  color: #073c49;
  background: #ffe16b;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25);
  cursor: pointer;
  transition: transform 0.06s ease-out, box-shadow 0.06s ease-out;
}
#pwa-install.hidden { display: none; }
#pwa-install.is-pressed,
#pwa-install:active {
  transform: translateY(2px) scale(0.96);
  box-shadow: 0 0 0 rgba(0,0,0,0.2);
}

#auth-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  width: min(92vw, 380px);
  padding: 1rem 1rem 0.9rem;
  border-radius: 16px;
  background: rgba(6, 28, 34, 0.97);
  border: 1px solid rgba(255,255,255,0.16);
  box-shadow: 0 18px 50px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
#auth-panel.hidden { display: none; }
.auth-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  color: #ffe16b;
}
.auth-status {
  font-size: 0.78rem;
  line-height: 1.35;
  color: rgba(232, 255, 248, 0.88);
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(200, 240, 230, 0.9);
}
.auth-field input {
  border-radius: 10px;
  border: 1px solid rgba(232, 197, 71, 0.45);
  background: rgba(0,0,0,0.4);
  color: #f2efe6;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  padding: 0.55rem 0.65rem;
}
.auth-age {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 4px 0 2px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: rgba(223, 233, 230, 0.85);
  text-align: left;
  cursor: pointer;
}
.auth-age input {
  width: 20px;
  height: 20px;
  flex: none;
  margin: 1px 0 0;
  accent-color: #e8c547;
}
.auth-error {
  min-height: 1.1rem;
  font-size: 0.75rem;
  color: #ffb4a2;
}
.auth-actions {
  display: flex;
  justify-content: stretch;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.auth-actions.secondary { justify-content: space-between; }
.auth-actions .pad-btn.confirm,
.auth-actions .pad-btn.ghost {
  width: auto;
  flex: 1 1 auto;
  min-width: 96px;
  height: 42px;
  border-radius: 999px;
  padding: 0 0.95rem;
}



/* ── Vetrata Infranta: controlli touch ───────────────────────────── */
.stick {
  background: radial-gradient(circle, rgba(6, 20, 26, 0.2) 50%, rgba(13, 79, 92, 0.45) 100%);
  box-shadow: inset 0 0 0 1px rgba(207, 232, 228, 0.18), 0 0 0 5px rgba(207, 232, 228, 0.04);
}
.stick-btn {
  background: linear-gradient(180deg, rgba(244, 241, 230, 0.22), rgba(207, 232, 228, 0.08));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 6px rgba(0, 0, 0, 0.35);
}
.stick-btn::after { background: rgba(244, 241, 230, 0.92); }
.pad-btn.ghost {
  border: 0;
  border-radius: 0;
  clip-path: polygon(0 9px, 9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%);
  background: linear-gradient(180deg, rgba(18, 58, 66, 0.9), rgba(6, 20, 24, 0.95));
  box-shadow: inset 0 1px 0 rgba(242, 198, 109, 0.55);
  color: var(--parchment);
  letter-spacing: 0.02em;
}
.pad-btn.confirm {
  border: 0;
  border-radius: 0;
  clip-path: polygon(50% 0, 100% 27%, 100% 73%, 50% 100%, 0 73%, 0 27%);
  background: linear-gradient(180deg, #ffe7a8 0%, #f2c66d 45%, #c98a2e 100%);
  color: #2a1a06;
  font-family: var(--font-display);
  font-weight: 400;
  box-shadow: none;
}
.actions .pad-btn.confirm { filter: drop-shadow(0 0 12px rgba(242, 198, 109, 0.45)); }
.pad-btn.confirm.is-pressed,
.pad-btn.confirm:active { box-shadow: none; filter: brightness(1.15) drop-shadow(0 0 18px rgba(242, 198, 109, 0.7)); }
.auth-actions .pad-btn.confirm,
.save-import-actions .pad-btn.confirm {
  clip-path: polygon(0 9px, 9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%);
  border-radius: 0;
}
#auth-panel, #save-import-panel {
  border-radius: 0;
  clip-path: polygon(0 14px, 14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%);
  background: linear-gradient(180deg, rgba(18, 58, 66, 0.97), rgba(6, 20, 26, 0.98));
  border: 0;
  box-shadow: inset 0 1px 0 rgba(242, 198, 109, 0.55);
}
.auth-title { color: var(--aurora); font-weight: 400; }
#pwa-install {
  border-radius: 0;
  clip-path: polygon(0 8px, 8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%);
  background: linear-gradient(180deg, #ffe7a8, #f2c66d 50%, #c98a2e);
  color: #2a1a06;
  box-shadow: none;
}
