/* WorldHistory - Global Styles */

:root {
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #999;
    --border-color: #e0e0e0;
    --accent: #4a6fa5;
    --accent-hover: #3a5f95;
    --danger: #d44;
    --success: #4a9;
    --panel-width: 600px;
    --timeline-height: 80px;
    --topbar-height: 48px;
    --ad-width: 0px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 8px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ===== TOP BAR ===== */
#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-primary);
}

.logo-icon {
    color: var(--accent);
    flex-shrink: 0;
}

.logo-text {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: var(--text-primary);
}

.logo-accent {
    color: var(--accent);
    font-weight: 600;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-left: 16px;
    border-left: 1px solid var(--border-color);
}

.nav-link {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.nav-link:hover {
    color: var(--accent);
    background: rgba(74, 111, 165, 0.06);
}

.btn-account {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    text-decoration: underline;
    margin-left: 4px;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-borders {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    padding: 4px 10px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.toggle-borders:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-secondary);
}

.toggle-borders input {
    cursor: pointer;
    accent-color: var(--accent);
}

.btn-donate {
    background: none;
    border: 1px solid rgba(199, 94, 94, 0.3);
    color: #c75e5e;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.btn-donate:hover {
    background: #c75e5e;
    border-color: #c75e5e;
    color: white;
}

.btn-github {
    background: none;
    border: 1px solid rgba(51, 51, 51, 0.3);
    color: #555;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    text-decoration: none;
}

.btn-github:hover {
    background: #333;
    border-color: #333;
    color: white;
}

.btn-auth {
    background: var(--accent);
    color: white;
    border: none;
    padding: 5px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.2px;
}

.btn-auth:hover {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(74, 111, 165, 0.3);
}

/* Logged in state */
.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.user-info .username {
    font-weight: 600;
    color: var(--text-primary);
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    text-decoration: underline;
}

/* ===== MAP CONTROLS ===== */
#map-controls {
    position: fixed;
    top: calc(var(--topbar-height) + 12px);
    right: 12px;
    z-index: 700;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 120px;
}

.control-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-label {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.control-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

.granularity-btn {
    display: block;
    width: 100%;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #f5f5f5;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.granularity-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.granularity-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-item.category-btn {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: opacity 0.2s;
    user-select: none;
}

.legend-item.category-btn:hover {
    opacity: 0.8;
}

.legend-item.category-btn:not(.active) {
    opacity: 0.45;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background 0.2s, border 0.2s;
    box-sizing: border-box;
}

.category-btn:not(.active) .legend-dot {
    background: transparent !important;
}

/* ===== AD SPACE ===== */
#ad-space {
    display: none;
}

.ad-placeholder {
    width: 220px;
    flex: 1;
    max-height: 45%;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 12px;
}

/* ===== MAP ===== */
#map {
    position: fixed;
    top: var(--topbar-height);
    left: var(--ad-width);
    right: 0;
    bottom: var(--timeline-height);
    z-index: 100;
}

/* Hide Leaflet attribution clutter */
.leaflet-control-attribution {
    font-size: 10px;
    opacity: 0.7;
}

/* ===== YEAR DISPLAY ===== */
#year-display {
    position: fixed;
    bottom: calc(var(--timeline-height) + 12px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 6px 20px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    z-index: 600;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: opacity var(--transition);
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.year-step-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
    transition: color 0.15s ease;
}
.year-step-btn:hover {
    color: var(--text-primary);
}

#year-input-container {
    display: flex;
    align-items: center;
    gap: 6px;
}

#year-input {
    width: 72px;
    padding: 2px 6px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    -moz-appearance: textfield;
}
#year-input::-webkit-outer-spin-button,
#year-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
#year-input:focus {
    border-color: var(--accent);
}

#year-era-toggle {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.era-btn {
    padding: 1px 8px;
    font-size: 10px;
    font-weight: 700;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1.4;
    transition: all 0.15s ease;
}

