:root {
    --bg: #0f1115;
    --bg-2: #161a22;
    --bg-3: #1f2531;
    --bg-4: #2a3142;
    --text: #e6e6e6;
    --text-dim: #a0a8b8;
    --accent: #8b5cf6;
    --accent-2: #c4b5fd;
    --gold: #ffd166;
    --danger: #ef4444;
    --green: #22c55e;
    --line: #2a3142;
}

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

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    font-size: 14px;
}

#app { display: flex; height: 100vh; width: 100vw; }

/* Sidebar */
#sidebar {
    width: 340px;
    background: var(--bg-2);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s ease;
    z-index: 1000;
}

#sidebar.collapsed { margin-left: -340px; }

.sidebar-head {
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--line);
}
.sidebar-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-head-actions {
    display: flex;
    gap: 6px;
}
.sidebar-head h1 {
    color: var(--accent-2);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.sidebar-head .subtitle {
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 2px;
}

/* Search */
.search {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    position: relative;
}
.search input,
.input {
    width: 100%;
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}
.search input:focus,
.input:focus { border-color: var(--accent); }

.search-results {
    position: absolute;
    top: calc(100% - 4px);
    left: 14px;
    right: 14px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 100;
}
.search-results.hidden { display: none; }
.search-result {
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--bg-4); }
.search-result .kind {
    color: var(--text-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--line);
    background: var(--bg-2);
}
.tab {
    flex: 1;
    padding: 10px 6px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
    color: var(--accent-2);
    border-bottom-color: var(--accent);
}

/* Panels */
.panels { flex: 1; overflow-y: auto; }
.panel { display: none; padding: 12px 14px 24px; }
.panel.active { display: block; }

/* Layer rows */
.layer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    border-radius: 6px;
}
.layer-row:hover { background: var(--bg-3); }
.layer-name { flex: 1; font-size: 13px; }
.layer-count {
    color: var(--text-dim);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

/* Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    flex-shrink: 0;
}
.switch input { display: none; }
.switch span {
    position: absolute;
    inset: 0;
    background: var(--bg-4);
    border-radius: 18px;
    cursor: pointer;
    transition: background 0.15s;
}
.switch span::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    top: 2px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: transform 0.15s, background 0.15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before {
    transform: translateX(14px);
    background: #fff;
}

/* Section head */
.section-head {
    margin: 18px 4px 6px;
    color: var(--accent-2);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

/* Chips */
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.chip {
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--bg-3);
    border: 1px solid var(--line);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s;
    color: var(--text-dim);
}
.chip:hover { background: var(--bg-4); }
.chip.on {
    background: rgba(139, 92, 246, 0.18);
    color: var(--accent-2);
    border-color: var(--accent);
}

/* Bulk row */
.bulk-row {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.btn {
    padding: 6px 12px;
    background: var(--bg-3);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s;
}
.btn:hover { background: var(--bg-4); }

.row { display: flex; gap: 8px; margin-bottom: 8px; }
.num { flex: 1; font-size: 12px; color: var(--text-dim); display: flex; flex-direction: column; gap: 4px; }
.num input { width: 100%; }
.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
}

/* NPC panel — layer toggle at top */
.npc-layer-toggle {
    margin-bottom: 10px;
    padding: 8px 8px;
    background: var(--bg-3);
    border-radius: 6px;
    border: 1px solid var(--line);
}

/* NPC panel — level range row */
.npc-level-row {
    margin-top: 8px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 10px;
}
.npc-level-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.npc-level-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.npc-level-field input[type="number"] {
    width: 100%;
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 10px;
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
    -moz-appearance: textfield;
}
.npc-level-field input[type="number"]::-webkit-inner-spin-button,
.npc-level-field input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
}
.npc-level-field input[type="number"]:focus {
    border-color: var(--accent);
}
.npc-level-sep {
    color: var(--text-dim);
    font-size: 13px;
    padding-bottom: 8px;
}

/* NPC panel — filter chips (aggressive / combat) */
.npc-chip-row {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}
.npc-chip {
    flex: 1;
    cursor: pointer;
    user-select: none;
}
.npc-chip input { display: none; }
.npc-chip-inner {
    display: block;
    text-align: center;
    padding: 6px 10px;
    border-radius: 6px;
    background: var(--bg-3);
    border: 1px solid var(--line);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    transition: all 0.15s;
}
.npc-chip-inner:hover {
    background: var(--bg-4);
    color: var(--text);
}
.npc-chip input:checked + .npc-chip-inner {
    background: rgba(139, 92, 246, 0.18);
    color: var(--accent-2);
    border-color: var(--accent);
}
#chip-aggressive input:checked + .npc-chip-inner {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
    border-color: var(--danger);
}
#chip-combat input:checked + .npc-chip-inner {
    background: rgba(139, 92, 246, 0.18);
    color: var(--accent-2);
    border-color: var(--accent);
}
.slider {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    margin: 6px 0;
}
.slider input { flex: 1; }

/* Filter tree */
.filter-tree { margin-top: 8px; }
.skill-group { margin-bottom: 10px; }
.skill-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--accent-2);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 8px;
    background: var(--bg-3);
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
}
.skill-header .caret { transition: transform 0.15s; }
.skill-group.collapsed .caret { transform: rotate(-90deg); }
.skill-group.collapsed .skill-items { display: none; }
.skill-items { padding: 4px 0 4px 6px; }

