/* ============================================================
 * Hynfinity WebMap — topbar + right-drawer layout
 * ============================================================ */

:root {
    --wm-topbar-h: 48px;
    --wm-drawer-w: 260px;
    --wm-bg: #0d0f1a;
    --wm-surface: rgba(16, 18, 32, 0.92);
    --wm-surface-solid: #111323;
    --wm-border: rgba(255, 255, 255, 0.08);
    --wm-text: #e6e8f0;
    --wm-text-dim: #9aa0b4;
    --wm-accent: #4fc3f7;
    --wm-follow: #ffc107;
    --wm-danger: #ef5350;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: var(--wm-bg);
    color: var(--wm-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 13px;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */

.wm-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    height: calc(var(--wm-topbar-h) + env(safe-area-inset-top));
    background: var(--wm-surface);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--wm-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1200;
    gap: 12px;
}

.wm-topbar-left, .wm-topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.wm-topbar-left { flex: 1; min-width: 0; }

.wm-select {
    background: rgba(255, 255, 255, 0.06);
    color: var(--wm-text);
    border: 1px solid var(--wm-border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    max-width: 160px;
}
.wm-select:focus { outline: 2px solid var(--wm-accent); outline-offset: 1px; }

.wm-online-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(79, 195, 247, 0.12);
    border: 1px solid rgba(79, 195, 247, 0.25);
    border-radius: 999px;
    color: var(--wm-accent);
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
}
.wm-online-badge .wm-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #4caf50;
    box-shadow: 0 0 6px rgba(76, 175, 80, 0.6);
}

.wm-coords {
    color: var(--wm-text-dim);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* ---------- Overflow menu (layers + settings) ---------- */

.wm-overflow-menu { position: relative; }

.wm-overflow-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: var(--wm-surface-solid);
    border: 1px solid var(--wm-border);
    border-radius: 8px;
    padding: 4px 0;
    z-index: 1300;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.wm-overflow-panel.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.wm-overflow-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    color: var(--wm-text);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s;
}
.wm-overflow-item:hover { background: rgba(255, 255, 255, 0.06); }
.wm-overflow-item.hidden { display: none; }

