/* Карта мира Koban — своё поверх общей темы /v/theme.css.
 *
 * Раскладка: карта на весь экран, поверх неё стеклянные панели.
 *  - topbar: слева «назад» и заголовок, справа кнопки панелей;
 *  - sheet: слои и фильтры — боковая панель слева, на телефоне — шторка снизу;
 *  - dock: игроки (справа сверху) и чат (справа снизу), на телефоне — шторки;
 *  - zoombar: масштаб в правом нижнем углу;
 *  - poiCard: карточка объекта внизу по центру.
 */

html, body {
    margin: 0;
    padding: 0;
    background: #000;
    overflow: hidden;
    height: 100%;
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text-main);
    touch-action: none;
}

body {
    background-image: url('tile.webp');
    background-repeat: repeat;
}

/* Сцена перелистывается целиком, вместе с панелями. */
.stage {
    position: fixed;
    inset: 0;
}

canvas {
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    width: 100%;
    height: 100%;
    clip-path: circle(42.725% at center);
}

.map {
    position: fixed;
    /* Кнопки масштаба и двойной тап меняют размер плавно; колесо — мгновенно
       (класс zooming снимает переход). */
}

.map.zoom-anim {
    transition: width 260ms var(--ease-out), height 260ms var(--ease-out),
                left 260ms var(--ease-out), top 260ms var(--ease-out);
}

body .map.zooming {
    transition: none;
}

.mapBorder {
    width: 100%;
    height: 100%;
    pointer-events: none;
    position: absolute;
    top: 0;
    left: 0;
    overflow: visible;
}

.mapBorder__ring {
    fill: none;
    stroke: rgba(200, 164, 90, 0.55);
    stroke-width: 3;
    filter: drop-shadow(0 0 6px rgba(200, 164, 90, 0.35));
}

/* Второе кольцо — пунктир, медленно ползёт по кругу: компас живой. */
.mapBorder__dash {
    fill: none;
    stroke: rgba(200, 164, 90, 0.28);
    stroke-width: 5;
    stroke-dasharray: 14 22;
    transform-box: fill-box;
    transform-origin: center;
    animation: ringSpin 240s linear infinite;
}

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

.vignette {
    position: fixed;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 52%, rgba(0, 0, 0, 0.55) 100%);
}

/* ---------- загрузка ---------- */

.loading {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: rgba(4, 10, 9, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 480ms var(--ease);
}

.loading.is-done { opacity: 0; pointer-events: none; }
.loading.is-error .loading__rune { animation: none; border-color: rgba(232, 104, 104, 0.6); }

.loading__rune {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid rgba(200, 164, 90, 0.25);
    border-top-color: var(--accent-hover);
    animation: runeSpin 1.1s linear infinite;
    box-shadow: 0 0 24px rgba(200, 164, 90, 0.18);
}

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

.loading__text {
    margin: 0;
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(200, 164, 90, 0.85);
}

/* ---------- верхняя панель ---------- */

.topbar {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: 12px;
    right: 12px;
    z-index: 30;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    pointer-events: none;
}

.topbar__group {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-radius: 999px;
}

.topbar__title {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: 0 14px 0 4px;
}

.topbar__kicker { font-size: 0.56rem; padding: 0.18rem 0.6rem 0.18rem 0.5rem; }

.topbar__h1 {
    font-size: 0.95rem;
    letter-spacing: 0.14em;
    line-height: 1.1;
}

.btn-icon--flat {
    background: none;
    border-color: transparent;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.btn-icon--flat:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.06);
    border-color: transparent;
    transform: none;
}

/* Кнопка панели: иконка, подпись и счётчик. */
.tbtn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 0 14px 0 12px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    border: 1px solid transparent;
}

.tbtn svg { width: 20px; height: 20px; flex: none; }

.tbtn:hover:not(:disabled) {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.06);
}

.tbtn[aria-pressed="true"] {
    color: var(--accent-hover);
    background: rgba(200, 164, 90, 0.14);
    border-color: rgba(200, 164, 90, 0.4);
}

.tbtn__badge { margin-left: 2px; }

