/**
 * GUARDIÃO DA ÁGUA - TUTORIAL SYSTEM CSS
 * RPG-style tutorial interface for 6th-graders (about 11 years old)
 */

/* ===== GAME OVER CONTAINER ===== */
#gameover-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    display: none;
    flex-direction: column;
    background: #000;
}

#gameover-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: brightness(0.7);
    z-index: 1;
}

#gameover-portrait {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    border: 5px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    object-fit: cover;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

#gameover-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.2rem;
    line-height: 1.6;
    color: #2D3561;
    margin-bottom: 1.5rem;
    font-weight: 500;
}

/* Título no cartão claro: o h2 global é branco (feito para fundo escuro) e sumia aqui.
   Lilita One só tem peso 400 (sem negrito falso), cor escura do jogo e sem contorno branco. */
#gameover-title {
    margin: 0;
    font-family: 'Lilita One', cursive;
    font-weight: normal;
    font-size: 2rem;
    line-height: 1.15;
    color: #b3261e;
    -webkit-text-stroke: 0;
    text-shadow: 2px 2px 0 rgba(26, 26, 26, 0.18);
}

@media screen and (max-width: 768px) {
    #gameover-title {
        font-size: 1.5rem;
    }
}

#gameover-menu-btn {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    border-color: #d63031;
    color: white;
}

#gameover-menu-btn:hover {
    background: linear-gradient(135deg, #ee5a24 0%, #d63031 100%);
    transform: scale(1.05);
}

/* ===== TUTORIAL CONTENT ===== */
.tutorial-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 2rem;
}

/* ===== CHARACTER PORTRAIT ===== */
.tutorial-portrait-container {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    padding: 20px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: background-image 0.5s ease;
}

/* ===== DIALOG BOX ===== */
.tutorial-dialog-box {
    overflow: auto;
    padding-bottom: 2rem;
}

.tutorial-dialog {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(240, 240, 255, 0.95) 100%);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    border: 4px solid rgba(255, 255, 255, 0.8);
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* ===== CHARACTER NAME ===== */
.tutorial-character-name {
    font-family: 'Lilita One', cursive;
    font-size: 1.5rem;
    color: #4a9eff;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.1);
}

/* ===== DIALOG HEADER ===== */
.tutorial-dialog-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid rgba(74, 158, 255, 0.3);
}

/* ===== TUTORIAL CONTROLS ===== */
.tutorial-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.tutorial-buttons {
    display: flex;
    gap: 1rem;
}

.tutorial-btn {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0.75rem 1.5rem;
    border-radius: 16px;
    border: 3px solid;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tutorial-btn:active {
    transform: translateY(3px);
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
}

.tutorial-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== ANIMATIONS ===== */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tutorial-dialog {
    animation: fadeIn 0.5s ease-out;
}

/* ===== MOBILE RESPONSIVE ===== */
@media screen and (max-width: 768px) {
    .tutorial-content {
        padding: 1rem;
    }

    .tutorial-portrait-container {
        padding: 15px;
    }

    .tutorial-dialog {
        padding: 1.5rem;
        border-radius: 16px;
    }

    .tutorial-character-name {
        font-size: 1.2rem;
    }

    .tutorial-controls {
        flex-direction: column;
        gap: 0.75rem;
    }

    .tutorial-buttons {
        width: 100%;
        flex-direction: column;
    }

    .tutorial-btn {
        width: 100%;
        font-size: 1rem;
        padding: 0.75rem 1rem;
    }

    #gameover-portrait {
        width: 100px;
        height: 100px;
    }

    #gameover-text {
        font-size: 1rem;
        line-height: 1.5;
    }
}

/* ===== LANDSCAPE MOBILE ===== */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .tutorial-portrait-container {
        margin-bottom: 0.5rem;
        padding: 10px;
    }

    .tutorial-dialog {
        padding: 1rem;
    }

    #gameover-portrait {
        width: 80px;
        height: 80px;
    }

    #gameover-text {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }
}

