:root {
    color-scheme: dark;
    --bg: #0a0a0a;
    --bg-soft: rgba(18, 18, 18, 0.92);
    --panel: #161616;
    --panel-strong: #121212;
    --ink: #f2ede6;
    --ink-soft: #cfc6bc;
    --muted: #8f8880;
    --line: rgba(242, 237, 230, 0.1);
    --line-strong: rgba(242, 237, 230, 0.18);
    --radius-lg: 14px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --accent: #3b82f6;            /* подменяется по фракции */
    --accent-soft: rgba(59, 130, 246, 0.16);
    --blue: #3b82f6;
    --green: #22c55e;
    --font-sans: "Inter", "Segoe UI", "Helvetica Neue", sans-serif;
    --font-mono: "IBM Plex Mono", "SFMono-Regular", "Consolas", monospace;
}

body[data-faction="blue"]  { --accent: var(--blue);  --accent-soft: rgba(59, 130, 246, 0.16); }
body[data-faction="green"] { --accent: var(--green); --accent-soft: rgba(34, 197, 94, 0.16); }

[x-cloak] { display: none !important; }

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    -webkit-tap-highlight-color: transparent;
}

#map {
    position: absolute;
    inset: 0;
}

.mono { font-family: var(--font-mono); }

/* ---- кнопки ---- */
.btn {
    display: inline-block;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel);
    color: var(--ink);
    font: inherit;
    padding: 12px 18px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
    background: var(--accent);
    border-color: transparent;
    color: #06121f;
    font-weight: 600;
}
.btn.primary:hover { box-shadow: 0 0 0 4px var(--accent-soft); }
.btn.ghost { background: transparent; padding: 8px 12px; font-size: 13px; color: var(--ink-soft); }
.btn.round {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    background: var(--bg-soft);
    backdrop-filter: blur(8px);
}

/* ---- гейт (вход / фракция) ---- */
.gate {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 40%),
        radial-gradient(circle at 85% 90%, rgba(255, 255, 255, 0.04), transparent 35%),
        var(--bg);
    z-index: 30;
}
.gate-card {
    width: min(340px, 88vw);
    padding: 36px 28px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    text-align: center;
    backdrop-filter: blur(12px);
}
.logo {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--ink);
}
.logo::after { content: "_"; color: var(--accent); }
.gate-sub { color: var(--muted); margin: 10px 0 26px; }
.faction-choices { display: flex; gap: 12px; }
.btn.faction { flex: 1; font-weight: 700; font-size: 16px; }
.btn.faction.blue  { color: var(--blue);  border-color: var(--blue); }
.btn.faction.green { color: var(--green); border-color: var(--green); }
.btn.faction:hover { background: var(--panel-strong); box-shadow: 0 0 18px -6px currentColor; }

/* ---- верхняя панель ---- */
.topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
    z-index: 20;
    pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.player-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    backdrop-filter: blur(8px);
}
.avatar { width: 26px; height: 26px; border-radius: 50%; }
.player-name { font-size: 14px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge.blue  { color: var(--blue);  background: rgba(59, 130, 246, 0.14); }
.badge.green { color: var(--green); background: rgba(34, 197, 94, 0.14); }
.badge.neutral, .badge[class="badge"] { color: var(--muted); background: rgba(140, 140, 140, 0.14); }

/* ---- кнопки карты ---- */
.map-buttons {
    position: absolute;
    right: 12px;
    bottom: calc(env(safe-area-inset-bottom) + 18px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 20;
}

/* ---- карточка портала ---- */
.portal-card {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    max-width: 420px;
    margin: 0 auto;
    background: var(--bg-soft);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    z-index: 25;
    backdrop-filter: blur(12px);
}
.portal-photo {
    display: block;
    width: 100%;
    height: 170px;
    object-fit: cover;
}
.portal-card .close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: var(--ink);
    font-size: 18px;
    cursor: pointer;
}
.portal-body { padding: 14px 16px 16px; }
.portal-body h2 { margin: 0 0 8px; font-size: 17px; line-height: 1.3; }
.portal-meta { margin: 0 0 6px; color: var(--ink-soft); font-size: 14px; }
.portal-coords { margin: 0; color: var(--muted); font-size: 12px; }

/* ---- гео-заметка ---- */
.geo-note {
    position: absolute;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom) + 90px);
    transform: translateX(-50%);
    padding: 10px 16px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--ink-soft);
    z-index: 22;
    max-width: 86vw;
    text-align: center;
}