.topMessage {
    position: fixed;
    top: calc(max(12px, env(safe-area-inset-top)) + 64px);
    left: 50%;
    transform: translate(-50%, 0);
    z-index: 35;
    max-width: 90vw;
    padding: 0.4rem 1rem;
    border-radius: 999px;
    background: rgba(8, 16, 15, 0.85);
    border: 1px solid var(--accent-line);
    color: var(--accent-hover);
    font-family: var(--font-display);
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 240ms var(--ease), transform 240ms var(--ease-out);
}

.topMessage.is-on { opacity: 1; transform: translate(-50%, 4px); }

/* ---------- затемнение под шторкой (телефон) ---------- */

.scrim {
    position: fixed;
    inset: 0;
    z-index: 38;
    background: rgba(2, 6, 5, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 260ms var(--ease);
}

.scrim.is-on { opacity: 1; pointer-events: auto; }

/* ---------- панель слоёв ---------- */

.sheet {
    position: fixed;
    z-index: 40;
    display: flex;
    flex-direction: column;
    top: calc(max(12px, env(safe-area-inset-top)) + 64px);
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    width: min(360px, calc(100vw - 24px));
    padding: 0;
    transform: translateX(calc(-100% - 24px));
    transition: transform 380ms var(--ease-out), opacity 300ms var(--ease);
    opacity: 0;
    touch-action: pan-y;
}

.sheet.is-open { transform: none; opacity: 1; }

.sheet__grip { display: none; }

.sheet__head,
.dock__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 8px 4px 18px;
}

.sheet__title,
.dock__title {
    margin: 0;
    padding: 0;
    border: none;
}

.sheet__search { padding: 6px 14px 10px; }

.sheet__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 8px 12px 10px;
    touch-action: pan-y;
}

/* Слой: заголовок с выключателем всего слоя, ниже — категории. */
.layer {
    border-top: 1px solid rgba(200, 164, 90, 0.1);
}

.layer:first-child { border-top: none; }

.layer__head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 6px;
}

.layer__toggle {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 50px;
    padding: 0 6px;
    text-align: left;
    font-family: var(--font-display);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-main);
    border-radius: var(--radius-xs);
}

.layer__toggle:hover:not(:disabled) { background: rgba(255, 255, 255, 0.04); }

.layer__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chev {
    flex: none;
    width: 18px;
    height: 18px;
    opacity: 0.55;
    transition: transform 260ms var(--ease-spring), opacity var(--t-fast);
}

.chev svg { width: 100%; height: 100%; display: block; }

.is-open > .layer__head .chev,
.cat.is-open > .cat__row .chev { transform: rotate(90deg); opacity: 0.9; }

/* Разворачивание через grid-rows: высота анимируется без замеров в JS. */
.layer__body,
.cat__subs {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 320ms var(--ease-out);
}

.layer__body > div,
.cat__subs > div {
    overflow: hidden;
    min-height: 0;
}

.layer.is-open > .layer__body,
.cat.is-open > .cat__subs { grid-template-rows: 1fr; }

.layer__body > div { padding: 0 0 6px 4px; }

.cat__row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 2px;
}

.cat__main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 46px;
    padding: 0 6px;
    text-align: left;
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-main);
    border-radius: var(--radius-xs);
    transition: background var(--t-fast), opacity var(--t-fast);
}

.cat__main:hover:not(:disabled) { background: rgba(255, 255, 255, 0.04); }

.cat.is-off .cat__main { opacity: 0.5; }

.cat__glyph {
    flex: none;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.cat__glyph svg { display: block; filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.6)); }

.cat__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cat__subs > div { padding-left: 44px; }

.sub {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 8px 0 6px;
    border-radius: var(--radius-xs);
    font-size: 0.86rem;
    color: rgba(226, 232, 226, 0.82);
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--t-fast);
}

.sub:hover { background: rgba(255, 255, 255, 0.04); }

