* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
    background: #0a0a1a;
    color: #e0e0e0;
}

#app {
    display: flex; width: 100%; height: 100%;
}

/* === Sidebar === */
#sidebar {
    width: 320px; min-width: 320px;
    background: rgba(20, 20, 40, 0.95);
    backdrop-filter: blur(12px);
    border-right: 1px solid rgba(255,255,255,0.08);
    display: flex; flex-direction: column;
    z-index: 10;
    position: relative;
    transition: width 0.3s ease, min-width 0.3s ease;
}

#sidebar.collapsed {
    width: 0; min-width: 0;
}

#sidebar.collapsed > #sidebar-inner {
    display: none;
}

/* collapsible toggle button */
#sidebar-toggle {
    position: absolute;
    left: 100%; top: 50%;
    transform: translateY(-50%);
    z-index: 30;
    background: rgba(20,20,40,0.9);
    border: 1px solid rgba(255,255,255,0.1);
    border-left: none;
    border-radius: 0 6px 6px 0;
    padding: 14px 6px;
    cursor: pointer;
    color: #8888aa;
    font-size: 11px;
    line-height: 1;
    transition: color 0.2s, background 0.2s;
    white-space: nowrap;
}

#sidebar-toggle:hover {
    color: #fff;
    background: rgba(40,40,70,0.95);
}

#sidebar-inner {
    display: flex; flex-direction: column;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

#sidebar-inner::-webkit-scrollbar { width: 4px; }
#sidebar-inner::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

#sidebar h1 {
    font-size: 20px; font-weight: 700;
    padding: 20px 20px 12px;
    color: #fff;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

#sidebar h1 small {
    display: block;
    font-size: 12px; font-weight: 400;
    color: #8888aa; margin-top: 4px;
    letter-spacing: 0;
}

.control-group {
    padding: 12px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.control-group label {
    display: block;
    font-size: 11px; font-weight: 600;
    color: #8888aa; text-transform: uppercase;
    letter-spacing: 1px; margin-bottom: 6px;
}

.control-group select {
    width: 100%; padding: 8px 12px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: #e0e0e0; font-size: 14px;
    outline: none; cursor: pointer;
    transition: border-color 0.2s;
}

.control-group select:focus {
    border-color: #4488ff;
}

.control-group select:disabled {
    opacity: 0.4; cursor: not-allowed;
}

.control-group select option {
    background: #1a1a30; color: #e0e0e0;
}

.control-group input[type="range"] {
    width: 100%; height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    background: #4488ff;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.3);
}

#exaggeration-value {
    float: right;
    color: #4488ff;
    font-size: 13px;
}

/* toggle switches */
.toggle-row {
    display: flex; flex-wrap: wrap; gap: 4px;
    margin-top: 4px;
}
.toggle-item {
    font-size: 12px; color: #a0a0c0; cursor: pointer;
    display: flex; align-items: center; gap: 3px;
    padding: 2px 6px; border-radius: 4px;
    background: rgba(255,255,255,0.04);
    transition: background 0.2s, color 0.2s;
}
.toggle-item:hover { background: rgba(255,255,255,0.1); color: #d0d0f0; }
.toggle-item input { accent-color: #4488ff; cursor: pointer; }
.toggle-flat { border-color: rgba(68,136,255,0.25); }
.toggle-flat:has(input:checked) { background: rgba(68,136,255,0.12); color: #88bbff; }

/* === Info Panel === */
#info-panel {
    flex: 1; padding: 16px 20px;
    min-height: 100px;
}

#info-title {
    font-size: 18px; font-weight: 600;
    color: #fff; margin-bottom: 8px;
}

#info-content {
    font-size: 13px; line-height: 1.7;
    color: #a0a0c0;
}

#info-content .stat-row {
    display: flex; justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

#info-content .stat-row .label { color: #8888aa; }
#info-content .stat-row .value { color: #d0d0f0; }

#info-content .landmark-list {
    margin-top: 8px;
    list-style: none;
}

