/* Mobile-responsive styles for Citadeli */
/* Portrait-first design for phones 360-430px width */

/* Viewport meta is set in header.ejs */

/* ===== GLOBAL MOBILE STYLES ===== */
@media (max-width: 768px) {
    body {
        padding-bottom: 60px !important;
        margin-bottom: 0 !important;
        font-size: 14px;
    }
    
    .container {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    /* Hide desktop-only elements */
    .d-mobile-none {
        display: none !important;
    }
}

/* ===== HEADER / NAVIGATION ===== */
@media (max-width: 768px) {
    /* Compact header */
    .header-wrapper {
        padding: 8px 0;
        margin-bottom: 15px !important;
    }
    
    .header-wrapper .container .row {
        height: auto !important;
    }
    
    /* Hide logo image on mobile, show text logo */
    .header-wrapper .col-lg-4.order-lg-0 {
        display: none !important;
    }
    
    /* Center logo */
    .header-wrapper .col-lg-4.order-lg-1 {
        text-align: center;
    }
    
    .header-wrapper .col-lg-4.order-lg-1 img {
        height: 60px !important;
        margin-top: 0 !important;
    }
    
    /* Stats bar smaller */
    .header-wrapper .col-lg-4.order-lg-1 > div[style*="position: absolute"] {
        position: static !important;
        font-size: 11px;
        margin-top: 5px;
    }
    
    /* User area compact */
    .header-wrapper .col-lg-4.order-lg-2 {
        position: absolute;
        right: 10px;
        top: 8px;
    }
    
    .header-wrapper .lk-actions {
        font-size: 12px;
    }
}

/* ===== BURGER MENU / OFFCANVAS ===== */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    bottom: 15px;
    left: 15px;
    z-index: 1050;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #278eaf;
    border: none;
    color: white;
    font-size: 24px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    cursor: pointer;
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Hide left menu on mobile by default */
    #left-menu {
        display: none;
    }
    
    /* Offcanvas menu */
    .mobile-offcanvas {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 300px;
        height: 100vh;
        background: white;
        z-index: 1060;
        overflow-y: auto;
        transition: left 0.3s ease;
        padding: 20px;
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    }
    
    .mobile-offcanvas.open {
        left: 0;
    }
    
    .mobile-offcanvas-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1055;
        display: none;
    }
    
    .mobile-offcanvas-backdrop.open {
        display: block;
    }
    
    .mobile-offcanvas .close-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        font-size: 24px;
        background: none;
        border: none;
        cursor: pointer;
    }
    
    /* Left menu in offcanvas */
    .mobile-offcanvas #left-menu {
        display: block;
    }
    
    .mobile-offcanvas .list-group-item {
        padding: 12px 15px;
        font-size: 16px;
    }
}

/* ===== 3-COLUMN LAYOUT ===== */
@media (max-width: 768px) {
    .col-md-3.order-md-0,
    .left-menu-desktop {
        display: none !important;
    }
    
    .col-md-9.order-md-1 {
        width: 100%;
        padding: 0;
    }
    
    .col-lg-8.order-md-1 {
        width: 100%;
        padding: 0 5px;
    }
    
    /* Chat in toggleable panel */
    .col-lg-4.order-md-2 {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        z-index: 1040;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        border-top: 2px solid #278eaf;
    }
    
    .col-lg-4.order-md-2.chat-open {
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* ===== CHAT PANEL ===== */
.chat-toggle-btn {
    display: none;
}

@media (max-width: 768px) {
    .chat-toggle-btn {
        display: flex;
        position: fixed;
        bottom: 15px;
        right: 15px;
        z-index: 1050;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background: #278eaf;
        border: none;
        color: white;
        font-size: 20px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.3);
        cursor: pointer;
        align-items: center;
        justify-content: center;
    }
    
    #worldchat, #gamechat {
        max-height: 50vh;
    }
    
    #worldchat-messages, .chat__messages {
        max-height: 35vh !important;
        min-height: 100px !important;
    }
}