.era-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ===== MAP STYLE SWITCHER ===== */
#map-style-switcher {
    position: fixed;
    bottom: calc(var(--timeline-height) + 20px);
    right: 12px;
    z-index: 600;
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 5px;
    box-shadow: var(--shadow-sm);
}

.style-option {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: none;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.style-option:hover {
    background: rgba(0, 0, 0, 0.04);
}

.style-option.active {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.style-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

/* ===== TIMELINE ===== */
#timeline-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--timeline-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 800;
    cursor: pointer;
}

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

/* ===== SIDE PANEL ===== */
#side-panel {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    width: var(--panel-width);
    bottom: var(--timeline-height);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 900;
    transform: translateX(100%);
    transition: transform var(--transition);
    overflow-y: auto;
    overflow-x: hidden;
}

#side-panel.panel-open {
    transform: translateX(0);
}

.panel-close-btn {
    position: sticky;
    top: 0;
    float: right;
    background: var(--bg-secondary);
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 50%;
    transition: all var(--transition);
}

.panel-close-btn:hover {
    background: #f0f0f0;
    color: var(--text-primary);
}

#panel-content {
    padding: 16px 24px 24px;
}

.panel-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    color: var(--text-muted);
    font-size: 14px;
}

#panel-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--accent);
}

#panel-title {
    font-size: 24px;
    font-weight: 800;
    line-height: 1.25;
    margin-bottom: 8px;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.panel-dates {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.panel-category-badge {
    display: inline-block;
    font-size: 10px;
    padding: 3px 12px;
    border-radius: 4px;
    background: var(--accent);
    color: white;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.btn-favorite {
    float: right;
    background: none;
    border: 1px solid var(--border-color);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--radius);
    transition: all var(--transition);
    color: var(--text-muted);
}

.btn-favorite:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-favorite.favorited {
    color: #e8a838;
    border-color: #e8a838;
}

#panel-summary {
    font-size: 14.5px;
    line-height: 1.8;
    color: #3a3a4a;
    margin-bottom: 28px;
}

#panel-summary p {
    margin-bottom: 16px;
}

#panel-summary p:first-child::first-letter {
    font-size: 2.2em;
    font-weight: 800;
    float: left;
    line-height: 1;
    margin-right: 2px;
    margin-top: 2px;
    color: var(--drop-cap-color, var(--accent));
}

/* ===== CROSS-EVENT LINKS ===== */
.event-crosslink {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid rgba(74, 111, 165, 0.3);
    cursor: pointer;
    transition: all var(--transition);
    font-weight: 500;
}

.event-crosslink:hover {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-hover);
    background: rgba(74, 111, 165, 0.06);
}

/* ===== IMAGE GALLERY ===== */
#panel-images h3,
#panel-figures h3,
#panel-links h3,
#panel-comments h3 {
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.image-gallery {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 24px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE */
}
.image-gallery::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.gallery-item {
    flex-shrink: 0;
    width: 180px;
    cursor: pointer;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    scroll-snap-align: start;
}

.gallery-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
    transition: transform 0.2s ease;
}

.gallery-item:hover img {
    transform: scale(1.05);
}

/* Gallery arrow navigation */
.gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 1px 4px rgba(0,0,0,0.18);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, box-shadow 0.15s;
    line-height: 1;
    padding: 0;
}
.gallery-arrow:hover {
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.22);
}
.gallery-arrow-left { left: -4px; }
.gallery-arrow-right { right: -4px; }

/* ===== LIGHTBOX ===== */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    background: none;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    z-index: 3001;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 75vh;
    object-fit: contain;
    border-radius: 4px;
}

