/* ============================================
   SOVEREIGNTY — Spectator UI
   Neural Command aesthetic
   ============================================ */

:root {
    --bg:       #0b0e14;
    --bg-panel: rgba(12, 16, 24, 0.88);
    --bg-hover: rgba(0, 212, 255, 0.06);
    --bg-active:rgba(0, 212, 255, 0.12);

    --border:   rgba(255, 255, 255, 0.06);
    --border-hi:rgba(0, 212, 255, 0.25);

    --cyan:     #00d4ff;
    --magenta:  #e040fb;
    --green:    #2ecc71;
    --amber:    #f0a030;
    --red:      #ff4455;
    --blue:     #6e8efb;

    --text:     #e0e4ec;
    --text-dim: #6a7080;
    --text-mute:#3d4250;

    --font-mono:'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
    --font-ui:  'Inter', system-ui, -apple-system, sans-serif;

    --header-h: 44px;
    --radius:   8px;
    --blur:     12px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%; width: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── HEADER ──────────────────────────────── */
#header {
    height: var(--header-h);
    background: rgba(12, 16, 24, 0.95);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 200;
    position: relative;
    backdrop-filter: blur(8px);
}

.header-left, .header-right { display: flex; align-items: center; gap: 12px; }

.logo-mark {
    font-size: 20px;
    color: var(--cyan);
    text-shadow: 0 0 12px var(--cyan);
    line-height: 1;
}

.logo-name {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 3px;
    background: linear-gradient(135deg, var(--cyan), var(--magenta));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.status-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 3px 10px;
    border-radius: 20px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
}

.status-badge.connected   { background: rgba(46,204,113,0.1); border: 1px solid rgba(46,204,113,0.4); color: var(--green); }
.status-badge.disconnected { background: rgba(255,68,85,0.1); border: 1px solid rgba(255,68,85,0.3); color: var(--red); }
.status-badge.connecting   { background: rgba(240,160,48,0.1); border: 1px solid rgba(240,160,48,0.3); color: var(--amber); }

.status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 6px currentColor;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.header-stat {
    display: flex; align-items: baseline; gap: 6px;
    font-family: var(--font-mono);
}

.stat-key { font-size: 9px; font-weight: 600; letter-spacing: 1px; color: var(--text-dim); }
.stat-val { font-size: 14px; font-weight: 700; }
.accent-cyan    { color: var(--cyan); }
.accent-magenta { color: var(--magenta); }

/* ── GAME CONTAINER ──────────────────────── */
#game-container {
    position: absolute;
    top: var(--header-h);
    left: 0; right: 0; bottom: 0;
    overflow: hidden;
    background: var(--bg);
    cursor: crosshair;
    touch-action: none;
}

#game-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ── SELECTION BOX ───────────────────────── */
#selection-box {
    position: absolute;
    pointer-events: none;
    border: 2px solid var(--cyan);
    box-shadow: 0 0 8px var(--cyan), inset 0 0 8px rgba(0,212,255,0.15);
    z-index: 50;
    animation: sel-pulse 1.8s ease-in-out infinite;
}

@keyframes sel-pulse {
    0%,100% { box-shadow: 0 0 6px var(--cyan), inset 0 0 6px rgba(0,212,255,0.1); }
    50%     { box-shadow: 0 0 14px var(--cyan), inset 0 0 12px rgba(0,212,255,0.25); }
}

/* ── PANELS (shared) ─────────────────────── */
.panel {
    position: absolute;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    pointer-events: auto;
    z-index: 100;
    transition: opacity 0.2s, transform 0.2s;
}

.panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
}

.panel-head .badge {
    background: var(--cyan);
    color: var(--bg);
    font-size: 9px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.panel-head .toggle-arrow {
    margin-left: auto;
    font-size: 8px;
    color: var(--text-mute);
    transition: transform 0.2s;
}

/* ── AGENT PANEL ─────────────────────────── */
.panel-left {
    top: 12px;
    left: 12px;
    width: 180px;
    max-height: calc(100% - 24px);
    display: flex;
    flex-direction: column;
}

.panel-left.collapsed .agent-list { display: none; }
.panel-left.collapsed .toggle-arrow { transform: rotate(-90deg); }

.agent-list {
    overflow-y: auto;
    max-height: 240px;
    scrollbar-width: thin;
    scrollbar-color: var(--text-mute) transparent;
}

.agent-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    font-size: 12px;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: background 0.15s;
    border-left: 2px solid transparent;
}

.agent-row:hover { background: var(--bg-hover); }
.agent-row.active {
    background: var(--bg-active);
    border-left-color: var(--cyan);
}

.agent-row.placeholder {
    color: var(--text-mute);
    cursor: default;
    font-size: 11px;
}