/* ---- энергия и слоты портала ---- */
.portal-energy { margin: 4px 0 10px; }
.bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
}
.bar.big { height: 12px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.bar-fill.blue { background: var(--blue); }
.bar-fill.green { background: var(--green); }
.bar-fill.neutral { background: #8a8a8a; }
.energy-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 12px;
    color: var(--ink-soft);
}
.slots { display: flex; gap: 4px; }
.slot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid var(--line-strong);
    background: transparent;
}
.slot.filled.neutral { background: #9a9a9a; border-color: #9a9a9a; }
.slot.filled.blue { background: var(--blue); border-color: var(--blue); }
.slot.filled.green { background: var(--green); border-color: var(--green); }
.dist { color: var(--muted); }

/* ---- действия в карточке ---- */
.portal-actions { display: flex; gap: 8px; margin: 8px 0; }
.btn.act {
    flex: 1;
    padding: 10px 12px;
    font-size: 14px;
    background: var(--panel-strong);
    border-color: var(--line-strong);
}
.btn.act:hover:not(:disabled) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.act:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.act.danger:hover:not(:disabled) { border-color: var(--danger, #f87171); }
.lvl-select {
    padding: 10px;
    background: var(--panel-strong);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    font: inherit;
}

/* ---- инвентарь ---- */
.inv-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 40;
    display: grid;
    place-items: end center;
}
.inv-panel {
    width: 100%;
    max-width: 480px;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--bg-soft);
    border: 1px solid var(--line-strong);
    border-bottom: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 16px 18px calc(env(safe-area-inset-bottom) + 18px);
    backdrop-filter: blur(12px);
}
.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.inv-progress { margin-bottom: 14px; }
.inv-energy {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 14px;
}
.inv-items { list-style: none; margin: 0; padding: 0; }
.inv-items li {
    display: flex;
    justify-content: space-between;
    padding: 8px 4px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}
.muted { color: var(--muted); }

/* ---- тосты ---- */
.toasts {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 58px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 50;
    pointer-events: none;
}
.toast {
    padding: 10px 16px;
    background: var(--bg-soft);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--ink);
    white-space: nowrap;
    backdrop-filter: blur(8px);
    animation: toast-in 0.2s ease-out;
}
.toast.good { border-color: var(--accent); }
.toast.bad { border-color: var(--danger, #f87171); color: #f87171; }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- кнопка атаки ---- */
.fire-wrap {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
}
.btn.fire {
    padding: 14px 26px;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: 0.06em;
    color: #fff;
    background: linear-gradient(180deg, #ff6a3d, #d92c12);
    border: 1px solid rgba(255, 128, 90, 0.6);
    border-radius: 999px;
    box-shadow: 0 0 24px -4px rgba(255, 90, 40, 0.8);
}
.btn.fire:disabled { opacity: 0.35; box-shadow: none; }
.btn.fire:active:not(:disabled) { transform: translateY(1px) scale(0.98); }

/* ---- счёт фракций ---- */
.topbar .left { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.score-chip {
    display: inline-flex;
    gap: 10px;
    padding: 3px 10px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
    backdrop-filter: blur(8px);
}
.score-chip .blue { color: var(--blue); }
.score-chip .green { color: var(--green); }
.linkmode-hint {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--accent);
}
.inv-sub { margin: 16px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.inv-top { list-style: none; margin: 0; padding: 0; }
.inv-top li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}
.inv-top li .mono { margin-left: auto; color: var(--muted); font-size: 12px; }

/* ---- профиль (фуллскрин) ---- */
.profile {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 15% 8%, var(--accent-soft), transparent 40%),
        var(--bg);
    z-index: 45;
    overflow-y: auto;
    padding: calc(env(safe-area-inset-top) + 12px) 16px 24px;
}
.profile-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    align-items: center;
}
.profile-tabs button {
    flex: 1;
    padding: 9px 6px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    color: var(--ink-soft);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.profile-tabs button.on { border-color: var(--accent); color: var(--accent); }
.profile-tabs .close-tab { flex: 0 0 44px; font-size: 18px; }
.profile-head { display: flex; gap: 14px; margin-bottom: 18px; align-items: center; }
.avatar.big { width: 64px; height: 64px; border-radius: var(--radius-lg); border: 1px solid var(--line-strong); }
.profile-nick { font-size: 22px; font-weight: 700; }
.profile-lvl { margin-top: 4px; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.nick-input {
    width: 100%;
    margin-bottom: 14px;
    padding: 12px 14px;
    background: var(--panel-strong);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    color: var(--ink);
    font: inherit;
    text-align: center;
}
.nick-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.bad-text { color: #f87171; }
.score-big { display: flex; justify-content: space-around; font-size: 18px; margin-bottom: 10px; }
.score-big .blue { color: var(--blue); }
.score-big .green { color: var(--green); }
.admin-stats { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }

.settings { margin-top: 16px; }
.admin-grant { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.admin-grant .btn { padding: 6px 10px; font-size: 12px; }

.link-modal {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(0,0,0,.55);
    display: flex; align-items: flex-end; justify-content: center;
}
.link-modal-box {
    width: 100%; max-width: 420px; max-height: 70vh;
    background: var(--panel); border-radius: 16px 16px 0 0;
    padding: 16px; overflow-y: auto;
}
.link-modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.link-hint { font-size: 12px; color: var(--muted); margin: 4px 0 10px; }
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: 10px 8px; border-bottom: 1px solid var(--line);
    cursor: pointer;
}
.link-list li:active { background: var(--line); }
.link-list .lt { font-size: 12px; color: var(--muted); white-space: nowrap; }
