body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    width: 100%;
    height: 100vh;
    /* Modern viewport height that accounts for mobile browser UI */
    height: 100dvh; /* Dynamic viewport height - preferred */
    overflow: hidden;
    /* Ensure full viewport usage on mobile */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
.mosaic-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none; /* Prevent default touch behaviors */
}
.zoom-container {
    position: relative;
    transform-origin: center center;
    will-change: transform;
}
.zoom-container.smooth-transition {
    transition: transform 0.3s ease-out;
}
.mosaic-image {
    display: block;
    pointer-events: none; /* Prevent image drag on touch devices */
}

/* Desktop: use max-width/max-height for contained sizing */
@media (min-width: 769px) and (hover: hover) {
    .mosaic-image {
        max-width: 100%;
        max-height: 100%;
        width: auto;
        height: auto;
    }
}
.tile-region {
    position: absolute;
    cursor: pointer;
    transition: all 0.2s ease;
}
.tile-region:active {
    transform: scale(0.95);
}
.tile-region:hover {
    background-color: rgba(255, 255, 0, 0.3);
    border: 2px solid #ffcc00;
    z-index: 10;
}
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: auto;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 1000;
    max-width: 1500px;
    word-wrap: break-word;
    white-space: normal;
    visibility: hidden;
}
.tooltip-image {
    display: block;
    max-width: 25vw;
    max-height: 25vh;
    width: auto;
    height: auto;
    margin: 8px 0;
    border-radius: 4px;
    object-fit: contain;
}
.tile-region:hover .tooltip,
.tooltip:hover {
    opacity: 1;
    visibility: visible;
}
.distance-good { color: #28a745; }
.distance-medium { color: #ffc107; }
.distance-bad { color: #dc3545; }

/* Distance overlay styles */
.distance-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 5;
}
.distance-overlay.visible {
    opacity: 0.7;
}
.distance-overlay-tile {
    position: absolute;
    border: 1px solid rgba(255,255,255,0.2);
    min-width: 1px;
    min-height: 1px;
}
/* Distance color coding for overlay */
.overlay-distance-excellent { background: rgba(0, 255, 0, 0.8); }
.overlay-distance-good { background: rgba(40, 167, 69, 0.8); }
.overlay-distance-medium { background: rgba(255, 193, 7, 0.8); }
.overlay-distance-poor { background: rgba(255, 152, 0, 0.8); }
.overlay-distance-bad { background: rgba(220, 53, 69, 0.8); }

/* Mobile modal styles */
.mobile-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    animation: fadeIn 0.3s ease;
    pointer-events: none; /* Prevent interference when hidden */
}

.mobile-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto; /* Re-enable pointer events when active */
}

.modal-content {
    background: white;
    border-radius: 8px;
    padding: 20px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.3s ease;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
}

.modal-image {
    display: block;
    max-width: 100%;
    max-height: 50vh;
    min-width: 400px;
    height: auto;
    margin: 0 auto 15px;
    border-radius: 4px;
    object-fit: contain;
}

.modal-info {
    text-align: left;
    font-size: 14px;
    line-height: 1.5;
}

.modal-info strong {
    color: #333;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Flag Button Styles */
.flag-button {
    background: #ff6b6b;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    margin-top: 8px;
    transition: background-color 0.2s ease;
    width: 100%;
    box-sizing: border-box;
}

.flag-button:hover:not(:disabled) {
    background: #ff5252;
}

.flag-button:disabled {
    background: #666;
    cursor: default;
}

.flag-button:active:not(:disabled) {
    background: #d32f2f;
}

/* Mobile flag button */
.mobile-flag-btn {
    padding: 10px 16px;
    font-size: 14px;
    margin-top: 12px;
    border-radius: 6px;
}

/* Flag status display */
.flag-status {
    margin: 4px 0;
}

.flag-status div {
    font-size: 12px;
    line-height: 1.4;
}

/* Mobile flag container */
.mobile-flag-container {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    z-index: 10000;
    font-size: 14px;
    animation: slideUp 0.3s ease;
    pointer-events: none;
}

/* Year Filter Styles */
.year-filter-container {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border: 1px solid #ddd;
    z-index: 100;
    font-family: Arial, sans-serif;
    min-width: 200px;
}

/* Image-positioned year filter (dynamically positioned at image bottom-right) */
.year-filter-container.image-positioned {
    position: absolute;
    width: 100px;
    min-width: auto;
    padding: 4px 6px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(3px);
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(0, 0, 0, 0.1);
    z-index: 50;
    /* No transform - positioned by JavaScript */
}

.year-filter-label {
    display: block;
    font-size: 14px;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
}

.year-slider-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.year-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.year-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.year-display {
    font-size: 16px;
    font-weight: bold;
    color: #007bff;
    text-align: center;
    min-height: 20px;
}

/* Disabled tile styles - overlay effect */
.tile-region.disabled {
    pointer-events: none;
    background-color: rgba(0, 0, 0, 0.7);
    transition: background-color 0.2s ease;
}

.tile-region.disabled::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        45deg,
        rgba(0, 0, 0, 0.1),
        rgba(0, 0, 0, 0.1) 2px,
        transparent 2px,
        transparent 8px
    );
    z-index: 1;
}

