/* L'application occupe exactement le viewport, sans scroll du document. */
html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background-color: #000;
    font-family: "Slabo", Georgia, serif;
}

body {
    min-height: 0;
    display: flex;
    justify-content: center;
    text-align: center;
}

main {
    box-sizing: border-box;
    width: 100%;
    height: 100dvh;
    max-width: none;
    padding-inline: 0;
    padding-bottom: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

main.container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
}

main > .grid {
    width: 100%;
}

main > .grid:first-child {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-part {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(0.25rem, 1vh, 0.75rem);
    min-height: 0;
    margin: 0;
    padding: 0.25rem;
    width: 100%;
    height: 100%;
    text-align: center;
}

.game-part h1,
.game-part h2,
.game-part img,
.game-part button {
    display: none;
    margin: 0;
}

.game-part h1 {
    position: relative;
    color: #eee8d5;
    font-family: "Cormorant Garamond", Georgia, serif;
    font-size: clamp(2rem, 13vw, 5rem);
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 0.95;
    text-shadow: 0 2px 18px #c9a85c35;
}

.game-part h1.glitch-haunted {
    --glitch-opacity: 1;
    color: rgb(238 232 213 / calc(1 - var(--glitch-opacity)));
    text-shadow: none;
    animation: haunted-flicker 0.1s infinite steps(1, end);
}

.game-part h1.glitch-haunted::before,
.game-part h1.glitch-haunted::after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    overflow: hidden;
    content: attr(data-text);
    pointer-events: none;
    opacity: var(--glitch-opacity);
    transition: opacity 0.15s ease;
}

.game-part h1.glitch-haunted::before {
    color: #69222e;
    clip-path: inset(0 0 55% 0);
    animation: haunted-red 0.5s infinite steps(2, end);
    transform: translate(0.025em, -0.015em);
}

.game-part h1.glitch-haunted::after {
    color: #ff0101;
    clip-path: inset(58% 0 0 0);
    animation: haunted-blue 0.5s infinite steps(2, end);
    transform: translate(0.025em, 0.015em);
}

@keyframes haunted-flicker {
    0%, 92%, 100% { opacity: 1; }
    93% { opacity: 0.75; }
    94% { opacity: 1; }
    97% { opacity: 0.88; }
}

@keyframes haunted-red {
    0%, 100% { clip-path: inset(0 0 55% 0); }
    20% { clip-path: inset(35% 0 42% 0); transform: translate(0em, 0.02em); }
    45% { clip-path: inset(70% 0 10% 0); }
    70% { clip-path: inset(10% 0 78% 0); transform: translate(0.08em, -0.02em); }
}

@keyframes haunted-blue {
    0%, 100% { clip-path: inset(58% 0 0 0); }
    25% { clip-path: inset(62% 0 20% 0); transform: translate(0em, 1.02em); }
    50% { clip-path: inset(18% 0 60% 0); }
    80% { clip-path: inset(78% 0 4% 0); transform: translate(0em, 1em); }
}

.game-part h2 {
    max-width: min(80vw, 48rem);
    color: #b9b09b;
    font-family: "Slabo", Georgia, serif;
    font-size: clamp(1.25rem, 2.5vw, 2rem);
    font-weight: 400;
    font-style: italic;
    letter-spacing: 0.08em;
    line-height: 1.4;
}

.image-compare {
    position: relative;
    display: block;
    flex: none;
    max-width: 100%;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.image-compare.image-switching {
    opacity: 0;
}

.image-compare.image-noise .page-image {
    filter: url("#image-noise");
}

.image-compare.image-noise::after {
    position: absolute;
    inset: 0;
    content: "";
    pointer-events: none;
    opacity: 0.2;
    mix-blend-mode: screen;
    background: repeating-linear-gradient(
        0deg,
        transparent 0,
        transparent 3px,
        #fff2 4px,
        transparent 5px
    );
    animation: image-noise-scan 0.18s steps(2, end) infinite;
}

@keyframes image-noise-scan {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-1%, 1%); }
    50% { transform: translate(1%, -1%); }
    75% { transform: translate(0.5%, 0); }
    100% { transform: translate(-0.5%, 0.5%); }
}

.image-compare[hidden] {
    display: none;
}

