/* ==========================================================================
   STACK MASTER - Responsive & Orientation Transitions (responsive.css)
   ========================================================================== */

/* Universal full viewport adaptation & smooth transitions */
#appRoot {
    width: 100%;
    height: 100%;
    max-width: 100%;
    position: relative;
    overflow: hidden;
    transition: background 0.4s ease;
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: manipulation;
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
}

/* Smooth transition properties for HUD layout elements during orientation changes */
#gameHUD {
    transition: padding 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease;
}

.game-top-bar {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 1400px;
    margin: 0 auto;
}

.hud-left-stats,
.hud-center-wrap,
.hud-right-controls,
.hud-bottom-wrap {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease,
                gap 0.3s ease;
}

.hud-banner-title {
    transition: font-size 0.3s ease,
                letter-spacing 0.3s ease,
                margin 0.3s ease;
}

.current-score-text {
    transition: font-size 0.3s ease,
                transform 0.2s ease;
}

.hud-stat-level,
.hud-stat-best,
.hud-diamonds-badge,
.hud-hint-drop,
.hud-sound-status {
    transition: font-size 0.3s ease,
                opacity 0.25s ease;
}

.sound-toggle-btn,
.top-bar-btn {
    transition: width 0.25s ease,
                height 0.25s ease,
                border-radius 0.25s ease,
                background 0.2s ease,
                transform 0.15s ease;
}

/* ==========================================================================
   1. LANDSCAPE ORIENTATIONS
   ========================================================================== */

/* Widescreen Desktop / Large Tablet Landscape (> 768px wide) */
@media screen and (min-width: 768px) and (orientation: landscape) {
    #gameHUD {
        padding: 16px 32px 24px;
    }

    .game-top-bar {
        padding: 4px 12px;
    }

    .hud-banner-title {
        font-size: 44px;
        letter-spacing: 3px;
    }

    .hud-stat-level {
        font-size: 30px;
    }

    .hud-stat-best {
        font-size: 16px;
    }

    .current-score-text {
        font-size: 60px;
    }

    .hud-bottom-hint {
        font-size: 15px;
    }

    .menu-hero {
        margin-top: 24px;
        margin-bottom: 24px;
    }

    .game-title {
        font-size: 58px;
    }

    .menu-actions {
        max-width: 400px;
    }
}

/* Standard Tablet / Small Laptop Landscape (600px - 767px) */
@media screen and (min-width: 600px) and (max-width: 767px) and (orientation: landscape) {
    #gameHUD {
        padding: 12px 20px 16px;
    }

    .hud-banner-title {
        font-size: 32px;
        letter-spacing: 2px;
    }

    .hud-stat-level {
        font-size: 24px;
    }

    .hud-stat-best {
        font-size: 14px;
    }

    .current-score-text {
        font-size: 46px;
    }
}

