[hidden] { display: none !important; }
.history-tool { background: var(--fab-about-bg); color: var(--fab-icon-color); }
.history-tool svg { width: 23px; height: 23px; }
#mapTools {
    position: absolute;
    top: calc(var(--fab-size) + 10px);
    right: -10px;
    max-height: 0;
    padding: 0 10px 12px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-12px);
    transition: max-height .22s ease-out, opacity .14s ease-out, transform .22s ease-out, visibility 0s linear .22s;
}
#mapTools.is-open {
    max-height: min(420px, calc(100dvh - 150px));
    overflow: hidden;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: max-height .22s ease-out, opacity .14s ease-out, transform .22s ease-out, visibility 0s;
}
#mapTools.is-open.is-settled { overflow-y: auto; }
#mapTools { scrollbar-width: thin; scrollbar-color: rgba(134, 145, 164, .42) transparent; }
#mapTools::-webkit-scrollbar { width: 8px; }
#mapTools::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
#mapTools::-webkit-scrollbar-track { background: transparent; }
#mapTools::-webkit-scrollbar-thumb { background: rgba(134, 145, 164, .42); border: 2px solid transparent; background-clip: padding-box; border-radius: 999px; }
body.theme-light #mapTools { scrollbar-color: rgba(92, 106, 126, .42) transparent; }
body.theme-light #mapTools::-webkit-scrollbar-thumb { background-color: rgba(92, 106, 126, .42); }
#legend {
    position: absolute;
    z-index: 2600;
    top: calc(var(--fab-size) + 30px);
    right: calc(var(--fab-size) + 32px);
    max-height: calc(100dvh - var(--fab-size) - 44px);
    padding-right: 44px;
    overflow-y: auto;
}
#legend:not(.is-collapsed) { margin-top: 0; }
#legend .legend-toggle { position: absolute; top: 5px; right: 5px; width: 32px; height: 32px; }
#legend .legend-toggle svg { width: 20px; height: 20px; flex: none; }
#legend .legend-item > span:last-child { white-space: nowrap; overflow-wrap: normal; }
.history-journal { position: absolute; cursor: grab; z-index: 2700; color: var(--text-color); background: var(--popup-bg); border: 1px solid var(--popup-border); box-shadow: 0 6px 24px #0004; backdrop-filter: blur(14px); font: 500 12px/1.5 Montserrat, sans-serif; }
.journal-head { display: flex; align-items: center; gap: 12px; }
.history-journal button, .region-history-btn { border: 1px solid var(--legend-border); border-radius: 10px; background: var(--fab-about-bg); color: var(--fab-icon-color); font: inherit; cursor: pointer; }
.history-icon-button { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; width: 34px; height: 34px; padding: 0; line-height: 1; }
.history-icon-button svg { display: block; flex: none; width: 17px; height: 17px; }
.history-journal { width: min(420px, calc(100% - 32px)); top: 50%; left: 50%; right: auto; transform: translate(-50%, -50%); max-height: min(70dvh, 620px); padding: 16px; border-radius: 18px; display: flex; flex-direction: column; }
.journal-head { justify-content: space-between; padding-bottom: 10px; border-bottom: 1px solid var(--legend-border); cursor: grab; touch-action: none; }
.history-journal.is-dragging { cursor: grabbing; }
.journal-head small { color: var(--text-muted); font-size: 10px; font-weight: 700; letter-spacing: .6px; }
.journal-head h2 { font-size: 16px; line-height: 1.35; margin: 2px 0 0; }
.journal-head .history-icon-button { flex: none; min-width: 30px; width: 30px; height: 30px; }
.journal-head .history-icon-button svg { width: 15px; height: 15px; }
.journal-events { box-sizing: border-box; flex: 0 1 var(--journal-list-height, 364px); height: var(--journal-list-height, 364px); overflow-y: auto; overscroll-behavior: contain; min-height: 36px; scrollbar-width: thin; scrollbar-color: rgba(134, 145, 164, .42) transparent; }
.journal-events.is-empty { flex-basis: auto; height: auto; }
.journal-events::-webkit-scrollbar { width: 9px; }
.journal-events::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
.journal-events::-webkit-scrollbar-track { background: transparent; }
.journal-events::-webkit-scrollbar-thumb { background: rgba(134, 145, 164, .42); border: 2px solid transparent; background-clip: padding-box; border-radius: 999px; }
.journal-events::-webkit-scrollbar-thumb:hover { background-color: rgba(155, 169, 190, .7); }
body.theme-light .journal-events { scrollbar-color: rgba(92, 106, 126, .42) transparent; }
body.theme-light .journal-events::-webkit-scrollbar-thumb { background-color: rgba(92, 106, 126, .42); }
body.theme-light .journal-events::-webkit-scrollbar-thumb:hover { background-color: rgba(70, 84, 103, .7); }
.journal-day { box-sizing: border-box; height: 28px; padding: 9px 5px 4px; color: var(--text-muted); font-size: 11px; font-weight: 700; }
.journal-event { display: grid; grid-template-columns: 20px 48px minmax(0, 1fr); align-items: center; gap: 8px; box-sizing: border-box; height: 56px; padding: 8px 7px; border-radius: 8px; }
.journal-event + .journal-event { border-top: 1px solid var(--legend-border); border-radius: 0; }
.journal-indicator.legend-item { width: 20px; min-width: 20px; height: 20px; min-height: 20px; justify-content: center; }
.journal-indicator .dot.journal-cleared { --dot-color: #65b991; }
.journal-indicator .dot.journal-unknown { --dot-color: var(--text-muted); }
.journal-event time { color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.journal-event p { display: -webkit-box; margin: 0; font-size: 12px; line-height: 1.4; overflow: hidden; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.journal-empty { color: var(--text-muted); font-size: 11px; line-height: 1.5; margin: 12px 4px 4px; }
.journal-note { color: var(--text-muted); font-size: 9px; line-height: 1.4; margin: 8px 4px 2px; }
.region-history-btn { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; margin: 8px 0 -4px -8px; padding: 6px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--popup-text); font: 600 11px/1.25 Montserrat, sans-serif; text-align: left; }
.region-history-btn svg { display: block; flex: none; width: 15px; height: 15px; }
.region-history-btn:hover { background: rgba(128, 128, 128, .10); }
.history-journal button:focus-visible, .history-tool:focus-visible { outline: 2px solid #2aabee; outline-offset: 3px; }
@media (max-width: 600px) {
    #mapTools { top: calc(var(--fab-size) + 8px); }
    .history-journal { width: calc(100% - 20px); top: auto; left: 10px; right: auto; bottom: max(10px, env(safe-area-inset-bottom)); transform: none; max-height: min(56dvh, 480px); padding: 13px; }
    .journal-event { gap: 6px; }
    #legend {
        box-sizing: border-box;
        top: calc(var(--fab-size) + 24px);
        left: 12px;
        right: auto;
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
        padding-right: 12px;
        max-height: min(70dvh, 480px);
        overflow-y: auto;
        transform: none;
    }
    #legend .legend-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px 12px;
    }
    #legend .legend-item {
        min-height: 24px;
        font-size: 12px;
        line-height: 1.35;
    }
    #legend .legend-item > span:last-child {
        white-space: normal;
        overflow-wrap: normal;
        word-break: normal;
    }
    #legend .legend-threat-types { white-space: nowrap; }
    #legend .legend-directions-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px 12px;
    }
    #legend .legend-direction-line { width: 32px; flex-basis: 32px; }
    #legend .legend-direction-item { align-items: center; }
    #legend .legend-direction-item > span { min-width: 0; }
    .journal-events { flex-basis: min(var(--journal-list-height, 364px), calc(56dvh - 76px)); height: min(var(--journal-list-height, 364px), calc(56dvh - 76px)); }
}
@media (max-width: 360px) {
    #legend .legend-grid,
    #legend .legend-directions-grid { column-gap: 10px; }
    #legend .legend-item { gap: 6px; }
}

