:root {
    --bg-color: #0f1115;
    --card-bg: #1a1d23;
    --text-primary: #e0e6ed;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --border-color: #2d3748;
    --font-main: 'JetBrains Mono', 'Noto Sans JP', monospace;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
    /* App-like feel */
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    /* Full width */
    margin: 0;
}

.resizer {
    height: 8px;
    background: #1a1d23;
    cursor: ns-resize;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    transition: background 0.2s;
    z-index: 50;
}

.resizer:hover,
.resizer.dragging {
    background: var(--accent-color);
}

.resizer::after {
    content: '';
    width: 40px;
    height: 4px;
    background: #4b5563;
    border-radius: 2px;
}

.resizer:hover::after {
    background: #fff;
}

.app-header {
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(15, 17, 21, 0.8);
    backdrop-filter: blur(10px);
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo h1 {
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -0.5px;
    background: linear-gradient(90deg, #fff, #94a3b8);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}


.header-controls {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    font-size: 0.9rem;
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #1e222a;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.archive-control {
    position: relative;
}

.archive-trigger {
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.archive-trigger:hover {
    background: #2d3748;
    color: #fff;
}

.archive-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    /* Align right */
    margin-top: 5px;
    background: #1f2937;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem;
    width: 200px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 200;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.archive-dropdown.hidden {
    display: none;
}

.archive-link {
    display: block;
    padding: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.2s;
    font-size: 0.9rem;
}

.archive-link:hover {
    background: #374151;
    color: #fff;
}

.archive-link.active {
    background: var(--accent-color);
    color: #fff;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: bold;
    padding: 0 0.5rem;
    transition: color 0.2s;
    line-height: 1;
}

.nav-btn:hover:not(:disabled) {
    color: var(--accent-color);
}

.nav-btn:disabled {
    color: #4b5563;
    cursor: not-allowed;
}

.date-display {
    font-family: var(--font-main);
    color: var(--text-primary);
    min-width: 100px;
    text-align: center;
    font-weight: 500;
}


.about-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

.about-link:hover {
    color: var(--text-primary);
}

.share-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.share-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-family: var(--font-main);
    font-size: 1rem;
}

.share-btn:hover {
    background: #2d3748;
    color: #fff;
    border-color: var(--text-secondary);
}

/* Grid Layout - Horizontal Split */
.main-grid {
    display: flex;
    flex-direction: row;
    /* Desktop: Side by Side */
    height: 100vh;
    overflow: hidden;
}

/* Left Column (Map + Feed) */
.left-column {
    display: flex;
    flex-direction: column;
    flex: 1.5;
    /* Takes ~60% */
    min-width: 0;
    border-right: 1px solid var(--border-color);
    position: relative;
    height: 100%;
}

/* Map Panel (Top of Left Column) */
.map-panel {
    height: 40vh;
    /* Default height */
    flex: none;
    /* Height controlled by JS/CSS, not flex grow */
    position: relative;
    background: #121418;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
}

#world-map {
    width: 100%;
    height: 100%;
    z-index: 0;
    background: #121418;
}

/* Summary Panel (Right Column) */
.summary-panel {
    flex: 1;
    /* Takes remaining space ~40% */
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    min-width: 320px;
    height: 100%;
}

/* Tabs in Summary Panel */
.summary-panel .tabs {
    flex-shrink: 0;
}

.scrollable-summary {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

/* Map Stats Overlay */
.map-overlay {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(26, 29, 35, 0.9);
    backdrop-filter: blur(8px);
    padding: 10px 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    gap: 20px;
    z-index: 1000;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-weight: 700;
    font-size: 1.2rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Content Section */
.content-section {
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
}

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.scroll-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

/* Markdown Content Styling */
.markdown-body {
    line-height: 1.8;
    color: #cbd5e1;
}

.markdown-body h1 {
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.markdown-body h2 {
    font-size: 1.4rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.markdown-body h3 {
    font-size: 1.1rem;
    margin-top: 1.5rem;
    color: #fff;
    border-left: 4px solid var(--accent-color);
    padding-left: 10px;
}

.markdown-body p {
    margin-bottom: 1rem;
    color: #b0b8c4;
}

.markdown-body ul {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.markdown-body li {
    margin-bottom: 0.5rem;
}

.markdown-body a {
    color: var(--accent-color);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body strong {
    color: #fff;
    font-weight: 600;
}

/* Bottom Section: Feed */
.content-section {
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    flex: 1;
    min-height: 300px;
    /* Minimum height */
    overflow: hidden;
    position: relative;
    /* Optional: making it resizable would require JS or resize property, 
       but standard flex behavior handles window resize. 
       User asked for "changeable height", maybe vertical resize? */
    /* Resize handled by JS splitter now */
    /* resize: vertical; */
    overflow: hidden;
}


.feed-header {
    padding: 1rem 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    /* Ensure z-index is higher than scroll content */
}

.feed-header h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.filter-bar {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
    /* Firefox */
}

.filter-bar::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.filter-btn {
    background: #2d3748;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-main);
}

.filter-btn:hover {
    background: #4b5563;
    color: #fff;
}

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

.feed-list-container {
    padding-top: 0;
    /* Handled by header now */
}

.feed-list {
    list-style: none;
    margin-top: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 1rem;
}

.feed-item {
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: transform 0.2s, background 0.2s;
}

.feed-item:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.05);
}

.feed-item .source {
    font-size: 0.75rem;
    color: var(--accent-color);
    display: block;
    margin-bottom: 4px;
}

.feed-item a.title-link {
    text-decoration: none;
    display: block;
    margin-top: 5px;
}

.title-ja {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 4px;
}

.title-sub {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 400;
}

.feed-item:hover .title-ja {
    color: var(--accent-color);
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 4px;
}

/* Leaflet Customization for Dark Mode */
.leaflet-container {
    background: #121418 !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {

    /* Main Layout Stack */
    .main-grid {
        flex-direction: column;
        height: 100vh;
        overflow-y: auto;
        /* Allow whole body scroll */
    }

    /* Mobile Header Fixes */
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .header-controls {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: space-between;
    }

    .date-nav {
        flex-grow: 1;
        justify-content: space-between;
    }

    .share-controls {
        margin-left: auto;
        /* Push to right */
    }

    /* Left Column Reset */
    .left-column {
        display: contents;
        /* Ungroup visual box for ordering */
        /* Note: display:contents removes the box, children participate in .main-grid flex */
        /* If display:contents causes issues, use flex column with order. */
        /* Let's try explicit Flex Column */
        display: flex;
        flex-direction: column;
        width: 100%;
        height: auto;
        flex: none;
        order: 2;
        /* Map+Feed after Summary */
        border-right: none;
    }

    /* ORDERING for Mobile: Summary -> Map -> Feed */
    /* Summary Panel (Order 1) */
    .summary-panel {
        order: 1;
        width: 100%;
        height: auto;
        min-height: 0;
        flex: none;
        border-bottom: 1px solid var(--border-color);
    }

    /* Map Panel (Order 1 in Left Col) */
    .map-panel {
        /* order: 1; implicit */
        height: auto;
        flex: none;
        border-bottom: 1px solid var(--border-color);
    }

    /* Hide Resizer */
    .resizer {
        display: none;
    }

    /* Bottom Section (Feed) (Order 2 in Left Col) */
    .content-section {
        /* order: 2; implicit */
        height: auto;
        overflow: visible;
        flex: none;
    }

    .scroll-container {
        height: auto;
        overflow: visible;
    }

    /* Panel Headers (Accordion) */
    .mobile-only {
        display: flex !important;
    }

    .panel-header {
        padding: 0.75rem 1rem;
        background: #1f2937;
        color: var(--text-primary);
        font-weight: 600;
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid var(--border-color);
    }

    .panel-header:hover {
        background: #374151;
    }

    .toggle-icon {
        font-size: 0.8rem;
        transition: transform 0.3s;
    }

    /* Content Wrapper Logic */
    .content-wrapper {
        transition: max-height 0.3s ease-out, opacity 0.3s;
        max-height: 8000px;
        /* Increased to prevent clipping of long content */
        /* Arbitrary large max-height */
        opacity: 1;
        overflow: hidden;
    }

    /* Collapsed State */
    .content-wrapper.collapsed {
        max-height: 0;
        opacity: 0;
        padding: 0;
        border: none;
        transition: max-height 0.3s ease-in, opacity 0.1s;
    }

    .panel-header.collapsed .toggle-icon {
        transform: rotate(-90deg);
    }

    /* Map specific: Fix height when expanded */
    #map-content {
        height: 50vh;
        /* Increased from 40vh for better visibility */
        /* Fixed height when visible */
    }

    #map-content.collapsed {
        height: 0;
    }

    /* Filter Toggle specific */
    .header-top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.5rem;
    }

    .toggle-btn {
        font-size: 0.85rem;
        color: var(--accent-color);
        cursor: pointer;
    }

    .map-overlay {
        position: absolute;
        bottom: 10px;
        left: 10px;
    }
}

/* Hide mobile-only elements on Desktop */
@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }

    /* Ensure content is always visible on desktop */
    .content-wrapper {
        display: flex !important;
        flex-direction: column;
        flex: 1;
        max-height: none !important;
        opacity: 1 !important;
        height: 100%;
        overflow: hidden;
    }

    .content-wrapper.collapsed {
        display: flex !important;
        max-height: none !important;
        opacity: 1 !important;
        padding: 0;
        border: none;
    }

    #map-content {
        height: 100%;
    }

    .map-panel {
        display: flex;
        flex-direction: column;
        /* height controlled by parent/style */
    }

    /* Fix Filter Bar layout on Desktop */
    .filter-bar.content-wrapper {
        display: flex !important;
        flex-direction: row;
        flex-wrap: wrap;
        height: auto;
        overflow: visible;
        max-height: none !important;
        opacity: 1 !important;
    }
}

/* Read More Link */
.read-more {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--accent-color);
    text-decoration: none;
    display: inline-block;
    transition: color 0.2s;
}

.read-more:hover {
    color: #60a5fa;
    text-decoration: underline;
}

/* Introduction/Description Accordion */
.feed-description {
    margin-top: 0.5rem;
    color: var(--text-secondary);
}

.feed-description summary {
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
    user-select: none;
    outline: none;
    transition: color 0.2s;
    list-style: none;
}

.feed-description summary::-webkit-details-marker {
    display: none;
}

.feed-description summary::after {
    content: " ▼";
    font-size: 0.7em;
}

.feed-description[open] summary::after {
    content: " ▲";
}

.feed-description summary:hover {
    color: var(--text-primary);
}

.description-content {
    margin-top: 0.5rem;
    padding-left: 0.5rem;
    border-left: 2px solid var(--border-color);
}

.description-content p {
    margin: 0 0 0.5rem 0;
    line-height: 1.5;
    font-size: 0.9rem;
}

.description-content .read-more {
    margin-top: 0;
    font-size: 0.85rem;
}