/* ==========================================================================
   css/historia.css
   View genérica de história — livro infantil ilustrado interativo
   O Caminho das Virtudes
   ========================================================================== */

/* ============================================================
   TELA
   ============================================================ */

.tela-historia {
    width: 100%;
    min-height: 100dvh;

    background-color: #8fb16c;
    background-image:
        linear-gradient(rgba(255, 246, 222, 0.14),
            rgba(245, 218, 166, 0.18)),
        url("../assets/fundos/fundo-historias.webp");

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

    overflow-x: hidden;
}

.historia-wrap {
    width: 100%;
    min-height: 100dvh;

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

    padding: 14px 12px 32px;

    overflow-x: hidden;
}

/* ============================================================
   TOPO — alinhado com a coluna do livro
   ============================================================ */

.historia-topo {
    width: min(92vw, 520px);

    display: flex;
    justify-content: flex-start;

    margin-bottom: 10px;
}

/* ============================================================
   BOTÃO VOLTAR AO MAPA
   — visual e largura base em .btn-ui + .btn-voltar-mapa (componentes.css)
   — override de tamanho para o contexto de topo da história
   ============================================================ */

.historia-topo .btn-voltar-mapa {
    width: min(40vw, 180px);
}

/* ============================================================
   BANNER DA HISTÓRIA
   — mesma largura do corpo para formar coluna única de livro
   ============================================================ */

.historia-banner {
    width: min(92vw, 520px);
    height: auto;

    display: block;
    object-fit: contain;

    margin: 0 auto 12px;

    filter: drop-shadow(0 6px 16px rgba(35, 22, 8, 0.34));
}

/* Fallback textual quando não há banner */
.historia-titulo-fallback {
    width: min(92vw, 520px);

    margin: 0 auto 12px;

    color: #fff8df;

    font-size: 1.35rem;
    font-weight: 950;
    text-align: center;

    text-shadow: 0 2px 6px rgba(40, 25, 10, 0.5);
}

/* ============================================================
   CORPO — container dinâmico das cenas
   Mesma largura do banner: coluna de livro unificada
   ============================================================ */

.historia-corpo {
    width: min(92vw, 520px);

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

    gap: 10px;
}

/* ============================================================
   IMAGEM DA CENA
   ============================================================ */

.historia-cena-img {
    width: 100%;
    height: auto;
    max-height: 38dvh;

    display: block;
    align-self: center;

    object-fit: contain;

    border-radius: 18px;

    background: transparent;
    box-shadow: none;
}

/* ============================================================
   CARD DE TEXTO — sem scroll interno; página rola
   ============================================================ */

.historia-card {
    width: 100%;

    max-height: none;
    overflow: visible;

    padding: 16px 16px 14px;

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

    box-shadow: 0 8px 20px rgba(35, 22, 8, 0.16);
}

.historia-texto {
    margin: 0;

    font-size: 1rem;
    color: #4a3420;
    line-height: 1.68;

    white-space: pre-line;
}

/* ============================================================
   CONTROLES — áudio + contador + navegação
   ============================================================ */

.historia-controles {
    display: flex;
    flex-direction: column;
    gap: 10px;

    margin-top: 14px;
}

