/* Chronicle Atlas - Campaign World Map */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Crimson+Text:ital,wght@0,400;0,600;1,400&family=JetBrains+Mono:wght@400&display=swap');

:root {
    --bg-dark: #0f0e0c;
    --bg-panel: #1a1814;
    --bg-panel-hover: #242018;
    --bg-input: #12110f;
    --border: #2e2a22;
    --border-light: #3d3729;
    --text-primary: #d4c5a9;
    --text-secondary: #9a8e76;
    --text-muted: #6b6152;
    --text-bright: #f0e6cf;
    --accent: #c0392b;
    --accent-glow: #e74c3c;
    --accent-gold: #d4a847;
    --accent-gold-dim: #a68532;
    --accent-blue: #4a90a8;
    --accent-green: #5a9a6b;
    --accent-purple: #8e6aad;
    --shadow: rgba(0, 0, 0, 0.6);
    --font-display: 'Cinzel', serif;
    --font-body: 'Crimson Text', serif;
    --font-mono: 'JetBrains Mono', monospace;
    --panel-width: 400px;
    --header-height: 56px;
    --age-tint: rgba(164, 120, 52, 0.16);
}

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

body {
    font-family: var(--font-body);
    background:
        radial-gradient(1100px 600px at 20% -10%, var(--age-tint), rgba(0, 0, 0, 0)),
        radial-gradient(900px 500px at 120% 110%, rgba(255, 255, 255, 0.03), rgba(0, 0, 0, 0)),
        var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    transition: background-color 280ms ease, color 280ms ease;
}

.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(1200px 460px at 10% -10%, rgba(212, 168, 71, 0.12), transparent 60%),
        radial-gradient(900px 420px at 90% 110%, rgba(192, 57, 43, 0.16), transparent 65%),
        linear-gradient(160deg, #12100c 0%, #1a1711 55%, #0f0d09 100%);
}

.splash-card {
    width: min(460px, 92vw);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    background: rgba(30, 26, 19, 0.92);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    padding: 24px 22px;
}

.splash-brand {
    text-align: center;
    margin-bottom: 16px;
}

.splash-brand svg {
    width: 34px;
    height: 34px;
    fill: var(--accent-gold);
    margin-bottom: 8px;
}

.splash-brand h1 {
    font-family: var(--font-display);
    color: var(--text-bright);
    letter-spacing: 1.4px;
    margin: 0;
    font-size: 1.3rem;
}

.splash-brand p {
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.splash-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.splash-tabs .btn {
    flex: 1;
}

.splash-divider {
    margin: 14px 0;
    text-align: center;
    position: relative;
}

.splash-divider::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    border-top: 1px solid var(--border);
}

.splash-divider span {
    position: relative;
    background: rgba(30, 26, 19, 0.92);
    color: var(--text-muted);
    padding: 0 10px;
    font-size: 0.78rem;
}

