/* ============================================================
 * Modern Pet Page — refinements for meadow-mode
 * ============================================================
 * Override CSS caricato DOPO style.css. Non modifica markup né
 * comportamento: agisce solo su body.meadow-mode (= modalità
 * "Moderno") rendendo HUD, side toggles, care-panel, action
 * buttons e gotchi-name più puliti, moderni e coerenti.
 *
 * Tutte le classi qui usate ESISTONO già in templates/index.html.
 * Nessun nuovo elemento è richiesto.
 *
 * Compatibile con: no-distractions-mode, sleep-mode, egg-mode.
 * ============================================================ */

/* ---------- HUD (ora · età · mondo) -- mobile first ---- */
body.meadow-mode .device-top-info {
    gap: 2px;
    padding: 5px 7px;
    border-radius: 999px;
    background: rgba(14, 26, 32, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.24);
    box-shadow:
        0 10px 24px rgba(6, 16, 22, 0.26),
        inset 0 1px 0 rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(12px) saturate(1.1);
    -webkit-backdrop-filter: blur(12px) saturate(1.1);
    transition: var(--transition-base);
    min-height: 0;
}

body.meadow-mode .device-top-info:hover {
    background: rgba(14, 26, 32, 0.6);
}

body.meadow-mode .device-top-pill {
    padding: 3px 8px;
    gap: 5px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.01em;
    color: #f7fbff;
    border-radius: 999px;
    background: transparent;
}

body.meadow-mode .device-top-pill:hover {
    background: rgba(255, 255, 255, 0.10);
}

body.meadow-mode .device-top-icon {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    font-size: 10px;
    line-height: 1;
    background: rgba(255, 255, 255, 0.16);
    border-radius: 50%;
    filter: none;
    flex-shrink: 0;
}

/* Quando il JS sostituisce l'emoji con SVG (.modern-hud-icon),
   togliamo il bg cerchio: il SVG e' gia' chiaro su pill scura. */
body.meadow-mode .device-top-icon.modern-hud-icon {
    background: transparent;
    width: 18px;
    height: 18px;
}

body.meadow-mode .modern-hud-svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: #ffffff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.95;
}

body.meadow-mode .device-top-divider {
    width: 1px;
    height: 12px;
    background: rgba(255, 255, 255, 0.22);
    margin: 0 1px;
}

@media (min-width: 600px) {
    body.meadow-mode .device-top-info {
        gap: 4px;
        padding: 7px 10px;
    }
    body.meadow-mode .device-top-pill {
        padding: 4px 10px;
        font-size: 13px;
        gap: 6px;
    }
    body.meadow-mode .device-top-icon {
        width: 20px;
        height: 20px;
        font-size: 12px;
    }
    body.meadow-mode .device-top-icon.modern-hud-icon {
        width: 20px;
        height: 20px;
    }
    body.meadow-mode .device-top-divider {
        height: 14px;
    }
}

/* ---------- Pet name (in alto a sinistra) -- mobile first - */
body.meadow-mode .gotchi-name {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px 6px 9px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(255, 255, 255, 0.95);
    color: #14213d;
    font-weight: 800;
    font-size: 13px;
    text-shadow: none;
    box-shadow:
        0 10px 22px rgba(6, 18, 22, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 1);
    backdrop-filter: blur(14px) saturate(1.1);
    -webkit-backdrop-filter: blur(14px) saturate(1.1);
    cursor: pointer;
    transition: var(--transition-base);
    letter-spacing: -0.01em;
    max-width: min(60vw, 240px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.meadow-mode .gotchi-name:hover {
    background: #fff;
}

/* Pet name upgrade (JS) — testo + gender pill */
body.meadow-mode .gotchi-name .modern-name-text {
    display: inline-block;
    line-height: 1.2;
}

body.meadow-mode .gotchi-name .modern-name-gender {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    margin-left: 2px;
    flex-shrink: 0;
}

body.meadow-mode .gotchi-name .modern-name-gender--male {
    color: #1a55a3;
    background: #cfe2ff;
    border: 1px solid #b6d4ff;
}

body.meadow-mode .gotchi-name .modern-name-gender--female {
    color: #a23b78;
    background: #ffd9eb;
    border: 1px solid #ffc3e0;
}

@media (min-width: 600px) {
    body.meadow-mode .gotchi-name {
        padding: 8px 14px 8px 10px;
        border-radius: 16px;
        font-size: 15px;
        max-width: min(40vw, 320px);
    }
    body.meadow-mode .gotchi-name .modern-name-gender {
        width: 22px;
        height: 22px;
        font-size: 13px;
    }
}

/* ---------- Side toggles (Status / Pets / Store / ...) ------ */
/* ---------- Side toggles base (look generico, no bubble) ---
 * Quando l'utente non ha ancora attivato il bubble (es. caricamento
 * iniziale prima che il JS inietti il FAB), i toggle hanno look
 * neutro coerente col meadow-mode esistente. Una volta che il JS
 * inietta il FAB e posiziona i toggle, i selettori dedicati nella
 * sezione "Bubble side menu" piu' avanti prendono il sopravvento.
 * ----------------------------------------------------------- */
body.meadow-mode .device-side-toggle {
    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

/* ---------- Care panel -- mobile first ------------------- */
body.meadow-mode .care-panel {
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(12, 28, 22, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.24);
    box-shadow:
        0 12px 26px rgba(4, 14, 10, 0.26),
        inset 0 1px 0 rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(14px) saturate(1.1);
    -webkit-backdrop-filter: blur(14px) saturate(1.1);
}

body.meadow-mode .care-need {
    font-size: 0.78rem;
    font-weight: 700;
    color: #f6fff2;
    line-height: 1.35;
    letter-spacing: -0.005em;
    margin-bottom: 6px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

body.meadow-mode .care-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    font-size: 0.68rem;
}

@media (min-width: 600px) {
    body.meadow-mode .care-panel {
        padding: 12px 14px;
        border-radius: 18px;
    }
    body.meadow-mode .care-need {
        font-size: 0.86rem;
    }
    body.meadow-mode .care-meta {
        gap: 6px;
        font-size: 0.72rem;
    }
}

body.meadow-mode .care-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    color: #f6fff2;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.10);
    font-weight: 700;
}

body.meadow-mode #care-mood {
    background: rgba(65, 211, 154, 0.18);
    border: 1px solid rgba(65, 211, 154, 0.42);
    color: #b6f5d6;
    text-transform: capitalize;
}

body.meadow-mode #care-mood::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #41d39a;
    box-shadow: 0 0 6px rgba(65, 211, 154, 0.7);
}