.agent-dot {
    width: 8px; height: 8px;
    border-radius: 2px;
    flex-shrink: 0;
    box-shadow: 0 0 4px var(--c, #555);
    background: var(--c, #555);
}

.agent-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.agent-count {
    font-size: 10px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

/* ── RESOURCE PANEL ──────────────────────── */
.panel-top-right {
    top: 12px;
    right: 12px;
    min-width: 160px;
}

.res-grid { padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }

.res {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-family: var(--font-mono);
}

.res-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--c);
    box-shadow: 0 0 4px var(--c);
    flex-shrink: 0;
}

.res-key { color: var(--text-dim); flex: 1; font-family: var(--font-ui); font-size: 11px; }
.res-val { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* ── MINIMAP ─────────────────────────────── */
.panel-bottom-right {
    bottom: 12px;
    right: 12px;
    padding: 6px;
}

#minimap-canvas {
    border-radius: 4px;
    background: var(--bg);
    display: block;
    cursor: pointer;
}

.minimap-coords {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-mute);
    margin-top: 4px;
    letter-spacing: 1px;
}

/* ── SELECTION BAR ───────────────────────── */
.panel-bottom-center {
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    min-width: 280px;
    max-width: 520px;
    padding: 10px 16px;
}

.sel-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    padding: 2px 0;
}

.sel-label {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-dim);
    min-width: 50px;
}

.sel-val {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
}

.dim { color: var(--text-dim); }

/* Unit info */
.unit-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.unit-type-badge {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--cyan);
    letter-spacing: 1px;
}

.unit-id-tag {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-mute);
}

.unit-owner-tag {
    font-size: 11px;
    color: var(--text-dim);
}

.unit-bars {
    display: flex;
    gap: 16px;
    margin-bottom: 6px;
}

.bar-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.bar-label {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 600;
    color: var(--text-dim);
    width: 18px;
}

.bar {
    flex: 1;
    height: 5px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}

.bar-fill.hp { background: linear-gradient(90deg, var(--red), #ff8866); }
.bar-fill.en { background: linear-gradient(90deg, var(--amber), #ffd060); }

.bar-val {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    width: 48px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.unit-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}

.status-tag {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    padding: 1px 6px;
    border-radius: 3px;
}

.status-tag.idle     { color: var(--green);  background: rgba(46,204,113,0.12); }
.status-tag.moving   { color: var(--cyan);   background: rgba(0,212,255,0.12); }
.status-tag.working  { color: var(--amber);  background: rgba(240,160,48,0.12); }
.status-tag.depleted { color: var(--red);    background: rgba(255,68,85,0.12); }
.status-tag.dead     { color: var(--text-mute); background: rgba(255,255,255,0.04); }

/* ── CONTROLS HINT ───────────────────────── */
.hint-overlay {
    position: absolute;
    bottom: 12px;
    left: 12px;
    padding: 6px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    backdrop-filter: blur(var(--blur));
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: 0.5px;
    pointer-events: none;
    opacity: 1;
    transition: opacity 3s ease 6s;
    z-index: 90;
}

body.interacted .hint-overlay { opacity: 0; }

/* ── ERROR OVERLAY ───────────────────────── */
#error-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11,14,20,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.error-card {
    background: rgba(20,24,36,0.95);
    border: 1px solid rgba(255,68,85,0.3);
    border-radius: 12px;
    padding: 40px 48px;
    text-align: center;
}

.error-icon { font-size: 40px; color: var(--red); margin-bottom: 12px; }
.error-card h2 { font-family: var(--font-mono); font-size: 18px; letter-spacing: 3px; color: var(--red); margin-bottom: 10px; }
.error-card p { color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }

.error-card button {
    background: var(--red);
    color: #fff;
    border: none;
    padding: 10px 28px;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    border-radius: 6px;
    cursor: pointer;
    transition: box-shadow 0.2s;
}

.error-card button:hover { box-shadow: 0 0 20px rgba(255,68,85,0.4); }

/* ── HEADER BUTTONS ─────────────────────── */
.header-btn {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.03);
    color: var(--text-dim);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.header-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-hi); }
.header-btn.active { background: var(--bg-active); color: var(--cyan); border-color: var(--cyan); }
.header-btn.accent { color: var(--green); border-color: rgba(46,204,113,0.4); }
.header-btn.accent:hover { background: rgba(46,204,113,0.1); }

.header-sep {
    width: 1px; height: 20px;
    background: var(--border);
    margin: 0 4px;
}

/* ── LIVE FEED PANEL ────────────────────── */
.panel-feed {
    top: calc(var(--header-h) + 12px);
    left: 200px;
    width: 260px;
    max-height: 220px;
    display: flex;
    flex-direction: column;
}

.panel-feed.collapsed .feed-list { display: none; }
.panel-feed.collapsed .toggle-arrow { transform: rotate(-90deg); }

.feed-list {
    overflow-y: auto;
    max-height: 160px;
    scrollbar-width: thin;
    scrollbar-color: var(--text-mute) transparent;
}

.feed-item {
    padding: 4px 12px;
    font-size: 11px;
    font-family: var(--font-mono);
    border-bottom: 1px solid rgba(255,255,255,0.02);
    line-height: 1.4;
    color: var(--text-dim);
}

.feed-item .feed-time {
    color: var(--text-mute);
    font-size: 9px;
    margin-right: 6px;
}

.feed-item .feed-agent { color: var(--cyan); }
.feed-item .feed-action { color: var(--amber); }
.feed-item .feed-target { color: var(--magenta); }

.feed-item.event-spawn { border-left: 2px solid var(--green); }
.feed-item.event-attack { border-left: 2px solid var(--red); }
.feed-item.event-claim { border-left: 2px solid var(--amber); }
.feed-item.event-build { border-left: 2px solid var(--blue); }
.feed-item.event-epoch { border-left: 2px solid var(--magenta); }

/* ── LEGEND PANEL ───────────────────────── */
.panel-bottom-left {
    bottom: 12px;
    left: 12px;
    width: 200px;
    max-height: calc(100% - 24px);
    overflow-y: auto;
}

.legend-body { padding: 8px 12px; }

.legend-section { margin-bottom: 10px; }
.legend-section:last-child { margin-bottom: 0; }

.legend-title {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: var(--text-mute);
    margin-bottom: 4px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    padding: 2px 0;
    color: var(--text);
}

.legend-swatch {
    width: 10px; height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
    display: inline-block;
}

.legend-shape {
    width: 14px; height: 14px;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
}

.panel-close {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-mute);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.panel-close:hover { color: var(--text); }

/* ── LEADERBOARD PANEL ──────────────────── */
.panel-right {
    top: 120px;
    right: 12px;
    width: 260px;
    max-height: calc(100% - 132px);
    display: flex;
    flex-direction: column;
}

/* Leaderboard starts below resource panel (top: 120px in .panel-right) */

.leaderboard-season {
    padding: 6px 12px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
}

.leaderboard-list {
    overflow-y: auto;
    max-height: 400px;
    scrollbar-width: thin;
    scrollbar-color: var(--text-mute) transparent;
}

.lb-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 12px;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: background 0.15s;
    border-left: 2px solid transparent;
}