/* --- Header --- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
    box-shadow: 0 2px 20px var(--shadow);
    transition: background-color 280ms ease, border-color 280ms ease;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-brand svg {
    width: 28px;
    height: 28px;
    fill: var(--accent-gold);
}

.header-brand h1 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-bright);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.header-brand .age-label {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--accent-gold-dim);
    font-style: italic;
    margin-left: 8px;
    letter-spacing: 0;
    text-transform: none;
}

.age-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    overflow: visible;
    max-width: min(56vw, 980px);
    padding-bottom: 2px;
}

.age-nav::-webkit-scrollbar {
    height: 4px;
}

.age-chip {
    position: relative;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-family: var(--font-display);
    letter-spacing: 0.4px;
    white-space: nowrap;
    cursor: pointer;
}

.age-chip:hover,
.age-chip:focus-visible {
    color: var(--text-bright);
    border-color: var(--accent-gold-dim);
    outline: none;
}

.age-chip.active {
    color: var(--text-bright);
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 1px rgba(212, 168, 71, 0.3) inset;
}

.age-chip-preview {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    width: min(320px, 70vw);
    display: none;
    z-index: 1200;
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 10px;
    color: var(--text-primary);
    white-space: normal;
    line-height: 1.35;
    font-family: var(--font-body);
    font-size: 0.86rem;
    text-align: left;
    box-shadow: 0 8px 24px var(--shadow);
}

.age-chip:hover .age-chip-preview,
.age-chip:focus-visible .age-chip-preview {
    display: block;
}

.age-chip-preview.flip-left {
    left: auto;
    right: 0;
}

body[data-age-theme="primordial-age"] {
    --bg-dark: #13100d;
    --bg-panel: #1e1812;
    --bg-panel-hover: #2a2218;
    --bg-input: #17120d;
    --border: #3b3023;
    --border-light: #4a3c2d;
    --text-primary: #d9ccb2;
    --text-secondary: #a89778;
    --text-muted: #7e6f58;
    --accent: #8a5a2b;
    --accent-gold: #d5b074;
    --accent-gold-dim: #ab8451;
    --age-tint: rgba(156, 108, 46, 0.24);
}

body[data-age-theme="low-magic-age"] {
    --bg-dark: #100f0d;
    --bg-panel: #1b1915;
    --bg-panel-hover: #26221b;
    --bg-input: #14120f;
    --border: #312c24;
    --border-light: #413a2f;
    --text-primary: #d4c5a9;
    --text-secondary: #9a8e76;
    --text-muted: #6b6152;
    --accent: #9c3a2f;
    --accent-gold: #c49f50;
    --accent-gold-dim: #9e7b33;
    --age-tint: rgba(150, 86, 62, 0.16);
}

body[data-age-theme="high-magic-age"] {
    --bg-dark: #10111a;
    --bg-panel: #1a1d2a;
    --bg-panel-hover: #23283a;
    --bg-input: #151827;
    --border: #2f3550;
    --border-light: #3f496c;
    --text-primary: #d2d8ef;
    --text-secondary: #a8b2d2;
    --text-muted: #7b85a7;
    --accent: #5f4ca8;
    --accent-gold: #8ea2ff;
    --accent-gold-dim: #7a87d3;
    --accent-blue: #6e8ef2;
    --age-tint: rgba(110, 126, 208, 0.22);
}

body[data-age-theme="magitech-age"] {
    --bg-dark: #0f1416;
    --bg-panel: #162024;
    --bg-panel-hover: #1e2c31;
    --bg-input: #111a1d;
    --border: #2a3d42;
    --border-light: #365158;
    --text-primary: #cbe0df;
    --text-secondary: #9fb8b8;
    --text-muted: #739090;
    --accent: #2f7c8e;
    --accent-gold: #78c3d1;
    --accent-gold-dim: #4d9cab;
    --accent-green: #4fb5a4;
    --age-tint: rgba(72, 144, 160, 0.2);
}

body[data-age-theme="cataclysm-age"] {
    --bg-dark: #17110f;
    --bg-panel: #241916;
    --bg-panel-hover: #30211c;
    --bg-input: #1b1311;
    --border: #4a3028;
    --border-light: #5a3c31;
    --text-primary: #e0c1b7;
    --text-secondary: #b8968b;
    --text-muted: #936f66;
    --accent: #a03d34;
    --accent-gold: #d07b5b;
    --accent-gold-dim: #aa583f;
    --age-tint: rgba(164, 86, 60, 0.22);
}

body[data-age-theme="spacefaring-age"] {
    --bg-dark: #0b1320;
    --bg-panel: #141f31;
    --bg-panel-hover: #1c2a40;
    --bg-input: #11192a;
    --border: #2c4362;
    --border-light: #3b5980;
    --text-primary: #c8d8ef;
    --text-secondary: #99b1d2;
    --text-muted: #6f8bb0;
    --accent: #3465a4;
    --accent-gold: #6fb6ff;
    --accent-gold-dim: #4f8bcc;
    --accent-purple: #7b78d9;
    --age-tint: rgba(83, 122, 190, 0.24);
}

body[data-age-theme="age-of-sword-stone"],
body[data-age-theme="medieval"] {
    --bg-dark: #100f0d;
    --bg-panel: #1b1915;
    --bg-panel-hover: #26221b;
    --bg-input: #14120f;
    --border: #312c24;
    --border-light: #413a2f;
    --text-primary: #d4c5a9;
    --text-secondary: #9a8e76;
    --text-muted: #6b6152;
    --accent: #9c3a2f;
    --accent-gold: #c49f50;
    --accent-gold-dim: #9e7b33;
    --age-tint: rgba(150, 86, 62, 0.16);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-box {
    position: relative;
}

.search-box input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 8px 14px 8px 36px;
    border-radius: 6px;
    width: 260px;
    outline: none;
    transition: border-color 0.2s, background-color 280ms ease, color 280ms ease;
}

.search-box input:focus {
    border-color: var(--accent-gold-dim);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-box svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    fill: var(--text-muted);
}

.search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 8px 30px var(--shadow);
    transition: background-color 280ms ease, border-color 280ms ease;
}

.search-results.active { display: block; }

.search-result-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.search-result-item:hover { background: var(--bg-panel-hover); }

.search-result-item .result-name {
    font-family: var(--font-display);
    font-size: 0.85rem;
    color: var(--text-bright);
}

.search-result-item .result-type {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.search-group-title {
    padding: 8px 14px 4px;
    font-family: var(--font-display);
    font-size: 0.7rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.result-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-right: 6px;
    border: 1px solid var(--border-light);
}

.result-badge.location {
    color: #bfe2d4;
    border-color: rgba(96, 170, 138, 0.6);
    background: rgba(56, 112, 88, 0.28);
}

.result-badge.history {
    color: #f3d8aa;
    border-color: rgba(186, 143, 69, 0.7);
    background: rgba(120, 84, 34, 0.28);
}

.tag-btn {
    cursor: pointer;
}

.history-entry.highlighted {
    border-left-color: var(--accent-gold);
    background: rgba(212, 168, 71, 0.08);
}

.history-timeline.reader-mode .history-content {
    font-size: 1.08rem;
    line-height: 1.75;
}

.mention-item.active {
    background: var(--bg-panel-hover);
}

body.presentation-mode .header {
    display: none;
}

body.presentation-mode .side-panel {
    display: none;
}

body.presentation-mode .main-container {
    height: 100vh;
    margin-top: 0;
}

.presentation-exit-btn {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1100;
    display: none;
}

body.presentation-mode .presentation-exit-btn {
    display: inline-flex;
}

.btn {
    font-family: var(--font-display);
    font-size: 0.75rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-panel);
    color: var(--text-primary);
}

.btn:hover {
    border-color: var(--accent-gold-dim);
    color: var(--text-bright);
}

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

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

.btn-danger {
    background: rgba(140, 40, 36, 0.85);
    border-color: rgba(176, 66, 58, 0.9);
    color: #fff;
}

.btn-danger:hover {
    background: rgba(171, 48, 43, 0.92);
    border-color: rgba(202, 78, 69, 0.95);
}

.btn-small {
    font-size: 0.7rem;
    padding: 5px 10px;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-panel-hover);
    border-color: var(--border);
}

/* --- Layout --- */
.main-container {
    display: flex;
    height: calc(100vh - var(--header-height));
    margin-top: var(--header-height);
}

