/**
 * GLITCH ZERO - CENTRALIZED RESPONSIVE CONTROLLER
 * v1.0 - Consolidated & Standardized
 * 
 * BREAKPOINTS:
 * - Mobile:  max-width: 768px
 * - Tablet:  min-width: 769px and max-width: 1024px
 */

/* ==========================================================================
   GLOBAL VARIABLES & RESETS
   ========================================================================== */
:root {
    --safe-area-bottom: env(safe-area-inset-bottom, 20px);
    --header-height-mobile: 50px;
    --nav-height-mobile-top: 60px;
    --nav-height-mobile-bottom: 70px;
}

/* Default state for logout text (hidden on desktop) */
.logout-text {
    display: none;
}

/* ==========================================================================
   MOBILE DEVICES (max-width: 768px)
   ========================================================================== */
@media screen and (max-width: 768px) {

    /* ----------------------------------------------------------------------
       1. GLOBAL LAYOUT & CONTAINER
       ---------------------------------------------------------------------- */
    body {
        overflow-x: hidden;
        -webkit-tap-highlight-color: transparent;
    }

    .game-container {
        padding: 0;
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
        display: flex;
        flex-direction: column;
    }

    /* ----------------------------------------------------------------------
       2. HEADER STRATEGY (Compact & Sticky)
       ---------------------------------------------------------------------- */
    .game-header {
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100%;
        height: var(--header-height-mobile) !important;
        min-height: var(--header-height-mobile) !important;
        max-height: var(--header-height-mobile) !important;
        padding: 0 0.5rem;
        z-index: 12000;
        /* Highest priority */

        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        flex-wrap: nowrap !important;

        background: rgba(10, 10, 16, 0.98);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid rgba(0, 242, 255, 0.2);
    }

    /* Hide redundant elements in header */
    .logo-text,
    .header-center,
    .stamina-display,
    .reputation-display,
    .company-display {
        display: none !important;
    }

    /* Simplified Resources */
    .resource-display {
        gap: 5px;
    }

    .coin-display {
        padding: 2px 8px;
        font-size: 0.8rem;
    }

    /* Fix Header Right Section & More Button */
    .header-right {
        gap: 5px !important;
    }

    #btn-header-more {
        background: rgba(255, 255, 255, 0.1) !important;
        border: 1px solid rgba(0, 242, 255, 0.3) !important;
        padding: 2px 8px !important;
        height: 30px !important;
        font-size: 1.2rem !important;
        color: var(--accent-neon) !important;
        border-radius: 4px !important;
        margin-left: 5px !important;
    }

    /* Full Screen Mobile Menu Overlay */
    #headerExtraInfo {
        position: fixed !important;
        top: 0 !important;
        right: -100% !important;
        /* Start off-screen */
        width: 85% !important;
        max-width: 320px !important;
        height: 100vh !important;
        background: rgba(8, 8, 12, 0.98) !important;
        backdrop-filter: blur(20px) !important;
        border-left: 2px solid var(--accent-neon) !important;
        border-bottom: none !important;
        border-radius: 0 !important;
        /* Square corners */
        clip-path: none !important;
        /* Ensure no clipping */
        padding: 80px 20px 20px 20px !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
        z-index: 15000 !important;
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.9) !important;
        transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1) !important;
        overflow-y: auto !important;
        pointer-events: auto !important;
    }

    #headerExtraInfo.active {
        right: 0 !important;
    }

    /* Prevent scrolling when menu is open */
    body.menu-open {
        overflow: hidden !important;
    }

    /* Menu Sections */
    .wallet-section {
        background: rgba(255, 255, 255, 0.03);
        padding: 15px;
        border-radius: 8px;
        border: 1px solid rgba(0, 242, 255, 0.1);
    }

    .audio-controls {
        margin-top: 15px;
        border-top: 1px solid rgba(255, 255, 255, 0.05);
        padding-top: 15px;
    }

    /* Mobile Nav in Menu */
    .mobile-nav-container {
        flex: 1;
    }

    .mobile-nav-container .unified-nav-bar {
        height: auto !important;
        position: static !important;
        display: block !important;
        pointer-events: auto !important;
    }

    .mobile-nav-container .game-tabs,
    .mobile-nav-container .social-tabs {
        position: static !important;
        height: auto !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        flex-direction: column !important;
        gap: 10px !important;
        padding: 0 !important;
        margin-bottom: 25px !important;
    }

    .mobile-nav-container .main-tabs,
    .mobile-nav-container .social-nav {
        flex-direction: column !important;
        display: flex !important;
        gap: 8px !important;
    }

    .mobile-nav-container .main-tab-btn,
    .mobile-nav-container .nav-link-btn {
        flex-direction: row !important;
        justify-content: flex-start !important;
        padding: 12px 15px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border-radius: 0 !important;
        /* Square buttons */
        width: 100% !important;
        text-align: left !important;
        gap: 15px !important;
    }

    .mobile-nav-container .btn-text,
    .mobile-nav-container .tab-label,
    .mobile-nav-container .nav-label {
        display: block !important;
        font-size: 1rem !important;
        font-family: 'Rajdhani', sans-serif !important;
        font-weight: 700 !important;
        letter-spacing: 1px !important;
        color: #e0e0e0 !important;
        text-transform: uppercase !important;
    }

    .mobile-nav-container .main-tab-btn.active .tab-label,
    .mobile-nav-container .nav-link-btn.active .nav-label {
        color: var(--accent-neon) !important;
    }

    /* Relocated Logout Button in Menu Footer */
    .menu-footer {
        margin-top: auto;
        padding-top: 20px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    #headerExtraInfo .btn-logout {
        width: 100% !important;
        height: 50px !important;
        background: rgba(255, 46, 99, 0.1) !important;
        border: 1px solid rgba(255, 46, 99, 0.5) !important;
        color: #ff2e63 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 12px !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
    }

    #headerExtraInfo .btn-logout .logout-text {
        display: inline !important;
    }

    /* HIDE FIXED NAV BARS ON MOBILE */
    .unified-nav-bar:not(.mobile-nav-container .unified-nav-bar) {
        display: none !important;
    }

    /* ADJUST MAIN PADDING (Now that nav bars are gone) */
    .game-main {
        padding-top: calc(var(--header-height-mobile) + 10px) !important;
        padding-bottom: 20px !important;
        margin: 0 !important;
    }

    /* Position the mobile quick actions area */
    .mobile-panel-toggles {
        display: flex !important;
        position: sticky;
        top: var(--header-height-mobile);
        z-index: 1000;
        background: rgba(10, 10, 16, 0.8);
        padding: 10px !important;
        margin: 0 -0.5rem 10px -0.5rem !important;
        border-bottom: 1px solid rgba(0, 242, 255, 0.2);
    }

    /* Button Styling Reset */
    .nav-link-btn,
    .main-tab-btn {
        flex: 1 !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        padding: 5px 0;
        margin: 0 !important;
        min-width: 0;
    }

    /* Hide Text Labels only for fixed bars (Legacy, will be hidden anyway by global hide rule) */
    .unified-nav-bar:not(.mobile-nav-container .unified-nav-bar) .btn-text,
    .unified-nav-bar:not(.mobile-nav-container .unified-nav-bar) .tab-label,
    .unified-nav-bar:not(.mobile-nav-container .unified-nav-bar) .nav-label {
        display: none !important;
    }

    /* Icon Sizing */
    .tab-icon,
    .nav-icon {
        font-size: 1.5rem !important;
        margin: 0 !important;
    }

    /* Active State */
    .nav-link-btn.active,
    .main-tab-btn.active {
        color: var(--accent-neon);
        background: rgba(0, 242, 255, 0.1);
        border-radius: 4px;
    }

    /* ----------------------------------------------------------------------
       4. MAIN GAME AREA (Padding Strategy)
       ---------------------------------------------------------------------- */
    .game-main {
        display: flex;
        flex-direction: column;
        gap: 1rem;

        /* Calculated Padding for Fixed Bars */
        /* Top: Header(50) + Gap(15) = 65px */
        padding-top: 65px !important;
        /* Reduced from 120px */

        /* Bottom: BottomNav(70) + Gap(15) = 85px */
        padding-bottom: 85px !important;

        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* ----------------------------------------------------------------------
       5. PANEL SYSTEM (Stacked & Toggleable)
       ---------------------------------------------------------------------- */
    /* Mobile Toggle Buttons */
    .mobile-panel-toggles {
        display: flex !important;
        gap: 10px;
        margin-bottom: 10px;
    }

    .btn-panel-toggle {
        flex: 1;
        padding: 12px;
        background: rgba(10, 10, 16, 0.8);
        border: 1px solid var(--accent-neon);
        color: #fff;
        font-family: 'Rajdhani', sans-serif;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 1px;
        border-radius: 4px;
        box-shadow: 0 0 10px rgba(0, 242, 255, 0.1);
        transition: all 0.3s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }

    .btn-panel-toggle:active {
        background: rgba(0, 242, 255, 0.2);
        transform: scale(0.98);
        box-shadow: 0 0 15px rgba(0, 242, 255, 0.3);
    }

    /* Side Panels (Hidden by default on mobile) */
    .left-panel,
    .right-panel {
        display: none;
        /* JS toggles 'active' class */
        position: fixed;
        top: 110px;
        /* Header + TopNav */
        left: 0;
        width: 100%;
        height: calc(100vh - 110px - 70px);
        /* Minus Headers & BottomNav */
        z-index: 10500;
        background: #050510;
        overflow-y: auto;
        padding: 20px;
        animation: slideUp 0.3s ease-out;
    }

    .left-panel.active,
    .right-panel.active {
        display: block !important;
    }

    .center-panel {
        width: 100%;
        min-height: 50vh;
    }

    @keyframes slideUp {
        from {
            transform: translateY(20px);
            opacity: 0;
        }

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

    /* ----------------------------------------------------------------------
       6. COMBAT RESPONSIVENESS
       ---------------------------------------------------------------------- */
    .combat-battle-header {
        flex-direction: column;
        gap: 10px;
    }

    .combat-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .btn-combat {
        padding: 12px;
        font-size: 1rem;
    }

    /* ----------------------------------------------------------------------
       7. GRID SYSTEMS (Inventory, etc.)
       ---------------------------------------------------------------------- */
    .inventory-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
        gap: 5px;
    }

    /* Workshop & Crafting Fixes – mobilde üstte reçeteler, altta malzeme durumu */
    .workshop-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
    }

    .workshop-left,
    .workshop-right {
        width: 100% !important;
        max-width: 100% !important;
        position: relative !important;
    }

    .crafting-list {
        display: grid !important;
        grid-template-columns: 1fr !important;
        /* Stack cards vertically on mobile */
        gap: 15px !important;
        padding: 5px !important;
    }

    .craft-item {
        width: 100% !important;
        padding: 15px !important;
        min-height: auto !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }

    .craft-header {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .craft-name {
        font-size: 1.1rem !important;
    }

    .craft-description,
    .craft-materials,
    .craft-stamina {
        font-size: 0.9rem !important;
        margin: 2px 0 !important;
    }

    .btn-craft {
        width: 100% !important;
        margin-top: 10px !important;
        height: 45px !important;
    }

    /* Mastery Bar Adjustments */
    .crafting-mastery-display {
        margin-bottom: 15px !important;
    }

    .mastery-row-main {
        flex-direction: column !important;
        gap: 10px !important;
        align-items: flex-start !important;
    }

    .mastery-progress-slim {
        width: 100% !important;
    }

    .action-buttons {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    .btn-action {
        width: 100% !important;
        flex-direction: column;
        text-align: center;
        padding: 10px 5px;
    }

    /* ----------------------------------------------------------------------
       8. MODALS & OVERLAYS
       ---------------------------------------------------------------------- */
    .modal-content {
        width: 95% !important;
        height: auto !important;
        max-height: 90vh !important;
        margin: 5% auto;
        padding: 15px;
    }

    /* Fix Notification Overlap */
    .notification-toast-container {
        top: 120px !important;
        /* clear headers */
        right: 10px !important;
        left: 10px !important;
        width: auto !important;
        z-index: 20000 !important;
        /* Above everything */
    }

    /* Fix Coin Display Cutoff */
    .game-header {
        padding-right: 1rem !important;
    }

    /* Chat Floating Button */
    .btn-chat-toggle {
        display: flex !important;
        position: fixed;
        bottom: 80px;
        /* Above Bottom Nav */
        right: 15px;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background: var(--accent-neon);
        z-index: 10000;
        align-items: center;
        justify-content: center;
        box-shadow: 0 0 15px var(--accent-neon);
    }

    /* MIGRATED FROM style.css */
    .chat-box {
        width: calc(100% - 40px);
        height: 400px;
        bottom: 10px;
        right: 10px;
    }

    .tutorial-content {
        padding: 2rem 1.5rem;
        max-width: 95%;
    }

    .tutorial-text {
        font-size: 1.1rem;
    }

    .tutorial-btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.95rem;
    }

    .tutorial-btn-start {
        font-size: 1.1rem;
        padding: 1rem 2rem;
    }

    .first-quest-tooltip {
        max-width: 90%;
        right: 5%;
        bottom: 10px;
        padding: 1rem;
    }

    .tooltip-text {
        font-size: 0.9rem;
    }

    .class-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .class-card {
        padding: 1rem;
    }

    .class-icon {
        font-size: 2.5rem;
    }

    .class-card h3 {
        font-size: 1.1rem;
    }

    .class-description {
        font-size: 0.8rem;
    }

    .btn-select-class {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }
}

