/* AI RPG Specific Styles */
.ai-rpg-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.game-wrapper {
    background: linear-gradient(145deg, #1a1a1a, #2d2d2d);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    border: 1px solid #333;
}

.game-canvas-container {
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

#gameCanvas {
    display: block;
    max-width: 100%;
    height: auto;
    border: 2px solid #444;
    border-radius: 4px;
}

.game-stats-bar {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    border: 1px solid #555;
}

.progress {
    background-color: #333;
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar {
    border-radius: 10px;
    transition: width 0.6s ease;
}

.menu-screen {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.menu-content {
    max-width: 400px;
    width: 90%;
    background: linear-gradient(145deg, #2c3e50, #34495e);
    border: 1px solid #555;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    border-radius: 12px;
}

.ai-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 500px;
    z-index: 1000;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.modal-content {
    background: linear-gradient(145deg, #2c3e50, #34495e);
    border: 1px solid #555;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    border-radius: 12px;
}

.game-sidebar {
    background: linear-gradient(145deg, #ecf0f1, #bdc3c7);
    border-left: 4px solid #3498db;
    border-radius: 8px;
    max-height: 700px;
    overflow-y: auto;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.game-sidebar h5 {
    color: #2c3e50;
    font-weight: 600;
    border-bottom: 2px solid #3498db;
    padding-bottom: 8px;
    margin-bottom: 16px;
}

.ai-features-panel .btn {
    margin-bottom: 8px;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.ai-features-panel .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.ai-features-panel .btn-outline-primary:hover {
    border-color: #007bff;
    background: #007bff;
    color: white;
}

.ai-features-panel .btn-outline-success:hover {
    border-color: #28a745;
    background: #28a745;
    color: white;
}

.ai-features-panel .btn-outline-warning:hover {
    border-color: #ffc107;
    background: #ffc107;
    color: #212529;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px;
}

.inventory-slot {
    background: linear-gradient(145deg, #ffffff, #f1f3f4);
    border: 2px solid #dee2e6;
    border-radius: 8px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.inventory-slot:hover {
    background: linear-gradient(145deg, #e9ecef, #f8f9fa);
    border-color: #3498db;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.inventory-slot::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s;
}

.inventory-slot:hover::before {
    left: 100%;
}

.inventory-slot.usable-item {
    border-color: #28a745;
    background: linear-gradient(145deg, #d4edda, #f8f9fa);
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.3);
}

.inventory-slot.usable-item:hover {
    border-color: #20c997;
    background: linear-gradient(145deg, #a3d5a5, #e8f5e8);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

.quest-item {
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    border: 1px solid #dee2e6;
    border-left: 4px solid #28a745;
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.quest-item:hover {
    transform: translateX(8px);
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.2);
    border-color: #28a745;
}

.quest-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(to bottom, #28a745, #20c997);
    transition: width 0.3s ease;
}

.quest-item:hover::before {
    width: 8px;
}

.quest-title {
    color: #2c3e50;
    font-size: 0.9rem;
}

.quest-description {
    color: #6c757d;
    font-size: 0.8rem;
    line-height: 1.3;
}

.quest-progress .progress {
    height: 6px;
    background-color: #e9ecef;
}

.quest-progress .progress-bar {
    background: linear-gradient(90deg, #28a745, #20c997);
}

.control-item {
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    margin-bottom: 2px;
}

.control-item:hover {
    background: linear-gradient(90deg, rgba(52, 152, 219, 0.1), rgba(52, 152, 219, 0.05));
    transform: translateX(4px);
}

.control-item .badge {
    min-width: 45px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    background: linear-gradient(135deg, #6c757d, #495057);
    border-radius: 4px;
}

.chat-message {
    margin-bottom: 12px;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    text-align: right;
}

.user-message .message-content {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    padding: 8px 12px;
    border-radius: 18px 18px 4px 18px;
    display: inline-block;
    max-width: 80%;
    word-wrap: break-word;
}

.ai-message .message-content {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
    padding: 8px 12px;
    border-radius: 18px 18px 18px 4px;
    display: inline-block;
    max-width: 80%;
    word-wrap: break-word;
}

.system-message .message-content {
    background: linear-gradient(135deg, #6c757d, #495057);
    color: white;
    padding: 6px 10px;
    border-radius: 12px;
    display: inline-block;
    font-size: 0.85rem;
    font-style: italic;
}

/* Scrollbar Styling */
.game-sidebar::-webkit-scrollbar,
#aiChatHistory::-webkit-scrollbar {
    width: 6px;
}

.game-sidebar::-webkit-scrollbar-track,
#aiChatHistory::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.game-sidebar::-webkit-scrollbar-thumb,
#aiChatHistory::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #3498db, #2980b9);
    border-radius: 3px;
}

.game-sidebar::-webkit-scrollbar-thumb:hover,
#aiChatHistory::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #2980b9, #21618c);
}

/* Responsive Design */
@media (max-width: 768px) {
    .ai-rpg-header {
        padding: 1.5rem;
        margin-bottom: 1rem;
    }
    
    .game-wrapper {
        padding: 16px;
    }
    
    .game-sidebar {
        margin-top: 20px;
        border-left: none;
        border-top: 4px solid #3498db;
        border-radius: 8px 8px 0 0;
    }
    
    .ai-modal {
        width: 95%;
        top: 20px;
        transform: translate(-50%, 0);
    }
    
    .inventory-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .menu-content {
        width: 95%;
        padding: 20px;
    }
}

@media (max-width: 576px) {
    .ai-rpg-header h1 {
        font-size: 1.8rem;
    }
    
    .ai-rpg-header p {
        font-size: 0.9rem;
    }
    
    .inventory-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .game-stats-bar .row > div {
        margin-bottom: 8px;
    }
}

/* Animation for game loading */
.loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Glow effects for interactive elements */
.btn-primary:focus,
.btn-success:focus,
.btn-info:focus {
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.5);
}

.form-control:focus {
    border-color: #3498db;
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.3);
}

/* Custom button styles for AI features */
.ai-features-panel .btn {
    position: relative;
    overflow: hidden;
}

.ai-features-panel .btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.ai-features-panel .btn:hover::before {
    left: 100%;
}

/* Conversation Display Styles */
.conversation-display {
    max-height: 200px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.conversation-message {
    margin-bottom: 1rem;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.character-face {
    font-size: 2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    min-width: 48px;
    text-align: center;
}

.message-bubble {
    border-radius: 15px;
    padding: 12px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    position: relative;
}

.hero-message .message-bubble {
    background: linear-gradient(135deg, #007bff, #0056b3) !important;
    margin-left: auto;
}

.npc-message .message-bubble {
    background: linear-gradient(135deg, #6c757d, #495057) !important;
    margin-right: auto;
}

.character-name {
    font-weight: bold;
    opacity: 0.9;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.75rem;
}

.message-text {
    line-height: 1.4;
    word-wrap: break-word;
}

/* Improved interaction modal */
.interaction-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
    z-index: 1000;
    animation: modalFadeIn 0.3s ease;
}

.interaction-modal .modal-content {
    background: linear-gradient(145deg, #1a1a1a, #2d2d2d);
    border: 2px solid #444;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8);
    border-radius: 15px;
}

/* Combat modal improvements */
.combat-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
    z-index: 9999 !important;
    background: rgba(0, 0, 0, 0.8) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    animation: modalFadeIn 0.3s ease;
}

.combat-modal.d-none {
    display: none !important;
}

.combat-modal .modal-content {
    background: linear-gradient(145deg, #1a1a1a, #2d2d2d);
    border: 2px solid #dc3545;
    box-shadow: 0 25px 50px rgba(220, 53, 69, 0.3);
    border-radius: 15px;
    position: relative;
    z-index: 10000;
}

/* Scrollbar styling for conversation display */
.conversation-display::-webkit-scrollbar {
    width: 6px;
}

.conversation-display::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.conversation-display::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.conversation-display::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.combat-info {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid #444;
}

.enemy-stats {
    background: rgba(139, 69, 19, 0.15);
    border: 1px solid #8B4513;
    border-radius: 6px;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.stat-item {
    text-align: center;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-weight: bold;
    font-size: 0.9rem;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.7rem;
    line-height: 1;
    margin-top: 2px;
}

.tiny {
    font-size: 0.65rem !important;
}

#enemy-type {
    font-weight: 500;
    font-style: italic;
}

/* Magic Attack Interface */
.magic-input {
    border: 2px solid #17a2b8;
    border-radius: 8px;
    background: rgba(23, 162, 184, 0.1) !important;
    transition: all 0.3s ease;
}

.magic-input textarea {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #17a2b8;
    border-radius: 4px;
    color: #333;
    resize: vertical;
    min-height: 60px;
}

.magic-input textarea:focus {
    background: rgba(255, 255, 255, 1);
    border-color: #138496;
    box-shadow: 0 0 10px rgba(23, 162, 184, 0.3);
}

#magicCost.text-danger {
    color: #dc3545 !important;
    font-weight: bold;
}

#magicCost.text-success {
    color: #28a745 !important;
    font-weight: bold;
}

#magicCost.text-warning {
    color: #ffc107 !important;
    font-weight: bold;
}

.combat-log-entry.magic-result {
    color: #17a2b8;
    font-style: italic;
    background: rgba(23, 162, 184, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    margin: 2px 0;
}

.combat-log-entry.magic-context {
    color: #e74c3c;
    font-weight: 500;
    background: rgba(231, 76, 60, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    margin: 2px 0;
    border-left: 3px solid #e74c3c;
}

.combat-log-entry.spell-name {
    color: #f39c12;
    font-weight: bold;
    background: rgba(243, 156, 18, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    margin: 2px 0;
    border-left: 3px solid #f39c12;
    text-shadow: 0 0 5px rgba(243, 156, 18, 0.3);
}

/* Disabled attack button styling */
.btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-outline-danger.disabled {
    border-color: #dc3545;
    color: #dc3545;
}

.btn-outline-danger.disabled:hover {
    background-color: transparent !important;
    border-color: #dc3545 !important;
    color: #dc3545 !important;
}

/* Mobile and Tablet Responsive Styles */
@media (max-width: 1199px) {
    .ai-rpg-header {
        padding: 1.5rem;
    }
    
    .ai-rpg-header h1 {
        font-size: 2.5rem;
    }
    
    .game-wrapper {
        padding: 16px;
    }
}

@media (max-width: 991px) {
    .container-fluid {
        padding: 0 10px;
    }
    
    .ai-rpg-header {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .ai-rpg-header h1 {
        font-size: 2rem;
    }
    
    .ai-rpg-header .lead {
        font-size: 1rem;
    }
    
    /* Stack layout on medium screens */
    .row.no-gutters {
        flex-direction: column;
    }
    
    .col-lg-9, .col-md-8 {
        width: 100%;
        margin-bottom: 1rem;
    }
    
    .col-lg-3, .col-md-4 {
        width: 100%;
    }
    
    .game-sidebar {
        min-height: auto;
        max-height: none;
    }
    
    /* Canvas container responsive */
    .game-canvas-container {
        width: 100%;
        height: 400px;
        overflow: hidden;
    }
    
    #gameCanvas {
        width: 100%;
        height: 100%;
        max-width: none;
        object-fit: contain;
    }
    
    /* Touch-friendly buttons */
    .btn {
        min-height: 44px;
        font-size: 16px;
        padding: 10px 16px;
    }
    
    .btn-sm {
        min-height: 38px;
        font-size: 14px;
        padding: 8px 12px;
    }
    
    /* Combat modal adjustments */
    .combat-modal .modal-content {
        max-width: 95vw;
        width: 95vw;
        max-height: 85vh;
    }
    
    /* Interaction modal adjustments */
    .interaction-modal .modal-content {
        max-width: 95vw;
        width: 95vw;
        padding: 20px;
    }
    
    /* Player stats panel mobile */
    .player-stats-panel .row {
        margin: 0;
    }
    
    .player-stats-panel .col-6 {
        padding: 2px;
    }
    
    /* Inventory grid mobile */
    .inventory-grid {
        gap: 3px;
    }
    
    .inventory-slot {
        padding: 8px 4px;
        font-size: 12px;
    }
}

@media (max-width: 767px) {
    .ai-rpg-header h1 {
        font-size: 1.75rem;
    }
    
    .game-wrapper {
        padding: 12px;
        overflow: visible; /* Allow scaled content to be visible */
        display: flex;
        justify-content: center;
    }
    
    /* Mobile canvas sizing - scale down to 70% and center on screen */
    .game-canvas-container {
        transform: scale(0.7);
        transform-origin: center;
        width: 142.86%; /* 100% / 0.7 to maintain container size */
        height: 430px; /* Scaled height for 600px canvas */
        margin: 0 auto -120px auto; /* Center horizontally and adjust for scaling */
        overflow: visible;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    #gameCanvas {
        width: 800px !important;
        height: 600px !important;
        max-width: none !important; /* Override responsive max-width */
        display: block;
        background-color: #000; /* Ensure black background is visible */
    }
    
    .game-wrapper {
        overflow: visible; /* Changed from hidden to visible for mobile scaling */
        padding: 8px;
        display: flex;
        justify-content: center;
    }
    
    /* Mobile controls removed - using gesture controls only */
    
    /* Mobile sidebar adjustments */
    .game-sidebar {
        padding: 15px;
    }
    
    .player-stats {
        padding: 15px;
    }
    
    .player-avatar {
        width: 36px !important;
        height: 36px !important;
    }
    
    .player-avatar img {
        width: 24px !important;
        height: 24px !important;
    }
    
    /* Mobile combat modal */
    .combat-modal .modal-content {
        padding: 15px;
        max-height: 90vh;
    }
    
    .combat-info .col-6 {
        padding: 0 5px;
    }
    
    .player-stats, .enemy-stats {
        padding: 8px;
        margin-top: 8px;
    }
    
    .combat-actions .btn {
        padding: 8px 4px;
        font-size: 12px;
    }
    
    /* Mobile interaction modal */
    .interaction-modal .modal-content {
        padding: 15px;
    }
    
    .conversation-display {
        max-height: 150px;
        padding: 10px;
    }
    
    /* Mobile menu adjustments - counter-scale to appear normal size on scaled canvas */
    .menu-content {
        transform: scale(1.43); /* Counter 0.7 scale = 1/0.7 ≈ 1.43 */
        transform-origin: center;
        padding: 1.5rem 1rem;
        width: 280px;
        max-width: 350px;
        margin: 0 auto;
        font-size: 1rem;
        position: relative;
        z-index: 11;
    }
    
    .menu-buttons .btn {
        font-size: 1.1rem;
        padding: 0.8rem 0.5rem;
        margin-bottom: 0.8rem;
        width: 100%;
    }
    
    /* Ensure game overlay works within scaled container */
    .game-overlay {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
    }
}

@media (max-width: 575px) {
    .container-fluid {
        padding: 0 5px;
    }
    
    .ai-rpg-header {
        padding: 0.75rem;
    }
    
    .ai-rpg-header h1 {
        font-size: 1.5rem;
    }
    
    .game-wrapper {
        padding: 8px;
    }
    
    /* Extra small mobile canvas - scale to 50% and center for very small screens */
    .game-canvas-container {
        transform: scale(0.5);
        transform-origin: center;
        width: 200%; /* 100% / 0.5 to maintain container size */
        height: 300px; /* Scaled height for 600px canvas */
        margin: 0 auto -180px auto; /* Center horizontally and adjust for scaling */
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    #gameCanvas {
        width: 800px !important;
        height: 600px !important;
        max-width: none !important; /* Override responsive max-width */
        display: block;
        background-color: #000; /* Ensure black background is visible */
    }
    
    /* Mobile controls removed - using gesture controls only */
    
    /* Minimal sidebar on tiny screens */
    .game-sidebar {
        padding: 10px;
    }
    
    .instructions-panel {
        display: none; /* Hide instructions on very small screens */
    }
    
    /* Extra small mobile menu adjustments - counter-scale for 0.5 scaling */
    .menu-content {
        transform: scale(2); /* Counter 0.5 scale = 1/0.5 = 2 */
        transform-origin: center;
        padding: 1rem 0.5rem;
        width: 200px;
        max-width: 250px;
        margin: 0 auto;
        font-size: 0.9rem;
        position: relative;
        z-index: 11;
    }
    
    .menu-buttons .btn {
        font-size: 1rem;
        padding: 0.6rem 0.3rem;
        margin-bottom: 0.6rem;
        width: 100%;
    }
    
    /* Compact combat modal */
    .combat-modal .modal-content {
        padding: 10px;
    }
    
    .combat-info .enemy-avatar span,
    .combat-info .player-avatar img {
        width: 24px;
        height: 24px;
        font-size: 24px;
    }
    
    .combat-actions {
        gap: 5px;
    }
    
    .combat-actions .btn {
        padding: 6px 8px;
        font-size: 11px;
    }
    
    /* Magic input mobile */
    .magic-input {
        padding: 6px;
    }
    
    .magic-input .form-control {
        font-size: 14px;
    }
}

/* Message Container - properly sized notification */
.message-container {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 9999 !important;
    max-width: 400px !important;
    width: auto !important;
    min-width: 300px !important;
}

.message-container .alert {
    margin-bottom: 0 !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
    border-radius: 8px !important;
}

/* Mobile message container adjustments */
@media (max-width: 767px) {
    .message-container {
        max-width: 90vw !important;
        min-width: 280px !important;
        left: 50% !important;
        right: auto !important;
    }
}

/* Touch-specific enhancements */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    .btn {
        min-height: 48px;
        padding: 12px 20px;
    }
    
    .btn-sm {
        min-height: 42px;
        padding: 10px 16px;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover {
        transform: none;
    }
    
    /* Touch-friendly inventory slots */
    .inventory-slot {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Touch-friendly canvas interaction */
    #gameCanvas {
        touch-action: none; /* Prevent default touch behaviors */
    }
}

/* Landscape orientation optimizations */
@media (max-width: 991px) and (orientation: landscape) {
    .row.no-gutters {
        flex-direction: row;
    }
    
    .col-lg-9, .col-md-8 {
        width: 70%;
        margin-bottom: 0;
    }
    
    .col-lg-3, .col-md-4 {
        width: 30%;
    }
    
    .game-canvas-container {
        height: 350px;
    }
    
    .game-sidebar {
        max-height: 350px;
        overflow-y: auto;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #gameCanvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
        image-rendering: pixelated;
    }
}

/* Game canvas touch controls */
.game-canvas-container {
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: manipulation;
}

/* Mobile touch controls removed - using gestures only */
.mobile-controls {
    display: none;
}

.mobile-controls.active {
    display: none;
}

.mobile-actions button {
    width: 50px;
    height: 50px;
    border: 2px solid rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 50%;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.mobile-actions button:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

/* Pan gesture indicator */
.pan-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 12px;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pan-indicator.visible {
    opacity: 1;
}

/* Movement instruction indicator */
.movement-hint {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(52, 152, 219, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 15;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    text-align: center;
    white-space: nowrap;
}

.movement-hint.visible {
    opacity: 1;
}

.movement-hint.fade-out {
    animation: fadeOut 2s ease-out forwards;
}

@keyframes fadeOut {
    0% { opacity: 1; }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* Enhanced game canvas cursor feedback */
#gameCanvas {
    cursor: grab;
    transition: cursor 0.2s ease;
}

#gameCanvas:active {
    cursor: grabbing;
}

.mobile-device #gameCanvas {
    cursor: default; /* Remove cursor on mobile */
}

/* Visual feedback for interaction targets */
.interaction-target-hint {
    position: absolute;
    pointer-events: none;
    z-index: 20;
    background: rgba(40, 167, 69, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    transform: translate(-50%, -100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.interaction-target-hint.visible {
    opacity: 1;
    animation: bounce 0.5s ease-in-out;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translate(-50%, -100%) translateY(0);
    }
    40% {
        transform: translate(-50%, -100%) translateY(-10px);
    }
    60% {
        transform: translate(-50%, -100%) translateY(-5px);
    }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .game-canvas-container {
        -webkit-overflow-scrolling: touch;
    }
    
    #gameCanvas {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
}

/* Prevent pull-to-refresh on mobile */
body {
    overscroll-behavior-y: contain;
}

.game-canvas-container {
    overscroll-behavior: none;
}

/* Fix for mobile viewport issues */
@media screen and (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
    
    .container-fluid {
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Hide mobile controls by default */
.mobile-controls {
    display: none;
}

/* Show controls on touch devices */
@media (hover: none) and (pointer: coarse) {
    .mobile-controls.active {
        display: flex !important;
    }
}

/* Performance optimizations for mobile */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    .game-wrapper {
        will-change: transform;
    }
    
    #gameCanvas {
        will-change: transform;
    }
}
