/* ==========================================================================
   css/mapa.css
   Tela do Mapa das Virtudes — O Caminho das Virtudes
   ========================================================================== */

.tela-mapa {
    width: 100%;
    min-height: 100dvh;
    position: relative;

    background-color: #8fb16c;
    background-image:
        linear-gradient(rgba(255, 248, 220, 0.08),
            rgba(80, 110, 45, 0.10)),
        url("../assets/fundos/fundo-historias.webp");

    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;

    overflow-x: hidden;
}

.mapa-overlay {
    width: 100%;
    min-height: 100dvh;

    display: flex;
    flex-direction: column;
    align-items: center;

    padding: 12px 12px 26px;

    background:
        linear-gradient(to bottom,
            rgba(255, 248, 226, 0.10) 0%,
            rgba(255, 248, 226, 0.02) 38%,
            rgba(50, 72, 28, 0.08) 100%);
}

/* ============================================================
   TOPO
   ============================================================ */

.mapa-topo {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}

.mapa-banner {
    width: min(78vw, 360px);
    height: auto;
    display: block;
    object-fit: contain;
    filter: drop-shadow(0 6px 12px rgba(60, 40, 15, 0.24));
}

/* ============================================================
   PERFIL DO JOGADOR
   ============================================================ */

.mapa-jogador {
    display: flex;
    align-items: center;
    gap: 9px;

    margin: 2px 0 8px;
    padding: 6px 13px 6px 7px;

    background: rgba(255, 249, 237, 0.84);
    border: 1.5px solid rgba(232, 204, 138, 0.78);
    border-radius: 999px;

    backdrop-filter: blur(5px);
    box-shadow: 0 4px 12px rgba(42, 29, 12, 0.16);
}

.mapa-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e8cc8a;
    flex-shrink: 0;
    display: block;
}

.mapa-avatar-vazio {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(232, 204, 138, 0.38);
    border: 2px solid #e8cc8a;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 1.05rem;
    flex-shrink: 0;
}