/* Compact Mobile Landscape (Smartphones rotated sideways: height <= 540px) */
@media screen and (max-height: 540px) and (orientation: landscape) {
    #gameHUD {
        padding: max(4px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    }

    .game-top-bar {
        align-items: center;
    }

    .hud-left-stats {
        gap: 0;
        flex-shrink: 0;
    }

    .hud-stat-level {
        font-size: 15px;
        line-height: 1.1;
    }

    .hud-stat-best {
        font-size: 11px;
    }

    .hud-center-wrap {
        margin-top: 0;
        flex: 1;
        min-width: 0;
        padding: 0 4px;
    }

    .hud-banner-title {
        display: none; /* Hide banner title during compact landscape gameplay to maximize headroom */
    }

    .game-center-score {
        margin-top: 0;
    }

    .current-score-text {
        font-size: 32px;
        line-height: 1;
    }

    .combo-badge {
        font-size: 9px;
        padding: 1px 6px;
        margin-top: 1px;
    }

    .hud-right-controls {
        gap: 4px;
        flex-shrink: 0;
    }

    .hud-diamonds-badge {
        font-size: 17px;
    }

    .hud-diamonds-badge .diamond-icon {
        font-size: 13px;
    }

    .hud-hint-drop {
        display: none;
    }

    .hud-sound-status {
        display: none; /* Hide secondary sound label to maximize vertical visibility */
    }

    .hud-buttons-row {
        gap: 4px;
    }

    .sound-toggle-btn,
    .top-bar-btn {
        width: 32px;
        height: 32px;
        border-radius: 8px;
        font-size: 13px;
    }

    .top-bar-btn svg {
        width: 13px;
        height: 13px;
    }

    .hud-bottom-wrap {
        margin-bottom: 2px;
    }

    .hud-bottom-hint {
        font-size: 10px;
    }

    .hud-milestone-toast {
        top: 50px;
        font-size: 10px;
        padding: 2px 10px;
    }

    /* Main menu 2-column landscape layout: no scrolling, zero overlap */
    #mainMenuScreen {
        display: grid;
        grid-template-columns: 1fr 1.25fr;
        grid-template-rows: auto 1fr;
        align-items: center;
        justify-items: center;
        padding: max(8px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
        gap: 4px 20px;
        overflow-y: auto;
    }

    .menu-header {
        grid-column: 1 / -1;
        width: 100%;
        max-width: 620px;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .stat-pill {
        padding: 3px 10px;
        font-size: 11px;
    }

    .menu-hero {
        grid-column: 1;
        margin: 0;
        padding: 0;
        text-align: center;
        flex-shrink: 0;
    }

    .game-title {
        font-size: 26px;
        line-height: 1.05;
    }

    .game-tagline {
        display: block;
        font-size: 10px;
        letter-spacing: 2px;
        margin-top: 2px;
    }

    .menu-actions {
        grid-column: 2;
        display: grid;
        grid-template-columns: 1fr 1fr;
        max-width: 360px;
        gap: 5px;
        margin: 0;
        flex-shrink: 0;
    }

    .btn-play-hero {
        grid-column: span 2;
        padding: 8px 14px;
        font-size: 13px;
        letter-spacing: 1px;
    }

    .btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .modal-card {
        max-height: calc(100vh - 16px);
        overflow-y: auto;
        padding: 10px 18px;
        max-width: 480px;
    }

    .modal-title {
        font-size: 17px;
        margin-bottom: 6px;
    }

    .gameover-score-wrap {
        margin-bottom: 6px;
    }

    .gameover-big-score {
        font-size: 32px;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        margin-bottom: 8px;
        gap: 6px;
    }

    .stat-box {
        padding: 4px 3px;
    }

    .stat-box-value {
        font-size: 15px;
    }

    .stat-box-label {
        font-size: 8.5px;
    }

    .modal-btn-stack {
        flex-direction: row;
        gap: 8px;
        justify-content: center;
    }

    .modal-btn-stack .btn {
        flex: 1;
        padding: 7px 10px;
        font-size: 11px;
    }

    .how-to-play-content {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px 12px;
        margin-bottom: 8px;
        text-align: left;
    }

    .settings-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        margin-bottom: 10px;
    }

    .setting-item {
        padding: 6px 10px;
    }
}

/* ==========================================================================
   2. PORTRAIT ORIENTATIONS
   ========================================================================== */

/* Standard Portrait Tablets (min-width: 600px and portrait) */
@media screen and (min-width: 600px) and (orientation: portrait) {
    #gameHUD {
        padding: 24px 32px 28px;
    }

    .hud-banner-title {
        font-size: 40px;
        letter-spacing: 2.5px;
    }

    .hud-stat-level {
        font-size: 28px;
    }

    .hud-stat-best {
        font-size: 16px;
    }

    .current-score-text {
        font-size: 58px;
    }

    .sound-toggle-btn,
    .top-bar-btn {
        width: 48px;
        height: 48px;
        border-radius: 14px;
        font-size: 20px;
    }
}