.sub__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.k-check {
    appearance: none;
    -webkit-appearance: none;
    flex: none;
    width: 20px;
    height: 20px;
    margin: 0;
    display: grid;
    place-items: center;
    border: 1px solid var(--accent-line);
    border-radius: 6px;
    background: rgba(6, 15, 14, 0.7);
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.k-check::after {
    content: "";
    width: 5px;
    height: 10px;
    border: solid #ffe9ba;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translate(-1px, -1px) scale(0);
    transition: transform 180ms var(--ease-spring);
}

.k-check:checked {
    background: rgba(200, 164, 90, 0.35);
    border-color: rgba(200, 164, 90, 0.7);
    box-shadow: 0 0 10px rgba(200, 164, 90, 0.2);
}

.k-check:checked::after { transform: rotate(45deg) translate(-1px, -1px) scale(1); }

/* Поиск: что не подходит — прячем. */
.is-hidden { display: none !important; }

.sheet__nothing {
    margin: 14px 8px;
    color: var(--text-dim);
    font-style: italic;
    font-size: 0.86rem;
}

/* ---------- панели игроков и чата ---------- */

.dock {
    position: fixed;
    z-index: 36;
    display: flex;
    flex-direction: column;
    right: 12px;
    width: min(300px, calc(100vw - 24px));
    max-height: calc(50vh - 60px);
    padding: 0;
    opacity: 0;
    transform: translateX(calc(100% + 24px));
    transition: transform 380ms var(--ease-out), opacity 300ms var(--ease);
    touch-action: pan-y;
}

.dock.is-open { transform: none; opacity: 1; }

.dock--players { top: calc(max(12px, env(safe-area-inset-top)) + 64px); }

.dock--chat {
    bottom: max(12px, env(safe-area-inset-bottom));
    right: 68px;
    width: min(360px, calc(100vw - 92px));
}

.dock__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2px 10px 10px;
    touch-action: pan-y;
}

.dock__hint,
.dock__empty {
    margin: 0;
    padding: 4px 18px 14px;
    font-size: 0.78rem;
    color: var(--text-dim);
}

.dock__empty { font-style: italic; }
.dock__empty[hidden], .dock__hint[hidden] { display: none; }

.player {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 10px;
    margin: 0 0 4px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}

.player:hover { background: rgba(255, 255, 255, 0.04); }

.player.selected {
    background: rgba(200, 164, 90, 0.12);
    border-color: rgba(200, 164, 90, 0.45);
    box-shadow: 0 0 18px rgba(200, 164, 90, 0.12);
}

.player__top { display: flex; align-items: center; gap: 8px; }

.player__dot {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--online);
    box-shadow: 0 0 10px rgba(110, 231, 168, 0.5);
    animation: playerPulse 2.4s ease-in-out infinite;
}

@keyframes playerPulse {
    0%, 100% { opacity: 0.85; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.15); }
}

.player.is-dead .player__dot { background: var(--bad); box-shadow: 0 0 10px rgba(232, 104, 104, 0.5); animation: none; }
.player.is-hidden-pos .player__dot { background: var(--text-muted); box-shadow: none; animation: none; }

.player__name {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player__flags { display: flex; gap: 4px; font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); }

.player__flag {
    padding: 2px 6px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.player__flag--pvp { color: var(--bad); border-color: rgba(232, 104, 104, 0.35); }
.player__flag--follow { color: var(--accent-hover); border-color: rgba(200, 164, 90, 0.45); }

.player__details[hidden] { display: none; }

.hpBar {
    position: relative;
    height: 10px;
    width: 100%;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 85, 85, 0.35);
    overflow: hidden;
}

.hp {
    width: 100%;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #c0392b, #ff6b5a);
    transition: width 0.5s linear;
}

.hpText {
    position: absolute;
    font-family: var(--font-mono);
    font-size: 8px;
    line-height: 8px;
    top: 0;
    left: 50%;
    transform: translate(-50%, 0);
    white-space: nowrap;
    color: #fff;
    text-shadow: 0 0 3px #000;
}

/* Чат. */
.chat { font-size: 0.82rem; }