/* ==========================================================================
   TABLET DEVICES (769px - 1024px)
   ========================================================================== */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    .game-main {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .left-panel {
        width: 250px;
        flex: 0 0 250px;
    }

    .center-panel {
        flex: 1;
        min-width: 300px;
    }

    .right-panel {
        width: 100%;
        order: 4;
        /* Move to bottom on smaller tablets */
    }

    /* Travel Map Fixes for Tablet */
    .travel-layout-wrapper {
        flex-direction: column;
    }

    .map-view-container {
        flex: 1;
        height: 50%;
        min-height: 400px;
    }

    .location-details-pane {
        flex: none;
        height: auto;
    }
}

/* ==========================================================================
   SPECIFIC FIXES FOR WORLD TAB & OVERLAYS
   ========================================================================== */
@media screen and (max-width: 768px) {

    /* Ensure World Tab Content respects header padding */
    #worldTab {
        padding-top: 10px;
        /* Extra breathing room below fixed header */
    }

    /* Fix Image Overlay UI Overlap with Bottom Nav & Chat */
    .image-overlay-ui {
        padding-bottom: 90px !important;
        /* Clear Bottom Nav (70px) + Chat Button space */
        justify-content: flex-end;
    }

    /* Ensure the location image container doesn't overflow or hide under header */
    .location-image-container {
        height: calc(100vh - 220px) !important;
        /* Viewport - (Header 120 + Bottom 100) */
        min-height: 400px;
        position: relative;
    }

    /* Adjust Action Buttons Grid for Mobile */
    .image-overlay-ui .action-buttons {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        width: 100%;
        margin-bottom: 20px;
        /* Space before text/log */
    }

    /* Make buttons bigger/easier to tap */
    .image-overlay-ui .btn-action {
        width: 100%;
        min-height: 60px;
        padding: 10px;
    }
}