.lb-row:hover { background: var(--bg-hover); }

.lb-rank {
    width: 22px;
    text-align: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.lb-rank.gold   { color: #ffd700; text-shadow: 0 0 6px rgba(255,215,0,0.4); }
.lb-rank.silver { color: #c0c0c0; text-shadow: 0 0 6px rgba(192,192,192,0.3); }
.lb-rank.bronze { color: #cd7f32; text-shadow: 0 0 6px rgba(205,127,50,0.3); }

.lb-info { flex: 1; min-width: 0; }

.lb-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    font-size: 12px;
}

.lb-stats {
    display: flex;
    gap: 8px;
    font-size: 9px;
    color: var(--text-dim);
    margin-top: 2px;
}

.lb-xp-bar {
    width: 40px; height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
    align-self: center;
}

.lb-xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--cyan), var(--magenta));
    border-radius: 2px;
    transition: width 0.4s;
}

.lb-level {
    font-size: 10px;
    font-weight: 600;
    color: var(--cyan);
    flex-shrink: 0;
}

/* ── MODAL OVERLAY ──────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    padding: 20px;
}

.modal-card {
    background: rgba(14,18,28,0.98);
    border: 1px solid var(--border-hi);
    border-radius: 12px;
    width: 100%;
    max-width: 440px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    padding: 28px 24px;
}

.modal-lg { max-width: 560px; }

.modal-close {
    position: absolute;
    top: 12px; right: 14px;
    background: none;
    border: none;
    color: var(--text-mute);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    z-index: 2;
}

.modal-close:hover { color: var(--text); }

.modal-title {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--cyan);
    margin-bottom: 20px;
    text-align: center;
}

.modal-body { font-size: 13px; line-height: 1.6; color: var(--text); }

/* Help sections */
.help-section { margin-bottom: 18px; }
.help-section:last-child { margin-bottom: 0; }
.help-section h3 {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: var(--cyan);
    margin-bottom: 6px;
}
.help-section p { color: var(--text-dim); font-size: 12px; }

.help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.help-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.help-table td:first-child { white-space: nowrap; color: var(--text); }
.help-table td:last-child { color: var(--text-dim); }

.help-table .legend-swatch { vertical-align: middle; margin-right: 4px; }

kbd {
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    color: var(--text);
}

