*, *::before, *::after { box-sizing: border-box; }

body, html {
    width: 100%; max-width: 100vw; height: 100dvh; 
    margin: 0; padding: 0; font-family: 'Segoe UI', sans-serif;
    overflow: hidden; background: #111;
}

/* FEATURE 4: Ambient Window Seat UI */
#ambient-bg {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; /* Map clicks pass right through it */
    z-index: 1000; /* Above Map (0), below UI Cards (2500) */
    transition: background 1.5s ease, opacity 1.5s ease;
    opacity: 0;
}

/* Sunny / Day tint */
#ambient-bg.theme-day {
    background: linear-gradient(to bottom, rgba(255, 230, 150, 0.15), rgba(0, 0, 0, 0));
    opacity: 1;
}

/* Night tint */
#ambient-bg.theme-night {
    background: linear-gradient(to bottom, rgba(0, 15, 40, 0.4), rgba(0, 0, 0, 0.1));
    opacity: 1;
}

/* Rain Animation Effect */
#ambient-bg.ambient-rain {
    opacity: 1;
    background-image: 
        linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0) 100%);
    background-size: 4px 120px;
    animation: rainDrop 0.4s linear infinite;
}

#ambient-bg.theme-night.ambient-rain {
    background-color: rgba(0, 5, 20, 0.5); /* Darker rain */
}

@keyframes rainDrop {
    0% { background-position: 0px -100px; }
    100% { background-position: -20px 100vh; /* Slight slant */ }
}

#app-wrapper {
    display: grid; width: 100%; height: 100%; overflow: hidden;
    grid-template-columns: 1fr; 
    grid-template-rows: 1fr max-content; 
    grid-template-areas: "map" "controls";
}

#app-wrapper.show-sidebar {
    grid-template-columns: 1fr 350px; 
    grid-template-areas:
        "map sidebar"
        "controls sidebar";
}

#map-container { grid-area: map; position: relative; width: 100%; height: 100%; }

/* Map Overlays & Panels */
.map-overlay {
    position: relative; /* Changed from absolute */
    background: rgba(20, 20, 20, 0.95);
    color: #fff; border: 1px solid #444; border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5); 
    pointer-events: auto; width: 100%; 
}

#floating-search-bar { display: flex; flex-direction: column; padding: 10px; overflow: hidden; gap: 10px; }

#floating-search-bar input {
    flex: 1; border: none; padding: 0 16px; font-size: 15px;
    outline: none; background: transparent; color: #fff;
}

#floating-search-bar button {
    border: none; background: #0288D1; color: #fff; padding: 0 16px;
    cursor: pointer; font-weight: bold; transition: background 0.2s;
}

#floating-search-bar button:hover { background: #026ca8; }

#floating-location-card { padding: 12px; }
#teleporter-card { padding: 12px; }

.loc-header-row { display: flex; justify-content: space-between; align-items: center; }
.info-coords { font-size: 15px; font-weight: 800; font-family: monospace; }

.search-row { display: flex; width: 100%; height: 32px; border: 1px solid #444; border-radius: 4px; overflow: hidden; }

.search-row input {
    flex: 1; border: none; padding: 0 10px; font-size: 14px;
    outline: none; background: transparent; color: #fff;
}

.search-row button {
    border: none; background: #0288D1; color: #fff; padding: 0 16px;
    cursor: pointer; font-weight: bold; transition: background 0.2s;
}

.search-row button:hover { background: #026ca8; }

.file-row { display: flex; flex-direction: column; }

#left-panel {
    position: absolute; top: 15px; left: 15px; z-index: 2500;
    display: flex; flex-direction: column; gap: 15px;
    width: 360px; max-width: calc(100vw - 30px);
    pointer-events: none; /* Let map clicks pass through the gaps */
}

/* Mobile Panel Toggle Button */
#panel-toggle-btn {
    display: none; /* Hidden on desktop */
    position: absolute;
    right: -40px; /* Sticks out to the right of the panel */
    top: 0;
    width: 40px;
    height: 40px;
    background: rgba(20, 20, 20, 0.95);
    color: #fff;
    border: 1px solid #444;
    border-left: none; /* Seamless connection to the search bar */
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    pointer-events: auto;
    font-size: 16px;
    align-items: center;
    justify-content: center;
    box-shadow: 4px 4px 15px rgba(0,0,0,0.5);
    z-index: 2600;
}

/* The Teleporter's Briefing Grid */
.briefing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.brief-item {
    font-size: 12px; background: rgba(255,255,255,0.05); padding: 6px;
    border-radius: 4px; display: flex; align-items: center; gap: 6px;
}

.hidden { opacity: 0; pointer-events: none; display: none !important; }

/* Sidebar Logic for Feature 1 */
#sidebar-column {
    grid-area: sidebar; display: flex; flex-direction: column;
    background: #1a1a1a; border-left: 1px solid #333; z-index: 2100; color: #fff;
}

.sidebar-header { padding: 20px; border-bottom: 1px solid #333; }
.sidebar-header h2 { margin: 0; font-size: 20px; color: #ffea00; }
.sidebar-header p { margin: 5px 0 0 0; font-size: 12px; color: #aaa; }

.sidebar-content { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; gap: 15px; }

.wiki-card { display: flex; gap: 12px; background: #222; padding: 10px; border-radius: 8px; border: 1px solid #333; }
.wiki-thumb { width: 60px; height: 60px; border-radius: 4px; object-fit: cover; }
.wiki-thumb-placeholder { width: 60px; height: 60px; border-radius: 4px; background: #333; display: flex; justify-content: center; align-items: center; font-size: 24px; }
.wiki-info { flex: 1; }
.wiki-title { color: #4da6ff; text-decoration: none; font-weight: bold; font-size: 14px; display: block; margin-bottom: 4px; }
.wiki-title:hover { text-decoration: underline; }
.wiki-desc { font-size: 11px; color: #ccc; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Feature 3 Controls Bottom Banner */
#controls {
    grid-area: controls; background: rgba(20, 20, 20, 0.98); color: #fff;
    padding: 12px 20px; box-shadow: 0 -4px 15px rgba(0, 0, 0, .5); z-index: 2000; 
}

.compact-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #444; padding-bottom: 6px; margin-bottom: 8px; }
.highlight-data { font-weight: 800; color: #ffea00; font-size: 16px; }

.pinned-controls { display: grid; gap: 20px; align-items: center; }
.pinned-item { display: flex; flex-direction: column; }
.pinned-item label { font-size: 11px; color: #aaa; text-transform: uppercase; margin-bottom: 4px; }

/* Mobile Adjustments */
/* Mobile Adjustments */
@media (max-width: 768px) {
    #app-wrapper.show-sidebar {
        grid-template-columns: 1fr; grid-template-rows: 1fr max-content 300px;
        grid-template-areas: "map" "controls" "sidebar";
    }
    #sidebar-column { border-left: none; border-top: 1px solid #333; }
    
    /* Mobile Toggle Logic */
    #panel-toggle-btn { display: flex; }
    
    #left-panel { 
        width: calc(100vw - 65px); /* Shrink slightly to leave room for the sticking-out button */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* When toggled, slide the panel completely off the left edge */
    #left-panel.collapsed {
        transform: translateX(calc(-100% - 15px)); 
    }
}

.spinner { border: 3px solid #333; border-top: 3px solid #ffea00; border-radius: 50%; width: 30px; height: 30px; animation: spin 1s linear infinite; margin: 0 auto 10px; }
@keyframes spin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }