/* ─── Self-hosted font (privacy: no request to Google Fonts) ───
   Nunito è un font variabile (asse peso 400–900) rilasciato con licenza
   SIL Open Font License 1.1. I file sono serviti dal nostro dominio, così
   il browser dell'utente non contatta più fonts.googleapis.com /
   fonts.gstatic.com e nessun indirizzo IP viene inviato a Google.
   Vedi assets/fonts/OFL.txt e THIRD_PARTY_NOTICES.md. */
@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 400 900;              /* variable font: copre 400/700/900 usati */
    font-display: swap;
    src: url('../assets/fonts/nunito-latin.woff2') format('woff2');
    /* latin: caratteri base */
    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+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 400 900;
    font-display: swap;
    src: url('../assets/fonts/nunito-latin-ext.woff2') format('woff2');
    /* latin-ext: accentate italiane (à è é ì ò ù ...) */
    unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

body {
    background: #1a1a2e;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    font-family: 'Nunito', 'Fredoka', sans-serif;
}

/* Phone frame - desktop only */
#phone-frame {
    width: 360px;
    height: 720px;
    background: #2d2d2d;
    border-radius: 40px;
    padding: 12px;
    box-shadow:
        0 0 0 3px #1a1a1a,
        0 0 40px rgba(0, 0, 0, 0.5),
        inset 0 0 10px rgba(255, 255, 255, 0.05);
    position: relative;
}

#phone-notch {
    width: 120px;
    height: 24px;
    background: #1a1a1a;
    border-radius: 0 0 16px 16px;
    margin: 0 auto 4px;
}

#game-container {
    width: 100%;
    height: calc(100% - 28px);
    background: #000;
    border-radius: 28px;
    overflow: hidden;
    position: relative;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
    top: 0; left: 0;
    z-index: 2;                 /* 2D canvas on top (HUD/overlays) */
    /* Smooth rendering — no pixel art */
}

/* 3D overworld canvas sits BEHIND the 2D canvas; shown only in overworld3d */
#game-canvas-3d {
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
    top: 0; left: 0;
    z-index: 1;
}

/* Floating joystick for the 3D overworld */
#joy3d-base, #joy3d-thumb {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    display: none;
    z-index: 40;
}
#joy3d-base {
    width: 120px; height: 120px; margin: -60px 0 0 -60px;
    background: rgba(15,15,35,0.45); border: 3px solid rgba(200,210,255,0.6);
}
#joy3d-thumb {
    width: 56px; height: 56px; margin: -28px 0 0 -28px;
    background: rgba(150,180,255,0.92); border: 2px solid rgba(255,255,255,0.9);
}
#exit3d {
    position: absolute;
    top: 10px; right: 10px;
    z-index: 50;
    display: none;
    background: rgba(155,58,213,0.92);
    color: #fff; font-weight: 700; font-size: 13px;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 10px; padding: 8px 12px;
}
#talk3d {
    position: absolute;
    bottom: 96px; left: 50%; transform: translateX(-50%);
    z-index: 50;
    display: none;
    background: rgba(58,123,213,0.95);
    color: #fff; font-weight: 700; font-size: 16px;
    border: 2px solid rgba(255,255,255,0.7);
    border-radius: 14px; padding: 12px 26px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.5);
}
/* Portal enter button — glossy cyan, sits above the talk button so both
   can show at once when you're near an NPC standing by a portal. */
#enter3d {
    position: absolute;
    bottom: 150px; left: 50%; transform: translateX(-50%);
    z-index: 50;
    display: none;
    background: linear-gradient(180deg, rgba(60,220,255,0.96), rgba(30,140,220,0.96));
    color: #06263a; font-weight: 800; font-size: 16px;
    border: 2px solid rgba(255,255,255,0.85);
    border-radius: 14px; padding: 12px 26px;
    box-shadow: 0 3px 16px rgba(60,200,255,0.6), inset 0 1px 0 rgba(255,255,255,0.6);
}

/* Camera view toggle — top-right, just under the Esci button. */
#cam3d {
    position: absolute;
    top: 52px; right: 10px;
    z-index: 50;
    display: none;
    background: rgba(30,40,70,0.9);
    color: #eaf2ff; font-weight: 700; font-size: 13px;
    border: 2px solid rgba(255,255,255,0.45);
    border-radius: 10px; padding: 8px 12px;
}

/* Dialogue box */
#dialogue-box {
    position: absolute;
    bottom: 80px;
    left: 8px;
    right: 8px;
    background: rgba(10, 10, 40, 0.95);
    border: 2px solid #a0a0ff;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    gap: 10px;
    min-height: 80px;
    z-index: 10;
}