.wm-overflow-item.wm-wakelock-toggle.active { color: #66bb6a; }
.wm-overflow-item.wm-wakelock-toggle:not(.active) { opacity: 0.5; }
.wm-overflow-item.wm-markers-toggle.active { color: #81c784; }
.wm-overflow-item.wm-claims-toggle.active { color: var(--wm-follow); }

.wm-overflow-toggle.has-active {
    background: rgba(129, 199, 132, 0.12);
    border-color: rgba(129, 199, 132, 0.3);
    color: #81c784;
}

/* ---------- Follow bar ---------- */

.wm-follow-bar {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: rgba(255, 193, 7, 0.15);
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 999px;
    color: var(--wm-follow);
    font-size: 12px;
    max-width: 300px;
    overflow: hidden;
}
.wm-follow-bar.hidden { display: none; }
.wm-follow-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}
.wm-follow-summary {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.wm-follow-status {
    color: rgba(255, 243, 205, 0.92);
    font-size: 10px;
    min-height: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wm-icon-btn {
    background: rgba(255, 255, 255, 0.06);
    color: var(--wm-text);
    border: 1px solid var(--wm-border);
    border-radius: 6px;
    width: 32px; height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    transition: background 0.15s, border-color 0.15s;
}
.wm-icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.wm-icon-btn:active { background: rgba(255, 255, 255, 0.18); }

.wm-follow-bar .wm-icon-btn {
    width: 22px; height: 22px;
    font-size: 11px;
    background: transparent;
    border-color: rgba(255, 193, 7, 0.4);
    color: var(--wm-follow);
}

/* ---------- Map ---------- */

#map {
    position: fixed;
    top: calc(var(--wm-topbar-h) + env(safe-area-inset-top));
    left: 0; right: 0; bottom: 0;
    background: #0a0b12;
    z-index: 1;
}

.leaflet-container { background: #0a0b12; font-family: inherit; }
.leaflet-control-zoom { border: 1px solid var(--wm-border) !important; }
.leaflet-control-zoom a {
    background: var(--wm-surface-solid) !important;
    color: var(--wm-text) !important;
    border-bottom-color: var(--wm-border) !important;
}
.leaflet-control-zoom a:hover { background: #1a1d32 !important; }

.leaflet-tile {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
}

/* ---------- Drawer (floating panel) ---------- */

/* The drawer floats over the map at the top-right. Its height auto-sizes to the
 * player list content up to a viewport-relative cap, so an empty server shows a
 * small pill and a busy server scrolls. Always toggleable — hidden on mobile by
 * default, open on desktop by default (decided in map.js). */
.wm-drawer {
    position: fixed;
    top: calc(var(--wm-topbar-h) + env(safe-area-inset-top) + 10px);
    right: 10px;
    width: var(--wm-drawer-w);
    max-height: calc(100vh - var(--wm-topbar-h) - env(safe-area-inset-top) - 24px);
    background: rgba(16, 18, 32, 0.85);
    backdrop-filter: blur(10px) saturate(140%);
    -webkit-backdrop-filter: blur(10px) saturate(140%);
    border: 1px solid var(--wm-border);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    transform: translateX(calc(100% + 16px));
    opacity: 0;
    pointer-events: none;
    transition: transform 0.22s ease, opacity 0.18s ease;
    overflow: hidden;
}
.wm-drawer.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.wm-drawer-header {
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--wm-text-dim);
    border-bottom: 1px solid var(--wm-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
}
.wm-drawer-close-btn {
    width: 24px;
    height: 24px;
    font-size: 11px;
    background: transparent;
    border-color: transparent;
    color: var(--wm-text-dim);
}
.wm-drawer-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--wm-text);
}

.wm-follow-section {
    border-bottom: 1px solid var(--wm-border);
    padding: 10px 0 8px;
    flex-shrink: 0;
}
.wm-follow-section.hidden { display: none; }

.wm-follow-section-head {
    padding: 0 14px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--wm-text-dim);
}

.wm-follow-section-hint {
    letter-spacing: normal;
    text-transform: none;
    font-size: 11px;
    font-weight: 500;
    color: var(--wm-follow);
}

.wm-following-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wm-follow-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    cursor: pointer;
    border-left: 3px solid var(--wm-follow);
    background: rgba(255, 193, 7, 0.07);
}
.wm-follow-entry:hover { background: rgba(255, 193, 7, 0.11); }
.wm-follow-entry.hidden-player {
    border-left-color: rgba(255, 193, 7, 0.35);
    background: rgba(255, 255, 255, 0.03);
}

.wm-follow-rank {
    width: 20px;
    height: 20px;
    border-radius: 999px;
    background: rgba(255, 193, 7, 0.18);
    border: 1px solid rgba(255, 193, 7, 0.35);
    color: var(--wm-follow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
}

.wm-follow-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.wm-follow-control-btn {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 1px solid var(--wm-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--wm-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    padding: 0;
}
.wm-follow-control-btn:hover { background: rgba(255, 255, 255, 0.08); }
.wm-follow-control-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.wm-player-list {
    list-style: none;
    margin: 0;
    padding: 6px 0;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}
.wm-player-list::-webkit-scrollbar { width: 6px; }
.wm-player-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 3px; }

.wm-player-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.12s;
    border-left: 3px solid transparent;
}
.wm-player-entry:hover { background: rgba(255, 255, 255, 0.04); }
.wm-player-entry.following {
    background: rgba(255, 193, 7, 0.08);
    border-left-color: var(--wm-follow);
}

