/* ========================================= */
/* === RESPONSIVE & MOBILE STYLES === */
/* === Phase 5 - Extracted from index.html === */
/* ========================================= */

/* ====================================== */
/* === TABLET & MOBILE (max-width: 768px) === */
/* ====================================== */

@media (max-width: 768px),
(max-height: 700px) {

    /* 1. Force alignment to TOP so Title isn't cut off */
    #start-screen {
        justify-content: flex-start !important;
        padding-top: 40px;
        height: auto;
        min-height: 100vh;
    }

    /* 2. Shrink Title */
    #start-screen .title {
        font-size: 40px;
        margin-bottom: 10px;
        line-height: 1;
    }

    /* 3. Tighter Spacing for Buttons */
    #start-screen .btn.cpu {
        margin-bottom: 10px;
    }

    .btn-row {
        margin-bottom: 10px;
    }

    /* 4. Hide Version Number completely on tiny screens */
    #start-screen div[style*="Version"] {
        display: none;
    }

    /* 1. Reset the Container to be a normal Flex Row */
    #start-tools-row {
        position: static !important;
        width: 100% !important;
        height: auto !important;
        display: flex !important;
        justify-content: center !important;
        gap: 30px !important;
        margin-top: 20px !important;
        padding-bottom: 30px !important;
        pointer-events: auto !important;
        order: 99 !important;
    }

    /* 2. Reset the Buttons to be relative to the row */
    #start-tools-row .corner-btn {
        position: relative !important;
        top: auto !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        transform: scale(1.1);
    }

    /* Target the Subtitle DIV immediately after Title */
    #start-screen .title+div {
        margin-bottom: 14px !important;
        margin-top: 0 !important;
    }

    #quick-chat-modal {
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        transform: translate(-50%, -50%);
        width: 80%;
        max-width: 320px;
    }

    .chat-option {
        padding: 15px;
        font-size: 16px;
        text-align: center;
    }

    /* === RESPONSIVE GAME OVER MODAL === */
    #game-over-modal {
        width: 95vw;
        max-width: none;
        border-radius: 12px;
    }

    #game-over-header {
        padding: 8px 12px;
    }

    #game-over-title {
        font-size: 14px;
        letter-spacing: 1px;
    }

    #game-over-content {
        padding: 2px 2px 15px 2px;
    }

    /* Reduce inner spacing in dynamically generated content */
    #game-over-content h2 {
        font-size: 22px !important;
    }

    /* === RESPONSIVE SETTINGS MODAL === */
    #settings-modal {
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%) !important;
        margin: 0 !important;
        width: 90% !important;
        max-width: 360px !important;
        max-height: 85vh !important;
        overflow-y: auto !important;
        border-radius: 15px !important;
        padding: 15px !important;
    }

    /* Ensure inner content allows scrolling */
    #settings-content {
        max-height: none !important;
        overflow: visible !important;
    }

    /* Mobile adjustments for game log */
    #game-log {
        width: 90%;
        left: 5%;
        bottom: 140px;
        font-size: 12px;
        max-height: 100px;
    }

    /* Hide the "DICE POOL" header text & Handle to save space */
    #controls-panel-header,
    #handle-dice {
        display: flex !important;
    }

    /* Optimize the Coin/Pool Display */
    #pool-display {
        font-size: 20px;
        margin: 0 5px;
        min-width: 30px;
    }

    /* Hide the visual coins on tiny screens (numbers are enough) */
    #coins-ui {
        display: flex !important;
        transform: scale(0.8);
        margin: 0 5px;
        gap: 4px;
    }

    /* Ensure the individual coins scale down if needed */
    .coin-ui {
        width: 28px;
        height: 28px;
        font-size: 12px;
        border-width: 1px;
    }

    /* Wrapper for the buttons */
    #btn-group-wrapper {
        flex: 1;
        justify-content: flex-end;
        width: auto;
    }

    /* THE HERO BUTTON: ROLL */
    #roll-btn {
        flex-grow: 1;
        height: 44px;
        font-size: 18px;
        margin: 0 !important;
        border-radius: 22px;
        background: linear-gradient(135deg, #2d1b15 0%, #3e2723 100%);
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    }

    /* Optimize Undo/Redo */
    #undo-btn,
    #redo-btn {
        width: 44px !important;
        height: 44px !important;
        padding: 0 !important;
        font-size: 12px !important;
        border-radius: 50%;
        margin: 0 2px !important;
    }

    /* Mobile Tweak for New Toast */
    .toast {
        width: 80%;
        font-size: 14px;
        top: 15%;
        bottom: auto;
    }

    .toast.show {
        top: 25%;
        bottom: auto;
    }

    /* === MOBILE FIX FOR COLLAPSIBLE HANDLES === */
    /* 1. Force Turn Panel to allow things outside it (The Arrow) */
    #turn-panel {
        overflow: visible !important;
        z-index: 200 !important;
        max-width: 60%;
    }

    /* 2. The Golden Arrow Tab */
    #handle-turn {
        width: 14px !important;
        height: 60px !important;
        left: 100% !important;
        right: auto !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        margin-left: -1px !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        font-size: 20px !important;
        color: #FFD700 !important;
        background: #1a1a1a !important;
        border: 1px solid #FFD700 !important;
        border-left: none !important;
        border-radius: 0 12px 12px 0 !important;
        z-index: 9999 !important;
        opacity: 1 !important;
        box-shadow: 4px 0 10px rgba(0, 0, 0, 0.5) !important;
        pointer-events: auto !important;
    }

    /* 3. Make Camera Handle Bigger too */
    #handle-cam {
        width: 60px !important;
        height: 16px !important;
        bottom: -25px !important;
        font-size: 16px !important;
        background: #222 !important;
        border: 1px solid #00e5ff !important;
        border-top: none !important;
    }

    /* 4. Make Dice Panel Handle Bigger */
    #handle-dice {
        width: 80px !important;
        height: 16px !important;
        top: -25px !important;
        font-size: 16px !important;
        background: #222 !important;
        border: 1px solid #FFD700 !important;
        border-bottom: none !important;
    }

    .mobile-only {
        display: flex;
    }

    /* === MOBILE UI OPTIMIZATION === */

    /* 1. Fix the Giant Title Screen */
    .title {
        font-size: 40px;
        letter-spacing: 5px;
        width: 100%;
        text-align: center;
        line-height: 1.2;
    }

    /* Resize the Giant Buttons */
    .btn {
        padding: 12px 24px;
        font-size: 16px;
        width: 80%;
        margin: 5px 0;
    }

    /* 2. Fix the Bottom Controls Panel (The "Mess" at the bottom) */
    #controls-panel {
        left: 50%;
        transform: translateX(-50%);
        width: 94%;
        bottom: 65px !important;
        height: auto;
        flex-wrap: wrap;
        justify-content: center;
        padding: 10px 5px;
        gap: 8px;
        background: rgba(15, 15, 20, 0.95);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 30px;
    }

    /* Adjust Status Panel for Mobile to sit ABOVE the dice panel */
    #status-panel {
        bottom: 15px !important;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: 94%;
        flex-wrap: wrap;
        margin: auto;
        justify-content: center;
        gap: 20px;
        background: rgba(15, 15, 20, 0.95);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 20px;
        height: 40px;
        z-index: 101;
    }

    /* 3. Tame the Top-Left Turn Panel */
    #turn-panel {
        top: 10px;
        left: 10px;
        padding: 8px 12px;
        max-width: 45%;
    }

    #status-text {
        font-size: 14px;
        margin-bottom: 2px;
    }

    #rank-text {
        font-size: 10px;
    }

    /* 4. Camera Controls (Keep them usable but not huge) */
    #camera-controls {
        top: 10px;
        right: 10px;
        gap: 4px;
        flex-wrap: wrap;
        max-width: 50%;
        justify-content: flex-end;
    }

    #camera-controls .btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
        padding: 0;
        margin: 2px;
    }

    /* 5. Fix the Game Log overlap */
    #game-log {
        bottom: 120px;
        font-size: 11px;
        width: 90%;
        left: 5%;
    }

    /* 6. Hide the Desktop Log Panel on Mobile */
    #log-panel {
        display: none !important;
    }

    /* === MOBILE UI FIXES === */

    /* 1. FIX RESUME BUTTON: Force Side-by-Side (Row) on Mobile */
    .resume-split-row {
        flex-direction: row !important;
        width: 95% !important;
        gap: 8px !important;
        align-items: stretch !important;
    }

    .btn-resume {
        width: auto !important;
        flex: none !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 10px 5px !important;
        font-size: 16px !important;
        min-height: 50px !important;
    }

    /* Ensure the subtext inside the button doesn't break layout */
    .btn-resume span {
        font-size: 9px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 2. FIX MULTIPLAYER BUTTONS (2, 3, 4 - Cut off) */
    .tertiary-row {
        flex-wrap: wrap !important;
        justify-content: center !important;
        width: 90% !important;
        gap: 8px !important;
    }

    .btn-ghost {
        flex: 1 1 30% !important;
        min-width: 80px !important;
        margin-bottom: 5px !important;
        font-size: 14px !important;
    }

    /* 3. FIX BOTTOM MENU ICONS (5 Icons - Cut off) */
    #start-tools-row {
        width: 98% !important;
        gap: 8px !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        padding-bottom: 20px !important;
    }

    /* Resize icons slightly for mobile so 5 fit in a row */
    #start-tools-row .corner-btn {
        width: 45px !important;
        height: 45px !important;
        font-size: 20px !important;
        margin: 0 !important;
        transform: none !important;
    }

    /* Adjust the SVG inside the icons to fit */
    #start-tools-row .corner-btn svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* === FIX ALL START SCREEN MODALS === */
    #customization-modal .modal-content,
    #lobby-settings-modal .modal-content,
    #new-profile-modal .modal-content,
    #how-to-play-modal .modal-content,
    #online-lobby-modal .modal-content,
    #color-select-modal .modal-content,
    #name-setup-modal .modal-content,
    #reset-confirm-modal .modal-content {
        max-height: 85vh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        width: 90% !important;
        max-width: 360px !important;
        padding: 15px !important;
        margin: auto !important;
    }

    /* Optional: Fix visual glitch where scrollbar covers rounded corners */
    .glass-panel {
        background-clip: padding-box;
    }
}

