/* ============================================
   MOBILE-FRIENDLY STYLES
   ============================================ */

/* Make game containers responsive instead of fixed width */
.rain-container,
.dark-forest,
.hills-container,
.river {
    max-width: 600px;
    width: 100%;
}

.ocean-scene {
    max-width: 600px;
    width: 100%;
}

/* Disable cursor:none on touch devices */
@media (hover: none) and (pointer: coarse) {
    .rain-container,
    .dark-forest {
        cursor: default !important;
    }
}

/* Mobile Controls for Steering Game */
.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    margin-top: 10px;
}

.ctrl-row {
    display: flex;
    gap: 10px;
}

.ctrl-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(240,240,255,0.9) 100%);
    border: 2px solid rgba(102, 126, 234, 0.4);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    position: relative;
}

.ctrl-btn img {
    display: none;
}

.ctrl-arrow {
    font-size: 22px;
    color: #667eea;
    font-weight: bold;
}

.ctrl-btn:active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transform: scale(0.92);
}

.ctrl-btn:active .ctrl-arrow {
    color: white;
}

/* Ensure game images don't overflow */
.game-screen img,
.charm img,
.charm-earned img,
.reward-text img {
    max-width: 100%;
    height: auto;
}

/* Fix charm display for images */
.charm {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.charm img {
    width: 24px;
    height: 24px;
}

.charm-earned img {
    width: 60px;
    height: 60px;
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* ============================================
   DETAIL SHEET (hidden on desktop)
   ============================================ */
.detail-sheet-backdrop {
    display: none;
}
.detail-sheet {
    display: none;
}

/* Tablet */
@media (max-width: 768px) {
    /* Show mobile controls */
    .mobile-controls {
        display: flex;
    }

    /* === MAP PINS LAYOUT === */
    /* Keep map full-screen with background visible */
    .map-container {
        width: 100vw;
        height: 100vh;
        overflow: hidden;
        position: relative;
        display: block;
        padding: 0;
    }

    /* Convert region cards to map marker pins */
    .region-card {
        position: absolute !important;
        width: 140px !important;
        height: 170px !important;
        border-radius: 0 !important;
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        border: none !important;
        overflow: visible;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        z-index: 50;
        transition: transform 0.2s ease;
        backdrop-filter: none !important;
    }

    .region-card::before {
        /* Marker pointer/triangle at bottom */
        content: '' !important;
        position: absolute;
        bottom: 22px;
        left: 50%;
        transform: translateX(-50%);
        width: 0;
        height: 0;
        border-left: 18px solid transparent;
        border-right: 18px solid transparent;
        border-top: 24px solid #667eea;
        z-index: 1;
        border-radius: 0 !important;
        background: none !important;
        filter: drop-shadow(0 3px 3px rgba(0,0,0,0.2));
    }

    .region-card:hover,
    .region-card:active {
        transform: scale(1.08) !important;
    }

    /* Circular image inside the marker bubble */
    .region-card .region-image-container {
        width: 130px !important;
        height: 130px !important;
        border-radius: 50% !important;
        margin: 0 !important;
        border: 5px solid #667eea;
        box-shadow:
            0 6px 18px rgba(0,0,0,0.3),
            inset 0 0 0 3px rgba(255,255,255,0.8);
        background: white;
        z-index: 2;
        position: relative;
        overflow: hidden;
    }

    .region-card .region-image-container img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    /* Hide text on the pin */
    .region-card h3,
    .region-card p {
        display: none !important;
    }

    /* Hide the pulse indicator or reposition */
    .region-card .pulse-indicator {
        width: 130px;
        height: 130px;
        top: 65px;
    }

    /* Pin label - show region name below the marker */
    .region-card::after {
        content: attr(data-pin-label);
        position: absolute;
        bottom: -2px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 13px;
        font-weight: 600;
        color: #fff;
        background: rgba(0, 0, 0, 0.65);
        padding: 3px 10px;
        border-radius: 10px;
        white-space: nowrap;
        pointer-events: none;
        font-family: 'Fredoka', sans-serif;
        z-index: 3;
    }

    /* Bounce animation on active pins */
    .region-card.active .region-image-container {
        border-color: #FFD93D;
        animation: pinBounce 1.5s ease-in-out infinite;
    }

    @keyframes pinBounce {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-6px); }
    }

    /* Mobile pin positions (tuned for portrait viewport) */
    #angry-volcano {
        top: 28% !important;
        left: auto !important;
        right: 17% !important;
        bottom: auto !important;
    }

    #sadness-swamp {
        top: auto !important;
        bottom: 28% !important;
        right: 6% !important;
        left: auto !important;
    }

    #fear-forest {
        top: 22% !important;
        left: 12% !important;
        right: auto !important;
        bottom: auto !important;
    }

    #happiness-hills {
        top: 17% !important;
        left: 42% !important;
        right: auto !important;
        bottom: auto !important;
    }

    #excitement-rapids {
        top: auto !important;
        bottom: 20% !important;
        left: 35% !important;
        right: auto !important;
    }

    #tenderness-cove {
        top: 55% !important;
        left: 7% !important;
        right: auto !important;
        bottom: auto !important;
    }

    /* === DETAIL SHEET === */
    .detail-sheet-backdrop {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 200;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .detail-sheet-backdrop.show {
        opacity: 1;
        pointer-events: auto;
    }

    .detail-sheet {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 201;
        background: linear-gradient(135deg, #ffffff 0%, #f0f0ff 100%);
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -8px 30px rgba(0,0,0,0.2);
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
        max-height: 55vh;
        overflow-y: auto;
    }

    .detail-sheet.show {
        transform: translateY(0);
    }

    .detail-sheet-handle {
        width: 40px;
        height: 5px;
        background: #ccc;
        border-radius: 3px;
        margin: 12px auto 8px;
    }

    .detail-sheet-content {
        padding: 5px 24px 30px;
    }

    .detail-sheet-content .sheet-region-header {
        display: flex;
        align-items: center;
        gap: 15px;
        margin-bottom: 12px;
    }

    .detail-sheet-content .sheet-region-img {
        width: 70px;
        height: 70px;
        border-radius: 15px;
        object-fit: cover;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }

    .detail-sheet-content .sheet-region-info h2 {
        font-size: 22px;
        color: #333;
        margin: 0 0 4px;
        font-family: 'Fredoka', sans-serif;
    }

    .detail-sheet-content .sheet-region-info p {
        font-size: 14px;
        color: #666;
        margin: 0;
        line-height: 1.4;
    }

    .detail-sheet-content .sheet-character {
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 10px 0;
    }

    .detail-sheet-content .sheet-skill-badge {
        background: linear-gradient(135deg, #f0f0ff 0%, #e8e0ff 100%);
        border-radius: 12px;
        padding: 10px 15px;
        margin-bottom: 15px;
        font-size: 14px;
        color: #555;
    }

    .detail-sheet-content .sheet-skill-badge strong {
        color: #667eea;
    }

    .detail-sheet-content .sheet-start-btn {
        width: 100%;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        padding: 16px;
        border-radius: 16px;
        font-size: 18px;
        font-weight: 600;
        font-family: 'Fredoka', sans-serif;
        cursor: pointer;
        box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .detail-sheet-content .sheet-start-btn:active {
        transform: scale(0.97);
    }

    /* Keep fixed elements out of the flow */
    .banner-overlay {
        position: fixed;
        top: 40px;
        width: 100%;
        z-index: 90;
    }

    .banner-overlay img {
        width: 95vw;
        max-width: 700px;
    }

    /* Explorer's log - centered pill below the banner */
    #explorers-log {
        position: fixed;
        top: 130px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        bottom: auto;
        width: auto;
        padding: 10px 20px;
        z-index: 91;
        display: flex;
        align-items: center;
        gap: 10px;
        border-radius: 25px;
        background: rgba(255, 255, 255, 0.92);
        box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    }

    #explorers-log h3 {
        font-size: 15px;
        margin-bottom: 0;
        white-space: nowrap;
    }

    #charm-collection {
        flex-wrap: nowrap;
        gap: 5px;
    }

    .charm {
        width: 32px;
        height: 32px;
    }

    .charm img {
        width: 20px;
        height: 20px;
    }

    /* Character guide - smaller, bottom left */
    .character-guide {
        bottom: 10px;
        left: 10px;
        transform: none;
        z-index: 92;
    }

    .character-guide img {
        width: 50px;
        height: 50px;
    }

    .speech-bubble {
        max-width: 180px;
        padding: 8px 12px;
    }

    .speech-bubble p {
        font-size: 11px;
    }

    /* Game screen adjustments */
    .game-header {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 8px;
    }

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

    .emotion-meter {
        flex-wrap: wrap;
        gap: 5px;
    }

    .emotion-meter label {
        font-size: 12px;
    }

    .meter-container {
        width: 120px;
        height: 20px;
    }

    .meter-label {
        font-size: 12px;
    }

    /* Game area - shift up so dialogue box doesn't cover game */
    #game-area {
        height: calc(100vh - 120px);
        padding: 10px;
        margin-top: -90px;
    }

    /* Mini-game containers responsive */
    .rain-container,
    .dark-forest,
    .hills-container,
    .river {
        width: 100%;
        max-width: 100%;
        height: 300px;
        border-radius: 15px;
    }

    .ocean-scene {
        width: 100%;
        max-width: 100%;
        height: 200px;
    }

    /* Volcano container */
    .volcano-container {
        width: 250px;
        height: 250px;
    }

    .breathing-circle {
        width: 120px;
        height: 120px;
        font-size: 14px;
    }

    /* Dialogue box */
    .dialogue-box {
        position: fixed;
        left: 10px !important;
        right: 10px !important;
        bottom: 10px !important;
        top: auto !important;
        transform: none !important;
        width: auto !important;
        max-width: none;
        padding: 15px 15px 15px 70px;
        z-index: 1000;
    }

    .dialogue-character img {
        width: 50px;
        height: 50px;
    }

    #dialogue-text {
        font-size: 13px;
    }

    .dialogue-option {
        font-size: 12px;
        padding: 6px 10px;
    }

    /* Modal */
    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 20px;
        border-radius: 15px;
    }

    .region-character-large {
        text-align: center;
    }

    .region-character-large img {
        width: 60px;
        height: 60px;
    }

    /* Shell container for harmony game */
    .shell-container {
        gap: 12px;
    }

    .shell {
        width: 50px;
        height: 50px;
    }

    .shell img {
        width: 24px;
        height: 24px;
    }

    /* Score displays */
    .score-display,
    .revealed-count,
    .flowers-bloomed,
    .rings-passed,
    .melodies-played {
        font-size: 16px;
        padding: 8px 15px;
    }

    /* Story ending */
    .story-container {
        padding: 25px 15px;
        max-width: 95%;
    }

    .story-title {
        font-size: 24px;
    }

    .story-text {
        font-size: 14px;
    }

    .lesson-box {
        padding: 15px;
    }

    .lesson-box h3 {
        font-size: 16px;
    }

    .lesson-box p {
        font-size: 14px;
    }

    .reward-text {
        font-size: 18px;
    }

    .continue-btn {
        padding: 12px 25px;
        font-size: 16px;
    }

    /* Instructions panel */
    .instructions-toggle {
        width: 45px;
        height: 45px;
        right: 10px;
    }

    .toggle-icon {
        font-size: 20px;
    }
}