.wm-entry-avatar {
    width: 32px; height: 32px;
    border-radius: 6px;
    background-size: cover;
    background-position: center;
    background-color: #2a2f4a;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}
.wm-entry-avatar svg {
    width: 20px; height: 20px;
    opacity: 0.9;
}

.wm-entry-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.wm-entry-name {
    font-weight: 500;
    color: var(--wm-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.wm-entry-coords {
    font-size: 11px;
    color: var(--wm-text-dim);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.wm-entry-follow-btn {
    background: transparent;
    border: 1px solid var(--wm-border);
    color: var(--wm-text-dim);
    width: 26px; height: 26px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.wm-entry-follow-btn:hover {
    border-color: var(--wm-follow);
    color: var(--wm-follow);
}
.wm-entry-follow-btn.active {
    background: var(--wm-follow);
    border-color: var(--wm-follow);
    color: #000;
}
.wm-entry-follow-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.wm-scrim {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
    z-index: 1050;
}
.wm-scrim.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ---------- Player marker on the map ---------- */

.wm-marker {
    position: relative;
    width: 32px;
    height: 32px;
    --angle: 0deg;
}

.wm-marker-arrow {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: 44px;
    margin-left: -22px;
    margin-top: -22px;
    transform: rotate(var(--angle));
    pointer-events: none;
    transition: transform 0.2s ease;
}
.wm-marker-arrow::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 0;
    margin-left: -6px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 9px solid #fff;
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8));
}

.wm-marker.no-arrow .wm-marker-arrow { display: none; }

.wm-marker-head {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 28px;
    height: 28px;
    margin-left: -14px;
    margin-top: -14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.85);
    background-size: cover;
    background-position: center;
    background-color: #2a2f4a;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.wm-marker-head svg {
    width: 18px; height: 18px;
    fill: #fff;
    opacity: 0.95;
}

.wm-marker.following .wm-marker-head {
    border-color: var(--wm-follow);
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.7);
}

.wm-marker-tooltip.leaflet-tooltip {
    background: var(--wm-surface-solid);
    color: var(--wm-text);
    border: 1px solid var(--wm-border);
    font-size: 11px;
    padding: 3px 7px;
    border-radius: 4px;
    box-shadow: none;
}
.wm-marker-tooltip.leaflet-tooltip::before { border-top-color: var(--wm-surface-solid); }

/* Player popup */
.wm-popup .leaflet-popup-content-wrapper {
    background: var(--wm-surface-solid);
    color: var(--wm-text);
    border: 1px solid var(--wm-border);
    border-radius: 8px;
}
.wm-popup .leaflet-popup-tip { background: var(--wm-surface-solid); }
.wm-popup .leaflet-popup-content { margin: 10px 12px; font-size: 12px; }