.tile-region.disabled:hover {
    background-color: rgba(0, 0, 0, 0.7) !important;
    border: none !important;
    transform: none !important;
}

@media (hover: hover) and (pointer: fine) {
    /* Ensure non-disabled tiles still show tooltips on desktop only */
    .tile-region:not(.disabled):hover .tooltip,
    .tile-region:not(.disabled) .tooltip:hover {
        opacity: 1;
        visibility: visible;
    }

    /* Ensure tooltips work on desktop only (devices with hover and fine pointer) */
    .tile-region:hover .tooltip,
    .tooltip:hover {
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* Enabled tiles should have a subtle highlight effect */
.tile-region:not(.disabled) {
    transition: background-color 0.2s ease, border 0.2s ease;
    background-color: transparent;
}

.tile-region:not(.disabled):hover {
    background-color: rgba(255, 255, 0, 0.3);
    border: 2px solid #ffcc00;
    z-index: 5;
}

/* Mobile viewport fixes */
@media only screen and (hover: none) and (pointer: coarse){

    /* Hide tooltips on mobile devices */
    .tooltip {
        display: none !important;
        visibility: hidden !important;
        pointer-events: none !important;
        opacity: 0 !important;
    }

    /* Prevent tooltip triggers on touch */
    .tile-region:hover .tooltip,
    .tile-region:active .tooltip,
    .tile-region:focus .tooltip {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }

    /* Disable hover effects that might trigger tooltips */
    .tile-region {
        -webkit-tap-highlight-color: transparent;
    }

    /* Override any tooltip show rules on mobile */
    .tile-region:hover .tooltip,
    .tile-region:not(.disabled):hover .tooltip {
        display: none !important;
        opacity: 0 !important;
    }

    body {
        /* Fallback for older browsers that don't support dvh */
        height: 100vh;
        height: 100dvh;
        /* iOS Safari specific fixes */
        -webkit-overflow-scrolling: touch;
        /* Prevent zoom on input focus */
        -webkit-text-size-adjust: 100%;
        /* Handle safe areas (iPhone notch, etc.) */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .mosaic-container {
        width: 100%;
        height: 100%;
    }
    /* Mobile responsive adjustments for year filter */
    .year-filter-container.image-positioned {
        width: 60px !important;
        padding: 6px 8px !important;
        background: transparent !important;
        backdrop-filter: none !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }

    .year-filter-label {
        display: none !important;
    }

    .year-slider-wrapper {
        position: relative !important;
        display: flex !important;
        align-items: center !important;
        gap: 0 !important;
    }

    .year-slider {
        width: 100% !important;
        height: 6px !important;
        border-radius: 3px !important;
        outline: none !important;
        -webkit-appearance: none !important;
        appearance: none !important;
        cursor: pointer !important;
        display: block !important;
        visibility: visible !important;
        touch-action: manipulation !important;
    }

    .year-slider::-webkit-slider-thumb {
        -webkit-appearance: none !important;
        appearance: none !important;
        width: 14px !important;
        height: 14px !important;
        border-radius: 50% !important;
        background: #007bff !important;
        cursor: pointer !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4) !important;
        border: none !important;
    }

    .year-slider::-moz-range-thumb {
        width: 14px !important;
        height: 14px !important;
        border-radius: 50% !important;
        background: #007bff !important;
        cursor: pointer !important;
        border: none !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4) !important;
    }

    .year-display {
        position: absolute !important;
        top: -26px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        font-size: 12px !important;
        color: white !important;
        padding: 3px 8px !important;
        border-radius: 6px !important;
        font-weight: 600 !important;
        white-space: nowrap !important;
        pointer-events: none !important;
        text-shadow: none !important;
        display: block !important;
        visibility: visible !important;
    }
}

/* Admin pane styles */
.admin-pane {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 300px;
    background: rgba(0, 0, 0, 0.95);
    color: white;
    padding: 15px;
    border-radius: 8px;
    font-size: 12px;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    display: none;
}
.admin-pane.visible {
    display: block;
}
.admin-pane h3 {
    margin: 0 0 10px 0;
    color: #ffd700;
    font-size: 14px;
}
.admin-button {
    width: 100%;
    padding: 8px;
    margin: 5px 0;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}
.admin-button:hover {
    background: #c82333;
}
.admin-button:disabled {
    background: #666;
    cursor: not-allowed;
}
.admin-button.active {
    background: #28a745;
    color: white;
}
.admin-button.active:hover {
    background: #218838;
}
.admin-status {
    margin: 10px 0;
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    font-size: 11px;
}
.flag-highlight {
    position: absolute;
    pointer-events: none;
    border: 3px solid #ff0000;
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
    z-index: 1000;
}