#dialogue-portrait {
    width: 56px;
    height: 56px;
    background: #333;
    border: 2px solid #a0a0ff;
    border-radius: 4px;
    flex-shrink: 0;
}

#dialogue-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#dialogue-name {
    color: #ffcc00;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
}

#dialogue-text {
    color: #fff;
    font-size: 12px;
    line-height: 1.4;
}

#dialogue-next {
    color: #a0a0ff;
    font-size: 10px;
    align-self: flex-end;
    animation: blink 0.8s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* D-pad */
#dpad {
    position: absolute;
    bottom: 60px;
    left: 16px;
    width: 100px;
    height: 100px;
    z-index: 20;
}

.dpad-btn {
    position: absolute;
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
}

.dpad-btn:active {
    background: rgba(255, 255, 255, 0.35);
}

#dpad-up { left: 33px; top: 0; }
#dpad-down { left: 33px; bottom: 0; }
#dpad-left { left: 0; top: 33px; }
#dpad-right { right: 0; top: 33px; }

#dpad-center {
    position: absolute;
    left: 33px;
    top: 33px;
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
}

/* Action buttons */
#action-buttons {
    position: absolute;
    bottom: 64px;
    right: 16px;
    z-index: 20;
}

.action-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.action-btn:active {
    background: rgba(255, 255, 255, 0.35);
}

#btn-a {
    position: absolute;
    right: 0;
    bottom: 24px;
}

#btn-b {
    position: absolute;
    right: 36px;
    bottom: 0;
}

/* Menu button */
.menu-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    z-index: 20;
}

/* Menu overlay */
#menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 40, 0.97);
    z-index: 30;
    display: flex;
    flex-direction: column;
    padding: 20px;
    color: #fff;
}

.menu-title {
    color: #ffcc00;
    font-size: 16px;
    text-align: center;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.menu-items {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-item {
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
    border-radius: 6px;
    color: #ccc;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.menu-item:hover,
.menu-item.selected {
    background: rgba(160, 160, 255, 0.15);
    border-color: #a0a0ff;
    color: #fff;
}

.menu-back {
    margin-top: auto;
    padding: 10px;
    text-align: center;
    color: #888;
    font-size: 12px;
    cursor: pointer;
}

.menu-back:hover {
    color: #fff;
}

/* Party member card */
.party-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.party-avatar {
    width: 40px;
    height: 40px;
    background: #333;
    border-radius: 4px;
    border: 1px solid #a0a0ff;
}

.party-info {
    flex: 1;
}

.party-name {
    color: #ffcc00;
    font-size: 12px;
    font-weight: bold;
}

.party-stats {
    color: #aaa;
    font-size: 10px;
    margin-top: 2px;
}

.party-hp-bar {
    width: 100%;
    height: 6px;
    background: #333;
    border-radius: 3px;
    margin-top: 4px;
    overflow: hidden;
}

.party-hp-fill {
    height: 100%;
    background: #4caf50;
    border-radius: 3px;
    transition: width 0.3s;
}

/* Save slots */
.save-slot {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    font-family: inherit;
    color: #ccc;
    font-size: 12px;
    text-align: left;
    width: 100%;
}

.save-slot:hover {
    border-color: #a0a0ff;
    background: rgba(160, 160, 255, 0.1);
}

.save-slot-empty {
    color: #555;
    font-style: italic;
}

/* Inventory item */
.inv-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 12px;
    color: #ccc;
}

.inv-item-name { color: #fff; }
.inv-item-qty { color: #ffcc00; }

/* Debug panel - now Canvas-based, old HTML panel hidden */
#debug-panel {
    display: none !important;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(160, 160, 255, 0.1);
    color: #ffcc00;
    font-size: 14px;
    font-weight: bold;
}

.debug-header button {
    background: none;
    border: none;
    color: #888;
    font-size: 16px;
    cursor: pointer;
}

.debug-body {
    padding: 12px 16px;
}

.debug-row {
    margin-bottom: 14px;
}

.debug-label {
    color: #ccc;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.debug-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.debug-slider-row input[type=range] {
    flex: 1;
    accent-color: #a0a0ff;
    height: 4px;
}

.debug-value {
    color: #ffcc00;
    font-size: 11px;
    min-width: 30px;
    text-align: right;
}

.debug-reset {
    width: 100%;
    margin-top: 16px;
    padding: 8px;
    background: rgba(255, 60, 60, 0.15);
    border: 1px solid rgba(255, 60, 60, 0.3);
    border-radius: 6px;
    color: #f44;
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
}

.debug-reset:hover {
    background: rgba(255, 60, 60, 0.25);
}

#debug-toggle {
    position: absolute;
    top: 8px;
    right: 44px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    z-index: 20;
}

/* Hidden utility */
.hidden { display: none !important; }

/* Mobile: remove phone frame */
@media (max-width: 500px) {
    body {
        background: #000;
    }

    #phone-frame {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        padding: 0;
        box-shadow: none;
        background: #000;
    }

    #phone-notch {
        display: none;
    }

    #game-container {
        height: 100%;
        border-radius: 0;
    }
}