#info-content .landmark-list li {
    padding: 3px 0;
    font-size: 12px;
}

#info-content .landmark-list .type-icon {
    display: inline-block; width: 16px;
    text-align: center; margin-right: 4px;
}

/* === Viewport === */
#viewport {
    flex: 1; position: relative;
    overflow: hidden;
}

#viewport canvas {
    display: block;
}

/* Loading overlay */
#loading-overlay {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: rgba(10,10,26,0.9);
    z-index: 20;
    transition: opacity 0.5s;
}

#loading-overlay.hidden {
    opacity: 0; pointer-events: none;
}

.spinner {
    width: 48px; height: 48px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: #4488ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loading-overlay p {
    margin-top: 16px; font-size: 14px; color: #8888aa;
}

/* Legend */
#legend {
    position: absolute; bottom: 24px; right: 24px;
    width: 36px; height: 180px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(0,0,0,0.3);
    z-index: 5;
}

/* Compass */
#compass {
    position: absolute;
    top: 12px; left: 12px;
    width: 64px; height: 64px;
    z-index: 15;
    background: rgba(20, 20, 40, 0.85);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 50%;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.compass-rotator {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    transform-origin: 50% 50%;
}
.compass-arrow {
    position: absolute;
    left: calc(50% - 5px);
    top: 10px;
    width: 0; height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 22px solid #ff6464;
    filter: drop-shadow(0 0 3px rgba(255, 100, 100, 0.6));
}
.compass-letter {
    position: absolute;
    font-size: 10px;
    font-weight: 700;
    color: #a0a0c0;
    line-height: 1;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
.compass-n { top: 3px; left: 50%; transform: translateX(-50%); color: #ff8888; font-size: 11px; }
.compass-e { right: 5px; top: 50%; transform: translateY(-50%); }
.compass-s { bottom: 3px; left: 50%; transform: translateX(-50%); }
.compass-w { left: 6px; top: 50%; transform: translateY(-50%); }

#legend canvas {
    display: block; width: 100%; height: 100%;
}

#legend-labels {
    position: absolute; left: -50px; top: 0; bottom: 0;
    display: flex; flex-direction: column;
    justify-content: space-between;
    font-size: 10px; color: #a0a0c0;
    pointer-events: none;
    text-align: right;
}

/* Coordinates tooltip */
#coord-tooltip {
    position: absolute; bottom: 24px; left: 24px;
    font-size: 12px; color: #a0a0c0;
    background: rgba(0,0,0,0.6);
    padding: 6px 12px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 5;
    display: none;
    font-family: 'SF Mono', 'Consolas', monospace;
}

/* Hover tooltip */
#hover-tooltip {
    position: absolute;
    font-size: 13px; color: #fff;
    background: rgba(0,0,0,0.8);
    padding: 6px 12px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 15;
    display: none;
    transform: translate(-50%, -100%);
    white-space: nowrap;
}

/* City labels - CSS2D */
.city-label {
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    text-shadow: 0 0 4px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.6);
    pointer-events: none;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(0,0,0,0.35);
}

.city-label.capital {
    font-size: 12px;
    background: rgba(200,150,0,0.3);
    border: 1px solid rgba(255,200,0,0.3);
}

.mountain-label {
    color: #e8c088;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 12px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.capital-label {
    color: #ffcc00;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.gdp-label {
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.lake-label {
    color: #88ccff;
    font-size: 11px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 12px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.province-label {
    color: rgba(180, 200, 230, 0.55);
    font-size: 14px;
    font-weight: 700;
    text-shadow: 0 0 8px rgba(0,0,0,0.95), 0 0 16px rgba(0,0,0,0.8), 0 2px 4px rgba(0,0,0,0.9);
    pointer-events: none;
    letter-spacing: 2px;
    font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans SC', sans-serif;
    white-space: nowrap;
}

.landmark-label {
    color: #aaddff;
    font-size: 10px;
    text-shadow: 0 0 4px rgba(0,0,0,0.9);
    pointer-events: none;
}

/* Scrollbar */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* === Responsive === */
@media (max-width: 768px) {
    #app { flex-direction: column; }
    #sidebar {
        width: 100%; min-width: unset;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.08);
    }
    #legend { width: 24px; height: 120px; }
}

