:root {
    --bg: #f6f7fb;
    --bg_end: #ffffff;
    --card: #fdfdfd;
    --muted: #6b7280;
    --accent: #6200ee;
    --text: #0f172a;
    --glass: rgba(255,255,255,0.6);
    --shadow: 0 2px 8px rgba(16,24,40,0.08);
    --hover-btn: #dddddd;
    --hover-btn-text: #000000;
    --border: #aaaaaa;
    --btn-bg: #f6f7fb;
    --btn-text:#0f172a;
    --tooltip-bg: rgba(20,20,20,0.95);
    --tooltip-text: #fff;
    --tooltip-border: rgba(20,20,20,0.95) transparent transparent transparent;
    --select-dropdown: #f8f8f8;
}

[data-theme="dark"] {
    --bg: #18294d;
    --bg_end: #2e4d88;
    --card: #121e2e;
    --muted: #9ca3af;
    --accent: #586eea;
    --text: #c9dcf4;
    --glass: rgba(255,255,255,0.03);
    --shadow: 0 6px 18px rgba(2,6,23,0.6);
    --hover-btn: #133F86;
    --hover-btn-text: #C4D9F0;
    --border: #102142;
    --btn-bg: #223553;
    --btn-text: #358eee;
    --tooltip-bg: rgba(91, 166, 241, 1);
    --tooltip-text: #000000;
    --tooltip-border: rgba(91, 166, 241, 1) transparent transparent transparent;
    --select-dropdown: #c9dcf4;
}

*{ box-sizing: border-box }

html,
body {
    height: 100%;
    margin: 0;
    font-family: Roboto, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    color: var(--text);
    background: linear-gradient(180deg,var(--bg), var(--bg_end));
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--glass);
    backdrop-filter: blur(6px);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 30;
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
}

.controls {
    display: flex;
    gap: 8px;
    align-items: center;    
}

.map-count {
    font-size: 0.95rem;
    color: var(--muted);
    padding-right: 6px;
    white-space: nowrap;
}

[data-theme="dark"] .map-count {
    color: #a7d7f9;
}

.controls input[type=search] {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(15,23,42,0.06);
    min-width: 180px;
    background-color: var(--select-dropdown);
}

.controls select {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(15,23,42,0.06);
    background-color: var(--select-dropdown);
}

.switch {
    display: inline-block;
    position: relative;
    width: 44px;
    height: 26px;
}

.switch input { display: none; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #e6e6e6;
    border-radius: 26px;
}

.slider:before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform .2s;
}

.switch input:checked + .slider { background: var(--accent); }

.switch input:checked + .slider:before { transform: translateX(18px); }

.container { padding:28px; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill,minmax(220px,1fr));
    gap: 20px;
}

.card {
    background: var(--card);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform .18s, box-shadow .18s;
}

.card:hover { transform: translateY(-6px) }

.thumb {
    height: 140px;
    object-fit: cover;
    width: 100%;
    display: block;
}

.card-body { padding: 12px }

.card-title {
    font-weight: 500;
    margin: 0 0 6px 0;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    font-size: 13px;
    color:var(--muted);
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
    position: relative;
}

.chips {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.chip {
    background: rgba(0,0,0,0.06);
    padding: 6px 8px;
    border-radius: 999px;
    font-size: 12px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 60;
}

.modal.show {
    display: flex;
}

.modal-backdrop {
    display: absolute;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: linear-gradient(180deg, rgba(2,6,23,0.6), rgba(2,6,23,0.4));
    backdrop-filter: blur(6px);
}
.modal-content {
    position: relative;
    max-width: none;
    width: 95%;
    max-width: 1400px;
    max-height: 90vh;
    border-radius: 14px;
    overflow: hidden;
    background: var(--card);
    box-shadow: var(--shadow);
    overflow-y: auto;
    box-sizing: border-box;
    z-index: 1001;
}

/* ============================
   FULLSCREEN IMAGE MODE
   For Map Type = "Biome Map"
   ============================ */
.modal-content.fullscreen-image {
    max-width: 100vw !important;
    width: 100% !important;
    height: 95vh !important;
    border-radius: 0;
}

.modal-content.fullscreen-image .modal-body {
    flex-direction: column;
    padding: 0;
    gap: 0;
}

.modal-content.fullscreen-image .modal-main {
    width: 100%;
    display: flex;
    justify-content: center;
}

.modal-content.fullscreen-image .gallery {
    flex: 1 1 100% !important;
    width: 100%;
    margin: 0;
}

.modal-content.fullscreen-image .media-wrap {
    width: 100% !important;
    max-height: 90vh !important;
    height: 90vh !important;
    background: #000;
}

.modal-content.fullscreen-image .details {
    display: none !important;
}

.modal-body {
    display: flex;
    flex-direction: row;
    justify-content: wrap;
    gap: 18px;
    padding: 18px;
    height: 100%;
    max-height: none;
    overflow: visible;
    transition: all 0.3s ease;
}
.modal-main {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    max-width: 90vw;
    width: 100%;
}

.modal-main.fullscreen-image {
    gap: 0 !important;
}

.modal-main.fullscreen-image .gallery {
    flex: 1 1 100% !important;
}

.gallery {
    display: flex;
    flex: 2 1 600px;
    min-width: 300px;
    align-items: center;
    justify-content: center;
    gap: 12px;    
}

.media-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.media-wrap {    
    max-height: 78vh;
    border-radius: 8px;
    flex: 1.9;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    position: relative;
    min-width: 65%;
}

.img-wrapper {
    display: inline-block;
    position: relative;
}

.img-container {
    position: relative;
    /* display: inline-block; */
    display: flex;
    /* min-height: 400px; */
    min-height: 200px;
}

.img-container img,
.img-container iframe {
    max-width: 100%;
    height: auto;
    /* display: block; */
}

.img-container.show-video .no-image-message {
    display: none !important;
}

.img-container.no-image canvas {
    pointer-events: none; /* blocks drawing */
    opacity: 0.3;
    cursor: not-allowed;
}


.media-img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    z-index: 1;
}

