/* Reset */
body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
}

/* Root Variables for Theme */
:root {
    --bg-color: rgba(255, 255, 255, 0.9);
    --text-color: #333;
    --btn-bg: #007bff;
    --btn-hover: #0056b3;
    --result-bg: #f8f9fa;
    --result-border: #ddd;
}

[data-theme="dark"] {
    --bg-color: rgba(30, 30, 30, 0.9);
    --text-color: #f0f0f0;
    --btn-bg: #0d6efd;
    --btn-hover: #0b5ed7;
    --result-bg: #2c2c2c;
    --result-border: #444;
}

/* Map Container */
#map {
    height: 100%;
    width: 100%;
    z-index: 0;
}

/* Controls Overlay */
#controls {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1000;
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    max-width: 320px;
    color: var(--text-color);
    max-height: 90vh;
    overflow-y: auto;
    transition: background-color 0.3s, color 0.3s;
}

.header-row {
    display: flex;
    justify-content: center;
    /* Center title */
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 5px;
}

#controls h1 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--text-color);
}

/* Top Right Controls */
#top-right-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    display: flex;
    gap: 10px;
    align-items: center;
}

.lang-buttons {
    display: flex;
    background: var(--bg-color);
    padding: 5px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.lang-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px 10px;
    font-size: 0.9rem;
    color: var(--text-color);
    border-radius: 4px;
    font-weight: bold;
    opacity: 0.6;
    transition: all 0.2s;
}

.lang-btn:hover {
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.05);
}

.lang-btn.active {
    opacity: 1;
    background-color: var(--btn-bg);
    color: white;
}

#theme-toggle {
    background: var(--bg-color);
    border: none;
    color: var(--text-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

#theme-toggle:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

/* Search Bar */
.search-container {
    margin-bottom: 15px;
}

#castle-search {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    border: 1px solid var(--result-border);
    border-radius: 4px;
    font-size: 1rem;
    background: var(--result-bg);
    color: var(--text-color);
}

/* Popup Styles */
div.leaflet-popup-content {
    min-width: 260px;
    max-width: 300px;
}

.popup-desc {
    max-height: 100px;
    overflow-y: auto;
    font-size: 0.9em;
    line-height: 1.5;
    margin: 8px 0;
    padding-right: 5px;
    color: #333;
    border-top: 1px solid #eee;
    padding-top: 5px;
}

/* Custom Scrollbar */
.popup-desc::-webkit-scrollbar {
    width: 6px;
}

.popup-desc::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.popup-desc::-webkit-scrollbar-thumb {
    background: #bbb;
    border-radius: 3px;
}

.popup-desc::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Details Table */
.popup-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 0.85em;
}

.popup-table tr {
    border-bottom: 1px solid #f0f0f0;
}

.popup-table th {
    text-align: left;
    white-space: nowrap;
    color: #666;
    padding: 3px 5px 3px 0;
    font-weight: normal;
    vertical-align: top;
    width: 60px;
}

.popup-table td {
    color: #333;
    padding: 3px 0;
}

/* Nav Buttons */
.popup-nav {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.nav-btn,
.nav-btn:visited,
.nav-btn:active,
.nav-btn:focus {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 20px;
    /* Pill shape */
    font-size: 0.8em;
    font-weight: bold;
    color: white !important;
    transition: opacity 0.2s;
    border: none;
    white-space: nowrap;
}

.nav-btn:hover {
    opacity: 0.9;
    color: white;
}

/* Google: Green-Blue Gradient */
.nav-google {
    background: linear-gradient(90deg, #4285F4 0%, #34A853 100%);
}

/* Apple: Black */
.nav-apple {
    background-color: #000;
}

/* Filter Buttons */
#filter-container {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.filter-btn {
    flex: 1;
    padding: 5px;
    background-color: #6c757d;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}

.filter-btn.active {
    background-color: #28a745;
    /* Green for active */
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
}

.action-buttons button {
    display: block;
    width: 100%;
    margin-bottom: 8px;
    padding: 8px 12px;
    background-color: var(--btn-bg);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.action-buttons button:hover {
    background-color: var(--btn-hover);
}

#result-display {
    margin-top: 10px;
    padding: 10px;
    background: var(--result-bg);
    border-radius: 4px;
    border: 1px solid var(--result-border);
    font-size: 0.9rem;
    display: none;
}

/* Responsive */
@media (max-width: 600px) {
    #controls {
        top: auto;
        bottom: 20px;
        left: 10px;
        right: 10px;
        max-width: none;
        width: auto;
    }
}