.msg {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 8px;
    padding: 6px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.msg:last-child { border-bottom: none; }

.msg__time {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    color: var(--text-dim);
    padding-top: 2px;
}

.msg__body { min-width: 0; overflow-wrap: anywhere; }

.msg__name { color: var(--accent); font-weight: 600; }
.msg__name::after { content: ": "; color: var(--text-dim); font-weight: 400; }
.msg.server .msg__name { color: #62c8ff; }
.msg.type2 .msg__text { color: gold; text-transform: uppercase; }
.msg p { display: contents; }

/* ---------- масштаб и координаты ---------- */

.zoombar {
    position: fixed;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 34;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.coords {
    position: fixed;
    left: 50%;
    bottom: max(10px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 20;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(8, 16, 15, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-family: var(--font-mono);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
    white-space: nowrap;
    user-select: none;
    pointer-events: none;
}

.coords:empty { display: none; }

/* ---------- значки на карте ---------- */

.mapText {
    color: #fff;
    font-size: 12px;
    white-space: nowrap;
    text-shadow: 0 0 6px #000, 0 0 6px #000, 0 0 3px #000;
    user-select: none;
    pointer-events: none;
}

.mapIcon {
    position: absolute;
    width: 32px;
    height: 32px;
    background-image: url('mapIcons.png');
    background-size: 192px;
    transform: translate(-50%, -50%);
}

.mapIcon .center {
    position: absolute;
    left: 50%;
    transform: translate(-50%, 0);
}

.mapIcon .text { bottom: -11px; }

.mapIcon.player {
    background-position: 0 0;
    filter: hue-rotate(240deg);
}

/* Кольцо вокруг игрока: его видно даже на далёком масштабе. */
.mapIcon.player::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border-radius: 50%;
    border: 2px solid rgba(110, 231, 168, 0.55);
    animation: playerRing 2.2s ease-out infinite;
    pointer-events: none;
}

@keyframes playerRing {
    0% { transform: scale(0.5); opacity: 0.9; }
    100% { transform: scale(1.5); opacity: 0; }
}

.mapIcon.fire { background-position: -32px 0; }
.mapIcon.dot { background-position: -64px 0; }
.mapIcon.mine { background-position: -96px 0; }
.mapIcon.house { background-position: -128px 0; }
.mapIcon.cave { background-position: 0 -32px; }
.mapIcon.boss { background-position: -32px -32px; }
.mapIcon.start { background-position: -64px -32px; }

.mapIcon.ping {
    background-position: -96px -32px;
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    from { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.5); }
    to { transform: translate(-50%, -50%) scale(1); }
}

.mapIcon.dead { background-position: -128px -32px; }
.mapIcon.pvp { filter: hue-rotate(0deg) !important; }

/* ---------- телефон: шторки снизу ---------- */

@media (max-width: 720px) {
    .topbar { left: 8px; right: 8px; gap: 6px; }
    .topbar__group { padding: 4px; gap: 2px; }
    .topbar__title { padding: 0 10px 0 2px; }
    .topbar__h1 { font-size: 0.82rem; letter-spacing: 0.1em; }
    .topbar__kicker { padding: 0.18rem; gap: 0; }
    .topbar__kicker-text { display: none; }
    .tbtn { padding: 0 8px; min-width: var(--tap); justify-content: center; }
    .tbtn__label { display: none; }
    .tbtn__badge { margin-left: 0; }

    .sheet,
    .dock {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: none;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-bottom: none;
        transform: translateY(105%);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sheet { height: min(74vh, 640px); }
    .dock { height: min(52vh, 480px); }
    .dock--chat { width: 100%; right: 0; }

    .sheet.is-open,
    .dock.is-open { transform: none; }

    /* Пока тянут за ручку, шторка следует за пальцем без перехода. */
    .sheet.is-dragging,
    .dock.is-dragging { transition: none; }

    .sheet__grip {
        display: flex;
        justify-content: center;
        padding: 10px 0 2px;
        touch-action: none;
        cursor: grab;
    }

    .sheet__grip span {
        width: 44px;
        height: 5px;
        border-radius: 999px;
        background: rgba(226, 232, 226, 0.25);
    }

    .sheet__head, .dock__head { padding-top: 4px; }

    .zoombar { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 4px); }
    .coords { display: none; }
    .topMessage { top: calc(max(12px, env(safe-area-inset-top)) + 60px); }
}

/* На пальце значки мелкие — расширяем область нажатия. */
@media (hover: none) and (pointer: coarse) {
    .mapIcon.poi::after {
        content: "";
        position: absolute;
        left: 50%;
        top: 50%;
        width: 36px;
        height: 36px;
        margin: -18px 0 0 -18px;
        border-radius: 50%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mapBorder__dash, .player__dot, .mapIcon.player::before, .loading__rune { animation: none; }
    .sheet, .dock, .scrim, .layer__body, .cat__subs, .map.zoom-anim { transition: none; }
}