.game-part .page-image {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.game-part .page-image-ia {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 1;
    background-color: #000;
}

.flag-game-layer[hidden] { display: none; }
.flag-game-layer { position: absolute; inset: 0; z-index: 3; }
.flag-piece {
    position: absolute;
    width: 13%;
    max-width: 9rem;
    cursor: grab;
    user-select: none;
    touch-action: none;
    transition: filter 0.2s, transform 0.2s;
}
.game-part .flag-piece { display: block; }
.flag-piece:active { cursor: grabbing; transform: scale(1.04); }
.flag-piece.flag-placed { filter: drop-shadow(0 0 0.5rem #d8bd68); }
.flag-slot { position: absolute; border: 1px dashed #d8bd6866; border-radius: 0.25rem; pointer-events: none; }

.game-part button {
    width: auto;
    min-width: 10rem;
    padding: 0.7rem 1.6rem;
    color: #eee8d5;
    font-family: "Slabo", Georgia, serif;
    font-size: 1rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    background: #16130d;
    border: 1px solid #b89a5a;
    border-radius: 0.15rem;
    box-shadow: 0 0 0 1px #b89a5a22 inset, 0 5px 20px #0008;
    transition: color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.game-part button:hover,
.game-part button:focus-visible {
    color: #16130d;
    background: #c9aa68;
    box-shadow: 0 0 20px #c9aa6840;
}

.game-part button.button-fade-in {
    animation: button-fade-in 0.8s ease both;
}

@keyframes button-fade-in {
    from { opacity: 0; transform: translateY(0.5rem); }
    to { opacity: 1; transform: translateY(0); }
}

main > .grid:last-child {
    flex-shrink: 0;
    margin-top: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.rangeWrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    width: 100%;
    padding: 1rem;
    box-sizing: border-box;
}

.image-text {
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(94vw, 64rem);
    /* Reserve two lines even while the typewriter text is empty. */
    height: 3em;
    min-height: 3em;
    flex-shrink: 0;
    line-height: 1.5;
    overflow: hidden;
    overflow-wrap: anywhere;
    max-width: 94vw;
    color: #b9b09b;
    font-family: "Slabo", Georgia, serif;
    font-size: 1.1rem;
    letter-spacing: 0.04em;
    text-align: center;
}

.volume {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.volumeIcon {
    font-size: 1.25rem;
}

.volume-toggle {
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
}

.volume-toggle:hover,
.volume-toggle:focus {
    background: transparent;
    box-shadow: none;
}

.volume-range {
    display: none;
}

.bar-hoverbox {
    width: 9rem;
    padding: 0.6rem 0.75rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.bar-hoverbox:hover {
    opacity: 1;
    cursor: pointer;
}

.bar {
    height: 0.45rem;
    width: 100%;
    overflow: hidden;
    pointer-events: none;
    background: #999;
    border-radius: 999px;
}

.bar-fill {
    width: 0%;
    height: 100%;
    pointer-events: none;
    background: #fff;
}

.rangeWrap input[type="range"] {
    width: 100%;
    height: 1.5rem;
    appearance: none;
    background: linear-gradient(180deg, #8f813d, #706048, #7a702a);
    border-radius: 1.5rem;
    box-shadow: 0 3px 2px -1px #ffffff40 inset, 0 0 10px #00000080,
        0 8px 4px -3px #00000026;
}

.rangeWrap input[type="range"]::-webkit-slider-runnable-track {
    height: 0.25rem;
    margin: 0 0.5rem;
    background: #222;
    border: 1px solid #00000040;
    border-radius: 1.5rem;
    box-shadow: 0 1px 1px #ffffff40, 0 2px 2px #ffffff26;
}

.rangeWrap input[type="range"]::-webkit-slider-thumb {
    width: 3rem;
    height: 3rem;
    margin-top: -1.375rem;
    appearance: none;
    cursor: pointer;
    border: 0;
    border-radius: 50%;
    background: radial-gradient(#444 45%, #555 50%, #222 55%, #8c7853 57.5%, #8c7853 100%),
        conic-gradient(#4b4b4b 10deg, #777 45deg, #5b5b6b 70deg, #9f9f9f 105deg,
            #444 140deg, #aaa 185deg, #666 210deg, #999 245deg, #777 285deg,
            #9f9f9f 320deg, #4b4b4b);
    background-blend-mode: overlay;
    box-shadow: 0 0 1px 1px #ffffff59 inset, 0 1px 1px 1px #ffffff40 inset,
        0 0 2px 2px #00000026 inset, 0 3px 2px 1px #00000040, 0 6px 4px 3px #00000026;
}

.rangeLabels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: -0.5rem;
}

#song-name {
    flex: 1;
    color: #b9b09b;
    font-size: 0.9rem;
    text-align: center;
}

.menu-dock {
    width: 100%;
    padding: 0 0.5rem;
    box-sizing: border-box;
}

.menu-dock-list {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 0.15rem;
    min-height: 4rem;
    width: 100%;
    box-sizing: border-box;
    padding: 0.4rem;
    overflow: visible;
    background: #ffffff12;
    border: 1px solid #ffffff20;
    border-radius: 1rem;
    box-shadow: 0 4px 30px #0008, 0 0 1em 1em #0005;
    backdrop-filter: blur(5px);
}

.menu-item {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    transform-origin: bottom;
    transition: transform 0.25s ease, margin 0.25s ease;
}

.menu-item:hover,
.menu-item:focus-visible {
    z-index: 2;
    transform: scale(2.2);
    margin-inline: 1rem;
    background: transparent;
    box-shadow: none;
}

.menu-item img,
.menu-item .menu-placeholder {
    display: block;
    width: 80%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 0.5rem;
}

.menu-placeholder {
    background: #ffffff22;
}

.music-menu-icon {
    display: grid;
    place-items: center;
    width: 80%;
    aspect-ratio: 1;
    border-radius: 0.5rem;
    color: #eee8d5;
    background: #b89a5a22;
    font: 1.7rem Georgia, serif;
}
.menu-item[href] { text-decoration: none; }

.menu-label {
    position: absolute;
    bottom: 100%;
    left: 50%;
    min-width: max-content;
    padding: 0.1rem 0.4rem;
    color: #000;
    font-size: 0.55rem;
    background: #aaad;
    border-radius: 0.4rem;
    opacity: 0;
    transform: translateX(-50%);
    transition: opacity 0.2s ease;
}

.menu-item:hover .menu-label,
.menu-item:focus-visible .menu-label {
    opacity: 1;
}
