/**
 * Alkimia : L'Atelier des Runes — Styles du Jeu Complet (Pop & Sticker Clair)
 * Plein écran 100dvh, zéro header web, zéro footer web, zéro marron, zéro doré.
 */

.play-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    height: 100dvh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding:
        calc(80px + var(--safe-top)) calc(12px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(12px + var(--safe-left));
    overflow: hidden;
}

/* Coins flottants : Logo haut-gauche & Menu haut-droite uniquement */
.hud-corner {
    position: fixed;
    top: calc(12px + var(--safe-top));
    z-index: 30;
}

.hud-corner--tl {
    left: calc(14px + var(--safe-left));
}

.hud-corner--tr {
    right: calc(14px + var(--safe-right));
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Bouton Son rapide : affiché uniquement sur tactile ou petit écran */
.sound-quick-btn {
    display: none;
    width: 46px;
    height: 46px;
    flex-shrink: 0;
}

.sound-quick-btn.is-muted {
    background: linear-gradient(180deg, #eef3f9 0%, #dce6f2 100%);
}

@media (max-width: 1023px),
(hover: none),
(pointer: coarse) {
    .sound-quick-btn {
        display: inline-flex;
    }
}

.brand-medallion {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.34rem 0.95rem 0.34rem 0.42rem;
    border-radius: 18px;
    border: 2.5px solid var(--ink-outline);
    background: linear-gradient(180deg, #ffffff 0%, #edf4fc 100%);
    box-shadow:
        0 4px 0 var(--ink-outline),
        0 8px 18px rgba(28, 36, 51, 0.14),
        inset 0 2px 0 #ffffff;
}

.brand-medallion__icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: 2px solid var(--ink-outline);
    background: linear-gradient(180deg, #e7f4ff 0%, #cce7ff 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-medallion__title {
    font-family: var(--font-display);
    font-size: clamp(1.05rem, 2.2vw, 1.32rem);
    font-weight: 900;
    letter-spacing: 0.06em;
    color: var(--ink-outline);
    line-height: 1;
}

/* =========================================================
   ÉCRAN 1 : CARTE DE PROGRESSION (5 NIVEAUX)
   ========================================================= */
.grimoire-screen {
    width: min(100%, 560px);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.grimoire-screen[hidden] {
    display: none;
}

.grimoire-status {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.42rem;
    padding: 0.48rem 0.72rem;
    border-radius: 18px;
    border: 2.5px solid var(--ink-outline);
    background-color: var(--surface-white);
    box-shadow: 0 4px 0 var(--ink-outline), 0 8px 18px rgba(28, 36, 51, 0.12);
}

.grimoire-status__top,
.grimoire-status__totals {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
}

.grimoire-status__totals {
    padding-top: 0.36rem;
    border-top: 1.5px solid #dce7f4;
}

.lives-row {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.stat-pill,
.streak-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    padding: 0.22rem 0.58rem;
    border-radius: 999px;
    border: 2px solid var(--ink-outline);
    background-color: #eef6ff;
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--ink-text);
    white-space: nowrap;
}

.stat-pill--stars {
    background-color: #fff7d6;
}

.stat-pill--score {
    background-color: #e8f5ff;
}

.stat-pill__mono {
    font-family: var(--font-mono);
    font-weight: 900;
    letter-spacing: -0.01em;
}

.grimoire-notice {
    width: 100%;
    padding: 0.45rem 0.75rem;
    border-radius: 14px;
    border: 2px solid var(--ink-outline);
    background-color: #fff0ee;
    color: #b7231e;
    font-size: 0.82rem;
    font-weight: 800;
    text-align: center;
}

.grimoire-notice[hidden] {
    display: none;
}

.grimoire-board {
    width: 100%;
    flex: 1;
    min-height: 0;
    padding: 0.7rem 0.75rem;
    border-radius: 26px;
    border: 3px solid var(--ink-outline);
    background: linear-gradient(180deg, #ffffff 0%, #dce9f7 100%);
    box-shadow: 0 7px 0 var(--ink-outline), 0 18px 34px rgba(28, 36, 51, 0.16);
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    overflow: hidden;
}

.chapter-nav {
    width: 100%;
    flex-shrink: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.45rem;
    border-bottom: 2px solid #c9dbee;
}

.chapter-nav__btn {
    width: 38px;
    height: 38px;
}

.chapter-nav__btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 0 var(--ink-outline);
}

.chapter-nav__info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.14rem;
    min-width: 0;
}

.chapter-nav__title {
    font-family: var(--font-display);
    font-size: 0.96rem;
    font-weight: 900;
    color: var(--ink-outline);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.chapter-nav__stars {
    display: inline-flex;
    align-items: center;
    gap: 0.24rem;
    padding: 0.08rem 0.48rem;
    border-radius: 999px;
    border: 1.5px solid var(--ink-outline);
    background-color: #fff7d6;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 900;
    color: var(--ink-text);
}

.map-nodes {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.52rem;
    overflow-y: auto;
    padding: 2px 2px 6px;
}

.level-node {
    position: relative;
    width: 100%;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 0.78rem;
    border-radius: 16px;
    border: 2.5px solid var(--ink-outline);
    background: linear-gradient(180deg, #ffffff 0%, #f1f6fd 100%);
    color: var(--ink-text);
    text-align: left;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--ink-outline);
    transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.12s ease;
}

.level-node:hover:not(:disabled) {
    background: linear-gradient(180deg, #ffffff 0%, #e1eefc 100%);
}

.level-node:active:not(:disabled) {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--ink-outline);
}

.level-node.is-current {
    background: linear-gradient(180deg, #e7f4ff 0%, #cfe8ff 100%);
}

.level-node.has-play-label {
    margin-block-start: 0.5rem;
}

.level-node.has-play-label .level-node__stars {
    align-self: end;
}

.level-node__play-label {
    position: absolute;
    inset-block-start: -0.34rem;
    inset-inline-end: 0.72rem;
    padding: 0.1rem 0.42rem;
    border: 2px solid var(--ink-outline);
    border-radius: 5px;
    background-color: #fff7d6;
    color: var(--ink-outline);
    box-shadow: 1px 2px 0 var(--ink-outline);
    font-family: var(--font-display);
    font-size: 0.72rem;
    font-weight: 900;
    line-height: 1.15;
    letter-spacing: 0.045em;
    text-transform: uppercase;
    transform: rotate(8deg);
}

.level-node.is-locked {
    opacity: 0.58;
    cursor: not-allowed;
    background: #e5edf6;
}

.level-node__num {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    border: 2.5px solid var(--ink-outline);
    background: linear-gradient(180deg, var(--pop-blue-top) 0%, var(--pop-blue) 100%);
    color: #ffffff;
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.level-node.is-locked .level-node__num {
    background: #b8c7d9;
    color: var(--ink-outline);
}

.level-node__info {
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
    min-width: 0;
}

.level-node__title {
    font-family: var(--font-display);
    font-size: 0.98rem;
    font-weight: 900;
    color: var(--ink-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.level-node__sub {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--ink-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.level-node__stars {
    display: inline-flex;
    align-items: center;
    gap: 0.12rem;
}

.grimoire-footer-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.55rem;
}

/* =========================================================
   ÉCRAN 2 : PLATEAU EN PARTIE + HUD COMPACT
   ========================================================= */
.play-screen {
    width: 100%;
    max-width: 860px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0.65rem;
}

.play-screen[hidden] {
    display: none;
}

.hud-bar {
    width: min(100%, 640px);
    flex-shrink: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.55rem;
    padding: 0.48rem 0.65rem;
    border-radius: 20px;
    border: 2.5px solid var(--ink-outline);
    background: linear-gradient(180deg, #ffffff 0%, #eef5fd 100%);
    box-shadow: 0 4px 0 var(--ink-outline), 0 8px 18px rgba(28, 36, 51, 0.12);
}

.hud-moves {
    display: inline-flex;
    align-items: center;
    gap: 0.38rem;
    padding: 0.34rem 0.65rem;
    border-radius: 14px;
    border: 2.5px solid var(--ink-outline);
    background: linear-gradient(180deg, var(--pop-blue-top) 0%, var(--pop-blue) 100%);
    color: #ffffff;
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.hud-moves.is-low {
    background: linear-gradient(180deg, var(--pop-coral-top) 0%, var(--pop-coral) 100%);
}

.hud-moves__val {
    font-family: var(--font-display);
    font-size: 1.32rem;
    font-weight: 900;
    line-height: 1;
    min-width: 1.6ch;
    text-align: center;
}

.hud-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.28rem;
    min-width: 0;
}

.hud-level-tag {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--ink-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.hud-goals {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.34rem;
}

.goal-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    padding: 0.18rem 0.5rem;
    border-radius: 999px;
    border: 2px solid var(--ink-outline);
    background-color: #ffffff;
    font-size: 0.78rem;
    font-weight: 900;
    color: var(--ink-text);
}

.goal-pill.is-done {
    background-color: #ddf8e7;
    color: #176c35;
}

.goal-dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 2px solid var(--ink-outline);
    flex-shrink: 0;
}

.goal-dot--ignis {
    background-color: #df3530;
}

.goal-dot--aqua {
    background-color: #1c84e0;
}

.goal-dot--terra {
    background-color: #259c57;
}

.goal-dot--solis {
    background-color: #eb9f16;
}

.goal-dot--umbra {
    background-color: #8f44c7;
}

.goal-dot--aether {
    background-color: #5ec9d4;
}

.hud-score {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.2rem;
    min-width: 84px;
}

.hud-score__val {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    font-weight: 900;
    color: var(--ink-text);
    line-height: 1;
}

.hud-star-progress {
    width: 84px;
    height: 9px;
    appearance: none;
    -webkit-appearance: none;
    border: 1.5px solid var(--ink-outline);
    border-radius: 999px;
    overflow: hidden;
    background-color: #dce7f4;
}

.hud-star-progress::-webkit-progress-bar {
    background-color: #dce7f4;
}

.hud-star-progress::-webkit-progress-value {
    background-color: var(--pop-green);
}

.hud-star-progress::-moz-progress-bar {
    background-color: var(--pop-green);
}

.hud-star-icons {
    display: inline-flex;
    align-items: center;
    gap: 0.1rem;
}

/* Plateau 8×8 carré parfait (ratio 1:1 garanti sur desktop & mobile) */
.board-shell {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.board-frame {
    --board-side: min(calc(100vw - 24px), calc(100dvh - 186px), 780px);
    width: var(--board-side);
    height: var(--board-side);
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    padding: 9px;
    border-radius: 26px;
    border: 3px solid var(--ink-outline);
    background: linear-gradient(180deg, #ffffff 0%, #dce9f7 100%);
    box-shadow:
        0 7px 0 var(--ink-outline),
        0 18px 36px rgba(28, 36, 51, 0.16),
        inset 0 2px 0 #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.board-frame__well {
    width: 100%;
    height: 100%;
    border-radius: 17px;
    border: 2.5px solid #bfd1e6;
    background-color: #f3f7fc;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#board-canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: pointer;
}

/* =========================================================
   MODALES SUPERPOSÉES (MENU & FIN DE NIVEAU)
   ========================================================= */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background-color: rgba(28, 36, 51, 0.44);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-card {
    width: min(92vw, 370px);
    padding: 1.2rem;
    border-radius: 26px;
    border: 3px solid var(--ink-outline);
    background: linear-gradient(180deg, #ffffff 0%, #eef4fc 100%);
    box-shadow:
        0 8px 0 var(--ink-outline),
        0 20px 44px rgba(28, 36, 51, 0.28),
        inset 0 2px 0 #ffffff;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    text-align: center;
}

.modal-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-card__title {
    font-family: var(--font-display);
    font-size: 1.32rem;
    font-weight: 900;
    color: var(--ink-outline);
}

.modal-card__sub {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--ink-muted);
}

.end-stars {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    margin: 0.2rem 0;
}

.end-score {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 900;
    color: var(--ink-text);
}

.end-streak {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--pop-blue-dark);
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.theme-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    text-align: left;
}

.theme-group__label {
    font-size: 0.74rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-muted);
}

.theme-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
}

.theme-picker .game-btn {
    padding: 0.46rem 0.35rem;
    font-size: 0.78rem;
}

/* =========================================================
   SPLASH SCREEN PATOBEUR STUDIO
   ========================================================= */
.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    padding:
        calc(24px + var(--safe-top)) calc(20px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(20px + var(--safe-left));
    background-color: var(--bg-sky);
    background-image:
        radial-gradient(circle at 22% 20%, rgba(77, 179, 255, 0.24) 0%, transparent 45%),
        radial-gradient(circle at 80% 82%, rgba(93, 224, 137, 0.2) 0%, transparent 46%),
        radial-gradient(rgba(28, 36, 51, 0.06) 1.5px, transparent 1.5px),
        linear-gradient(180deg, #f6faff 0%, #e1ecf8 100%);
    background-size: 100% 100%, 100% 100%, 24px 24px, 100% 100%;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.5s ease;
}

html[data-splash] .splash-screen:not([hidden]) {
    display: flex;
}

.splash-screen.is-fading {
    opacity: 0;
}

.splash-screen__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.05rem;
    animation: splash-pop 0.42s cubic-bezier(0.22, 1.18, 0.36, 1) both;
}

.splash-screen__icon {
    width: clamp(160px, 38vw, 220px);
    height: clamp(160px, 38vw, 220px);
    filter: drop-shadow(0 12px 24px rgba(28, 36, 51, 0.18));
}

.splash-screen__svg {
    width: 100%;
    height: 100%;
    display: block;
}

.splash-screen__title {
    font-family: var(--font-display);
    font-size: clamp(1.55rem, 5.2vw, 2.25rem);
    font-weight: 900;
    letter-spacing: 0.04em;
    color: var(--ink-outline);
    text-align: center;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.85);
}

@keyframes splash-pop {
    from {
        opacity: 0;
        transform: scale(0.88) translateY(8px);
    }

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

@media (prefers-reduced-motion: reduce) {
    .splash-screen__card {
        animation: none;
    }
}

@media (min-width: 1024px) {
    .play-viewport {
        padding-top: calc(14px + var(--safe-top));
        padding-bottom: calc(18px + var(--safe-bottom));
    }

    .grimoire-screen {
        padding-top: 62px;
    }

    .hud-bar {
        width: min(640px, calc(100vw - 370px));
    }

    .board-frame {
        --board-side: min(calc(100vw - 48px), calc(100dvh - 118px), 820px);
    }
}

@media (max-width: 540px) {
    .hud-corner--tr {
        gap: 0.38rem;
    }

    .sound-quick-btn {
        width: 42px;
        height: 42px;
    }

    @media (max-width: 390px) {
        .hud-corner--tr {
            gap: 0.3rem;
        }

        .sound-quick-btn {
            width: 38px;
            height: 38px;
        }
    }

    .grimoire-status {
        padding: 0.4rem 0.56rem;
        gap: 0.34rem;
    }

    .grimoire-status__totals {
        padding-top: 0.3rem;
    }

    .stat-pill,
    .streak-pill {
        padding: 0.18rem 0.48rem;
        font-size: 0.74rem;
        gap: 0.25rem;
    }

    .grimoire-board {
        padding: 0.58rem 0.58rem;
        border-radius: 22px;
    }

    .chapter-nav {
        padding-bottom: 0.36rem;
    }

    .chapter-nav__btn {
        width: 34px;
        height: 34px;
    }

    .chapter-nav__title {
        font-size: 0.86rem;
    }

    .play-viewport {
        padding:
            calc(78px + var(--safe-top)) calc(8px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(8px + var(--safe-left));
    }

    .hud-bar {
        padding: 0.4rem 0.48rem;
        gap: 0.35rem;
    }

    .hud-moves {
        padding: 0.28rem 0.48rem;
    }

    .hud-moves__val {
        font-size: 1.12rem;
    }

    .hud-score {
        min-width: 68px;
    }

    .hud-star-progress {
        width: 68px;
    }

    .board-frame {
        --board-side: min(calc(100vw - 16px), calc(100dvh - 178px));
        padding: 6px;
        border-radius: 20px;
    }
}