/* --- Map --- */
#map {
    flex: 1;
    background: var(--bg-dark);
    cursor: crosshair;
}

/* Leaflet overrides */
.leaflet-container {
    background: #0f0e0c !important;
    font-family: var(--font-body) !important;
}

.leaflet-control-zoom {
    border: 1px solid var(--border) !important;
    border-radius: 6px !important;
    overflow: hidden;
    box-shadow: 0 2px 10px var(--shadow) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-panel-hover) !important;
    color: var(--text-bright) !important;
}

.leaflet-control-attribution {
    background: rgba(15, 14, 12, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 0.7rem !important;
}

/* Custom map markers */
.poi-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    border: 2px solid rgba(255,255,255,0.3);
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    transition: transform 0.2s, box-shadow 0.2s;
}

.poi-marker:hover {
    transform: rotate(-45deg) scale(1.15);
    box-shadow: 0 4px 16px rgba(0,0,0,0.7);
}

.poi-marker-inner {
    transform: rotate(45deg);
    font-size: 14px;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.poi-marker-legacy {
    opacity: 0.5;
    filter: saturate(0.4);
    border-color: rgba(255, 255, 255, 0.18);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.poi-marker-container {
    opacity: 1;
    transition: opacity 150ms ease;
}

#map.age-switching .poi-marker-container {
    opacity: 0;
}

.poi-label {
    font-family: var(--font-display) !important;
    font-size: 11px !important;
    color: var(--text-bright) !important;
    text-shadow: 0 0 4px var(--bg-dark), 0 0 8px var(--bg-dark), 1px 1px 2px var(--bg-dark) !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    white-space: nowrap !important;
    letter-spacing: 1px !important;
}

.poi-label-legacy {
    display: none !important;
}

.poi-marker-legacy .poi-marker-inner {
    transform: rotate(45deg);
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.poi-hover-popup .leaflet-popup-content-wrapper {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-light) !important;
    border-radius: 8px !important;
    box-shadow: 0 10px 28px var(--shadow) !important;
    animation: poiTooltipRise 0.62s cubic-bezier(0.22, 0.8, 0.2, 1);
}

.poi-hover-popup .leaflet-popup-tip {
    background: var(--bg-panel) !important;
    border: 1px solid var(--border-light) !important;
    box-shadow: none !important;
}

.poi-hover-popup .leaflet-popup-content {
    margin: 10px 12px !important;
    min-width: 260px;
    max-width: min(460px, 62vw);
    font-size: 0.9rem !important;
    line-height: 1.5 !important;
    white-space: normal !important;
}

.poi-hover-popup-title {
    font-weight: 700;
    color: var(--text-bright);
}

.poi-hover-popup-meta {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.poi-hover-popup-desc {
    margin-top: 8px;
    color: var(--text-primary);
}

@keyframes poiTooltipRise {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Side Panel --- */
.side-panel {
    width: var(--panel-width);
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    transition: transform 0.3s ease, background-color 280ms ease, border-color 280ms ease;
    position: relative;
    flex-shrink: 0;
}

.side-panel.collapsed {
    transform: translateX(100%);
    width: 0;
    border: none;
    overflow: hidden;
}

.panel-toggle {
    position: absolute;
    left: -40px;
    top: 12px;
    width: 36px;
    height: 36px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: 6px 0 0 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.2s;
    z-index: 500;
}

.panel-toggle:hover { color: var(--text-bright); }

/* Panel content sections */
.panel-section {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.panel-section:last-child { border-bottom: none; }

#panel-list-view,
#poi-detail,
#panel-add-view {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.poi-tabs {
    display: flex;
    gap: 8px;
}

.poi-tab {
    flex: 1;
    font-family: var(--font-display);
    font-size: 0.72rem;
    letter-spacing: 1px;
    text-transform: none;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
}

.poi-tab:hover {
    border-color: var(--accent-gold-dim);
    color: var(--text-bright);
}

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

.panel-title {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-bright);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-title-history {
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
}

.panel-title-history > span {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px !important;
}

.panel-subtitle {
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-gold);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin: 16px 0 10px;
}

/* POI Detail View */
.poi-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.poi-detail-name {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-bright);
    line-height: 1.3;
}

.poi-detail-type {
    display: inline-block;
    font-family: var(--font-display);
    font-size: 0.65rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 3px 10px;
    border-radius: 3px;
    border: 1px solid;
    margin-top: 6px;
}

.poi-detail-description {
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--text-primary);
    margin-top: 12px;
}