.wm-popup-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.wm-popup-name { font-weight: 600; }
.wm-popup-coords { color: var(--wm-text-dim); font-family: ui-monospace, monospace; font-size: 11px; margin-bottom: 8px; }
.wm-popup-actions { display: flex; gap: 6px; }
.wm-popup-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--wm-border);
    color: var(--wm-text);
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}
.wm-popup-btn:hover { background: rgba(255, 255, 255, 0.15); }
.wm-popup-btn-follow.active { background: var(--wm-follow); color: #000; border-color: var(--wm-follow); }

/* ---------- Map markers overlay ---------- */

.wm-markers-toggle.hidden { display: none; }
.wm-markers-toggle.active {
    background: rgba(129, 199, 132, 0.18);
    border-color: rgba(129, 199, 132, 0.5);
    color: #81c784;
}

.wm-poi-marker {
    position: relative;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
}

.wm-poi-tooltip.leaflet-tooltip {
    background: var(--wm-surface-solid);
    color: var(--wm-text);
    border: 1px solid var(--wm-border);
    font-size: 11px;
    padding: 3px 7px;
    border-radius: 4px;
    box-shadow: none;
}
.wm-poi-tooltip.leaflet-tooltip::before { border-top-color: var(--wm-surface-solid); }

.wm-poi-popup .leaflet-popup-content-wrapper {
    background: var(--wm-surface-solid);
    color: var(--wm-text);
    border: 1px solid var(--wm-border);
    border-radius: 8px;
}
.wm-poi-popup .leaflet-popup-tip { background: var(--wm-surface-solid); }
.wm-poi-popup .leaflet-popup-content { margin: 10px 12px; font-size: 12px; }
.wm-poi-popup-name { font-weight: 600; margin-bottom: 4px; }
.wm-poi-popup-coords {
    color: var(--wm-text-dim);
    font-family: ui-monospace, monospace;
    font-size: 11px;
    margin-bottom: 4px;
}
.wm-poi-popup-type {
    color: var(--wm-text-dim);
    font-size: 11px;
}

/* ---------- Shop detail panel ---------- */

.wm-shop-panel {
    position: fixed;
    top: calc(var(--wm-topbar-h) + 10px);
    right: 10px;
    width: 320px;
    max-height: calc(100vh - var(--wm-topbar-h) - 20px);
    background: var(--wm-surface);
    backdrop-filter: blur(10px) saturate(140%);
    border: 1px solid var(--wm-border);
    border-radius: 10px;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    transform: translateX(calc(100% + 16px));
    opacity: 0;
    transition: transform 0.22s ease, opacity 0.18s ease;
    pointer-events: none;
}
.wm-shop-panel.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}
.wm-shop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--wm-border);
    flex-shrink: 0;
    font-weight: 600;
    font-size: 14px;
}
.wm-shop-close-btn { flex-shrink: 0; }
.wm-shop-content {
    overflow-y: auto;
    padding: 8px 12px;
    flex: 1;
}
.wm-shop-owner {
    color: var(--wm-text-dim);
    font-size: 11px;
    margin-bottom: 8px;
}
.wm-shop-closed {
    color: var(--wm-danger);
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 8px;
}
.wm-shop-empty {
    color: var(--wm-text-dim);
    font-size: 12px;
    text-align: center;
    padding: 16px 0;
}
.wm-shop-trade {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--wm-border);
}
.wm-shop-trade:last-child { border-bottom: none; }
.wm-shop-trade-items {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}
.wm-shop-trade-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--wm-text-dim);
    letter-spacing: 0.5px;
}
.wm-shop-gives .wm-shop-trade-label { color: #66bb6a; }
.wm-shop-wants .wm-shop-trade-label { color: #ef5350; }
.wm-shop-trade-arrow {
    margin: 0 10px;
    color: var(--wm-text-dim);
    font-size: 16px;
    flex-shrink: 0;
}
.wm-shop-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
}
.wm-shop-item-qty {
    font-weight: 600;
    color: var(--wm-accent);
    min-width: 28px;
}

@media (max-width: 899px) {
    .wm-shop-panel {
        left: 8px;
        right: 8px;
        width: auto;
    }
}

/* ---------- Claims overlay ---------- */

/* Toggle button gets an amber accent when the layer is visible so the state is
 * obvious at a glance. Hidden entirely when the server has simpleClaimsEnabled=false. */
.wm-claims-toggle.hidden { display: none; }
.wm-claims-toggle.active {
    background: rgba(255, 193, 7, 0.18);
    border-color: rgba(255, 193, 7, 0.5);
    color: var(--wm-follow);
}

/* Claim popup layout — same dark card as the player popup, with a header row
 * showing the party colour swatch + name, followed by owner/members and a
 * compact grid of protection flags. */
.wm-claim-popup .wm-popup-swatch {
    width: 14px; height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
}
.wm-claim-popup .wm-popup-owner {
    color: var(--wm-text-dim);
    font-size: 11px;
    margin-bottom: 4px;
}
.wm-claim-popup .wm-claim-flags {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 10px;
    font-size: 10px;
    color: var(--wm-text-dim);
}
.wm-claim-popup .wm-claim-flags .on  { color: #81c784; }
.wm-claim-popup .wm-claim-flags .off { color: var(--wm-text-dim); }

/* ---------- Chat panel (bottom-left) ---------- */

.wm-chat {
    position: fixed;
    bottom: 12px;
    left: 12px;
    width: 300px;
    max-height: 220px;
    background: rgba(16, 18, 32, 0.82);
    backdrop-filter: blur(10px) saturate(140%);
    -webkit-backdrop-filter: blur(10px) saturate(140%);
    border: 1px solid var(--wm-border);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(calc(100% + 16px));
    opacity: 0;
    pointer-events: none;
    transition: transform 0.22s ease, opacity 0.18s ease;
}
.wm-chat.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.wm-chat-header {
    padding: 7px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--wm-text-dim);
    border-bottom: 1px solid var(--wm-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.wm-chat-close-btn {
    width: 22px; height: 22px;
    font-size: 10px;
    background: transparent;
    border-color: transparent;
    color: var(--wm-text-dim);
}
.wm-chat-close-btn:hover { background: rgba(255,255,255,0.08); color: var(--wm-text); }

.wm-chat-messages {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.wm-chat-messages::-webkit-scrollbar { width: 4px; }
.wm-chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.wm-chat-msg {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-size: 12px;
    line-height: 1.45;
    min-width: 0;
}
.wm-chat-time {
    color: var(--wm-text-dim);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 10px;
    flex-shrink: 0;
    opacity: 0.6;
}
.wm-chat-name {
    font-weight: 600;
    flex-shrink: 0;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.wm-chat-sep {
    color: var(--wm-text-dim);
    flex-shrink: 0;
    margin-right: 1px;
}
.wm-chat-text {
    color: var(--wm-text);
    flex: 1;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.wm-chat-toggle.active {
    background: rgba(79, 195, 247, 0.15);
    border-color: rgba(79, 195, 247, 0.4);
    color: var(--wm-accent);
}

.wm-wakelock-toggle.active {
    background: rgba(102, 187, 106, 0.15);
    border-color: rgba(102, 187, 106, 0.4);
    color: #66bb6a;
}
/* When wake lock is off, dim the icon to signal inactivity */
.wm-wakelock-toggle:not(.active) {
    opacity: 0.45;
}
/* Hide when the API is not supported (set via JS) */
.wm-wakelock-toggle.hidden { display: none; }

/* ---------- Chat speech bubble on player markers ---------- */

.wm-chat-bubble {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    /* Explicit width required — the parent .wm-marker is only 32px wide.
       Without it, a position:absolute element shrinks to the parent width
       and wraps one character per line. */
    width: 160px;
    background: rgba(13, 15, 26, 0.93);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    padding: 4px 9px;
    font-size: 11px;
    line-height: 1.4;
    color: var(--wm-text);
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    pointer-events: none;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10;
    animation: wm-bubble-in 0.15s ease;
    text-align: center;
}
.wm-chat-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(13, 15, 26, 0.93);
}
@keyframes wm-bubble-in {
    from { opacity: 0; transform: translateX(-50%) translateY(4px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- Responsive ---------- */

/* Scrim only dims the map on narrow viewports where the drawer takes over. */
@media (min-width: 900px) {
    .wm-scrim { display: none; }
}

@media (max-width: 480px) {
    .wm-topbar { gap: 8px; padding: 0 8px; padding-top: env(safe-area-inset-top); }
    .wm-topbar-left, .wm-topbar-right { gap: 6px; }
    .wm-select { max-width: 110px; font-size: 12px; padding: 5px 8px; }
    .wm-online-badge { padding: 3px 7px; font-size: 11px; }
    .wm-coords { display: none; }
    .wm-follow-bar { max-width: 170px; font-size: 11px; }
    .wm-follow-status { font-size: 9px; }
    /* On phones the drawer fills most of the width so long names stay readable. */
    .wm-drawer {
        top: calc(var(--wm-topbar-h) + env(safe-area-inset-top) + 8px);
        right: 8px;
        left: 8px;
        width: auto;
        max-height: calc(100vh - var(--wm-topbar-h) - env(safe-area-inset-top) - 16px);
    }
    .wm-chat {
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        max-height: 180px;
    }
}