.mapa-jogador-info {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.mapa-jogador-nome {
    font-size: 0.84rem;
    font-weight: 900;
    color: #4d341c;
}

.mapa-jogador-titulo {
    font-size: 0.62rem;
    font-weight: 700;
    color: #8a6a3a;
}

/* ============================================================
   SOFIA — BALÃO CURTO NO MAPA
   ============================================================ */

.sofia-wrap {
    width: min(96vw, 430px);

    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 8px;

    margin: 2px 0 10px;

    animation: sofiaEntrada 0.32s ease;
}

@keyframes sofiaEntrada {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.sofia-balao--saindo {
    animation: sofiaSaida 0.26s ease forwards;
}

@keyframes sofiaSaida {
    to {
        opacity: 0;
        transform: translateY(-6px) scale(0.97);
    }
}

.sofia-personagem {
    width: 78px;
    height: auto;

    display: block;
    flex-shrink: 0;
    object-fit: contain;

    margin-top: 8px;

    filter: drop-shadow(0 4px 8px rgba(42, 29, 12, 0.22));
}

.sofia-balao-conteudo {
    position: relative;
    flex: 0 1 280px;
    min-width: 0;

    padding: 9px 11px;

    background: rgba(255, 249, 237, 0.97);
    border: 2px solid #e8cc8a;
    border-radius: 18px;

    box-shadow: 0 8px 20px rgba(42, 29, 12, 0.18);
}

.sofia-balao-conteudo::before {
    content: "";
    position: absolute;
    left: -9px;
    top: 18px;

    width: 16px;
    height: 16px;

    background: rgba(255, 249, 237, 0.97);
    border-left: 2px solid #e8cc8a;
    border-bottom: 2px solid #e8cc8a;

    transform: rotate(45deg);
}

.sofia-balao-corpo {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sofia-balao-texto {
    font-size: 0.82rem;
    color: #4d341c;
    line-height: 1.36;
    margin: 0;
}

.sofia-balao-btn {
    align-self: flex-start;
    padding: 6px 16px;

    border: none;
    border-radius: 999px;

    background: linear-gradient(180deg, #ffd46a 0%, #f0a01e 100%);
    color: #3d2409;

    font-size: 0.78rem;
    font-weight: 900;
    font-family: inherit;

    cursor: pointer;

    box-shadow: 0 4px 0 #a8650e;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.sofia-balao-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #a8650e;
}

.sofia-balao-btn:focus-visible {
    outline: 3px solid #6ab7ff;
    outline-offset: 3px;
}

/* ============================================================
   FEEDBACK
   ============================================================ */

.mapa-feedback {
    min-height: 1.35em;
    margin: 2px 0 8px;
    padding: 0 12px;

    font-size: 0.8rem;
    font-weight: 800;
    color: #854600;
    text-align: center;

    text-shadow: 0 1px 5px rgba(255, 249, 237, 0.95);
}

.mapa-feedback--ativo {
    background: rgba(255, 249, 237, 0.72);
    border: 1px solid rgba(232, 204, 138, 0.7);
    border-radius: 999px;
    padding: 6px 12px;
    box-shadow: 0 4px 12px rgba(42, 29, 12, 0.12);
}

/* ============================================================
   CAMINHO DAS VIRTUDES
   ============================================================ */

.mapa-caminho {
    width: 100%;
    max-width: 320px;

    display: grid;
    grid-template-columns: repeat(2, minmax(128px, 148px));
    justify-content: center;
    align-items: start;

    gap: 20px 12px;

    padding: 8px 0 16px;
}

/* ============================================================
   CARD DE FASE — imagem direta sobre o mapa
   ============================================================ */

.fase-card {
    width: 100%;
    max-width: 152px;

    position: relative;

    display: block;

    border: none;
    padding: 0;
    margin: 0;

    background: transparent;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;

    appearance: none;
    -webkit-appearance: none;

    font: inherit;
    color: inherit;
}

.fase-img {
    width: 100%;
    height: auto;

    display: block;
    object-fit: contain;

    filter: drop-shadow(0 9px 12px rgba(42, 29, 12, 0.28));

    user-select: none;
    pointer-events: none;
}

.fase-disponivel {
    cursor: pointer;
    transform-origin: center;
    animation: fasePulso 2.6s ease-in-out infinite;
}

@keyframes fasePulso {

    0%,
    100% {
        transform: translateY(0) scale(1);
    }

    50% {
        transform: translateY(-3px) scale(1.035);
    }
}

.fase-disponivel:hover {
    animation: none;
    transform: translateY(-5px) scale(1.045);
}

.fase-disponivel:active {
    transform: translateY(-1px) scale(1.01);
}

.fase-disponivel:focus-visible {
    outline: 3px solid #6ab7ff;
    outline-offset: 5px;
    border-radius: 18px;
}

/* Estado bloqueado preparado para expansão futura */

.fase-bloqueada .fase-img,
.fase-card.bloqueada .fase-img {
    filter: grayscale(0.75) sepia(0.12) opacity(0.72) drop-shadow(0 8px 10px rgba(42, 29, 12, 0.20));
}

.fase-bloqueada,
.fase-card.bloqueada {
    cursor: not-allowed;
}

.fase-lock,
.fase-cadeado {
    position: absolute;
    top: 8px;
    right: 8px;

    width: 28px;
    height: 28px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 50%;

    background: rgba(80, 90, 65, 0.82);
    color: #fff8df;

    font-size: 0.9rem;
    box-shadow: 0 3px 8px rgba(40, 30, 15, 0.22);
}

/* Garante que textos antigos não apareçam se ainda existirem no HTML/cache */

.fase-info,
.fase-titulo,
.fase-virtude {
    display: none !important;
}

/* ============================================================
   AÇÕES INFERIORES — botões ilustrados
   ============================================================ */

.mapa-acoes {
    width: min(92vw, 400px);

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;

    margin: 18px auto 8px;
}

.mapa-acao-btn {
    flex: 1;
    min-width: 0;

    padding: 0;
    margin: 0;
    border: none;
    background: transparent;

    appearance: none;
    -webkit-appearance: none;

    cursor: pointer;
    display: block;
    line-height: 0;

    transition: transform 0.14s ease, filter 0.14s ease;
}

.mapa-acao-btn:hover {
    transform: translateY(-3px) scale(1.04);
    filter: brightness(1.08);
}

.mapa-acao-btn:active {
    transform: translateY(1px) scale(0.98);
    filter: brightness(0.95);
    transition-duration: 0.06s;
}

.mapa-acao-btn:focus-visible {
    outline: 3px solid #6ab7ff;
    outline-offset: 4px;
    border-radius: 14px;
}

.mapa-acao-img {
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;

    object-fit: contain;
    user-select: none;
    pointer-events: none;

    filter: drop-shadow(0 5px 10px rgba(42, 29, 12, 0.26));
}

/* ============================================================
   MODAL DE AJUSTES — Configurações
   ============================================================ */

.modal-ajustes {
    position: fixed;
    inset: 0;
    z-index: 50;

    display: none;
    align-items: center;
    justify-content: center;

    padding: 16px;
    overflow-y: auto;

    background: rgba(20, 12, 4, 0.60);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.modal-ajustes.ativo {
    display: flex;
}

.modal-ajustes-card {
    position: relative;
    width: min(92vw, 460px);
    max-height: 90dvh;
    overflow-y: auto;

    padding: 0 0 18px;

    border-radius: 28px;

    background-color: #f5e9c8;
    background-image: url('../assets/fundos/fundo-popup.png');
    background-size: cover;
    background-position: center;

    border: 3px solid #c8a030;

    box-shadow:
        0 0 0 1px rgba(255, 220, 100, 0.25),
        0 24px 56px rgba(20, 12, 4, 0.44);
}

/* Banner superior */
.config-banner {
    display: block;
    width: min(52%, 180px);
    height: auto;
    margin: 10px auto 0;
    object-fit: contain;
    filter: drop-shadow(0 3px 8px rgba(20, 12, 4, 0.22));
}

/* Título de seção */
.config-section-title {
    margin: 16px 0 0;
    padding: 5px 16px 4px;

    color: #7a5820;
    font-size: 0.68rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.10em;

    border-bottom: 1px solid rgba(180, 140, 80, 0.22);
}

/* Linha de configuração */
.config-row {
    display: flex;
    align-items: center;
    gap: 9px;

    padding: 9px 16px;
    min-height: 46px;

    border: none;
    background: transparent;

    font-family: inherit;
    text-align: left;
    color: #4d341c;

    width: 100%;
    box-sizing: border-box;
}

.config-row--action {
    cursor: pointer;
    transition: background 0.12s ease;
}

.config-row--action:hover {
    background: rgba(255, 248, 210, 0.42);
}

.config-row--action:active {
    background: rgba(232, 204, 138, 0.32);
}

.config-row--action:focus-visible {
    outline: 3px solid #6ab7ff;
    outline-offset: -3px;
    border-radius: 4px;
}

.config-row--danger {
    color: #7a3422;
    margin-top: 2px;
}

/* Ícone da linha */
.config-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
    display: block;
    filter: drop-shadow(0 2px 4px rgba(20, 12, 4, 0.16));
}

/* Texto da linha */
.config-label {
    flex: 1;
    font-size: 0.86rem;
    font-weight: 900;
    line-height: 1.2;
}

.config-row-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.config-row-text .config-label {
    flex: none;
}

.config-row-sub {
    font-size: 0.63rem;
    font-weight: 600;
    color: #b8916a;
    line-height: 1.3;
}

/* Seta de ação */
.config-arrow {
    font-size: 1.0rem;
    color: #c8a870;
    flex-shrink: 0;
    line-height: 1;
}

/* Toggle button */
.config-toggle {
    display: flex;
    align-items: center;
    gap: 6px;

    padding: 6px 9px 6px 10px;

    border-radius: 999px;
    border: 2px solid transparent;

    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 800;

    cursor: pointer;
    flex-shrink: 0;

    min-width: 84px;
    justify-content: space-between;

    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.config-toggle:focus-visible {
    outline: 3px solid #6ab7ff;
    outline-offset: 2px;
}

.config-toggle[aria-pressed="true"] {
    background: linear-gradient(155deg, #52b84a 0%, #2a8228 100%);
    border-color: #1a6018;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(26, 96, 24, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.config-toggle[aria-pressed="false"] {
    background: rgba(160, 138, 100, 0.18);
    border-color: rgba(140, 112, 72, 0.35);
    color: #8a6e4a;
    box-shadow: none;
}

.toggle-knob {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    background: currentColor;
    opacity: 1;
}

/* Botão Fechar — visual herdado de .btn-ui + .btn-fechar (componentes.css) */
.btn-fechar-ajustes {
    display: block;
    margin: 14px auto 0;
}

/* ============================================================
   MODAL DE CONFIRMAÇÃO — Reiniciar progresso
   ============================================================ */

.modal-confirmar {
    position: fixed;
    inset: 0;
    z-index: 60;

    display: none;
    align-items: center;
    justify-content: center;

    padding: 16px;

    background: rgba(20, 12, 4, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-confirmar.ativo {
    display: flex;
}

.modal-confirmar-card {
    width: min(90vw, 360px);
    padding: 26px 22px 20px;

    border-radius: 24px;

    background-color: #f9f0d8;
    background-image: url('../assets/fundos/fundo-popup.png');
    background-size: cover;
    background-position: center top;

    border: 2px solid #e8cc8a;
    border-top: 4px solid #f5a623;

    box-shadow: 0 20px 42px rgba(20, 12, 4, 0.38);

    text-align: center;
}

.confirmar-titulo {
    margin: 0 0 8px;
    color: #7a3422;
    font-size: 1.08rem;
    font-weight: 900;
}

.confirmar-texto {
    margin: 0 0 20px;
    color: #5f4828;
    font-size: 0.84rem;
    line-height: 1.48;
}

.confirmar-acoes {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-cancelar {
    flex: 1;
    max-width: 140px;
    padding: 11px 16px;

    border: 2px solid rgba(180, 140, 80, 0.42);
    border-radius: 999px;

    background: rgba(255, 255, 255, 0.72);
    color: #5f4828;

    font-size: 0.88rem;
    font-weight: 900;
    font-family: inherit;

    cursor: pointer;
    transition: filter 0.12s ease;
}

.btn-cancelar:hover {
    filter: brightness(0.96);
}

.btn-cancelar:active {
    filter: brightness(0.90);
}

.btn-cancelar:focus-visible {
    outline: 3px solid #6ab7ff;
    outline-offset: 3px;
}

.btn-confirmar {
    flex: 1;
    max-width: 140px;
    padding: 11px 16px;

    border: none;
    border-top: 2px solid rgba(255, 180, 100, 0.45);
    border-radius: 999px;

    background: linear-gradient(180deg, #e85530 0%, #b82510 100%);
    color: #fff;

    font-size: 0.88rem;
    font-weight: 900;
    font-family: inherit;

    cursor: pointer;

    box-shadow: 0 4px 0 #7a1508, 0 8px 16px rgba(120, 30, 10, 0.24);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-confirmar:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #7a1508, 0 3px 8px rgba(120, 30, 10, 0.18);
}

.btn-confirmar:focus-visible {
    outline: 3px solid #6ab7ff;
    outline-offset: 3px;
}

/* ============================================================
   MOBILE PEQUENO
   ============================================================ */

@media (max-width: 420px) {
    .sofia-wrap {
        width: min(96vw, 360px);
        gap: 6px;
    }

    .sofia-personagem {
        width: 68px;
        margin-top: 10px;
    }

    .sofia-balao-conteudo {
        flex-basis: 255px;
        padding: 9px 11px;
    }

    .sofia-balao-conteudo::before {
        left: -8px;
        top: 16px;
        width: 14px;
        height: 14px;
    }

    .sofia-balao-texto {
        font-size: 0.78rem;
        line-height: 1.36;
    }

    .sofia-balao-btn {
        padding: 6px 15px;
        font-size: 0.75rem;
    }

    .mapa-acoes {
        width: min(94vw, 340px);
        gap: 8px;
    }
}

/* ============================================================
   MOBILE BAIXO / PAISAGEM
   ============================================================ */

@media (orientation: landscape) and (max-height: 520px) {
    .mapa-overlay {
        padding: 8px 12px 18px;
    }

    .mapa-topo {
        margin-bottom: 4px;
    }

    .mapa-banner {
        width: min(42vw, 210px);
    }

    .mapa-jogador {
        margin: 2px 0 4px;
        transform: scale(0.92);
        transform-origin: center;
    }

    .sofia-wrap {
        width: min(86vw, 420px);
        margin: 3px 0 5px;
        gap: 6px;
    }

    .sofia-personagem {
        width: 54px;
        margin-top: 6px;
    }

    .sofia-balao-conteudo {
        flex-basis: 240px;
        padding: 8px 10px;
    }

    .sofia-balao-texto {
        font-size: 0.74rem;
    }

    .sofia-balao-btn {
        padding: 5px 14px;
        font-size: 0.72rem;
    }

    .mapa-caminho {
        max-width: 600px;
        grid-template-columns: repeat(5, minmax(96px, 108px));
        gap: 10px 10px;
        padding: 4px 0 10px;
    }

    .fase-card {
        max-width: 108px;
        /* Reseta posicionamento explícito do layout desktop */
        grid-column: auto;
        grid-row: auto;
        justify-self: auto;
    }

    .mapa-acoes {
        width: min(92vw, 380px);
        margin-top: 2px;
        gap: 8px;
    }
}

/* ============================================================
   TABLET / DESKTOP
   ============================================================ */

@media (min-width: 768px) {
    .mapa-overlay {
        padding: 16px 20px 34px;
    }

    .mapa-banner {
        width: min(60vw, 420px);
    }

    .mapa-jogador {
        margin-top: 4px;
        margin-bottom: 12px;
    }

    .sofia-wrap {
        width: min(92vw, 520px);
        gap: 10px;
    }

    .sofia-personagem {
        width: 92px;
        margin-top: 4px;
    }

    .sofia-balao-conteudo {
        flex-basis: 320px;
        padding: 11px 13px;
    }

    .sofia-balao-texto {
        font-size: 0.88rem;
    }

    .mapa-caminho {
        max-width: 620px;
        grid-template-columns: repeat(3, 170px);
        gap: 32px 28px;
        padding: 16px 0 24px;
    }

    .fase-card {
        max-width: 170px;
    }

    /* Trilha em zigue-zague: rows 2 e 4 ficam com 2 cards nas colunas 1 e 3 */
    .fase-card:nth-child(4)  { grid-column: 1; grid-row: 2; justify-self: center; }
    .fase-card:nth-child(5)  { grid-column: 3; grid-row: 2; justify-self: center; }
    .fase-card:nth-child(6)  { grid-column: 1; grid-row: 3; justify-self: center; }
    .fase-card:nth-child(7)  { grid-column: 2; grid-row: 3; justify-self: center; }
    .fase-card:nth-child(8)  { grid-column: 3; grid-row: 3; justify-self: center; }
    .fase-card:nth-child(9)  { grid-column: 1; grid-row: 4; justify-self: center; }
    .fase-card:nth-child(10) { grid-column: 3; grid-row: 4; justify-self: center; }

    .mapa-acoes {
        width: min(72vw, 420px);
        margin-top: 10px;
        gap: 14px;
    }
}

/* ============================================================
   DESKTOP AMPLO
   ============================================================ */

@media (min-width: 1100px) {
    .mapa-caminho {
        max-width: 680px;
        grid-template-columns: repeat(3, 180px);
    }

    .fase-card {
        max-width: 180px;
    }

    .sofia-personagem {
        width: 100px;
    }

    .sofia-balao-conteudo {
        flex-basis: 340px;
    }
}