/* =====================================================================
   TUTORIAL (TutorialSystem.js)
   .tutorial--story: tela cheia, card widescreen (introdução e final)
   .tutorial--coach: jogo visível, card compacto + spotlight no alvo do HUD
   As classes .tutorial-* acima ficam só para o #gameover-container.
   ===================================================================== */
#tutorial-container {
    --tut-ink: #2D3561;
    --tut-muted: #6b7390;
    --tut-line: #e3e8f3;
    --tut-blue: #4a9eff;
    --tut-green: #00a85a;
    --tut-green-dark: #007a41;
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none; /* flex quando ativo */
    align-items: center;
    justify-content: center;
    padding: clamp(16px, 3vw, 40px);
    font-family: 'Fredoka', sans-serif;
    color: var(--tut-ink);
}

#tutorial-container.tutorial--story {
    background: #0b1530;
}

#tutorial-background {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) center / cover no-repeat;
}

#tutorial-background::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(8, 20, 48, 0.35) 0%, rgba(8, 20, 48, 0.8) 100%);
}

.tut-card {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    width: min(1200px, 100%);
    height: min(82vh, 760px);
    background: #fff;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    animation: tutIn 0.35s ease-out;
}

.tut-portrait {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem 1.5rem;
    background: linear-gradient(160deg, var(--tut-blue) 0%, var(--tut-ink) 100%) center / cover no-repeat;
    transition: background-image 0.4s ease;
}

.tut-name {
    font-family: 'Lilita One', cursive;
    font-size: 1.25rem;
    color: #fff;
    background: rgba(0, 0, 0, 0.4);
    padding: 0.35rem 1.1rem;
    border-radius: 999px;
    text-align: center;
}

.tut-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 1.75rem 2rem 1.25rem;
}

.tut-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 3px solid rgba(74, 158, 255, 0.25);
}

#tutorial-icon {
    font-size: 2.2rem;
    line-height: 1;
}

#tutorial-title {
    flex: 1;
    margin: 0;
    font-family: 'Lilita One', cursive;
    font-size: clamp(1.3rem, 2.2vw, 1.9rem);
    font-weight: normal;
    color: var(--tut-ink);
}

.tut-text {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem 0.5rem 1rem 0;
    font-size: 1.15rem;
    line-height: 1.65;
    font-weight: 500;
}

.tut-text::after {
    content: '';
    display: block;
    clear: both;
}

/* as imagens vêm inline no texto dos passos com width:100%: no desktop ficam ao lado do texto
   (:not(.ui-icon): os ícones SVG de uiIconsIn ficam na linha, do tamanho da letra) */
.tut-text img:not(.ui-icon) {
    float: right;
    width: 45% !important;
    margin: 0.25rem 0 1rem 1.5rem !important;
    border-radius: 12px !important;
}

.tut-hint {
    margin-top: 0.5rem;
    padding: 0.7rem 1rem;
    border-radius: 12px;
    background: #fff6d1;
    border: 2px solid #ffc845;
    color: #5a4300;
    font-weight: 600;
    animation: tutIn 0.25s ease-out;
}

.tut-hint[hidden] {
    display: none;
}

.tut-footer {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--tut-line);
}

.tut-progress {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--tut-muted);
}

#tutorial-progress {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tut-progress-bar {
    max-width: 320px;
    height: 8px;
    background: var(--tut-line);
    border-radius: 999px;
    overflow: hidden;
}

#tutorial-progress-fill {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--tut-blue), var(--tut-green));
    transition: width 0.3s ease;
}

.tut-nav {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.tut-btn {
    white-space: nowrap;
    min-height: 44px;
    padding: 0.65rem 1.4rem;
    border: none;
    border-radius: 14px;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.tut-btn:focus-visible {
    outline: 3px solid var(--tut-blue);
    outline-offset: 2px;
}

.tut-btn[hidden] {
    display: none;
}

.tut-btn--primary {
    background: var(--tut-green);
    color: #fff;
    box-shadow: 0 4px 0 var(--tut-green-dark);
}

.tut-btn--primary:hover:not(:disabled) {
    background: #00964f;
}

.tut-btn--primary:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--tut-green-dark);
}