.help-code-block {
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    margin-top: 8px;
}

.help-code-header {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.help-code {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--cyan);
    word-break: break-all;
    display: block;
    line-height: 1.6;
    user-select: all;
}

.help-link {
    color: var(--cyan);
    text-decoration: none;
    border-bottom: 1px solid rgba(0,212,255,0.3);
}

.help-link:hover { border-bottom-color: var(--cyan); }

/* ── JOIN / INSTALL ──────────────────────── */
.btn {
    display: inline-block;
    padding: 10px 24px;
    border: none;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    transition: box-shadow 0.2s, background 0.15s;
}

.btn-primary {
    background: var(--cyan);
    color: var(--bg);
}

.btn-primary:hover { box-shadow: 0 0 16px rgba(0,212,255,0.4); }

.join-intro {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 16px;
    line-height: 1.5;
}

.join-install-block {
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--cyan);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    text-align: center;
}

.join-install-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.join-install-code {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--cyan);
    line-height: 1.6;
    margin-bottom: 12px;
    user-select: all;
    word-break: break-word;
}

.join-copy-btn { margin-top: 4px; }

.join-compat {
    margin-bottom: 16px;
}

.join-compat-title {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.join-compat-list {
    font-size: 12px;
    color: var(--text-mute);
}

.join-divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

.join-manual-title {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

/* ── SCROLLBAR ───────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-mute); border-radius: 2px; }

/* ============================================
   MOBILE (<= 768px)
   ============================================ */

/* Mobile bottom bar — hidden on desktop */
#mobile-bar {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 52px;
    padding: 0 16px;
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: rgba(12,16,24,0.95);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(8px);
    z-index: 300;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.mobile-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.mobile-btn:active { background: var(--bg-active); }
.mobile-btn-icon { font-size: 8px; color: var(--cyan); }

/* Mobile sheets */
.mobile-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 400;
    opacity: 0;
    transition: opacity 0.2s;
}

.mobile-backdrop.open { display: block; opacity: 1; }

.mobile-sheet {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    max-height: 65vh;
    background: rgba(14,18,28,0.98);
    border-top: 1px solid var(--border-hi);
    border-radius: 16px 16px 0 0;
    z-index: 500;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    padding: 12px 16px 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
}

.mobile-sheet.open { display: block; transform: translateY(0); }
.mobile-sheet-mini { max-height: 50vh; }

.sheet-handle {
    width: 36px; height: 4px;
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
    margin: 0 auto 12px;
}

.sheet-title {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

/* Mobile agent list */
.mobile-agent-list { display: flex; flex-direction: column; gap: 6px; }

.mobile-agent-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border);
    font-size: 13px;
    cursor: pointer;
}

.mobile-agent-row.active {
    border-color: var(--border-hi);
    background: var(--bg-active);
}

.mobile-agent-row .agent-dot { width: 10px; height: 10px; }
.mobile-agent-row .agent-name { flex: 1; font-family: var(--font-mono); }
.mobile-agent-row .agent-count { color: var(--text-dim); font-size: 11px; }

/* Mobile resources */
.mobile-res-grid { display: flex; flex-direction: column; gap: 8px; }

.mobile-res {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-dim);
}

.mobile-res .res-val { margin-left: auto; color: var(--text); font-weight: 600; }

@media (max-width: 768px) {
    :root { --header-h: 40px; }

    .logo-name { font-size: 10px; letter-spacing: 2px; }
    .logo-mark { font-size: 16px; }
    .header-left, .header-right { gap: 8px; }
    .status-badge { padding: 2px 6px; font-size: 8px; gap: 4px; }
    .status-badge .status-label { display: none; }
    .stat-key { font-size: 8px; }
    .stat-val { font-size: 12px; }

    #game-container { bottom: 52px; }

    /* Hide desktop panels */
    .panel-left, .panel-top-right, .panel-bottom-right, .panel-bottom-left, .panel-right, .panel-feed, .hint-overlay { display: none; }

    .header-btn { font-size: 0; width: 0; padding: 0; border: none; overflow: hidden; display: none; }
    .header-sep { display: none; }

    /* Selection bar adapts */
    .panel-bottom-center {
        bottom: 4px;
        left: 4px; right: 4px;
        transform: none;
        min-width: auto;
        max-width: none;
    }

    .unit-bars { flex-direction: column; gap: 6px; }

    /* Show mobile bar */
    #mobile-bar { display: flex; }
}

@media (min-width: 769px) {
    #mobile-bar, .mobile-backdrop, .mobile-sheet { display: none !important; }
}

/* ── TABLET TWEAKS ───────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
    .panel-left { width: 160px; }
    .panel-top-right { min-width: 140px; }
    #minimap-canvas { width: 130px; height: 130px; }
}