.video-container {
    width: 100%;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#modalVideo {
    width: 100%;
    height: 100%;
    max-height: 100%;
    object-fit: contain;
    border: none;
    border-radius: 8px;
    display: none;
}

.media-wrap img {
    transition: opacity 0.3s ease;
}

.media-wrap::before {
    display: none;
}

.no-image-message {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 1.2rem;
    font-style: italic;
    text-align: center;
    opacity: 0.7;
    z-index: 2;
    pointer-events: none;
}

.media-wrap.no-image .no-image-message {
    display: flex;
}

/* .media-wrap.no-image::before {
    display: block;
    content: "No image available";
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -55%);
    color: var(--muted);
    font-size: 1rem;
    font-style: italic;
    text-align: center;
    opacity: 0.7;
    pointer-events: none;
    z-index: 2;    
} */

/* .media-wrap.no-image {
    visibility: hidden; 
} */


.media-wrap iframe {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
}

.media-wrap.video-active {
    width: 100%;
    max-width: none;
    height: 95vh;
}

.media-wrap.video-active .img-container {
    width: 100%;
    height: 100%;
}

.media-wrap.video-active iframe {
    width: 100%;
    height: 100%;
}

.nav-btn {
    background: none;
    border: 1px solid rgba(15,23,42,0.06);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow-wrap: break-word;
    height: auto;
    min-height: 48px;
    min-width: 48px;
}

.details {
    flex: 1.1 1.1 300px;
    min-width: 320px;
    max-width: 420px;
    overflow: visible;
}

.stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    border-radius: 8px;
    background: var(--glass);
}

.thumbs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.thumb-btn {
    width: 64px;
    height: 46px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
}

.close-btn {
    position: absolute;
    right: 12px;
    top: 12px;
    background: var(--card);
    border: none;
    border-radius: 5px;
    font-size: 20px;
    color: var(--muted);
    cursor: pointer;
    z-index: 1010;

}

@media (max-width:900px) {
    .modal-body {
        flex-direction: column
    }
    .media-wrap {
        width: 100%;
        height:56vw;
    }
}

/* Spots badge */
.spots {
    margin-left: auto;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 50px;
    font-size: 0.85rem;
}

.spot-badge {
    background-color: #e3f2fd;
    color: #1565c0;
}

/* Biome text */
.biome {
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.biome-card {
    border: 3px solid #1B8C9A;
}

.biome-lava {
    color: #f44336;
    border: 3px solid #f44336;
}

.biome-grass {
    color: #4caf50;
    border: 3px solid #4caf50;
}

.biome-ice {
    color: #2196f3; 
    border: 3px solid #2196f3;
}

.biome-fantasy {
    color: #9c27b0;
    border: 3px solid #9c27b0;
}

/* Biome icon */
.card-thumb-wrapper {
    position: relative;
    display: inline-block;
}

.card-thumb-wrapper .biome-icon {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 30px;
    height: 30px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 10;
}

.card-thumb-wrapper {
    position: relative;
    display: inline-block;
}

.parking-badge {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    background-color: rgba(0,0,0,0.6);
    padding: 4px 8px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
    z-index: 15;
}

#modalImage {
    display: block;
    width: 100%;
    height: auto;
}

#drawCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto;
}

.draw-canvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
    pointer-events: auto;
    z-index: 10;
    background: transparent;
}

.draw-tools {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-top: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    border-radius: 12px;
    position: relative;
    overflow: visible !important;
    z-index: 5000;
}

.draw-tools label,
.draw-tools input,
.draw-tools select,
.draw-tools button {
    flex: 1 1 auto;
    padding: 4px;
}

.draw-tools button {
    position: relative;
    overflow: visible !important;
    z-index: 55001;
}

/* When expand mode active, hide stats column */
.expand-active .details {
    display: none;
}

/* Let the gallery take full width */
.expand-active .gallery {
    flex: 1 1 100%;
}