.tut-btn--primary:disabled {
    background: #b8c2d6;
    box-shadow: 0 4px 0 #9aa5bc;
    cursor: not-allowed;
}

.tut-btn--ghost {
    background: #fff;
    color: var(--tut-ink);
    border: 2px solid #d5dcea;
}

.tut-btn--ghost:hover:not(:disabled) {
    background: #f2f5fb;
}

.tut-btn--ghost:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tut-btn--link {
    background: none;
    color: var(--tut-muted);
    text-decoration: underline;
    padding-inline: 0.5rem;
}

.tut-btn--link:hover {
    color: var(--tut-ink);
}

/* ===== MODO COACH ===== */
#tutorial-container.tutorial--coach {
    pointer-events: none; /* o jogo continua clicável; só o card captura cliques */
    background: transparent;
    padding: 16px;
}

.tutorial--coach #tutorial-background {
    display: none;
}

#tutorial-container.tutorial--coach[data-dock-y="bottom"] { align-items: flex-end; }
#tutorial-container.tutorial--coach[data-dock-y="top"] { align-items: flex-start; padding-top: 72px; }
#tutorial-container.tutorial--coach[data-dock-x="left"] { justify-content: flex-start; }
#tutorial-container.tutorial--coach[data-dock-x="right"] { justify-content: flex-end; }

.tutorial--coach .tut-card {
    pointer-events: auto;
    grid-template-columns: 120px minmax(0, 1fr);
    width: min(600px, 100%);
    height: auto;
    max-height: 48vh;
    border: 3px solid var(--tut-blue);
    border-radius: 20px;
}

.tutorial--coach .tut-portrait {
    padding: 0.75rem 0.5rem;
    gap: 0.4rem;
}

.tutorial--coach .tut-name {
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
}

.tutorial--coach .tut-body {
    padding: 0.9rem 1.2rem 0.8rem;
}

.tutorial--coach .tut-header {
    padding-bottom: 0.5rem;
    border-bottom-width: 2px;
}

.tutorial--coach #tutorial-icon {
    font-size: 1.6rem;
}

.tutorial--coach .read-aloud-btn {
    width: 36px;
    height: 36px;
    font-size: 1.05rem;
}

.tutorial--coach #tutorial-title {
    font-size: 1.3rem;
}

.tutorial--coach .tut-text {
    padding: 0.6rem 0;
    font-size: 1rem;
    line-height: 1.5;
}

.tutorial--coach .tut-footer {
    padding-top: 0.6rem;
}

/* Texto longo no coach: a linha do grid fica presa ao max-height do cartão, só #tutorial-text rola
   e cabeçalho, dica e rodapé ficam fixos (o rodapé ficava cortado e não dava para clicar) */
.tutorial--coach .tut-card {
    grid-template-rows: minmax(0, 1fr);
}

.tutorial--coach .tut-body {
    min-height: 0;
    overflow: hidden;
}

.tutorial--coach .tut-header,
.tutorial--coach .tut-hint,
.tutorial--coach .tut-footer {
    flex-shrink: 0;
}

.tutorial--coach .tut-text {
    flex: 1 1 auto;
    min-height: 3em;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.tutorial--coach .tut-btn {
    min-height: 40px;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
}

/* Spotlight: escurece tudo menos o alvo; não intercepta cliques */
#tutorial-spotlight {
    position: fixed;
    z-index: 1;
    pointer-events: none;
    border-radius: 14px;
    box-shadow: 0 0 0 9999px rgba(8, 20, 48, 0.55);
    transition: left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease;
}

#tutorial-spotlight::after {
    content: '';
    position: absolute;
    inset: -4px;
    border: 3px solid #ffc845;
    border-radius: 18px;
    animation: tutPulse 1.4s ease-in-out infinite;
}

#tutorial-spotlight[hidden] {
    display: none;
}

@keyframes tutIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes tutPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(1.05); }
}

@media (prefers-reduced-motion: reduce) {
    .tut-card, .tut-hint, #tutorial-spotlight::after { animation: none; }
    #tutorial-spotlight { transition: none; }
}

