/* ==========================================================================
   0. SPLASH / HERO — MEDIUM-WIDTH LANDSCAPE
   Keeps the two-column hero layout from feeling cramped on tablets and
   small laptop windows. Kept separate from the mobile/portrait block below
   so it never touches in-game HUD sizing.
   ========================================================================== */
@media (max-width: 860px) and (min-aspect-ratio: 6/5) {
    .hero-main {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    .hero-copy {
        align-items: center;
        text-align: center;
    }
    .hero-panel .difficulty-row,
    .hero-panel .start-btn {
        justify-content: center;
        align-self: center;
    }
    
}

/* ==========================================================================
   1. MOBILE / PORTRAIT BREAKPOINT
   ========================================================================== */
@media (orientation: portrait), (max-aspect-ratio: 6/5), (max-width: 680px) {
    /* Hero Section Adjustments */
    .hero-main {
        grid-template-columns: 1fr;
        gap: 24px;
    }
    .hero-copy {
        align-items: center;
        text-align: center;
    }
    .hero-panel {
        padding: 18px;
    }
    .hero-panel .difficulty-row,
    .hero-panel .start-btn {
        justify-content: center;
        align-self: center;
    }
    .diff-btn {
    padding: 14px 42px;
    width: 30%;
    border-radius: 100px;
    font-family: var(--font-ui);
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    transition: all .18s;
    } 
    .ach-grid {
        grid-template-columns: 1fr;
    }
    .badge-grid {
        grid-template-columns: 1fr;
    }
    .hero-stat {
        padding: 10px 6px;
    }
    .hero-stat-icon {
        font-size: 1.15rem;
    }
    .hero-stat b {
        font-size: 1.05rem;
    }
    .hero-stat span {
        font-size: .56rem;
    }
    .menu-bar-btn {
        font-size: .74rem;
        padding: 11px 4px;
        gap: 5px;
    }

    /* HUD Layout */
    .hud-left {
        top: calc(max(10px, env(safe-area-inset-top)) + 90px);
        max-width: 40vw;
    }
    .hud-left .stat-card {
        padding: 12px 16px;
        background: rgba(255, 255, 255, 0.02);
    }
    .hud-left .stat-row + .stat-row {
        margin-top: 8px;
        padding-top: 8px;
    }
    .hud-left .stat-value,
    .stat-value {
        font-size: 1.2rem;
    }
    .hud-left .stat-label {
        font-size: .65rem;
    }
    /* Portrait: icons hidden, panel is text + separator lines only */
    .hud-left .stat-icon {
        display: none;
    }
    .hud-left .stat-row {
        gap: 0;
    }

    .hud-center-top {
        top: max(20px, env(safe-area-inset-top));
        left: max(var(--hud-score-left), env(safe-area-inset-left));
        transform: none;
        width: 76%;
        max-width: 76%;
    }

    .hud-right {
        width: 8%;
        min-width: 70px;
        max-width: 120px;
        display: flex;
        flex-direction: column;
        gap: 1.2vh;
        top: max(20px, env(safe-area-inset-top));
        right: max(20px, env(safe-area-inset-right));
    }
    .hud-right .hud-ctrl-btn {
        width: 100%;
        aspect-ratio: 1/1;
        min-width: 44px;
        min-height: 44px;
    }
    .hud-right .hud-ctrl-btn .pause-mark {
        width: 21px;
        height: calc(21px * 0.88);
    }
    .hud-right .hud-ctrl-btn .label {
        font-size: .58rem;
    }
    .hud-right .hud-ctrl-btn .value {
        font-size: 1.2rem;
    }
    .hud-right .hud-ctrl-btn.acc-panel .value {
        font-size: 1.3rem;
    }

    /* Cards & XP */
    .level-xp-card {
        padding: 10px 16px;
        gap: 12px;
        min-height: 58px;
    }
    .level-hex {
        width: 44px;
        height: 44px;
    }
    .level-hex-num {
        font-size: 1.3rem;
    }
    .level-xp-title {
        font-size: .62rem;
    }
    .level-xp-nums {
        font-size: .66rem;
    }
    .level-xp-header {
        margin-bottom: 3px;
    }
    .xp-bar-wrap {
        height: 5px;
    }
    .xp-bar-fill::after {
        width: 11px;
        height: 11px;
        top: -3px;
    }
    .xp-gain {
        font-size: .68rem;
    }

    /* Bottom Section & Keypad */
    .hud-bottom {
        bottom: max(8px, env(safe-area-inset-bottom));
        width: min(480px, calc(100vw - 16px));
        gap: 6px;
    }
    .answer-shell {
        min-height: 56px;
        padding: 8px 14px;
        gap: 8px;
    }
    .answer-display {
        font-size: clamp(1.1rem, 4.5vw, 1.7rem);
    }
    .icon-btn {
        width: 46px;
        height: 46px;
        font-size: 1.1rem;
    }
    .q-type-badge {
        font-size: .65rem;
        padding: 4px 14px;
    }
    .keypad {
        gap: 6px;
    }
    .key {
        min-height: clamp(46px, 8vh, 60px);
        font-size: clamp(1.1rem, 4.5vw, 1.6rem);
        border-radius: 10px;
    }
    .key.enter {
        min-height: calc(clamp(46px, 8vh, 60px) * 2 + 6px);
        font-size: 1.4rem;
    }
    .key.ops {
        font-size: .72rem;
    }
    .key.back {
        font-size: 1.1rem;
    }
}

/* Compact Portrait Modifier (Height-constrained screens) */
@media (max-height: 620px) and (orientation: portrait) {
    .hud-left,
    .hud-right {
        transform: scale(.8);
        transform-origin: top left;
    }
    .hud-right {
        transform-origin: top right;
        min-width: 38px;
    }
    .hud-right .hud-ctrl-btn {
        min-width: 38px;
        min-height: 38px;
    }
    .hud-right .hud-ctrl-btn .pause-mark {
        width: 16px;
        height: calc(16px * 0.88);
    }
    .hud-right .hud-ctrl-btn .value {
        font-size: .95rem;
    }
    .hud-right .hud-ctrl-btn.acc-panel .value {
        font-size: 1rem;
    }
    .key {
        min-height: 38px;
    }
    .key.enter {
        min-height: calc(38px * 2 + 6px);
    }
    .keypad {
        gap: 4px;
    }
    .answer-shell {
        min-height: 44px;
        padding: 6px 10px;
    }
    .level-xp-card {
        min-height: 44px;
        padding: 6px 10px;
    }
    .level-hex {
        width: 36px;
        height: 36px;
    }
    .level-hex-num {
        font-size: 1rem;
    }
    .xp-bar-wrap {
        height: 4px;
    }
    .hud-left .stat-card {
        padding: 8px 10px;
    }
    .stat-value {
        font-size: .95rem;
    }
    .stat-row + .stat-row {
        margin-top: 6px;
        padding-top: 6px;
    }
    .hud-center-top {
        max-width: 75%;
    }
}

/* ==========================================================================
   2. NEAR-SQUARE BREAKPOINT (Tablets, Foldables, Split-screen, ~1:1 ratios)
   ========================================================================== */
@media (min-aspect-ratio: 4/5) and (max-aspect-ratio: 5/4) {
    /* Splash: session panel and stats panel become two separate, equal-width
       cards (instead of one card with a divider) with generous vertical
       rhythm between logo, description, session card, stats card, and the
       bottom nav bar. Mobile/portrait phones fall outside this aspect band
       and are unaffected. */
    .hero-wrap {
        gap: 16px;
        min-height:100vh;
        justify-content:space-between;
    }
    .hero-main {
        gap: 16px;
    }
    .hero-copy{
    margin-top: 5%;

    }

.hero-menu-bar{
    margin-bottom:50px;
}
    .hero-panel {
        background: none;
        border: none;
        box-shadow: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        padding: 0;
        gap: 16px;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
.hero-main{
    display: flex;
    flex-direction: column;
    align-items: center;
}


    .panel-divider {
        display: none;
    }

    .diff-btn {
    padding: 14px 42px;
    width: 30%;
    border-radius: 100px;
    font-family: var(--font-ui);
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    transition: all .18s;
    } 
   
    .session-block,
    .stats-block {
        padding: 18px;
        width: 80%;
        border-radius: var(--radius);
        border: 1px solid var(--border);
        background: var(--surface);
        backdrop-filter: blur(16px) saturate(1.4);
        -webkit-backdrop-filter: blur(16px) saturate(1.4);
    }

    :root {
        --hud-margin: 4%;
        --score-width: 20%;
        --right-width: 10%;
        --center-gap: 0.5%;
    }

    .hud-left {
        left: var(--hud-margin);
        width: var(--score-width);
    }

    .hud-right {
        right: max(40px, env(safe-area-inset-right));
        top: max(20px, env(safe-area-inset-top));
        bottom: max(30px, env(safe-area-inset-top));
        width: 10%;
        max-width: 100px;
        gap: 2%;
    }
    .hud-right .hud-ctrl-btn {
        min-width: 60px;
        min-height: 60px;
    }
    .hud-right .hud-ctrl-btn .pause-mark {
        width: 20px;
        height: calc(20px * 0.88);
    }
    .hud-right .hud-ctrl-btn .value {
        font-size: 1.15rem;
    }
    .hud-right .hud-ctrl-btn.acc-panel .value {
        font-size: 1.25rem;
    }
    .hud-right .hud-ctrl-btn .label {
        font-size: .58rem;
    }

    .hud-center-top {
        left: var(--hud-margin);
        right: calc(var(--hud-margin) + var(--right-width) + var(--center-gap));
        width: auto;
    }

    .level-hex-num {
        font-size: clamp(1rem, 2vw, 1.8rem);
    }
    .level-xp-title {
        font-size: clamp(.55rem, .75vw, .9rem);
    }
    .level-xp-nums {
        font-size: clamp(.65rem, .9vw, 1rem);
    }
    .level-xp-card {
        padding: clamp(.5rem, 1vw, 1rem);
        gap: clamp(.5rem, 1vw, 1rem);
    }
}

/* ==========================================================================
   3. LANDSCAPE / DESKTOP BREAKPOINT
   ========================================================================== */
@media (min-aspect-ratio: 6/5) {

    .hero-wrap{
        min-height:100vh;
        display:flex;
        flex-direction:column;
    }

    .hero-copy{
        display:flex;
        flex-direction:column;
        align-items:center;
        justify-content:center;
        text-align:center;
        margin-top: 38%;
    }
    .hero-panel{
        margin-top: 38%;
    }

    .hero-menu-bar{
        margin-top:auto;
        margin-bottom:30px;
    }

 .start-btn{
        width: min(360px, 65%);
        padding: 16px 32px;
        font-size: 1rem;
        align-self: center;
    }

    .hud-left {
        top: max(30px, env(safe-area-inset-top));
        left: max(30px, env(safe-area-inset-left));
        width: 18%;
        max-width: 18%;
    }
    .hud-left .stat-card {
        background: var(--surface);
    }

    .hud-center-top {
        width: 60%;
        left: max(56%, env(safe-area-inset-top));
        top: max(4%, env(safe-area-inset-top));
    }

    .hud-right {
        width: 5%;
        max-width: 120px;
        min-width: 80px;
        top: max(30px, env(safe-area-inset-top));
        right: max(30px, env(safe-area-inset-right));
    }
    .hud-right .hud-ctrl-btn {
        min-width: 52px;
        min-height: 52px;
    }
    .hud-right .hud-ctrl-btn .pause-mark {
        width: 22px;
        height: calc(22px * 0.88);
    }
    .hud-right .hud-ctrl-btn .value {
        font-size: 1.2rem;
    }
    .hud-right .hud-ctrl-btn.acc-panel .value {
        font-size: 1.3rem;
    }
    .hud-right .hud-ctrl-btn .label {
        font-size: .56rem;
    }

    .hud-center-top .level-xp-card {
        padding: 10px 18px;
        gap: 12px;
        min-height: 56px;
    }
    .level-hex {
        width: 46px;
        height: 46px;
    }
    .level-hex-num {
        font-size: 1.3rem;
    }
    .level-xp-title {
        font-size: .6rem;
    }
    .level-xp-nums {
        font-size: .66rem;
    }
    .xp-bar-wrap {
        height: 6px;
    }
    .xp-bar-fill::after {
        width: 12px;
        height: 12px;
        top: -3px;
    }

    .hud-bottom {
        width: min(460px, 58vw);
        gap: 8px;
    }
    .answer-shell {
        min-height: 64px;
        padding: 8px 16px;
        gap: 10px;
    }
    .answer-display {
        font-size: clamp(1.2rem, 4vw, 1.9rem);
    }
    .icon-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
    .q-type-badge {
        font-size: .7rem;
        padding: 4px 16px;
    }

    .keypad-landscape-wrap {
        display: none;
        position: absolute;
        bottom: max(10px, env(safe-area-inset-bottom));
        right: max(10px, env(safe-area-inset-right));
        width: min(360px, 46vw);
    }
    .keypad-landscape-wrap.visible {
        display: block;
    }
    .keypad-landscape-wrap .key {
        min-height: clamp(48px, 7.5vh, 62px);
        font-size: clamp(1.1rem, 3.2vw, 1.5rem);
    }
    .keypad-landscape-wrap .key.enter {
        min-height: calc(clamp(48px, 7.5vh, 62px) * 2 + 6px);
        font-size: 1.5rem;
    }
    .keypad-landscape-wrap .key.ops {
        font-size: .7rem;
    }
    .keypad-landscape-wrap .key.back {
        font-size: 1.1rem;
    }
    .keypad-landscape-wrap .keypad {
        gap: 5px;
    }

    #hudBottom .keypad {
        display: none !important;
    }
}

/* ==========================================================================
   3b. LANDSCAPE — HEIGHT-CONSTRAINED (phones & tablets held sideways)
   Section 3 above uses width-relative percentages (e.g. margin-top: 38%)
   tuned for tall desktop/laptop windows. On a phone or tablet turned
   sideways the viewport is wide but SHORT, so those same percentages push
   the splash content and HUD down past center — sometimes clipping the
   Launch button off the bottom — instead of balancing them vertically.
   This re-centers everything with flex/vh-based values for short landscape
   heights only, leaving the desktop rules above untouched.
   ========================================================================== */
@media (min-aspect-ratio: 6/5) and (max-height: 560px) {
    .hero-wrap {
        justify-content: center;
        padding-top: max(8px, env(safe-area-inset-top));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    .hero-copy {
        margin-top: 0;
        justify-content: center;
    }
    .hero-panel {
        margin-top: 0;
    }
    .hero-menu-bar {
        margin-top: 12px;
        margin-bottom: 10px;
    }

    .hud-left {
        top: max(10px, env(safe-area-inset-top));
    }
    .hud-center-top {
        top: max(10px, env(safe-area-inset-top));
    }
    .hud-right {
        top: max(10px, env(safe-area-inset-top));
    }
    .hud-center-top .level-xp-card {
        padding: 6px 14px;
        min-height: 40px;
        gap: 8px;
    }
    .level-hex {
        width: 34px;
        height: 34px;
    }

    /* The sideways keypad is the main overflow risk on short landscape
       screens — shrink it relative to viewport height instead of the
       desktop clamp() minimums. */
    .keypad-landscape-wrap {
        bottom: max(6px, env(safe-area-inset-bottom));
        width: min(320px, 44vw);
    }
    .keypad-landscape-wrap .key {
        min-height: clamp(32px, 14vh, 46px);
        font-size: clamp(.95rem, 3vw, 1.2rem);
    }
    .keypad-landscape-wrap .key.enter {
        min-height: calc(clamp(32px, 14vh, 46px) * 2 + 5px);
        font-size: 1.2rem;
    }
    .keypad-landscape-wrap .keypad {
        gap: 4px;
    }
}

/* ==========================================================================
   GLOBAL UTILITIES
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 99px;
}