/* Dune: Awakening - Deep Desert Map Styles */

/* Base styles */
body {
    font-family: 'Inter', sans-serif;
    overflow: hidden; /* Prevent scrolling of the whole page */
}

/* Map container and grid */
#map-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* This will contain the zoom */
    position: relative;
    cursor: grab; /* Indicate the map is pannable */
}

#map-container:active {
    cursor: grabbing;
}

#map-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    /* Desert theme colors */
    border: 2px solid #5a4a3a;
    background-color: #c2b280;
    background-image: linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px);
    background-size: calc(100% / 9) calc(100% / 9);
    position: absolute; /* Changed for pan/zoom positioning */
    transform-origin: 0 0; /* Zoom from the top-left for easier math */
}

/* Grid cells */
.grid-cell {
    border: 1px solid rgba(0, 0, 0, 0.2);
    position: relative;
}

.grid-cell-label {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(90, 74, 58, 0.5); /* A darker, less obtrusive version of the border color */
    font-size: 0.65rem;
    font-weight: 600;
    pointer-events: none; /* Make sure it doesn't interfere with clicks/drags */
    z-index: 1; /* Ensure it's behind the map nodes */
    user-select: none;
}

/* Map nodes */
.map-node {
    position: absolute;
    cursor: pointer;
    transition: filter 0.2s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(clamp(1.4rem, 3.2vmin, 2.2rem) * var(--regular-node-size-multiplier, 1));
    height: calc(clamp(1.4rem, 3.2vmin, 2.2rem) * var(--regular-node-size-multiplier, 1));
}

.claimed-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(clamp(1.4rem, 3.2vmin, 2.2rem) * 1.2); /* Make X slightly larger than node */
    color: #3b82f6; /* blue-500 */
    font-weight: 900;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
    pointer-events: none; /* Make sure it doesn't interfere with clicks */
    opacity: 0.85;
}

.map-node img {
     max-width: 100%;
     max-height: 100%;
     object-fit: contain;
}

.map-node .fallback-icon {
     width: 1.7rem;
     height: 1.7rem;
     font-size: 1.2rem;
     line-height: 1.7rem;
}

.map-node .small-spice-icon {
    transform: scale(0.75);
}

.map-node.dragging {
    opacity: 0.5;
    z-index: 1000 !important; /* Ensure dragging node is always on top */
}

.map-node.highlighted {
    /* High-contrast blue for better visibility */
    filter: drop-shadow(0 0 15px rgba(0, 191, 255, 0.9));
    border: 2px solid #00BFFF;
    border-radius: 50%;
}

/* Inventory nodes */
.inventory-node {
    cursor: grab;
    transition: background-color 0.2s;
    position: relative; /* Needed for positioning the checkmark */
}

.inventory-node img {
    max-width: 100%;
    max-height: 100%;
    pointer-events: none;
}

.inventory-node .fallback-icon {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 2rem;
    line-height: 2.5rem;
    pointer-events: none;
}

.inventory-node .small-spice-icon {
    transform: scale(0.75);
}

.inventory-node:active {
    cursor: grabbing;
}

.inventory-checkmark {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 1rem;
    height: 1rem;
    background-color: #22c55e; /* green-500 */
    color: white;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: bold;
    border: 1px solid white;
}

/* Tooltip */
#tooltip {
    position: fixed;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(42, 29, 19, 0.95), rgba(28, 20, 12, 0.95));
    color: #e3d5c1;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s;
    white-space: pre-wrap;
    border: 1px solid #5a4a3a;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    max-width: 250px;
}

/* Countdown timer */
#countdown-timer {
    background-color: rgba(28, 20, 12, 0.75);
    color: #ffc107;
    padding: 0.25rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid #5a4a3a;
    font-weight: bold;
    pointer-events: none;
    white-space: nowrap;
}

/* Dropdown items */
.dropdown-item:hover {
    background-color: #4a3b2d;
}



/* Real-time collaboration animations */
@keyframes nodeAppear {
    0% { 
        transform: translate(-50%, -50%) scale(0); 
        opacity: 0; 
    }
    70% { 
        transform: translate(-50%, -50%) scale(1.2); 
        opacity: 1; 
    }
    100% { 
        transform: translate(-50%, -50%) scale(1); 
        opacity: 1; 
    }
}

@keyframes nodeUpdate {
    0% { 
        transform: translate(-50%, -50%) scale(1); 
        box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.7); 
    }
    50% { 
        transform: translate(-50%, -50%) scale(1.1); 
        box-shadow: 0 0 0 10px rgba(251, 191, 36, 0.3); 
    }
    100% { 
        transform: translate(-50%, -50%) scale(1); 
        box-shadow: 0 0 0 0 rgba(251, 191, 36, 0); 
    }
}