/* ===== GAME SCREEN ===== */
@media (max-width: 768px) {
    /* Timeout bar */
    #timeout {
        font-size: 18px !important;
        padding: 8px !important;
        position: sticky;
        top: 0;
        z-index: 100;
    }
    
    #timeout div[style*="float:left"] {
        position: static !important;
        float: none !important;
        display: block;
        font-size: 10px;
        margin-bottom: 3px;
    }
    
    /* Character list */
    .charlist {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        padding: 5px 0;
        margin: 0 -10px;
        padding-left: 10px;
    }
    
    .charlist .charlist__char {
        flex: 0 0 auto;
        min-width: 55px;
        max-width: 65px !important;
    }
    
    .charlist .charlist__char-img img {
        width: 55px;
        border-radius: 8px;
    }
    
    .charlist .charlist__char-img span {
        font-size: 12px;
        bottom: 5px;
    }
    
    .charlist .effect {
        font-size: 9px !important;
    }
    
    /* Game cards */
    .gamecard {
        max-width: 70px !important;
        margin: 2px !important;
    }
    
    .gamecard img {
        width: 70px !important;
        border-radius: 4px;
    }
    
    /* Larger touch targets for clickable cards */
    a[onclick] > .gamecard,
    a > .gamecard {
        padding: 5px;
        margin: 0 !important;
    }
    
    /* Actions bar - bottom sticky */
    .actions {
        flex-wrap: wrap !important;
        position: sticky;
        bottom: 0;
        background: white;
        padding: 10px 5px;
        margin: 0 -10px;
        border-top: 1px solid #ddd;
        z-index: 50;
        justify-content: center !important;
    }
    
    div.action {
        width: auto !important;
        min-width: 100px;
        max-width: 150px;
        padding: 10px 8px !important;
        margin: 3px !important;
        font-size: 12px;
        flex-direction: column;
        text-align: center;
    }
    
    div.action .action-icon {
        float: none !important;
        margin: 0 auto 5px !important;
        width: 40px !important;
        height: 40px !important;
    }
    
    div.action .action-icon img {
        width: 40px;
        height: 40px;
    }
    
    div.action .action-name {
        font-size: 11px;
        line-height: 1.2;
    }
    
    /* Player info */
    .player-coins, .player-cards {
        font-size: 20px !important;
        line-height: 30px !important;
        margin-left: 0 !important;
        margin-right: 20px !important;
        padding-left: 28px !important;
        background-size: 24px !important;
    }
    
    /* Player boards collapsible */
    .player-board {
        border: 1px solid #ddd;
        margin-bottom: 8px;
        border-radius: 5px;
        overflow: hidden;
    }
    
    .player-board-header {
        padding: 8px 10px;
        background: #f5f5f5;
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .player-board-header::after {
        content: '▼';
        font-size: 10px;
        transition: transform 0.3s;
    }
    
    .player-board.collapsed .player-board-header::after {
        transform: rotate(-90deg);
    }
    
    .player-board-content {
        padding: 10px;
        transition: max-height 0.3s ease;
    }
    
    .player-board.collapsed .player-board-content {
        max-height: 0;
        padding: 0;
        overflow: hidden;
    }
    
    /* Player table */
    table.player-table {
        display: block;
    }
    
    table.player-table tbody {
        display: block;
    }
    
    table.player-table tr {
        display: block;
        margin-bottom: 10px;
        border: 1px solid #eee;
        border-radius: 5px;
        padding: 8px;
    }
    
    table.player-table td {
        display: block;
        width: 100% !important;
        padding: 3px 0;
    }
    
    .player-cell {
        width: 100% !important;
    }
    
    /* Hand cards - horizontal scrollable strip */
    .hand-cards {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 10px 5px;
        margin: 0 -10px;
        background: #f8f8f8;
        border-top: 1px solid #ddd;
        gap: 5px;
    }
    
    .hand-cards .gamecard {
        flex: 0 0 auto;
    }
    
    /* City districts - wrap */
    .city-districts {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    /* Modal improvements */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }
    
    .modal-body {
        padding: 15px;
        max-height: 70vh;
        overflow-y: auto;
    }
    
    /* Action content in modal */
    .action-content {
        max-height: 60vh;
        overflow-y: auto;
    }
    
    .action-content .charlist {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .action-content .charlist .charlist__char {
        margin: 5px;
    }
    
    /* Player select */
    .playerselect {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .playerselect__player {
        margin: 5px !important;
    }
    
    .playerselect__player label img,
    .playerselect__player label svg {
        width: 64px !important;
        height: 64px !important;
    }
    
    /* Token distribution */
    .token-distribution__token img {
        width: 35px !important;
    }
    
    .token-distribution .charlist .charlist__char-img > img {
        width: 45px !important;
    }
    
    /* Phase 1 character selection */
    .h3 {
        font-size: 1.2rem;
    }
    
    /* Game end screen */
    div[align="center"] > div[style*="width:400px"] {
        width: 100% !important;
        padding: 0 10px;
    }
}

/* ===== GAME WAITING / LOBBY ===== */
@media (max-width: 768px) {
    .game-lobby .player-slot {
        display: inline-block;
        width: calc(50% - 10px);
        margin: 5px;
        text-align: center;
    }
    
    .game-lobby .player-slot img,
    .game-lobby .player-slot svg {
        width: 60px;
        height: 60px;
    }
}

/* ===== GAME CREATE FORM ===== */
@media (max-width: 768px) {
    .form-group, .row.mb-3 {
        flex-direction: column;
    }
    
    .col-form-label, .col-3 {
        width: 100% !important;
        text-align: left !important;
        margin-bottom: 5px;
    }
    
    .col-9, .col-lg-9 {
        width: 100% !important;
    }
    
    .form-check-inline {
        margin-right: 10px;
    }
    
    /* Character/district selection grid */
    .character-select-grid,
    .district-select-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 5px;
    }
}

/* ===== GAME LIST / JOIN ===== */
@media (max-width: 768px) {
    .game-list-item {
        padding: 10px;
        margin-bottom: 10px;
        border: 1px solid #ddd;
        border-radius: 5px;
    }
    
    .table-responsive {
        margin: 0 -10px;
    }
    
    .table {
        font-size: 12px;
    }
    
    .table td, .table th {
        padding: 8px 5px;
    }
}

/* ===== AUTH PAGES ===== */
@media (max-width: 768px) {
    .auth-form {
        padding: 15px;
    }
    
    .auth-form .form-control {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }
    
    .auth-form .btn {
        width: 100%;
        padding: 12px;
        font-size: 16px;
    }
}

/* ===== USER PROFILE / STATS ===== */
@media (max-width: 768px) {
    .user-profile {
        text-align: center;
    }
    
    .user-profile img {
        width: 80px;
        height: 80px;
    }
    
    .leaderboard-table {
        font-size: 12px;
    }
    
    .leaderboard-table td, 
    .leaderboard-table th {
        padding: 6px 4px;
    }
}

/* ===== SHOP ===== */
@media (max-width: 768px) {
    .shop-product {
        margin-bottom: 20px;
    }
    
    .shop-product img {
        max-width: 100%;
        height: auto;
    }
}

/* ===== UTILITIES ===== */
@media (max-width: 768px) {
    /* Touch-friendly buttons */
    .btn {
        min-height: 44px;
        padding: 10px 15px;
    }
    
    .btn-sm {
        min-height: 36px;
    }
    
    /* Remove hover states for touch */
    .no-touch-hover:hover {
        background-color: inherit !important;
        color: inherit !important;
    }
    
    /* Scrollable containers */
    .scroll-x {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Safe area for notched phones */
    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
}

/* ===== PREVENT ZOOM ON INPUT FOCUS (iOS) ===== */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ===== HIDE HOVER-ONLY TOOLTIPS ON TOUCH ===== */
@media (hover: none) and (pointer: coarse) {
    [title] {
        position: relative;
    }
    
    .tooltip {
        display: none !important;
    }
}


/* Desktop: mobile-only elements must stay hidden */
@media (min-width: 769px) {
    .mobile-offcanvas,
    .mobile-offcanvas-backdrop,
    .mobile-menu-toggle,
    .mobile-chat-toggle {
        display: none !important;
    }
}