.pop-label {
    color: #aaccff;
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.spec-label {
    color: #88ddaa;
    font-size: 10px;
    font-weight: 500;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.famous-label {
    color: #ee8844;
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}
.arts-label {
    color: #cc77dd;
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}
.events-label {
    color: #dd6644;
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.basin-label {
    color: #ff8844;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.ethnic-label {
    color: #66bbaa;
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.river-label {
    color: #55aaff;
    font-size: 12px;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 12px rgba(0,0,0,0.8), 0 0 20px rgba(0,0,0,0.6);
    pointer-events: none;
    white-space: nowrap;
}

.range-label {
    color: #66bb55;
    font-size: 12px;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 12px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 2px;
}

.terrain-label {
    color: #ddbb66;
    font-size: 12px;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 12px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}
.terrain-sub-label {
    color: #aa8844;
    font-size: 9px;
    font-weight: 500;
    text-shadow: 0 0 4px rgba(0,0,0,0.95);
    pointer-events: none;
    white-space: nowrap;
}
.divide-label {
    color: #ff8866;
    font-size: 11px;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 12px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}
.divide-sub-label {
    color: #cc6644;
    font-size: 9px;
    font-weight: 500;
    text-shadow: 0 0 4px rgba(0,0,0,0.95);
    pointer-events: none;
    white-space: nowrap;
}
.sea-label {
    color: #88ccff;
    font-size: 13px;
    font-weight: 700;
    text-shadow: 0 0 8px rgba(0,0,0,0.95), 0 0 16px rgba(0,0,0,0.8), 0 0 24px rgba(0,40,80,0.6);
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 3px;
}

.desert-label {
    color: #ddbb66;
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.ancient-label {
    color: #ffcc88;
    font-size: 13px;
    font-weight: 700;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 12px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 3px;
}
.ancient-sub-label {
    color: #aa8866;
    font-size: 9px;
    font-weight: 500;
    text-shadow: 0 0 4px rgba(0,0,0,0.95);
    pointer-events: none;
    white-space: nowrap;
}

.sites-label {
    color: #cc8844;
    font-size: 10px;
    font-weight: 600;
    text-shadow: 0 0 6px rgba(0,0,0,0.95), 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    white-space: nowrap;
}

.silk-label { color: #cc8844; font-size: 11px; font-weight: 700; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.dialect-label { color: #88aadd; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.park-label { color: #44bb66; font-size: 11px; font-weight: 700; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.agri-label { color: #88bb55; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.food-label { color: #dd6644; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.tea-label { color: #66aa44; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.uni-label { color: #4488cc; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.uni-label-c9 { color: #dd3333; font-size: 11px; font-weight: 700; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.airport-label { color: #4488cc; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.temple-label { color: #cc8844; font-size: 11px; font-weight: 700; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.heritage-label { color: #aa77cc; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.battle-label { color: #cc5533; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.revolution-label { color: #dd2222; font-size: 11px; font-weight: 700; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.port-label { color: #2266aa; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.capital-label { color: #dd8844; font-size: 12px; font-weight: 700; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.capital-sub-label { color: #aa6622; font-size: 9px; font-weight: 500; text-shadow: 0 0 4px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.wall-label { color: #886644; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.invention-label { color: #cc8844; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.autonomy-label { color: #77aa44; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.density-label { color: #ff8844; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.religion-label { color: #cc8844; font-size: 10px; font-weight: 600; text-shadow: 0 0 6px rgba(0,0,0,0.95); pointer-events: none; white-space: nowrap; }
.grid-label { color: #4488aa; font-size: 9px; font-weight: 500; text-shadow: 0 0 4px rgba(0,0,0,0.9); pointer-events: none; white-space: nowrap; }