/* Desktop: hide d-pad and action buttons */
@media (min-width: 501px) {
    .mobile-only {
        display: none !important;
    }
}

/* Hide old D-pad when touch controls active (tap/joystick mode) */
body.touch-tap .mobile-only,
body.touch-joystick .mobile-only {
    display: none !important;
}

/* Menu button always visible on mobile */
body.touch-tap .menu-btn,
body.touch-joystick .menu-btn {
    display: block !important;
}

/* ─────────────────────────────────────────────────────────────
   Barra legale (privacy / termini / note legali / crediti)

   Link HTML reali: raggiungibili da tastiera (Tab) e annunciati dagli
   screen reader, a differenza di un menu disegnato sul canvas.
   Desktop: sempre visibile sotto il telefono.
   Mobile:  visibile solo nelle schermate iniziali, per non coprire i
            comandi di gioco. Lo stato arriva da Engine.loop, che scrive
            data-gs sul <body>.
   ───────────────────────────────────────────────────────────── */
#legal-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 4px 16px;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    background: rgba(10, 10, 26, 0.82);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    border-top: 1px solid rgba(160, 170, 255, 0.18);
    font-size: 12px;
    line-height: 1.4;
    text-align: center;
    /* il testo va selezionabile: il reset globale lo aveva disattivato */
    -webkit-user-select: text;
    user-select: text;
}

#legal-bar nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px 6px;
}

#legal-bar a {
    color: #b9d4ff;              /* contrasto ≈ 9:1 sullo sfondo scuro */
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 700;
    /* touch target ≥ 44px di altezza (WCAG 2.5.5) senza ingrossare la barra */
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 6px;
}

#legal-bar a:hover { color: #ffffff; }

#legal-bar a:focus-visible {
    outline: 3px solid #ffd68a;
    outline-offset: 2px;
    border-radius: 4px;
}

#legal-bar-owner {
    color: #9a9ab8;
    font-size: 11px;
}

/* Segnaposto ancora da compilare: evidenti finché non inserisci i dati reali */
.todo-inline {
    background: #3a2f14;
    border: 1px dashed #ffd68a;
    color: #ffe9bd;
    border-radius: 4px;
    padding: 0 4px;
}

/* Mobile: il gioco occupa tutto lo schermo, quindi la barra si mostra solo
   nelle schermate iniziali. Le pagine legali restano sempre accessibili via
   URL diretto (es. fibunnycci.app/privacy.html) e dal desktop. */
@media (max-width: 500px) {
    #legal-bar { display: none; }
    body[data-gs="home"]  #legal-bar,
    body[data-gs="title"] #legal-bar { display: flex; }
}

/* Se qualcuno preferisce meno animazioni, niente sfocature costose */
@media (prefers-reduced-motion: reduce) {
    #legal-bar {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        background: rgba(10, 10, 26, 0.95);
    }
}

/* ══════════════════════════════════════════════════════════════════
   AVVISO SVILUPPO — DA RIMUOVERE AL LANCIO
   Segnala a chi capita sul sito che il gioco non è ancora pubblico.
   È una richiesta, non una protezione tecnica: chiunque abbia l'URL
   può comunque entrare e condividerlo.
   Per rimuoverlo: togli questo blocco e il <p id="dev-notice"> in
   index.html. Cerca "AVVISO SVILUPPO" nel progetto per gli altri punti.
   ══════════════════════════════════════════════════════════════════ */
#dev-notice {
    /* occupa tutta la riga sopra i link legali */
    flex-basis: 100%;
    margin: 0 0 4px;
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(255, 176, 32, 0.16);
    border: 1px solid rgba(255, 200, 90, 0.55);
    color: #ffdf9e;              /* contrasto ≈ 8.9:1 sullo sfondo scuro */
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    -webkit-user-select: text;
    user-select: text;
}

#dev-notice strong { color: #ffc447; }

/* Su schermi molto stretti accorcia: il messaggio essenziale resta */
@media (max-width: 360px) {
    #dev-notice { font-size: 11px; padding: 5px 8px; }
}