.lightbox-caption {
    color: #ccc;
    font-size: 13px;
    margin-top: 12px;
    text-align: center;
    max-width: 600px;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    font-size: 36px;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-prev-btn { left: 16px; }
.lightbox-next-btn { right: 16px; }

/* ===== FIGURES GRID ===== */
.figures-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.figure-card {
    display: block;
    text-align: center;
    padding: 8px;
    border: 1px solid var(--border-color, #eee);
    border-radius: var(--radius);
    background: var(--bg-primary, #fff);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.figure-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.figure-card img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 6px;
}

.figure-card strong {
    display: block;
    font-size: 12px;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.figure-card p {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 0;
}

/* panel-links h3 styled above with other section headings */

#panel-link-list {
    list-style: none;
    margin-bottom: 24px;
}

#panel-link-list li {
    margin-bottom: 6px;
}

#panel-link-list a {
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}

#panel-link-list a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ===== COMMENTS ===== */
#panel-comments h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.comment {
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    position: relative;
}

.comment-delete-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color var(--transition);
    opacity: 0.5;
}

.comment-delete-btn:hover {
    color: var(--danger);
    opacity: 1;
}

.comment-username {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.comment-date {
    font-size: 11px;
    color: var(--text-muted);
}

.comment-body {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.comment-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
}

.comment-vote-btn,
.comment-reply-btn {
    background: none;
    border: none;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color var(--transition);
}

.comment-vote-btn:hover,
.comment-reply-btn:hover {
    color: var(--accent);
}

.comment-vote-btn.voted {
    color: var(--accent);
    font-weight: 600;
}

.comment-replies {
    margin-left: 20px;
    border-left: 2px solid #f0f0f0;
    padding-left: 16px;
}

.comment-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.comment-form textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    min-height: 36px;
    max-height: 120px;
    transition: border-color var(--transition);
}

.comment-form textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.comment-form button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition);
}

.comment-form button:hover {
    background: var(--accent-hover);
}

/* ===== AUTH MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 32px;
    width: 400px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-content h2 {
    font-size: 20px;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 18px;
}

.btn-primary {
    width: 100%;
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.auth-switch {
    text-align: center;
    margin-top: 14px;
    font-size: 13px;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

/* ===== EVENT DOT TOOLTIP ===== */
.event-tooltip {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

.event-tooltip .tooltip-dates {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 11px;
}

.event-tooltip .tooltip-category {
    display: block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* Dark map style overrides */
body.map-dark .event-tooltip {
    background: #2a2a2a;
    border-color: #444;
    color: #e0e0e0;
}
body.map-dark .event-tooltip .tooltip-dates {
    color: #aaa;
}
body.map-dark #map-style-switcher {
    background: rgba(40, 40, 40, 0.85);
    border-color: #444;
}
body.map-dark .style-option {
    color: #bbb;
}
body.map-dark .style-option.active {
    background: #333;
    border-color: #555;
    color: #eee;
}

/* ===== HIERARCHY MODE ===== */
.btn-hierarchy {
    background: none;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-left: 8px;
}

.btn-hierarchy:hover {
    background: var(--accent);
    color: white;
}

#hierarchy-overlay {
    position: absolute;
    top: 12px;
    left: 60px;
    z-index: 700;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    max-width: 340px;
    max-height: 350px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hierarchy-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.hierarchy-header button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
    line-height: 1;
}
.hierarchy-header button:hover {
    color: var(--text-primary);
}

.hierarchy-tree {
    padding: 8px 12px;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.6;
}

.hierarchy-tree ul {
    list-style: none;
    margin: 0;
    padding-left: 16px;
    border-left: 1px solid var(--border-color);
}

.hierarchy-tree li {
    position: relative;
}

.hierarchy-tree li::before {
    content: '';
    position: absolute;
    left: -16px;
    top: 10px;
    width: 12px;
    height: 1px;
    background: var(--border-color);
}

.hierarchy-tree a {
    display: inline-block;
    text-decoration: none;
    color: var(--text-primary);
    padding: 1px 6px;
    border-radius: 4px;
    transition: background 0.1s;
}

.hierarchy-tree a:hover {
    background: rgba(74, 111, 165, 0.1);
}

.hierarchy-tree a.hierarchy-active {
    background: rgba(74, 111, 165, 0.15);
    font-weight: 600;
}