body.meadow-mode #care-coins {
    background: linear-gradient(160deg, rgba(255, 210, 74, 0.22), rgba(255, 210, 74, 0.10));
    border: 1px solid rgba(255, 210, 74, 0.36);
    color: #ffe6a8;
}

body.meadow-mode #care-brooms {
    background: rgba(255, 255, 255, 0.10);
    color: #e6f3ff;
}

body.meadow-mode .affection-bar {
    width: 64px;
    height: 6px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.18);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.30);
}

body.meadow-mode .affection-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff7a8a 0%, #ffb380 100%);
    border-radius: 999px;
    box-shadow: 0 0 6px rgba(255, 122, 138, 0.5);
}

/* ---------- Controls (action buttons in basso) -- mobile first */
body.meadow-mode .controls {
    padding: 7px 9px;
    border-radius: 20px;
    background: rgba(8, 22, 22, 0.34);
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow:
        0 12px 26px rgba(4, 14, 12, 0.26),
        inset 0 1px 0 rgba(255, 255, 255, 0.10);
    backdrop-filter: blur(14px) saturate(1.1);
    -webkit-backdrop-filter: blur(14px) saturate(1.1);
}

body.meadow-mode #controls-alive .btn,
body.meadow-mode #controls-dead .btn {
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
    border-radius: 14px;
    border: none;
    color: #fff;
    font-weight: 800;
    box-shadow:
        inset 0 -3px 0 rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.36),
        0 8px 18px -6px rgba(0, 0, 0, 0.32);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

body.meadow-mode #controls-alive .btn:hover,
body.meadow-mode #controls-dead .btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.05);
}

body.meadow-mode #controls-alive .btn:active,
body.meadow-mode #controls-dead .btn:active {
    transform: translateY(1px);
    box-shadow:
        inset 0 -1px 0 rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.20),
        0 4px 12px -6px rgba(0, 0, 0, 0.32);
}

@media (min-width: 600px) {
    body.meadow-mode .controls {
        padding: 8px 10px;
        border-radius: 22px;
    }
    body.meadow-mode #controls-alive .btn,
    body.meadow-mode #controls-dead .btn {
        width: 52px;
        min-width: 52px;
        height: 52px;
        min-height: 52px;
        border-radius: 16px;
    }
}