/* ====================================== */
/* === DESKTOP ONLY (min-width: 769px) === */
/* ====================================== */

@media (min-width: 769px) {

    #handle-turn,
    #handle-cam,
    #handle-dice {
        display: none !important;
    }

    #start-screen {
        justify-content: center !important;
        padding-top: 0 !important;
    }

    /* Reset Button Position */
    #reset-save-container {
        bottom: 10px !important;
    }
}

/* ====================================== */
/* === SMALL PHONES (max-width: 480px) === */
/* ====================================== */

@media (max-width: 480px) {
    #host-warning-card {
        padding: 20px !important;
        width: 85% !important;
    }

    #host-timer-display {
        font-size: 60px !important;
        margin: 5px 0 !important;
    }

    #host-warning-card h2 {
        font-size: 20px !important;
    }

    #host-warning-card div {
        font-size: 30px !important;
    }

    /* === SYSTEM ALERT MODAL - MOBILE OPTIMIZATIONS === */
    #system-alert-card {
        width: 92%;
        max-width: none;
        padding: 25px 20px;
        margin: 0 15px;
        border-radius: 16px;
    }

    #system-alert-icon {
        font-size: 40px;
        margin-bottom: 12px;
    }

    #system-alert-title {
        font-size: 16px;
        letter-spacing: 1.5px;
        margin-bottom: 12px;
    }

    #system-alert-message {
        font-size: 13px;
        line-height: 1.5;
        margin-bottom: 20px;
    }

    #system-alert-ok-btn {
        width: 100%;
        padding: 14px 30px;
        font-size: 15px;
        min-height: 48px;
    }
}

/* ====================================== */
/* === LANDSCAPE MODE (max-height: 500px) === */
/* ====================================== */

@media (max-height: 500px) {
    #host-warning-card {
        padding: 10px 20px !important;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 20px;
        max-width: 500px;
    }

    #host-timer-display {
        font-size: 50px !important;
        margin: 0 !important;
    }

    /* Hide the extra text description in landscape to save space */
    #host-warning-card p {
        display: none;
    }

    /* === RESPONSIVE GAME OVER MODAL (Landscape) === */
    #game-over-modal {
        max-height: 90vh;
        top: 5%;
        transform: translateX(-50%);
    }

    #game-over-content {
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ====================================== */
/* === SAFE AREA INSETS (Notched Devices) === */
/* ====================================== */

@supports (padding: max(0px)) {
    #system-alert-modal {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}