.filter-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 15px;
}
.filter-label:hover { background: var(--bg-3); }
.filter-label.hidden { display: none; }
.filter-icon {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
}
.filter-level {
    margin-left: auto;
    color: var(--text-dim);
    font-size: 13px;
}

.hint {
    color: var(--text-dim);
    font-size: 12px;
    padding: 6px 4px;
}

/* Map */
#map {
    flex: 1;
    background: var(--bg);
}
.leaflet-container { background: var(--bg); }
.leaflet-control-zoom a {
    background: var(--bg-3);
    color: var(--text);
    border-color: var(--line);
}
.leaflet-control-zoom a:hover { background: var(--bg-4); color: #fff; }
.leaflet-bar { border: 1px solid var(--line); }

/* Sidebar toggle button */
.leaflet-control-sidebar {
    width: 30px;
    height: 30px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    text-decoration: none;
}

/* 3D view button */
.leaflet-control-3d {
    width: 30px;
    height: 30px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    color: var(--accent-2) !important;
}

/* HUD */
.hud {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(22, 26, 34, 0.92);
    color: var(--text);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    z-index: 1000;
    pointer-events: none;
    border: 1px solid var(--line);
}
.hud .sep { color: var(--text-dim); margin: 0 6px; }
#hud-coords { color: var(--accent-2); }

/* Popups */
.leaflet-popup-content-wrapper {
    background: var(--bg-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
}
.leaflet-popup-content { margin: 8px 12px; font-size: 13px; line-height: 1.5; }
.leaflet-popup-tip { background: var(--bg-2); }
.leaflet-popup-content strong { color: var(--accent-2); }
.leaflet-popup-content em { color: var(--text-dim); font-size: 12px; font-style: normal; }
.popup-row { display: flex; justify-content: space-between; gap: 12px; }
.popup-row .k { color: var(--text-dim); }
.popup-gold { color: var(--gold); font-weight: 600; }
.popup-danger { color: var(--danger); }

/* Map labels */
.map-label { background: transparent; border: none; }
.label-text {
    color: #fff;
    text-shadow: -1px -1px 2px #000, 1px -1px 2px #000, -1px 1px 2px #000, 1px 1px 2px #000, 0 0 4px #000;
    font-weight: 700;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.3px;
}

/* NPC ring */
.npc-marker {
    border-radius: 50%;
    border: 2px solid var(--text-dim);
    background: var(--bg-3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.npc-marker.aggressive { border-color: var(--danger); }
.npc-marker.friendly { border-color: var(--green); }

/* Workbench / fast-travel chip on map */
.bench-marker, .ft-marker {
    background: var(--bg-3);
    border: 1.5px solid var(--accent);
    border-radius: 4px;
    padding: 2px 6px;
    color: var(--accent-2);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.ft-marker { border-color: var(--gold); color: var(--gold); }

/* Highlight */
.highlight-marker {
    border: 3px solid var(--gold);
    border-radius: 50%;
    background: rgba(255, 209, 102, 0.15);
    box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.25);
}

/* Debug overlay */
.tile-label {
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 10px;
    white-space: nowrap;
}

/* Scrollbar */
.panels::-webkit-scrollbar,
.search-results::-webkit-scrollbar { width: 8px; }
.panels::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track { background: var(--bg-2); }
.panels::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 4px; }

@media (max-width: 768px) {
    #sidebar { width: 280px; position: absolute; height: 100%; }
    #sidebar.collapsed { margin-left: -280px; }
}

/* Crawler / no-JS fallback shown inside the map container */
.noscript {
    max-width: 32rem;
    margin: 12vh auto 0;
    padding: 1.5rem;
    text-align: center;
    color: var(--text);
}
.noscript h2 { color: var(--accent-2); margin-bottom: 0.75rem; }
.noscript p { color: var(--text-dim); line-height: 1.6; }

/* Feedback buttons + modal */
.feedback-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 5px;
    color: var(--text-dim);
    cursor: pointer;
    text-decoration: none;
    transition: background .12s, color .12s, border-color .12s;
}
.feedback-btn--default:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.feedback-btn--bug {
    color: #e05555;
    border-color: rgba(224, 85, 85, 0.4);
}
.feedback-btn--bug:hover {
    background: #e05555;
    color: #fff;
    border-color: #e05555;
}

.feedback-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}
.feedback-modal {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.feedback-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.feedback-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.feedback-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
}
.feedback-close:hover { color: var(--text); }
.feedback-textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    min-height: 100px;
    outline: none;
}
.feedback-textarea::placeholder { color: var(--text-dim); }
.feedback-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--line);
}
.feedback-status {
    font-size: 12px;
    color: var(--text-dim);
}
.feedback-footer-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.feedback-counter {
    font-size: 12px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}
.feedback-counter.over { color: var(--danger); }
.feedback-submit {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 5px;
    padding: 6px 18px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .12s;
}
.feedback-submit:hover { opacity: 0.85; }
.feedback-submit:disabled { opacity: 0.5; cursor: not-allowed; }