.historia-controles-linha {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

/* ── Botão de áudio ── */

.btn-audio {
    padding: 8px 14px;

    border: 1.5px solid rgba(180, 140, 80, 0.38);
    border-radius: 999px;

    background: rgba(255, 249, 237, 0.86);
    color: #7a6040;

    font-size: 0.82rem;
    font-weight: 700;
    font-family: inherit;

    cursor: pointer;
    flex-shrink: 0;

    backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(35, 22, 8, 0.1);

    transition: filter 0.12s ease;
}

.btn-audio:hover:not(:disabled) {
    filter: brightness(0.96);
}

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

.btn-audio--indisponivel {
    opacity: 0.52;
    cursor: not-allowed;
    font-size: 0.76rem;
}

/* ── Contador de cenas ── */

.historia-contador {
    font-size: 0.78rem;
    font-weight: 800;
    color: #9a6a18;
    white-space: nowrap;
}

/* ============================================================
   BOTÕES DE NAVEGAÇÃO
   ============================================================ */

.historia-nav-btns {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px;
}


/* ============================================================
   ESTADOS DE GUARDA — erro e em-breve
   ============================================================ */

.historia-guarda {
    width: min(92vw, 520px);
    margin: auto;
    padding: 28px 20px;

    background: rgba(255, 249, 237, 0.97);
    border: 2px solid #e8cc8a;
    border-radius: 22px;
    box-shadow: 0 20px 40px rgba(35, 22, 8, 0.28);

    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;

    text-align: center;
}

.historia-titulo-guarda {
    font-size: 1.1rem;
    font-weight: 900;
    color: #4d341c;
    line-height: 1.3;
}

.historia-erro,
.historia-em-breve {
    font-size: 0.92rem;
    color: #7a6040;
    line-height: 1.5;
    font-style: italic;
}

/* ============================================================
   CELULAR PEQUENO (≤480px)
   Mesma composição, apenas escala levemente reduzida.
   ============================================================ */

@media (max-width: 480px) {
    .historia-topo,
    .historia-banner,
    .historia-titulo-fallback,
    .historia-corpo,
    .historia-guarda {
        width: min(94vw, 430px);
    }

    .historia-texto {
        font-size: 0.95rem;
        line-height: 1.58;
    }
}

/* ============================================================
   MOBILE LANDSCAPE — trata como versão vertical mais larga.
   A página inteira rola. Sem scroll interno. Sem miniatura.
   Conteúdo ocupa a largura disponível, sem limite de altura.
   ============================================================ */

@media (orientation: landscape) and (max-height: 560px) {
    /* Página inteira pode rolar — não tentar encaixar na altura */
    .tela-historia {
        min-height: 100dvh;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .historia-wrap {
        min-height: 100dvh;
        padding: 10px 12px 24px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        overflow: visible;
    }

    .historia-topo {
        width: min(92vw, 560px);
        margin-bottom: 6px;
    }

    /* Banner visível e proporcional — sem limite de altura */
    .historia-banner {
        width: min(72vw, 340px);
        max-width: 100%;
        height: auto;
        max-height: none;
        object-fit: contain;
        display: block;
        margin: 0 auto 8px;
    }

    .historia-titulo-fallback {
        width: min(92vw, 560px);
        font-size: 1.15rem;
        margin-bottom: 8px;
    }

    /* Corpo: coluna única ocupando quase toda a largura */
    .historia-corpo {
        width: min(92vw, 560px);
        max-width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    /* Imagem grande, sem limite de altura — scroll cuida do resto */
    .historia-cena-img {
        width: min(84vw, 520px);
        max-width: 100%;
        height: auto;
        max-height: none;
        object-fit: contain;
        display: block;
        margin: 0 auto 10px;
    }

    /* Card com largura equivalente à da imagem */
    .historia-card {
        width: min(86vw, 540px);
        max-width: 100%;
        max-height: none;
        overflow: visible;
        padding: 14px 16px;
        margin: 0 auto;
    }

    .historia-texto {
        font-size: 0.92rem;
        line-height: 1.5;
    }

    .historia-controles {
        margin-top: 6px;
        gap: 8px;
    }

    .historia-controles-linha {
        gap: 8px;
    }

    .btn-audio {
        padding: 6px 12px;
        font-size: 0.78rem;
        min-height: 36px;
    }

    .historia-contador {
        font-size: 0.76rem;
    }

    .historia-nav-btns {
        gap: 8px;
    }
}

/* ============================================================
   TABLET / DESKTOP (≥768px) — coluna ligeiramente mais larga
   ============================================================ */

@media (min-width: 768px) {
    .historia-wrap {
        padding: 20px 16px 40px;
    }

    .historia-topo,
    .historia-banner,
    .historia-titulo-fallback,
    .historia-corpo,
    .historia-guarda {
        width: min(88vw, 600px);
    }

    .historia-cena-img {
        max-height: 42dvh;
    }

    .historia-card {
        padding: 22px 20px;
    }

    .historia-texto {
        font-size: 1.05rem;
    }
}

/* ==========================================================================
   Correção específica — celular horizontal com largura de tablet
   Evita que o bloco @media (min-width: 768px) reduza a imagem da cena
   ========================================================================== */

@media (orientation: landscape) and (max-height: 560px) and (min-width: 768px) {
    .historia-corpo {
        width: min(94vw, 680px);
        max-width: 100%;
    }

    .historia-cena-img {
        width: min(90vw, 620px);
        max-width: 100%;
        height: auto;
        max-height: none;
        object-fit: contain;
        display: block;
        margin: 0 auto 12px;
    }

    .historia-card {
        width: min(90vw, 620px);
        max-width: 100%;
        max-height: none;
        overflow: visible;
    }
}