/* ===== TUTORIAL MOBILE ===== */
@media screen and (max-width: 768px) {
    #tutorial-container.tutorial--story {
        padding: 0;
        align-items: stretch;
    }

    .tut-card {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .tut-portrait {
        flex-direction: row;
        justify-content: flex-start;
        gap: 0.75rem;
        padding: 0.6rem 1rem;
    }

    .tut-name {
        font-size: 1rem;
    }

    .tut-body {
        padding: 0.9rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    }

    #tutorial-icon {
        font-size: 1.7rem;
    }

    .tut-text {
        font-size: 1rem;
        line-height: 1.55;
        padding-right: 0;
    }

    .tut-text img:not(.ui-icon) {
        float: none;
        width: 100% !important;
        margin: 0.5rem 0 !important;
    }

    .tut-footer {
        flex-wrap: wrap;
        gap: 0.6rem;
    }

    .tut-progress {
        flex-basis: 100%;
    }

    .tut-progress-bar {
        max-width: none;
    }

    .tut-nav {
        width: 100%;
    }

    #tutorial-next-btn {
        flex: 1;
    }

    /* coach vira uma folha encostada embaixo (ou em cima) da tela */
    #tutorial-container.tutorial--coach {
        padding: 8px;
        justify-content: center;
    }

    #tutorial-container.tutorial--coach[data-dock-y="top"] {
        padding-top: 8px;
    }

    .tutorial--coach .tut-card {
        grid-template-columns: 72px minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr);
        width: 100%;
        max-height: 50vh;
        border-radius: 16px;
    }

    .tutorial--coach .tut-portrait {
        flex-direction: column;
        justify-content: center;
        padding: 0.4rem;
    }

    .tutorial--coach .tut-name {
        display: none;
    }

    .tutorial--coach #tutorial-next-btn {
        flex: 0 1 auto;
        margin-left: auto;
    }

    .tutorial--coach .tut-nav {
        gap: 0.4rem;
    }

    .tutorial--coach .tut-btn {
        padding: 0.5rem 0.8rem;
    }

    .tutorial--coach .tut-btn--link {
        padding-inline: 0.2rem;
    }

    .tutorial--coach .tut-body {
        padding: 0.6rem 0.9rem 0.7rem;
    }

    .tutorial--coach .tut-progress {
        display: none;
    }
}

@media screen and (max-width: 768px) and (orientation: landscape) {
    .tut-card {
        grid-template-columns: 140px minmax(0, 1fr);
        grid-template-rows: none;
    }

    .tut-portrait {
        flex-direction: column;
        justify-content: center;
    }

    .tutorial--coach .tut-card {
        grid-template-rows: minmax(0, 1fr);
        max-height: 70vh;
        width: min(560px, 100%);
    }
}

/* ===== Situação de emergência no fim de jogo (GameOverSystem.renderEmergencyOffer / declareEmergency) ===== */
#gameover-container .emergency-btn {
    background: linear-gradient(180deg, #ff7043, #e53935);
    border-color: #fff;
    color: #fff;
    animation: emergencyPulse 1.6s ease-in-out infinite;
}

#gameover-container .emergency-btn small { opacity: 0.9; }

#gameover-container .emergency-offer {
    margin-top: 0.8rem;
    padding: 0.6rem 0.8rem;
    border-radius: 12px;
    border: 2px dashed #e53935;
    background: rgba(229, 57, 53, 0.08);
}

#gameover-container .emergency-offer p { margin: 0.25rem 0; }
#gameover-container .emergency-offer.used { border-style: solid; border-color: #9e9e9e; background: rgba(0, 0, 0, 0.05); }

@keyframes emergencyPulse {
    0%, 100% { box-shadow: 0 4px 0 #8e1b17, 0 0 0 rgba(229, 57, 53, 0); }
    50% { box-shadow: 0 4px 0 #8e1b17, 0 0 18px rgba(229, 57, 53, 0.75); }
}

@media (prefers-reduced-motion: reduce) {
    #gameover-container .emergency-btn { animation: none; }
}
