:root {
    color-scheme: dark;
    --bg: #0b1118;
    --panel: rgba(14, 22, 31, 0.94);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text: #edf3f8;
    --muted: #8b9aaa;
    --gold: #f7c948;
    --green: #4ade80;
    --sidebar-width: 286px;
}

* { box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button { font: inherit; }

#map, #map-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
}

#map-canvas {
    cursor: grab;
    background-color: #081018;
    background-image:
        linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
    background-size: 32px 32px;
    touch-action: none;
}

#map-canvas.dragging { cursor: grabbing; }

.topbar {
    position: fixed;
    z-index: 20;
    top: 0;
    left: 0;
    right: 0;
    height: 68px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(180deg, rgba(7, 12, 18, .96), rgba(7, 12, 18, .68), transparent);
    pointer-events: none;
}

.topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, #f9d865, #c98f22);
    color: #15120a;
    font-weight: 900;
    box-shadow: 0 7px 24px rgba(247, 201, 72, .22);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: .01em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }

.coordinates, .zoom-label {
    padding: 8px 11px;
    border: 1px solid var(--panel-border);
    border-radius: 9px;
    background: rgba(9, 15, 22, .78);
    color: #c8d3de;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    backdrop-filter: blur(10px);
}

.sidebar {
    position: fixed;
    z-index: 15;
    top: 74px;
    left: 14px;
    right: auto;
    bottom: 14px;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 17px;
    overflow-y: auto;
    border: 1px solid var(--panel-border);
    border-radius: 15px;
    background: var(--panel);
    box-shadow: 0 16px 50px rgba(0, 0, 0, .38);
    backdrop-filter: blur(18px);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 9px;
    color: #aab7c4;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.collapsible-title {
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.collapsible-title:hover { color: #dce5ed; }
.section-title-meta { display: flex; align-items: center; gap: 6px; }
.collapse-chevron {
    display: inline-block;
    color: #718191;
    font-size: 14px;
    line-height: 1;
    transition: transform .16s ease;
}
#player-section.collapsed .stack,
#marker-section.collapsed .stack,
#warp-section.collapsed .stack,
#claim-section.collapsed .stack,
#player-claim-section.collapsed .stack { display: none; }
.collapsed .collapse-chevron { transform: rotate(-90deg); }

.badge {
    min-width: 20px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(255,255,255,.08);
    text-align: center;
    font-size: 10px;
}
.badge.online { color: var(--green); background: rgba(74, 222, 128, .12); }
.stack { display: grid; gap: 6px; }
.stack.muted { color: var(--muted); font-size: 12px; }

.layer-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}
.layer-filter {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 32px;
    padding: 7px 8px;
    border: 1px solid var(--panel-border);
    border-radius: 9px;
    background: rgba(255,255,255,.025);
    color: #cfd9e3;
    font-size: 11px;
    cursor: pointer;
    user-select: none;
}
.layer-filter:has(input:checked) { border-color: rgba(247,201,72,.24); background: rgba(247,201,72,.07); }
.layer-filter:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.layer-filter input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.filter-swatch { width: 9px; height: 9px; border-radius: 3px; background: #667686; }
.filter-swatch.players { border-radius: 50%; background: var(--green); }
.filter-swatch.markers { background: var(--gold); transform: rotate(45deg); }
.filter-swatch.warps { border: 2px solid #22d3ee; border-radius: 50%; background: rgba(34,211,238,.16); }
.filter-swatch.claims { border: 2px solid #55c2ff; background: rgba(85,194,255,.18); }
.filter-swatch.player-claims { border: 2px solid #4ade80; background: rgba(74,222,128,.18); }
.filter-swatch.chunks {
    border-radius: 2px;
    background:
        linear-gradient(90deg, transparent 42%, #e2e8f0 42%, #e2e8f0 58%, transparent 58%),
        linear-gradient(transparent 42%, #e2e8f0 42%, #e2e8f0 58%, transparent 58%);
}
.layer-disabled { opacity: .48; }
.layer-disabled .stack { display: none; }

.filter-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    gap: 6px;
    margin-top: 9px;
}
.filter-search input, .filter-search button {
    min-width: 0;
    height: 34px;
    border: 1px solid var(--panel-border);
    border-radius: 9px;
    outline: none;
    background: #0a121a;
    color: var(--text);
    font: inherit;
}
.filter-search input { padding: 0 10px; font-size: 11px; }
.filter-search input:focus { border-color: rgba(247,201,72,.45); }
.filter-search button { color: #b9c5d0; font-size: 18px; cursor: pointer; }
.filter-search button:disabled { opacity: .32; cursor: default; }
.detail-filter-group { display: grid; gap: 6px; margin-top: 9px; }
.detail-filter-group > span {
    color: #8493a3;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
}
.detail-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.detail-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 25px;
    padding: 4px 7px;
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    background: rgba(255,255,255,.025);
    color: #8594a4;
    font-size: 9px;
    cursor: pointer;
    user-select: none;
}
.detail-chip:has(input:checked) { border-color: rgba(247,201,72,.25); background: rgba(247,201,72,.08); color: #e7edf3; }
.detail-chip input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.list-button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: #cfd9e3;
    text-align: left;
    cursor: pointer;
}
.list-button:hover { background: rgba(255,255,255,.05); }
.list-button.active {
    border-color: rgba(247, 201, 72, .22);
    background: rgba(247, 201, 72, .10);
    color: #ffe598;
}
.list-button .dot {
    flex: 0 0 auto;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #667686;
}
.list-button .dot.player { background: var(--green); box-shadow: 0 0 0 4px rgba(74,222,128,.09); }
.player-head {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    overflow: hidden;
    border: 2px solid rgba(74, 222, 128, .75);
    border-radius: 7px;
    background: #243b31;
    image-rendering: pixelated;
}
.player-head img { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.marker-symbol {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border: 2px solid color-mix(in srgb, var(--symbol-color) 72%, white);
    border-radius: 8px 8px 8px 3px;
    background: color-mix(in srgb, var(--symbol-color) 82%, #081018);
    color: #081018;
    font-size: 13px;
    font-weight: 900;
    transform: rotate(-5deg);
}
.marker-symbol.claim {
    border-radius: 6px;
    background: color-mix(in srgb, var(--symbol-color) 24%, transparent);
    color: var(--symbol-color);
    transform: none;
}
.list-button .details { overflow: hidden; }
.list-button .details strong, .list-button .details small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-button .details strong { font-size: 12px; }
.list-button .details small { margin-top: 2px; color: var(--muted); font-size: 10px; }

.sidebar footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--panel-border);
    color: var(--muted);
    font-size: 11px;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }

.editor-panel {
    position: fixed;
    z-index: 18;
    top: 74px;
    left: auto;
    right: 14px;
    bottom: 14px;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 13px;
    padding: 17px;
    overflow-y: auto;
    border: 1px solid rgba(247,201,72,.26);
    border-radius: 15px;
    background: rgba(14,22,31,.97);
    box-shadow: 0 16px 50px rgba(0,0,0,.45);
    backdrop-filter: blur(18px);
}
.editor-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.editor-header strong { display: block; margin-top: 2px; font-size: 17px; }
.editor-kicker { color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.editor-close {
    width: 30px;
    height: 30px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: rgba(255,255,255,.04);
    color: var(--muted);
    font-size: 20px;
    cursor: pointer;
}
.editor-close:hover { color: var(--text); border-color: rgba(247,201,72,.3); }
.editor-session, .editor-status { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.editor-session { padding: 8px 10px; border-radius: 8px; background: rgba(247,201,72,.07); color: #d9c77f; }
#editor-form { display: grid; gap: 12px; }
.editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.editor-field { display: grid; gap: 5px; }
.editor-field.wide { grid-column: 1 / -1; }
.editor-field > span { color: #9eacba; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.editor-field input, .editor-field select {
    min-width: 0;
    height: 36px;
    padding: 0 9px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    outline: none;
    background: #0a121a;
    color: var(--text);
    font: inherit;
    font-size: 12px;
}
.editor-field input:focus, .editor-field select:focus { border-color: rgba(247,201,72,.55); box-shadow: 0 0 0 3px rgba(247,201,72,.08); }
.editor-field input[type="color"] { width: 100%; padding: 4px; cursor: pointer; }
.editor-status { min-height: 32px; padding: 8px 9px; border-left: 3px solid #526171; background: rgba(255,255,255,.025); }
.editor-status.success { border-color: var(--green); color: #b8f5cc; }
.editor-status.error { border-color: #fb7185; color: #fecdd3; }
.editor-status.placing { border-color: var(--gold); color: #ffe598; }
.editor-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.editor-button {
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: rgba(255,255,255,.06);
    color: var(--text);
    font-weight: 700;
    font-size: 11px;
    cursor: pointer;
}
.editor-button:hover:not(:disabled) { filter: brightness(1.12); }
.editor-button:disabled { opacity: .4; cursor: not-allowed; }
.editor-button.save { background: var(--gold); color: #171207; }
.editor-button.secondary { border-color: var(--panel-border); color: #cbd5df; }
.editor-button.secondary.active { border-color: var(--gold); background: rgba(247,201,72,.12); color: #ffe598; }
.editor-button.danger { border-color: rgba(251,113,133,.25); background: rgba(251,113,133,.09); color: #fda4af; }
.editor-warning { margin-top: auto; color: #758596; font-size: 10px; line-height: 1.45; }
.editor-active .map-controls { left: 16px; }
.editor-active .zoom-label { left: 68px; }
.editor-selected { border-color: rgba(247,201,72,.55); background: rgba(247,201,72,.12); }

.map-controls {
    position: fixed;
    z-index: 16;
    left: 16px;
    bottom: 18px;
    display: grid;
    gap: 7px;
}
.control-button, .icon-button {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: rgba(11, 18, 26, .9);
    color: var(--text);
    font-size: 21px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,.22);
}
.control-button:hover, .icon-button:hover { border-color: rgba(247,201,72,.35); color: var(--gold); }
.control-button.compass { font-size: 20px; }
.zoom-label { position: fixed; z-index: 16; left: 68px; bottom: 18px; }
.mobile-only { display: none; }

.empty-state {
    position: fixed;
    z-index: 8;
    left: 50%;
    top: 50%;
    display: grid;
    gap: 7px;
    max-width: 390px;
    padding: 18px 22px;
    transform: translate(-50%, -50%);
    border: 1px solid var(--panel-border);
    border-radius: 13px;
    background: rgba(11,18,26,.9);
    text-align: center;
    box-shadow: 0 15px 45px rgba(0,0,0,.4);
}
.empty-state span { color: var(--muted); font-size: 12px; }
.empty-state code { color: var(--gold); }
.hidden { display: none; }

.map-tooltip {
    position: fixed;
    z-index: 30;
    max-width: 240px;
    padding: 7px 10px;
    border: 1px solid rgba(85,194,255,.38);
    border-radius: 8px;
    background: rgba(5,11,17,.94);
    color: #dff4ff;
    font-size: 11px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(0,0,0,.38);
    pointer-events: none;
}
.map-toast {
    position: fixed;
    z-index: 35;
    left: 50%;
    bottom: 24px;
    max-width: min(440px, calc(100vw - 32px));
    padding: 10px 14px;
    transform: translateX(-50%);
    border: 1px solid rgba(34,211,238,.35);
    border-radius: 10px;
    background: rgba(7,18,25,.96);
    color: #c8f8ff;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 12px 35px rgba(0,0,0,.4);
}

.marker-details {
    position: fixed;
    z-index: 19;
    top: 74px;
    left: auto;
    right: 14px;
    bottom: 14px;
    width: 330px;
    padding: 17px;
    overflow-x: hidden;
    overflow-y: auto;
    border: 1px solid rgba(247,201,72,.25);
    border-radius: 15px;
    background: rgba(14,22,31,.97);
    box-shadow: 0 16px 50px rgba(0,0,0,.44);
    backdrop-filter: blur(18px);
}
.marker-details-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.marker-details-header strong { display: block; margin-top: 2px; font-size: 18px; }
.marker-details-kicker { color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.marker-details-header button {
    width: 30px;
    height: 30px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: rgba(255,255,255,.04);
    color: var(--muted);
    font-size: 20px;
    cursor: pointer;
}
.marker-details-image-wrap {
    position: relative;
    height: 210px;
    margin-top: 14px;
    overflow: hidden;
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    background:
        radial-gradient(circle at 50% 42%, rgba(247,201,72,.16), transparent 58%),
        #09121a;
}
.marker-details-image-wrap.loading::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 26px;
    height: 26px;
    margin: -15px 0 0 -15px;
    border: 3px solid rgba(255,255,255,.12);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: npc-preview-spin .8s linear infinite;
}
.marker-details-image-wrap img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
@keyframes npc-preview-spin { to { transform: rotate(360deg); } }
.marker-details-position, .marker-details-generic { color: var(--muted); font-size: 11px; line-height: 1.45; }
.marker-details-position { margin: 12px 0; font-variant-numeric: tabular-nums; }
.marker-details-generic { padding: 10px; border-radius: 9px; background: rgba(255,255,255,.03); }
.marker-details-shop { display: grid; gap: 10px; }
.marker-details-shop.hidden { display: none; }
.shop-summary { display: flex; align-items: center; justify-content: space-between; color: #d9e3ec; font-size: 12px; font-weight: 700; }
.marker-details.inventory-mode {
    left: 50%;
    right: auto;
    bottom: auto;
    width: min(520px, calc(100vw - 28px));
    max-height: calc(100vh - 88px);
    transform: translateX(-50%);
    border-color: rgba(198,198,198,.42);
}
.marker-details.inventory-mode .marker-details-image-wrap { height: 110px; }
.minecraft-inventory {
    width: min(485px, 100%);
    max-width: 100%;
    margin: 0 auto;
    padding: 11px;
    border: 3px solid;
    border-color: #f5f5f5 #555 #555 #f5f5f5;
    background: #c6c6c6;
    box-shadow: 0 0 0 2px #111, inset 0 0 0 2px #8b8b8b;
    image-rendering: pixelated;
}
.minecraft-inventory-grid {
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 2px;
}
.inventory-slot {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid;
    border-color: #555 #fff #fff #555;
    outline: none;
    background: #8b8b8b;
    color: #fff;
    font: inherit;
}
.inventory-slot.filler { background: #373737; border-color: #222 #555 #555 #222; }
.inventory-slot.empty { background: #777; }
.inventory-slot.item { cursor: help; }
.inventory-slot.item:hover, .inventory-slot.item:focus { background: #a8a8a8; }
.inventory-slot.navigation { cursor: pointer; background: #777; }
.inventory-slot.navigation:hover, .inventory-slot.navigation:focus { background: #aaa; }
.inventory-item-icon {
    position: relative;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    filter: drop-shadow(2px 2px 0 rgba(0,0,0,.52));
    font-size: 25px;
    line-height: 1;
    image-rendering: pixelated;
}
.inventory-item-texture {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}
.inventory-item-texture.model-render {
    inset: -3px;
    width: calc(100% + 6px);
    height: calc(100% + 6px);
}
.inventory-item-icon.has-model {
    filter: drop-shadow(2px 3px 1px rgba(0,0,0,.68));
}
.inventory-item-icon.has-texture {
    border: 0;
    background: transparent;
    text-shadow: none;
}
.inventory-item-icon.has-texture .inventory-item-fallback { display: none; }
.inventory-item-icon.custom {
    border: 2px solid #362819;
    background: linear-gradient(135deg, #8fce55, #3e7c35);
    color: #fff7c9;
    font-size: 14px;
    font-weight: 900;
    text-shadow: 1px 1px #173313;
}
.inventory-item-icon.custom.has-texture {
    border: 0;
    background: transparent;
    text-shadow: none;
}
.inventory-amount {
    position: absolute;
    right: 3px;
    bottom: 1px;
    color: white;
    font-family: monospace;
    font-size: 12px;
    font-weight: 900;
    text-shadow: 1px 1px 0 #202020, -1px -1px 0 #202020;
}
.inventory-tooltip {
    position: absolute;
    z-index: 60;
    left: 75%;
    top: 75%;
    display: none;
    min-width: 190px;
    width: max-content;
    max-width: min(270px, calc(100vw - 52px));
    padding: 8px 10px;
    border: 2px solid #2a0a4a;
    background: rgba(16,0,16,.96);
    color: #fff;
    text-align: left;
    overflow-wrap: anywhere;
    box-shadow: inset 0 0 0 1px #8b2be2, 3px 3px 0 rgba(0,0,0,.45);
    pointer-events: none;
}
.inventory-slot:nth-child(9n) .inventory-tooltip,
.inventory-slot:nth-child(9n - 1) .inventory-tooltip,
.inventory-slot:nth-child(9n - 2) .inventory-tooltip,
.inventory-slot:nth-child(9n - 3) .inventory-tooltip { right: 75%; left: auto; }
.inventory-slot:nth-child(n + 37) .inventory-tooltip { top: auto; bottom: 75%; }
.inventory-slot.item:hover .inventory-tooltip,
.inventory-slot.item:focus .inventory-tooltip { display: grid; gap: 3px; }
.inventory-tooltip strong { color: #fff; font-size: 11px; }
.inventory-tooltip span { color: #55ff55; font-size: 10px; }
.inventory-tooltip small { color: #aaa; font-size: 9px; }
.inventory-page-icon { font-size: 22px; filter: drop-shadow(2px 2px 0 rgba(0,0,0,.5)); }
.inventory-page-number { color: #ffff55; font-size: 10px; font-weight: 900; text-shadow: 1px 1px #222; }

@media (max-width: 720px) {
    .coordinates { position: fixed; top: 71px; left: 12px; }
    .mobile-only { display: grid; }
    .sidebar {
        top: 64px;
        left: 0;
        right: auto;
        bottom: 0;
        width: min(88vw, 320px);
        border-radius: 0 14px 0 0;
        transform: translateX(-105%);
        transition: transform .2s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .editor-panel {
        top: 64px;
        left: auto;
        right: 0;
        bottom: 0;
        width: min(92vw, 340px);
        border-radius: 14px 0 0 0;
    }
    .marker-details {
        top: 64px;
        left: auto;
        right: 0;
        bottom: 0;
        width: min(92vw, 350px);
        border-radius: 14px 0 0 0;
    }
    .marker-details.inventory-mode {
        left: 0;
        right: auto;
        width: 100vw;
        max-height: calc(100vh - 64px);
        transform: none;
        border-radius: 0;
    }
    .minecraft-inventory {
        padding: 8px;
    }
    .inventory-item-icon { width: 28px; height: 28px; font-size: 21px; }
    .editor-active .map-controls { left: 16px; }
    .editor-active .zoom-label { left: 68px; }
    .map-controls { bottom: max(14px, env(safe-area-inset-bottom)); }
    .zoom-label { bottom: max(14px, env(safe-area-inset-bottom)); }
}