/* allow image to grow larger vertically */
.expand-active .media-wrap {
    max-height: 90vh;
}

.expand-btn.active {
    background: var(--accent);
    color: #fff;
}

.modal-main.expanded .details {
    display: none;
}

.modal-main.expanded .gallery {
    flex: 1 1 100%;
}

.modal-main .gallery {
  flex: 0 1 70%; /* normal width */
  transition: flex 0.3s ease;
}

.modal-main .details {
  transition: opacity 0.3s ease;
}

#colorPresets {
    display: grid;
    grid-template-columns: repeat(3, 32px); /* 3 colors per row */
    gap: 6px;
    margin-bottom: 10px;
}

.color-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #444;
    cursor: pointer;
    padding: 0;
}

.color-btn.selected {
    border-color: #ccc; /* highlight selected */
    box-shadow: 0 0 4px #fff;
}

#eraserCursor {
    position: fixed;
    pointer-events: none;
    border: 1px solid black;
    box-shadow: 0 0 0 1px white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    display: none;
    z-index: 99999999;
    background-color: rgba(255, 255, 255, 0.6);
}


#expandToggle,
#drawCopy {
    width: 34px !important;
    min-width: 34px !important;
    max-width: 34px !important;

    height: 34px !important;
    min-height: 34px !important;
    max-height: 34px !important;

    overflow: hidden;
    padding: 0 !important;

    z-index: 2000;
}

#drawColor {
    flex: 0 0 auto !important;
    width: 64px !important;
    height: 64px !important;
    padding: 0 !important;
    border: 1px solid var(--border, #aaa);
    border-radius: 6px;
    background: var(--bg, #eee);
    cursor: pointer;
    box-sizing: border-box;
}


#drawColor::-webkit-color-swatch-wrapper {
    padding: 0;
}

#drawColor::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

#drawColor:hover {
    background: var(--hover, #ddd);
}

#Tools,
#shapeTools,
#brushSizes,
#saveTools
 {
    display: grid;
    grid-template-columns: repeat(4, 36px); /* 3 buttons per row */
    grid-template-rows: 36px 36px;
    gap: 6px;
    margin-bottom: 10px;
}

#saveTools {   
    grid-template-columns: repeat(1, 36px); /* 1 button per row */
}

#drawUndo { grid-column: 1; grid-row: 1; }
#drawRedo { grid-column: 2; grid-row: 1; }
#drawText { grid-column: 3; grid-row: 1; }
#drawEraser { grid-column: 1; grid-row: 2; }
#drawFill { grid-column: 2; grid-row: 2; }
#drawClear { grid-column: 3; grid-row: 2; }

#globalTooltip {
    position: fixed;
    padding: 6px 10px;
    background: var(--tooltip-bg, rgba(20,20,20,0.95));
    color: var(--tooltip-text, #fff);
    font-size: 12px;
    border-radius: 6px;
    pointer-events: none;
    white-space: nowrap;
    z-index: 999999999;
    opacity: 0;
    transform: translate(-50%, -4px);
    transition: opacity .12s ease;
}

#globalTooltip::after {
    content: "";
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px 5px 0 5px;
    border-style: solid;
    border-color: var(--tooltip-border, rgba(20,20,20,0.95) transparent transparent transparent);
}

.square-btn,
.shape-btn,
.size-btn,
.tool-btn,
.save-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border, #aaa);
    background: var(--btn-bg, #eee);
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, border-color 0.15s;
    z-index: 1001;
}

.square-btn:hover,
.size-btn:hover,
.save-btn:hover,
.tool-btn:hover,
.shape-btn:hover {    
    background: var(--hover-btn, #ddd);
}

.square-btn:hover svg,
.size-btn:hover svg,
.save-btn:hover svg,
.tool-btn:hover svg,
.shape-btn:hover svg {    
    stroke: var(--hover-btn-text, #fff);
}

.square-btn.selected,
.size-btn.selected,
.save-btn.selected,
.tool-btn.selected,
.shape-btn.selected,
#drawEraser.selected,
#drawText.selected {
    color: #ffffff;
    background: #4287f5;
    border-color: #1c5ed6;
}

.square-btn svg,
.size-btn svg,
.save-btn svg,
.tool-btn svg,
.shape-btn svg {
    stroke: var(--btn-text, #ddd);
}

.square-btn.selected svg,
.size-btn.selected svg,
.save-btn.selected svg,
.tool-btn.selected svg,
.shape-btn.selected svg {
    stroke: white;
}

.size-btn .dot {
    display: block;
    background: var(--btn-text, #ddd);
    border-radius: 50%;
    pointer-events: none;
}
.size-btn.selected .dot {   
    background: #ffffff;
    border-color: #1c5ed6;
}


@media (max-width: 900px) {
    .modal-body {
        flex-direction: column;
    }

    .media-wrap {
        height: auto !important;
        min-height: unset !important;
    }

    .gallery {
        align-items: flex-start !important;
    }

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