.history-journal, .history-journal * { -webkit-user-select: none; user-select: none; }

.history-journal {
    box-sizing: border-box;
    width: min(440px, calc(100vw - 32px));
    max-width: calc(100vw - 20px);
    border-radius: var(--ui-radius-lg);
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    font-size: 13px;
}
.journal-head { min-height: 54px; padding-bottom: 12px; }
.journal-head small { font-size: 11px; letter-spacing: .45px; }
.journal-head h2 { font-size: 17px; }
.journal-head .history-icon-button { width: 44px; min-width: 44px; height: 44px; }
.journal-head .history-icon-button svg { width: 16px; height: 16px; }
.journal-day { font-size: 12px; }
.journal-event { grid-template-columns: 22px 48px minmax(0, 1fr); height: 58px; gap: 8px; }
.journal-event time { font-size: 12px; }
.journal-event p { font-size: 13px; line-height: 1.35; }
.journal-empty, .journal-note { font-size: 12px; }
.region-history-btn { min-height: 44px; font-size: 13px; border-radius: var(--ui-radius-sm); }
.history-journal button:focus-visible, .history-tool:focus-visible,
.region-history-btn:focus-visible { outline-color: var(--ui-focus); }
#legend .legend-toggle { width: 44px; height: 44px; top: 0; right: 0; }
@media (max-width: 600px) {
    .history-journal {
        width: calc(100vw - 20px);
        max-height: min(68dvh, 580px);
        bottom: calc(max(12px, env(safe-area-inset-bottom)) + 56px);
    }
    .journal-events {
        flex-basis: min(var(--journal-list-height, 376px), calc(68dvh - 86px));
        height: min(var(--journal-list-height, 376px), calc(68dvh - 86px));
    }
    .journal-event { gap: 7px; }
}
@media (prefers-reduced-motion: reduce) {
    #mapTools, #mapTools.is-open { transition-duration: .01ms; }
}
