:root {
    color-scheme: dark;
    --bg: #10141c;
    --panel: #171d28;
    --panel-2: #1e2735;
    --line: #2a3547;
    --text: #e8edf6;
    --muted: #8b98ad;
    --accent: #58a6ff;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

.app-shell {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100vh;
}

/* --------------------------------------------------------------- landing */

.landing {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 48px 24px;
    background:
        radial-gradient(1100px 640px at 78% -8%, #1b2740 0%, transparent 60%),
        radial-gradient(900px 520px at 8% 110%, #16202e 0%, transparent 55%),
        var(--bg);
}

.landing-inner {
    width: 100%;
    max-width: 960px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.landing-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.landing-header h1 {
    margin: 0;
    font-size: 1.7rem;
    letter-spacing: 0.01em;
}

.icon-button {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    width: 38px;
    height: 38px;
    padding: 0;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    flex: none;
}

.icon-button:hover { filter: brightness(1.15); }

.landing-sub {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.server-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    color: var(--text);
    font: inherit;
    transition: border-color 0.12s ease, transform 0.12s ease;
}

.server-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    filter: none;
}

.card-thumb {
    position: relative;
    aspect-ratio: 16 / 9;
    background:
        linear-gradient(135deg, #1c2740 0%, #10141c 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: pixelated;
}

/* Placeholder glyph shown when a game has no basemap image. */
.card-thumb .thumb-glyph {
    font-size: 2.2rem;
    font-weight: 700;
    color: rgba(232, 237, 246, 0.18);
    letter-spacing: 0.04em;
}

.card-thumb .card-status {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.66rem;
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    border: 1px solid var(--line);
    color: var(--muted);
}

.card-status .pip { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.card-status[data-state="live"] .pip { background: var(--good); }
.card-status[data-state="error"] .pip { background: var(--bad); }

.card-body {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.card-game {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
}

.card-server {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 0.72rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.landing-footer { min-height: 1rem; }
#landing-error { font-size: 0.75rem; color: var(--bad); overflow-wrap: anywhere; }

.landing .auth-panel { max-width: 340px; }

/* ------------------------------------------------------------- game heading */

.back-button { padding: 5px 10px; }

.game-heading {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.game-kicker {
    font-size: 0.64rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
}

.game-kicker:empty { display: none; }

.game-heading strong { font-size: 1.05rem; }

/* ---------------------------------------------------------------- sidebar */

.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sidebar-header h1 {
    font-size: 1.15rem;
    margin: 0;
    letter-spacing: 0.02em;
}

.connection {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--muted);
    white-space: nowrap;
}

.connection .pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warn);
}

.connection[data-state="live"] .pulse { background: var(--good); }
.connection[data-state="error"] .pulse { background: var(--bad); }
.connection[data-state="connecting"] .pulse {
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    50% { opacity: 0.3; }
}

/* ---------------------------------------------------------------- switcher */

.switcher {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.switcher select {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    padding: 7px 8px;
    font-size: 0.82rem;
    width: 100%;
    min-width: 0;
    text-transform: none;
    letter-spacing: normal;
}

/* ----------------------------------------------------------------- metrics */

.metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.metrics:empty { display: none; }

.metrics div {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.metrics span {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.metrics strong { font-size: 0.95rem; font-variant-numeric: tabular-nums; }

.version-line {
    margin: 0;
    font-size: 0.72rem;
    color: var(--muted);
}

.map-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    background: var(--accent);
    color: #0b1017;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 0.8rem;
}

button.secondary {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
}

button:hover { filter: brightness(1.12); }

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--muted);
    cursor: pointer;
}

.coord-goto {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto;
    gap: 6px;
    align-items: end;
}

.coord-goto label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.coord-goto input {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 8px;
    font-size: 0.8rem;
    width: 100%;
    min-width: 0;
}

.coord-goto button { padding: 6px 10px; }

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.section-heading h2 {
    margin: 0;
    font-size: 0.9rem;
}

#snapshot-age {
    font-size: 0.7rem;
    color: var(--muted);
}

.team-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 0.72rem;
    color: var(--muted);
}

.team-filter select {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    padding: 5px 8px;
    font-size: 0.78rem;
}

.roster-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.entity-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    text-align: left;
    width: 100%;
    color: var(--text);
    font: inherit;
}

.entity-card.selected { border-color: var(--accent); }
.entity-card.offline { opacity: 0.55; }
.entity-card.dimmed { opacity: 0.35; }

.entity-card .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: none;
}

/* Avatar holds the colored dot; a composited player portrait replaces it once
   built (Necesse). */
.entity-card .avatar {
    position: relative;
    width: 30px;
    height: 30px;
    flex: none;
    display: grid;
    place-items: center;
}
.entity-card .avatar .portrait {
    position: absolute;
    inset: 0;
    width: 30px;
    height: 30px;
    image-rendering: pixelated;
    display: none;
}
.entity-card .avatar.has-portrait .dot { display: none; }
.entity-card .avatar.has-portrait .portrait { display: block; }

.entity-card .who { flex: 1; min-width: 0; }

.entity-card .who strong {
    display: block;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entity-card .who span {
    font-size: 0.7rem;
    color: var(--muted);
}

.entity-card .who .team { color: hsl(35, 70%, 62%); }

/* A small chip on cards whose entity is on a different map than the one shown. */
.entity-card .elsewhere {
    font-size: 0.62rem;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 1px 7px;
    white-space: nowrap;
}

.empty-state {
    color: var(--muted);
    font-size: 0.8rem;
    margin: 4px 0;
}

.entity-detail {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.entity-detail h3 { margin: 0; font-size: 0.95rem; }
.entity-detail dl {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 10px;
}
.entity-detail dt { color: var(--muted); }
.entity-detail dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.entity-detail .detail-actions { display: flex; gap: 8px; margin-top: 4px; }

.auth-panel {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-panel .label { margin: 0; font-size: 0.8rem; }

.auth-panel form { display: flex; gap: 6px; }

.auth-panel input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 8px;
    font-size: 0.8rem;
}

.auth-state { margin: 0; font-size: 0.75rem; color: var(--warn); }

footer { margin-top: auto; }
#error-line { font-size: 0.72rem; color: var(--bad); overflow-wrap: anywhere; }

/* -------------------------------------------------------------------- map */

.map-stage {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(1200px 700px at 70% 30%, #16202e 0%, var(--bg) 70%);
}

#map-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none; /* we handle pan/pinch ourselves; don't let the browser scroll/zoom */
}

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

.map-toolbar {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    gap: 6px;
    z-index: 2;
}

.map-legend,
.shortcuts-panel {
    position: absolute;
    top: 48px;
    left: 10px;
    z-index: 2;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.76rem;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    gap: 5px;
    pointer-events: none;
}

.map-legend strong,
.shortcuts-panel strong {
    color: var(--text);
    font-size: 0.78rem;
    margin-bottom: 2px;
}

.map-legend span,
.shortcuts-panel span {
    display: flex;
    align-items: center;
    gap: 7px;
}

.map-legend .swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex: none;
}

.map-legend .swatch.online { background: hsl(210, 80%, 60%); }
.map-legend .swatch.offline { background: rgba(139, 152, 173, 0.6); }
.map-legend .swatch.selected { background: transparent; box-shadow: 0 0 0 2px hsl(210, 90%, 70%); }
.map-legend .swatch.trail { background: linear-gradient(90deg, transparent, hsl(210, 80%, 65%)); border-radius: 2px; }

.shortcuts-panel { top: auto; bottom: 42px; }
.shortcuts-panel kbd {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: inherit;
    font-size: 0.72rem;
    color: var(--text);
}

.shortcuts-button {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 2;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 50%;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    font-weight: 700;
}

.map-hint {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 420px;
    background: color-mix(in srgb, var(--panel) 88%, transparent);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.78rem;
    color: var(--muted);
    pointer-events: none;
}

.map-hint strong { color: var(--text); }
.map-hint p { margin: 4px 0 0; }
.map-hint code { color: var(--accent); }

.map-coords {
    position: absolute;
    right: 10px;
    bottom: 10px;
    background: color-mix(in srgb, var(--panel) 88%, transparent);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.72rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- necesse theme */

/* Per-game theme, scoped to the map view (app-shell). Redefining the CSS
   variables here re-skins the whole subtree; the landing and admin overlay sit
   outside app-shell and keep the base theme. Mirrors the Necesse mod's look. */
.app-shell[data-theme="necesse"] {
    --bg: #09110f;
    --panel: #10211d;
    --panel-2: #17322b;
    --line: rgba(157, 211, 183, 0.16);
    --text: #edf7f2;
    --muted: #91aaa0;
    --accent: #7fe0a7;
    --good: #7fe0a7;
    --warn: #f3bd68;
    --bad: #ff8f84;
}

.app-shell[data-theme="necesse"] .sidebar {
    background:
        radial-gradient(circle at 0 0, rgba(38, 117, 84, 0.22), transparent 24rem),
        rgba(10, 20, 18, 0.98);
    box-shadow: 14px 0 36px rgba(0, 0, 0, 0.22);
}

.app-shell[data-theme="necesse"] .map-stage {
    background: radial-gradient(1200px 700px at 70% 30%, #123a2d 0%, var(--bg) 72%);
}

.app-shell[data-theme="necesse"] .game-kicker { color: var(--accent); }

/* -------------------------------------------------------------- admin portal */

.admin-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(6, 9, 14, 0.7);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
}

.admin-panel {
    width: 100%;
    max-width: 560px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.admin-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-head h2 { margin: 0; font-size: 1.15rem; }

.admin-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 9px 12px;
}

.admin-row .pip { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.admin-row[data-state="live"] .pip { background: var(--good); }
.admin-row[data-state="error"] .pip { background: var(--bad); }

.admin-row .row-main { flex: 1; min-width: 0; }
.admin-row .row-name { font-size: 0.9rem; display: flex; align-items: center; gap: 8px; }
.admin-row .row-sub { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.badge {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 1px 6px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
}
.badge.type { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

.admin-row .row-actions { display: flex; gap: 6px; flex: none; }
.admin-row .row-actions button { padding: 5px 10px; font-size: 0.74rem; }

button.ghost { background: transparent; color: var(--muted); border: 1px solid transparent; }
button.ghost:hover { color: var(--text); }
button.danger { background: transparent; color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 40%, var(--line)); }
button.danger:hover { background: color-mix(in srgb, var(--bad) 16%, transparent); filter: none; }

.admin-add { align-self: flex-start; }

.admin-form { display: flex; flex-direction: column; gap: 12px; }
.admin-form h3 { margin: 0; font-size: 1rem; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.72rem; color: var(--muted); }
.field span { text-transform: uppercase; letter-spacing: 0.05em; }
.field em { text-transform: none; letter-spacing: normal; font-style: normal; opacity: 0.7; }
.field input, .field select {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    padding: 8px 10px;
    font-size: 0.85rem;
    width: 100%;
    min-width: 0;
}
.field input:disabled { opacity: 0.55; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-fields { display: flex; flex-direction: column; gap: 12px; }

.form-result {
    margin: 0;
    font-size: 0.78rem;
    padding: 8px 10px;
    border-radius: 7px;
    overflow-wrap: anywhere;
}
.form-result.ok { color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.form-result.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.form-result.pending { color: var(--muted); background: var(--panel-2); }

.admin-form-actions { display: flex; gap: 8px; align-items: center; }
.admin-form-actions #f-cancel { margin-left: auto; }

.admin-auth form { display: flex; gap: 6px; }
.admin-auth input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    padding: 8px 10px;
    font-size: 0.85rem;
}

@media (max-width: 760px) {
    /* Map-first on phones: the map gets most of the height, the sidebar becomes
       a scrollable panel beneath it. */
    .app-shell { grid-template-columns: 1fr; grid-template-rows: 62dvh 38dvh; height: 100dvh; }
    .sidebar { order: 2; border-right: none; border-top: 1px solid var(--line); padding: 12px; min-height: 0; }
    .map-stage { order: 1; }
    .metrics { grid-template-columns: repeat(3, 1fr); }
    .metrics span { font-size: 0.62rem; }
    .map-legend, .shortcuts-panel { font-size: 0.72rem; padding: 8px 10px; }
    /* Bigger touch targets on the overlay controls. */
    .map-toolbar button { padding: 8px 12px; }
    .coord-goto button, button { min-height: 34px; }

    .landing { padding: 20px 14px; }
    .landing-header h1 { font-size: 1.4rem; }
    .server-grid { grid-template-columns: 1fr; gap: 12px; }

    .admin-overlay { padding: 12px; align-items: stretch; }
    .admin-panel { max-width: none; }
    .field-row { grid-template-columns: 1fr; }
}