.node-appear {
    animation: nodeAppear 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.node-update {
    animation: nodeUpdate 0.8s ease-out;
}

.auto-saving-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(34, 197, 94, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.auto-saving-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

.real-time-status {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 11px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 6px;
}

.real-time-status.connected {
    background: rgba(34, 197, 94, 0.8);
}

.real-time-status.disconnected {
    background: rgba(239, 68, 68, 0.8);
}

.real-time-status .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}


/* Community Spice Toggle Styles */
.toggle-bg {
    transition: background-color 0.2s ease;
}

.toggle-dot {
    transition: transform 0.2s ease;
}

#community-spice-toggle:checked + .toggle-bg {
    background-color: #059669; /* Green when enabled */
}

#community-spice-toggle:checked + .toggle-bg + .toggle-dot {
    transform: translateX(1rem);
}

.custom-toggle:checked + .toggle-bg {
    background-color: #059669; /* Green when enabled */
}

.custom-toggle:checked + .toggle-bg + .toggle-dot {
    transform: translateX(1rem);
}

/* Community Spice Node Styles */
.community-spice-node {
    position: relative;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.1);
}

.community-spice-node .timer {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fbbf24;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    z-index: 10;
}

.community-spice-node .voting-buttons {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    gap: 4px;
    z-index: 20;
}

.community-spice-node .vote-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s ease;
}

.community-spice-node .vote-positive {
    background: #10b981;
    color: white;
}

.community-spice-node .vote-positive:hover {
    background: #059669;
    transform: scale(1.1);
}

.community-spice-node .vote-negative {
    background: #ef4444;
    color: white;
}

.community-spice-node .vote-negative:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* Community Resources Section */
.community-resources-section {
    border: 2px dashed #f59e0b;
    border-radius: 8px;
    background: rgba(245, 158, 11, 0.05);
    padding: 12px;
    margin-top: 16px;
}

.community-resources-section h4 {
    color: #f59e0b;
    font-weight: bold;
    margin-bottom: 8px;
    text-align: center;
}

.community-resources-section .inventory-item {
    border: 1px solid #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

/* Hide community resources when toggle is off */
.community-resources-section.hidden {
    display: none;
}

/* Proximity warning popup */
.proximity-warning {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 20px;
    border-radius: 8px;
    border: 2px solid #f59e0b;
    z-index: 1000;
    max-width: 400px;
    text-align: center;
}

.proximity-warning .existing-node {
    margin: 10px 0;
    padding: 10px;
    background: rgba(245, 158, 11, 0.2);
    border-radius: 4px;
    border: 1px solid #f59e0b;
}

/*
 * Fix for invisible overlay blocking clicks on desktop.
 * This ensures the mobile-only overlay is not present on medium screens and larger.
 */
 @media (min-width: 768px) {
    #mobile-overlay {
        display: none;
    }
}

.timer-icon {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 1rem;
    height: 1rem;
    background-color: #3b82f6; /* A nice blue color */
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    border: 1px solid white;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
    pointer-events: none; /* Make sure it doesn't interfere with clicks */
}

/* --- Cluster Styles --- */

.map-cluster {
    position: absolute;
    cursor: default; /* Clusters aren't draggable, the nodes inside are clickable */
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cluster-icon-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
    background-color: rgba(42, 29, 19, 0.7);
    border: 2px solid #f59e0b;
    border-radius: 50%;
    padding: 5px;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

/* Dynamic grid layouts for clusters */
.cluster-grid-1x1 {
    grid-template-columns: 1fr !important;
    gap: 2px !important;
    padding: 5px !important;
}

.cluster-grid-1x2 {
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr 1fr !important;
    gap: 2px !important;
    padding: 5px !important;
}

.cluster-grid-2x2 {
    grid-template-columns: 1fr 1fr !important;
    grid-template-rows: 1fr 1fr !important;
    gap: 2px !important;
    padding: 5px !important;
}

.cluster-grid-3x2 {
    grid-template-columns: 1fr 1fr 1fr !important;
    grid-template-rows: 1fr 1fr !important;
    gap: 1px !important;
    padding: 4px !important;
}

/* 3x3 grid layout for clusters with more icons */
.cluster-grid-3x3 {
    grid-template-columns: 1fr 1fr 1fr !important;
    gap: 1px !important;
    padding: 3px !important;
}

.cluster-grid-item {
    /* Make cluster icons configurable size */
    width: calc(clamp(1.4rem, 3.2vmin, 2.2rem) * var(--cluster-icon-size-multiplier, 1)) !important;
    height: calc(clamp(1.4rem, 3.2vmin, 2.2rem) * var(--cluster-icon-size-multiplier, 1)) !important;
}

/* This is a node INSIDE a cluster */
.map-node-in-cluster {
    position: relative; /* Overrides absolute positioning from .map-node */
}

.map-node-in-cluster .fallback-icon {
     font-size: 0.8rem;
}

.cluster-count {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #dc2626; /* red-600 */
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    border-radius: 9999px;
    min-width: 1.25rem;
    height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 1px solid white;
}

/* --- Horizontal Dashed Line --- */
.horizontal-midline {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 0;
    border-top: 2px dashed rgba(90, 74, 58, 0.7);
    z-index: 5; /* Places it above the grid labels but below all map nodes */
    transform: translateY(-50%);
    grid-column: 1 / -1; /* ADDED: This makes the line span all 9 columns of the grid. */
}