/* Mobile Portrait Phones (max-width: 480px) */
@media screen and (max-width: 480px) and (orientation: portrait) {
    #gameHUD {
        padding: 12px 14px 16px;
    }

    .game-top-bar {
        align-items: flex-start;
    }

    .hud-left-stats {
        flex-shrink: 0;
    }

    .hud-center-wrap {
        flex: 1;
        min-width: 0;
        padding: 0 4px;
    }

    .hud-right-controls {
        flex-shrink: 0;
    }

    .hud-banner-title {
        font-size: 20px;
        letter-spacing: 1.2px;
        white-space: nowrap;
    }

    .hud-stat-level {
        font-size: 20px;
    }

    .hud-stat-best {
        font-size: 13px;
    }

    .current-score-text {
        font-size: 52px;
    }

    .hud-diamonds-badge {
        font-size: 22px;
    }

    .hud-diamonds-badge .diamond-icon {
        font-size: 17px;
    }

    .hud-hints-group {
        display: none; /* Keep top bar clean on narrow smartphone portrait */
    }

    .sound-toggle-btn,
    .top-bar-btn {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        font-size: 15px;
    }

    .top-bar-btn svg {
        width: 15px;
        height: 15px;
    }

    .hud-bottom-hint {
        font-size: 12px;
    }

    .game-title {
        font-size: 36px;
    }

    .splash-title {
        font-size: 30px;
    }

    .gameover-big-score {
        font-size: 44px;
    }

    .menu-actions {
        max-width: 280px;
        gap: 8px;
    }

    .btn {
        padding: 10px 18px;
        font-size: 13px;
    }

    .btn-play-hero {
        padding: 13px 22px;
        font-size: 16px;
    }

    .modal-card {
        padding: 20px 16px;
        width: 94%;
        max-height: calc(100vh - 24px);
    }
}

/* Compact / Short Portrait Phones (height <= 680px and portrait) */
@media screen and (max-height: 680px) and (orientation: portrait) {
    #mainMenuScreen {
        padding: 12px 14px 12px;
        gap: 8px;
    }

    .menu-hero {
        margin: 4px 0;
        padding: 2px 0;
    }

    .game-title {
        font-size: 30px;
    }

    .game-tagline {
        font-size: 11px;
        margin-top: 2px;
    }

    .menu-actions {
        gap: 6px;
        max-width: 270px;
    }

    .btn-play-hero {
        padding: 11px 18px;
        font-size: 15px;
    }

    .btn {
        padding: 8px 14px;
        font-size: 12px;
    }

    .current-score-text {
        font-size: 44px;
    }

    .modal-card {
        padding: 16px 14px;
        max-height: calc(100vh - 20px);
    }

    .modal-title {
        font-size: 20px;
        margin-bottom: 12px;
    }

    .gameover-big-score {
        font-size: 38px;
    }

    .gameover-score-wrap {
        margin-bottom: 10px;
    }

    .stats-grid {
        gap: 6px;
        margin-bottom: 10px;
    }

    .stat-box {
        padding: 8px 6px;
    }

    .stat-box-value {
        font-size: 16px;
    }
}

/* Very Small / Ultra-Narrow Phones (max-width: 360px) */
@media screen and (max-width: 360px) {
    #gameHUD {
        padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    .game-top-bar {
        align-items: center;
    }

    .hud-banner-title {
        display: none; /* Hide banner title on ultra-narrow screens to keep score large and clean without crowding */
    }

    .hud-stat-level {
        font-size: 15px;
    }

    .hud-stat-best {
        font-size: 10px;
    }

    .current-score-text {
        font-size: 38px;
        line-height: 1;
    }

    .combo-badge {
        font-size: 9px;
        padding: 1px 5px;
    }

    .hud-diamonds-badge {
        font-size: 15px;
    }

    .hud-diamonds-badge .diamond-icon {
        font-size: 12px;
    }

    .hud-buttons-row {
        gap: 3px;
    }

    .sound-toggle-btn,
    .top-bar-btn {
        width: 30px;
        height: 30px;
        border-radius: 8px;
        font-size: 12px;
    }

    .top-bar-btn svg {
        width: 12px;
        height: 12px;
    }

    .game-title {
        font-size: 28px;
    }

    .game-tagline {
        font-size: 10px;
        letter-spacing: 2px;
    }

    .menu-actions {
        max-width: 250px;
        gap: 6px;
    }

    .btn {
        padding: 7px 12px;
        font-size: 11px;
    }

    .btn-play-hero {
        padding: 10px 16px;
        font-size: 14px;
    }
}

/* ==========================================================================
   3. ACCESSIBILITY & TOUCH INTERACTION
   ========================================================================== */

@media (pointer: coarse) {
    .btn,
    .top-bar-btn,
    .sound-toggle-btn,
    .setting-item {
        min-height: 38px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #gameHUD,
    .game-top-bar,
    .hud-banner-title,
    .current-score-text,
    .sound-toggle-btn,
    .top-bar-btn {
        transition: none !important;
        animation: none !important;
    }
}