/* Small phone */
@media (max-width: 480px) {
    /* Slightly smaller marker pins on small phones */
    .region-card {
        width: 110px !important;
        height: 140px !important;
    }

    .region-card .region-image-container {
        width: 100px !important;
        height: 100px !important;
    }

    .region-card .pulse-indicator {
        width: 100px;
        height: 100px;
        top: 50px;
    }

    .region-card::before {
        border-left-width: 14px !important;
        border-right-width: 14px !important;
        border-top-width: 20px !important;
        bottom: 18px !important;
    }

    .region-card::after {
        font-size: 11px;
        bottom: -4px;
    }

    .banner-overlay {
        top: 30px;
    }

    .banner-overlay img {
        width: 90vw;
    }

    #explorers-log {
        top: 115px;
    }

    /* Game containers even smaller */
    .rain-container,
    .dark-forest,
    .hills-container,
    .river {
        height: 250px;
    }

    .ocean-scene {
        height: 180px;
    }

    .volcano-container {
        width: 200px;
        height: 200px;
    }

    .breathing-circle {
        width: 100px;
        height: 100px;
        font-size: 12px;
    }

    /* Steering controls smaller */
    .ctrl-btn {
        width: 50px;
        height: 50px;
    }

    .ctrl-arrow {
        font-size: 18px;
    }

    /* Dolphin/harmony */
    .dolphin img {
        width: 40px !important;
        height: 40px !important;
    }

    .shell {
        width: 45px;
        height: 45px;
    }

    .character-guide {
        display: none;
    }
}

/* Landscape on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #game-area {
        height: calc(100vh - 60px);
    }

    .game-header {
        padding: 5px 15px;
    }

    .breathing-game {
        flex-direction: row;
        gap: 15px;
    }

    .volcano-container {
        width: 180px;
        height: 180px;
    }

    .breathing-circle {
        width: 80px;
        height: 80px;
        font-size: 11px;
    }

    .rain-container,
    .dark-forest,
    .hills-container,
    .river {
        height: 220px;
    }

    .steering-game {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .mobile-controls {
        margin-top: 0;
        margin-left: 10px;
    }
}