/* Coordinated gradients per le classi colore esistenti */
body.meadow-mode .btn-red    { background: linear-gradient(160deg, #ff8c97 0%, #f06070 100%) !important; }
body.meadow-mode .btn-blue   { background: linear-gradient(160deg, #6db7ff 0%, #3d83e3 100%) !important; }
body.meadow-mode .btn-yellow { background: linear-gradient(160deg, #ffd24a 0%, #f0a830 100%) !important; color: #5a3a08 !important; }
body.meadow-mode .btn-pink   { background: linear-gradient(160deg, #ff9bd4 0%, #d65aa3 100%) !important; }
body.meadow-mode .btn-green  { background: linear-gradient(160deg, #6bd99b 0%, #38a06a 100%) !important; }
body.meadow-mode .btn-slate  { background: linear-gradient(160deg, #b3bfd1 0%, #7c8a9f 100%) !important; }

body.meadow-mode .btn-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@media (min-width: 600px) {
    body.meadow-mode .btn-icon svg {
        width: 22px;
        height: 22px;
    }
}

body.meadow-mode .btn-label {
    display: none;
}

/* ---------- App modals (Status, Pets, Trophies, Options, ...) -- */
body.meadow-mode .app-modal-panel {
    border-radius: 28px;
    background: linear-gradient(180deg, #1d3253 0%, #0f1d36 100%);
    border: 1px solid rgba(255, 255, 255, 0.10);
    box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.55);
}

body.meadow-mode .app-modal-panel h2 {
    letter-spacing: -0.01em;
    text-align: center;
}

/* ---------- Accessibility ------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    body.meadow-mode .device-side-toggle,
    body.meadow-mode .device-top-info,
    body.meadow-mode .gotchi-name,
    body.meadow-mode #controls-alive .btn,
    body.meadow-mode #controls-dead .btn {
        transition: none;
    }
    body.meadow-mode .device-side-toggle:hover,
    body.meadow-mode .device-top-info:hover,
    body.meadow-mode .gotchi-name:hover,
    body.meadow-mode #controls-alive .btn:hover,
    body.meadow-mode #controls-dead .btn:hover {
        transform: none;
    }
}

body.meadow-mode .device-side-toggle:focus-visible,
body.meadow-mode .gotchi-name:focus-visible,
body.meadow-mode #controls-alive .btn:focus-visible,
body.meadow-mode #controls-dead .btn:focus-visible {
    outline: 2px solid #8fd2ff;
    outline-offset: 2px;
}

/* ============================================================
 * Bubble side menu (FAB "+") — mobile first
 * ============================================================
 * Comportamento (mock-aligned):
 *   - Solo FAB "+" visibile in alto a destra di default
 *   - Click → 6 toggle bianchi esplodono SOTTO il FAB con stagger
 *   - Label slide-in a sinistra di ogni bubble quando espanso
 *   - Badge tondo rosso angolo TR per notifiche (.modern-side-badge)
 *
 * IMPORTANTE: il positioning dei toggle è gestito INLINE da
 * static/js/modern-side-menu.js (non da queste regole) per
 * battere qualunque cascade conflittuale. Qui c'è SOLO l'aspetto.
 * ============================================================ */

/* --- FAB principale --------------------------------------- */
body.meadow-mode .modern-side-fab {
    position: absolute;
    right: max(10px, env(safe-area-inset-right, 0px));
    top: max(54px, calc(env(safe-area-inset-top, 0px) + 52px));
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.92);
    background:
        linear-gradient(160deg, #ffffff 0%, #f0f6ff 100%);
    color: #14213d;
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 8;
    box-shadow:
        0 12px 24px rgba(8, 22, 30, 0.32),
        inset 0 1px 0 rgba(255, 255, 255, 1);
    transition: transform 0.22s cubic-bezier(.4,1.4,.5,1), background 0.22s ease, box-shadow 0.22s ease;
    -webkit-tap-highlight-color: transparent;
}

body.meadow-mode .modern-side-fab:hover {
    transform: scale(1.06);
}

body.meadow-mode .modern-side-fab:active {
    transform: scale(0.96);
}

body.meadow-mode .modern-side-fab svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: opacity 0.22s ease, transform 0.32s cubic-bezier(.4,1.4,.5,1);
    position: absolute;
}

body.meadow-mode .modern-side-fab__plus  { opacity: 1; transform: rotate(0deg); }
body.meadow-mode .modern-side-fab__close { opacity: 0; transform: rotate(-45deg); }

body.modern-side-expanded.meadow-mode .modern-side-fab {
    background: linear-gradient(160deg, #6db7ff 0%, #3d83e3 100%);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.7);
    box-shadow:
        0 14px 28px rgba(61, 131, 227, 0.42),
        inset 0 1px 0 rgba(255, 255, 255, 0.55);
}
body.modern-side-expanded.meadow-mode .modern-side-fab__plus  { opacity: 0; transform: rotate(90deg); }
body.modern-side-expanded.meadow-mode .modern-side-fab__close { opacity: 1; transform: rotate(0deg); }

/* --- Toggle laterali (aspetto white glass, mock-style) --- */
body.meadow-mode .device-side-toggle {
    /* Override completo del look in modo che, quando il JS
       inserisce position/top/transform inline, l'aspetto sia
       mock-aligned a prescindere dallo stato collapsed/expanded. */
    border: 1px solid rgba(255, 255, 255, 0.92) !important;
    background:
        linear-gradient(160deg, #ffffff 0%, #f0f6ff 100%) !important;
    color: #14213d !important;
    box-shadow:
        0 12px 22px rgba(8, 22, 30, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 1) !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transform-origin: 50% 0%;
    -webkit-tap-highlight-color: transparent;
}

body.modern-side-expanded.meadow-mode .device-side-toggle:hover {
    /* Lift orizzontale (NON Y per non sovrascrivere translateY del JS) */
    filter: brightness(1.04);
    box-shadow:
        0 16px 28px rgba(8, 22, 30, 0.34),
        inset 0 1px 0 rgba(255, 255, 255, 1) !important;
}

body.meadow-mode .device-side-toggle svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Tinta sottile per categoria (icona) quando in bubble menu */
body.meadow-mode .device-status-toggle   { color: #ef5b5b !important; }
body.meadow-mode .device-pets-toggle     { color: #3d83e3 !important; }
body.meadow-mode .device-store-toggle    { color: #f0a830 !important; }
body.meadow-mode .device-trophies-toggle { color: #d49a00 !important; }
body.meadow-mode .device-mail-toggle     { color: #7c5cff !important; }
body.meadow-mode .device-options-toggle  { color: #5a6b80 !important; }

/* --- Label slide-in accanto al bubble -------------------- */
body.meadow-mode .modern-side-label {
    position: absolute;
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(8px);
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(15, 30, 55, 0.78);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    box-shadow: 0 8px 18px rgba(6, 16, 22, 0.32);
    backdrop-filter: blur(8px) saturate(1.1);
    -webkit-backdrop-filter: blur(8px) saturate(1.1);
    transition: opacity 0.2s ease 0s, transform 0.28s cubic-bezier(.34,1.56,.64,1) 0s;
}

body.modern-side-expanded.meadow-mode .device-side-toggle .modern-side-label {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
    /* Stagger: la label appare DOPO il bubble (delay = bubble stagger + 80ms) */
    transition-delay: calc(var(--modern-stagger-fallback, 0) * 45ms + 180ms);
}

/* Fallback stagger value via attribute selector (JS imposta data-modern-stagger) */
body.modern-side-expanded.meadow-mode .device-side-toggle[data-modern-stagger="0"] .modern-side-label { --modern-stagger-fallback: 0; }
body.modern-side-expanded.meadow-mode .device-side-toggle[data-modern-stagger="1"] .modern-side-label { --modern-stagger-fallback: 1; }
body.modern-side-expanded.meadow-mode .device-side-toggle[data-modern-stagger="2"] .modern-side-label { --modern-stagger-fallback: 2; }
body.modern-side-expanded.meadow-mode .device-side-toggle[data-modern-stagger="3"] .modern-side-label { --modern-stagger-fallback: 3; }
body.modern-side-expanded.meadow-mode .device-side-toggle[data-modern-stagger="4"] .modern-side-label { --modern-stagger-fallback: 4; }
body.modern-side-expanded.meadow-mode .device-side-toggle[data-modern-stagger="5"] .modern-side-label { --modern-stagger-fallback: 5; }

/* --- Badge contatore (notifiche) ------------------------- */
body.meadow-mode .modern-side-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef5b5b;
    color: #ffffff;
    font-size: 10px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    border: 2px solid #ffffff;
    box-shadow: 0 4px 8px rgba(239, 91, 91, 0.45);
    pointer-events: none;
    box-sizing: content-box;
}

/* Badge anche sul FAB (somma di tutti se collapsed) */
body.meadow-mode .modern-side-fab .modern-side-badge {
    top: -2px;
    right: -2px;
}

/* --- Tablet / desktop: leggermente più grandi ------------ */
@media (min-width: 600px) {
    body.meadow-mode .modern-side-fab {
        width: 48px;
        height: 48px;
        top: max(60px, calc(env(safe-area-inset-top, 0px) + 56px));
    }
    body.meadow-mode .modern-side-fab svg { width: 22px; height: 22px; }
    body.meadow-mode .device-side-toggle svg { width: 22px; height: 22px; }
    body.meadow-mode .modern-side-label {
        font-size: 13px;
        padding: 7px 14px;
    }
    body.meadow-mode .modern-side-badge {
        min-width: 20px;
        height: 20px;
        line-height: 20px;
        font-size: 11px;
        border-radius: 10px;
    }
}

/* --- Reduced motion -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    body.meadow-mode .modern-side-fab svg,
    body.meadow-mode .modern-side-label,
    body.meadow-mode .device-side-toggle {
        transition: none !important;
    }
}

/* --- Focus visibili -------------------------------------- */
body.meadow-mode .modern-side-fab:focus-visible,
body.meadow-mode .device-side-toggle:focus-visible {
    outline: 2px solid #8fd2ff;
    outline-offset: 3px;
}