.poi-detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.tag {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 3px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-secondary);
}

.poi-detail-coords {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* History Timeline */
.history-timeline {
    position: relative;
    padding-left: 20px;
    margin-top: 8px;
}

.history-timeline::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-light);
}

.history-entry {
    position: relative;
    margin-bottom: 20px;
    padding-bottom: 4px;
}

.history-entry::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-gold);
    border: 2px solid var(--bg-panel);
    box-shadow: 0 0 0 2px var(--accent-gold-dim);
}

.history-year {
    font-family: var(--font-display);
    font-size: 0.7rem;
    color: var(--accent-gold);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.history-title {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 4px;
}

.history-content {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.history-content .inline-mention-chip {
    display: inline-flex;
    align-items: center;
    margin: 0 2px;
    padding: 1px 7px;
    border-radius: 999px;
    border: 1px solid var(--border-light);
    background: rgba(212, 168, 71, 0.16);
    color: var(--text-bright);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 1.2;
    vertical-align: baseline;
}

.history-content button.inline-mention-chip {
    cursor: pointer;
}

.history-content button.inline-mention-chip:hover {
    border-color: var(--accent-gold-dim);
    background: rgba(212, 168, 71, 0.24);
}

.history-content .inline-mention-chip-muted {
    opacity: 0.82;
}

.history-content.clamped {
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-toggle {
    margin-top: 6px;
    margin-bottom: 6px;
    padding-left: 0;
}

.history-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-style: italic;
}

.history-links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.chip-groups {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chip-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.chip-group-label {
    font-family: var(--font-display);
    font-size: 0.66rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.chip-group-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ref-chip {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid var(--border-light);
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
}

.ref-chip:hover {
    border-color: var(--accent-gold-dim);
    color: var(--text-bright);
}

.ref-chip.active {
    border-color: var(--accent-gold);
    color: var(--text-bright);
    background: rgba(212, 168, 71, 0.18);
}

.mention-picker {
    margin-top: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    max-height: 180px;
    overflow-y: auto;
}

.mention-item {
    display: flex;
    gap: 10px;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.mention-item:last-child {
    border-bottom: none;
}

.mention-item:hover {
    background: var(--bg-panel-hover);
}

.mention-kind {
    color: var(--accent-gold);
    font-family: var(--font-mono);
}

.entity-drawer {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(36, 32, 24, 0.6), rgba(26, 24, 20, 0.9));
}

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

.form-group label {
    display: block;
    font-family: var(--font-display);
    font-size: 0.7rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.label-with-help {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    padding: 8px 12px;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--accent-gold-dim);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
    line-height: 1.6;
}

.form-group select {
    cursor: pointer;
}

.form-group .has-error {
    border-color: #bf5a55 !important;
}

.field-error {
    margin-top: 4px;
    font-size: 0.78rem;
    color: #dd8f89;
    line-height: 1.35;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* --- POI List --- */
.poi-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}

.poi-list-item:hover { background: var(--bg-panel-hover); }

.poi-list-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.poi-list-thumb {
    width: 34px;
    height: 34px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.poi-list-info {
    flex: 1;
    min-width: 0;
}

.poi-list-name {
    font-family: var(--font-display);
    font-size: 0.85rem;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.poi-list-type {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* --- Coordinate Display --- */
.coord-display {
    position: fixed;
    bottom: 12px;
    left: 12px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(15, 14, 12, 0.85);
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    z-index: 500;
}

/* --- Add POI Mode Banner --- */
.add-mode-banner {
    position: fixed;
    top: calc(var(--header-height) + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 1px;
    padding: 10px 24px;
    border-radius: 6px;
    z-index: 999;
    display: none;
    box-shadow: 0 4px 20px rgba(192, 57, 43, 0.4);
    cursor: pointer;
}

.add-mode-banner.active { display: block; }

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    fill: var(--text-muted);
    opacity: 0.4;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 0.95rem;
    line-height: 1.6;
}

.inline-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.media-section {
    margin-top: 12px;
}

.media-upload-row input[type="file"] {
    padding: 6px;
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.media-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    background: var(--bg-input);
}

.media-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-light);
}

.media-map-card img {
    height: 180px;
}

.media-meta {
    margin-top: 6px;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.media-badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--accent-gold-dim);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.68rem;
    color: var(--text-bright);
    background: rgba(212, 168, 71, 0.16);
}

.inline-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 0.85s linear infinite;
}

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

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .side-panel {
        position: fixed;
        right: 0;
        top: var(--header-height);
        bottom: 0;
        z-index: 900;
        width: 100%;
        max-width: var(--panel-width);
    }

    .search-box input { width: 180px; }
    .header {
        padding: 0 10px;
    }
    .header-brand h1 {
        font-size: 0.95rem;
        letter-spacing: 1px;
    }
    .age-nav {
        max-width: 48vw;
    }
}

/* --- Toasts --- */
.toast-root {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 5000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    max-width: 360px;
    background: rgba(18, 18, 18, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    border-color: rgba(217, 83, 79, 0.7);
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-card {
    width: min(560px, 100%);
    max-height: 85vh;
    overflow: auto;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
}

.confirm-dialog {
    border: none;
    padding: 0;
    background: transparent;
}

.confirm-dialog::backdrop {
    background: rgba(0, 0, 0, 0.48);
}

.confirm-dialog-card {
    min-width: 320px;
    max-width: min(92vw, 460px);
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 16px;
    color: var(--text-primary);
}

.confirm-dialog-card h3 {
    font-family: var(--font-display);
    margin-bottom: 8px;
}

.confirm-dialog-card p {
    margin-bottom: 14px;
    line-height: 1.45;
}

.mention-help-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mention-help-toggle {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 999px;
}

.mention-help-bubble {
    display: none;
    margin-top: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
}

.mention-help-bubble.open {
    display: block;
}

.shortcuts-grid {
    display: grid;
    gap: 8px;
}

.shortcuts-grid kbd {
    display: inline-block;
    min-width: 20px;
    padding: 2px 6px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-bright);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* --- AI Feature Blocks --- */
.ai-summary-block,
.ai-suggestions-block {
    margin: 8px 0 4px;
    padding: 10px 12px;
    background: #1a1430;
    border-left: 3px solid #7c5cbf;
    border-radius: 0 6px 6px 0;
    font-size: 0.87rem;
    line-height: 1.55;
    color: var(--text-muted);
}

.ai-block-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.ai-block-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9d7de0;
    flex: 1;
}

.ai-block-content {
    white-space: pre-wrap;
}

.btn-ai {
    background: #2a1f42;
    color: #b09de8;
    border: 1px solid #4a3570;
}

.btn-ai:hover {
    background: #3a2a5a;
    color: #d0c0ff;
}

.btn-ai.loading {
    opacity: 0.65;
    cursor: wait;
    pointer-events: none;
}
