/*
 * Puzzle game: mobile landscape only.
 *
 * Every visual override for this mode belongs in this file and must be scoped
 * below html.puzzle-mobile-landscape. Desktop and mobile portrait styles remain
 * in the page template and are not affected by this layer.
 */

@media (orientation: landscape) and (max-width: 1024px) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
    html.puzzle-mobile-landscape {
        /* Safe hooks for upcoming landscape layout work. */
        --puzzle-landscape-viewport-width: 100vw;
        --puzzle-landscape-viewport-height: 100svh;
        --puzzle-landscape-header-height: 64px;
        --puzzle-landscape-menu-top: max(72px, calc(env(safe-area-inset-top) + 64px));
    }

    /* Parent puzzle page: collapse the decorative site header. */
    html.puzzle-mobile-landscape #header {
        position: relative !important;
        width: 100% !important;
        height: 0 !important;
        min-height: 0 !important;
        overflow: visible !important;
        z-index: 100000;
    }

    html.puzzle-mobile-landscape #header .headerImage,
    html.puzzle-mobile-landscape #header .logo,
    html.puzzle-mobile-landscape #header #logo,
    html.puzzle-mobile-landscape #header #learning,
    html.puzzle-mobile-landscape #header #note {
        display: none !important;
    }

    /* Keep only the existing mobile navigation button at the top-right. */
    html.puzzle-mobile-landscape #mainNav {
        position: fixed !important;
        top: max(6px, env(safe-area-inset-top)) !important;
        right: max(6px, env(safe-area-inset-right)) !important;
        width: 50px;
        height: 50px;
        margin: 0 !important;
        z-index: 100001;
    }

    html.puzzle-mobile-landscape #mainNav .site-menu {
        padding: 0 !important;
        background: transparent !important;
    }

    html.puzzle-mobile-landscape #mobile-menu-btn {
        display: block !important;
        position: absolute !important;
        inset: 0 !important;
        width: 50px !important;
        height: 50px !important;
        padding: 0 !important;
        background: #1e90ff !important;
        color: #fff !important;
        border: 2px solid #fff !important;
        border-radius: 8px !important;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3) !important;
        font-size: 32px !important;
        line-height: 44px !important;
        cursor: pointer !important;
        z-index: 100002;
    }

    /* Navigation drawer opened by the landscape menu button. */
    html.puzzle-mobile-landscape #primary-menu {
        display: none !important;
        position: fixed !important;
        top: calc(max(6px, env(safe-area-inset-top)) + 58px) !important;
        right: max(6px, env(safe-area-inset-right)) !important;
        width: 250px !important;
        margin: 0 !important;
        padding: 10px !important;
        flex-direction: column !important;
        background: #1e90ff !important;
        border: 2px solid #fff;
        border-radius: 8px;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
        z-index: 100001;
    }

    html.puzzle-mobile-landscape #primary-menu.menu-open {
        display: flex !important;
    }

    html.puzzle-mobile-landscape #primary-menu .menu-item {
        display: block;
        width: 100%;
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    }

    html.puzzle-mobile-landscape #primary-menu .menu-item a {
        display: block;
        padding: 10px;
        color: #fff;
    }

    html.puzzle-mobile-landscape #puzzle-menu-page {
        width: var(--puzzle-landscape-viewport-width);
        max-width: none;
        height: auto;
        min-height: 100svh;
        margin-top: 0;
        margin-bottom: 0;
        padding-top: var(--puzzle-landscape-menu-top);
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        box-sizing: border-box;
        align-items: flex-start;
        background-position: center;
        background-size: cover;
    }

    html.puzzle-mobile-landscape #puzzle-menu-page.game-active {
        height: 100svh;
        min-height: 100svh;
        margin: 0;
        padding: 0;
        position: relative;
        background: #fff;
        overflow: hidden;
    }

    html.puzzle-mobile-landscape #puzzle-menu-page.game-active #game-frame {
        position: absolute;
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        margin: 0;
    }

    html.puzzle-mobile-landscape #puzzle-menu-page.game-active + #gameCursel {
        display: block;
        position: relative;
        margin-top: 0;
    }

    html.puzzle-mobile-landscape .puzzle-menu-panel {
        height: auto;
        min-height: 0;
        max-height: none;
        margin-top: 0;
        margin-bottom: 0;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
    }

    html.puzzle-mobile-landscape .puzzle-menu-panel::before,
    html.puzzle-mobile-landscape .puzzle-menu-panel::after {
        content: "";
        position: fixed;
        top: 0;
        pointer-events: none;
    }

    html.puzzle-mobile-landscape .puzzle-menu-panel::before {
        left: 0;
        width: 100vw;
        height: var(--puzzle-landscape-header-height);
        background: url("/puzzle-game/images/headerBar.png") center top / 100% 100% no-repeat;
        z-index: 1;
    }

    html.puzzle-mobile-landscape .puzzle-menu-panel::after {
        left: 50%;
        width: 224px;
        height: 91px;
        background: url("/puzzle-game/images/puzzleLogo.png") center top / contain no-repeat;
        transform: translateX(-50%);
        z-index: 2;
    }

    html.puzzle-mobile-landscape .puzzle-subject-list {
        flex: 0 0 auto;
        min-height: auto;
        max-height: none;
        overflow: visible;
        -webkit-overflow-scrolling: auto;
        overscroll-behavior: auto;
        scrollbar-gutter: auto;
        scrollbar-width: auto;
    }

    html.puzzle-mobile-landscape .puzzle-start-btn {
        flex: 0 0 auto;
    }

    html.puzzle-mobile-landscape .puzzle-subject-list::-webkit-scrollbar {
        width: 18px;
    }

    html.puzzle-mobile-landscape .puzzle-subject-list::-webkit-scrollbar-track {
        background: rgba(5, 10, 25, 0.88);
        border-radius: 8px;
    }

    html.puzzle-mobile-landscape .puzzle-subject-list::-webkit-scrollbar-thumb {
        background: #63b32e;
        min-height: 44px;
        border: 3px solid rgba(5, 10, 25, 0.88);
        border-radius: 8px;
    }

    /* Iframe game layout: full viewport with a vertical choice rail. */
    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape body {
        width: 100vw;
        height: 100svh;
        margin: 0 !important;
        overflow: hidden;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape #animation_container {
        position: relative !important;
        width: 100vw !important;
        height: 100svh !important;
        overflow: hidden !important;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape #canvas,
    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape #dom_overlay_container {
        position: absolute !important;
        inset: 0 !important;
        width: 100vw !important;
        height: 100svh !important;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape #dom_overlay_container {
        overflow: visible !important;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape #answer-bar {
        /* Positive values spread both columns outward; negative values pull them inward. */
        --puzzle-landscape-column-spacing-adjust: 0px;
        --puzzle-landscape-column-shift-min: -12px;
        --puzzle-landscape-column-shift-max: 12px;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100svh !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box;
        display: block;
        pointer-events: none;
        z-index: 2000;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape #target-pill {
        position: absolute;
        top: calc(var(--puzzle-landscape-puzzle-top) + var(--puzzle-landscape-puzzle-height) - 4px);
        right: auto;
        left: 50%;
        width: auto;
        max-width: min(70vw, var(--puzzle-landscape-puzzle-width));
        margin: 0;
        padding: 5px 8px;
        box-sizing: border-box;
        transform: translate(-50%, -100%);
        font-size: clamp(20px, 5.5svh, 28px);
        font-weight: 700;
        line-height: 1.05;
        text-align: center;
        white-space: nowrap;
        pointer-events: auto;
        z-index: 3;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape.puzzle-game-complete #target-pill {
        top: var(--puzzle-landscape-complete-target-top) !important;
        transform: translate(-50%, -50%) !important;
        z-index: 5;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape.puzzle-game-complete #answer-bar::before {
        content: "";
        position: absolute;
        top: max(0px, env(safe-area-inset-top));
        left: 50%;
        width: clamp(130px, 20vw, 200px);
        aspect-ratio: 224 / 91;
        background: url("/puzzle-game/images/puzzleLogo.png") center / contain no-repeat;
        transform: translateX(-50%);
        pointer-events: none;
        z-index: 4;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape .choice-row {
        position: absolute;
        top: var(--puzzle-landscape-puzzle-top);
        right: auto;
        bottom: auto;
        left: 50%;
        width: calc(var(--puzzle-landscape-puzzle-width) + var(--puzzle-landscape-choice-size) + var(--puzzle-landscape-choice-size) + var(--puzzle-landscape-choice-gap) + var(--puzzle-landscape-choice-gap));
        height: var(--puzzle-landscape-puzzle-height);
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        display: grid;
        grid-template-columns: var(--puzzle-landscape-choice-size) var(--puzzle-landscape-puzzle-width) var(--puzzle-landscape-choice-size);
        grid-template-rows: repeat(2, var(--puzzle-landscape-choice-size));
        column-gap: var(--puzzle-landscape-choice-gap);
        row-gap: var(--puzzle-landscape-choice-gap);
        justify-content: center;
        align-content: space-evenly;
        transform: translateX(-50%);
        pointer-events: none;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape .choice-card {
        width: var(--puzzle-landscape-choice-size) !important;
        height: var(--puzzle-landscape-choice-size) !important;
        pointer-events: auto;
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape .choice-card:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
        left: calc(0px - clamp(var(--puzzle-landscape-column-shift-min), var(--puzzle-landscape-column-spacing-adjust), var(--puzzle-landscape-column-shift-max)));
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape .choice-card:nth-child(2) {
        grid-column: 3;
        grid-row: 1;
        left: clamp(var(--puzzle-landscape-column-shift-min), var(--puzzle-landscape-column-spacing-adjust), var(--puzzle-landscape-column-shift-max));
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape .choice-card:nth-child(3) {
        grid-column: 1;
        grid-row: 2;
        left: calc(0px - clamp(var(--puzzle-landscape-column-shift-min), var(--puzzle-landscape-column-spacing-adjust), var(--puzzle-landscape-column-shift-max)));
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape .choice-card:nth-child(4) {
        grid-column: 3;
        grid-row: 2;
        left: clamp(var(--puzzle-landscape-column-shift-min), var(--puzzle-landscape-column-spacing-adjust), var(--puzzle-landscape-column-shift-max));
    }

    @keyframes puzzleLandscapeChoiceRowIn {
        from {
            transform: translateX(calc(-50% + 100vw));
            opacity: 0;
        }

        to {
            transform: translateX(-50%);
            opacity: 1;
        }
    }

    html.puzzle-mobile-landscape.puzzle-game-iframe-landscape .choice-row.choice-row-enter-right {
        animation: puzzleLandscapeChoiceRowIn 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards !important;
    }

    /* Add iframe game layout overrides below this point. */
}