.hierarchy-tree .hier-year {
    color: var(--text-muted);
    font-size: 10px;
}

body.map-dark #hierarchy-overlay {
    background: rgba(40, 40, 40, 0.92);
    border-color: #444;
}
body.map-dark .hierarchy-header {
    border-color: #444;
    color: #ddd;
}
body.map-dark .hierarchy-tree a {
    color: #ddd;
}
body.map-dark .hierarchy-tree ul {
    border-color: #555;
}
body.map-dark .hierarchy-tree li::before {
    background: #555;
}

/* Category badge colors in panel */
.panel-category-badge[data-cat="empire"]       { background: #E8EDF4; color: #5A6F8E; }
.panel-category-badge[data-cat="war"]          { background: #F4E8E8; color: #A55A5A; }
.panel-category-badge[data-cat="civilization"] { background: #E8F0E6; color: #6B8A5C; }
.panel-category-badge[data-cat="discovery"]    { background: #F4EFE2; color: #A8883C; }
.panel-category-badge[data-cat="religion"]     { background: #EDE6F4; color: #8A6BA2; }
.panel-category-badge[data-cat="cultural"]     { background: #E2F0F4; color: #5A98A8; }
.panel-category-badge[data-cat="trade"]        { background: #F4EDE2; color: #A2805B; }

/* ===== LEAFLET OVERRIDES ===== */
.leaflet-container {
    background: #f8f9fa;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.panel-open #panel-body {
    animation: fadeIn 0.3s ease-out;
}

/* ===== MOBILE-ONLY ELEMENTS (hidden on desktop) ===== */
.hamburger-btn,
.mobile-nav-link,
.map-controls-toggle {
    display: none;
}

/* ============================================================
   MOBILE RESPONSIVE — max-width: 768px
   ============================================================ */
@media (max-width: 768px) {

    /* --- Hamburger Button --- */
    .hamburger-btn {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        width: 36px;
        height: 36px;
        padding: 6px;
        background: none;
        border: none;
        cursor: pointer;
        margin-left: 8px;
        flex-shrink: 0;
    }
    .hamburger-btn span {
        display: block;
        width: 100%;
        height: 2px;
        background: var(--text-primary);
        border-radius: 2px;
        transition: transform 0.25s, opacity 0.25s;
    }
    /* Animate to X when open */
    body.menu-open .hamburger-btn span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }
    body.menu-open .hamburger-btn span:nth-child(2) {
        opacity: 0;
    }
    body.menu-open .hamburger-btn span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    /* --- Top Bar --- */
    #top-bar {
        padding: 0 12px;
    }
    .logo-text {
        display: none;
    }
    .top-nav {
        display: none;
    }

    /* --- Mobile Nav Dropdown --- */
    .top-bar-right {
        display: none;
        position: absolute;
        top: var(--topbar-height);
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        box-shadow: var(--shadow-md);
        flex-direction: column;
        padding: 8px 0;
        z-index: 1000;
    }
    body.menu-open .top-bar-right {
        display: flex;
    }
    .mobile-nav-link {
        display: flex;
        align-items: center;
        padding: 12px 20px;
        font-size: 14px;
        font-weight: 500;
        color: var(--text-primary);
        text-decoration: none;
        min-height: 44px;
    }
    .mobile-nav-link:hover {
        background: var(--bg-primary);
    }
    .top-bar-right .toggle-borders {
        padding: 12px 20px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    .top-bar-right .btn-donate,
    .top-bar-right .btn-github {
        justify-content: flex-start;
        padding: 12px 20px;
        min-height: 44px;
        border-radius: 0;
        font-size: 14px;
        width: 100%;
        text-align: left;
    }
    .top-bar-right #user-menu {
        padding: 8px 20px;
        width: 100%;
    }
    .top-bar-right #user-menu .btn-auth {
        width: 100%;
        text-align: center;
    }

    /* --- Ad Space (mobile-ready, still hidden) --- */
    #ad-space {
        /* display: none — remains hidden until ads are enabled */
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        right: 0;
        height: 50px;
        z-index: 950;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
    }
    #ad-space .ad-placeholder {
        width: 100%;
        max-width: 320px;
        height: 50px;
        max-height: none;
    }

    /* --- Map --- */
    #map {
        top: var(--topbar-height);
        left: 0;
        right: 0;
        bottom: var(--timeline-height);
    }

    /* --- Map Controls Toggle Button (mobile) --- */
    .map-controls-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: calc(var(--topbar-height) + 10px);
        right: 10px;
        width: 40px;
        height: 40px;
        background: rgba(255, 255, 255, 0.92);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: 8px;
        box-shadow: var(--shadow-sm);
        cursor: pointer;
        z-index: 700;
        color: var(--text-secondary);
    }
    .map-controls-toggle:active {
        background: rgba(240, 240, 240, 0.95);
    }

    /* --- Map Controls (collapsed by default) --- */
    #map-controls {
        display: none;
        top: calc(var(--topbar-height) + 56px);
        right: 10px;
        max-height: calc(100vh - var(--topbar-height) - var(--timeline-height) - 80px);
        overflow-y: auto;
    }
    body.controls-open #map-controls {
        display: flex;
    }

    /* --- Map Style Switcher --- */
    #map-style-switcher {
        bottom: calc(var(--timeline-height) + 8px);
        right: 10px;
        padding: 3px;
    }
    #map-style-switcher .style-option {
        font-size: 10px;
        padding: 3px 8px;
    }
    #map-style-switcher .style-swatch {
        width: 10px;
        height: 10px;
    }

    /* --- Year Display --- */
    #year-display {
        font-size: 16px;
        padding: 5px 14px;
        bottom: calc(var(--timeline-height) + 8px);
    }

    /* --- Timeline --- */
    #timeline-container {
        height: var(--timeline-height);
    }

    /* --- Side Panel (full-screen on mobile) --- */
    #side-panel {
        width: 100%;
        top: var(--topbar-height);
        bottom: 0;
        z-index: 950;
        border-left: none;
    }
    #side-panel .panel-close-btn {
        width: 44px;
        height: 44px;
        font-size: 28px;
    }
    #panel-content {
        padding: 0 16px 24px;
    }
    #panel-header {
        padding-top: 8px;
    }
    #panel-summary {
        font-size: 14px;
        line-height: 1.7;
    }
    .figures-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .image-gallery {
        scroll-snap-type: x mandatory;
    }
    .gallery-item {
        min-width: 150px;
        scroll-snap-align: start;
    }

    /* --- Hide hierarchy features --- */
    .btn-hierarchy {
        display: none !important;
    }
    #hierarchy-overlay {
        display: none !important;
    }

    /* --- Auth Modal --- */
    .modal-content {
        width: 92vw;
        padding: 24px 20px;
    }
    .modal-content input {
        min-height: 44px;
        font-size: 16px;
    }
    .modal-content .btn-primary {
        min-height: 44px;
        font-size: 16px;
    }

    /* --- Lightbox --- */
    .lightbox-img {
        max-width: 96vw;
        max-height: 70vh;
    }
    .lightbox-nav {
        padding: 12px 18px;
        font-size: 28px;
    }
    .lightbox-prev-btn {
        left: 6px;
    }
    .lightbox-next-btn {
        right: 6px;
    }
    .lightbox-close {
        top: 10px;
        right: 14px;
        font-size: 28px;
        padding: 8px;
    }

    /* --- Account Page --- */
    .account-page {
        padding: 70px 16px 40px;
    }
    .account-section {
        padding: 16px;
    }
    .account-field input,
    .account-field select {
        min-height: 44px;
        font-size: 16px;
    }

    /* --- Body scroll lock when panel is open --- */
    body.panel-open-mobile {
        overflow: hidden;
    }

}
