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

:root {
    --bg: #0e1116;
    --panel: rgba(20, 24, 31, 0.86);
    --border: rgba(120, 150, 180, 0.22);
    --text: #e7ecf2;
    --muted: #9aa6b2;
    --accent: #6cc4ff;
    --gold: #ffcc44;
}

html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

#viewer-container { position: fixed; inset: 0; }
canvas { display: block; }

/* ---------- Loading ---------- */
#loading {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 50% 35%, #1a2230, #0a0d12 70%);
    transition: opacity 0.6s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.loader-content { text-align: center; }
.loader-content h2 {
    font-size: 24px; letter-spacing: 4px; font-weight: 700;
    background: linear-gradient(90deg, #6cc4ff, #ffffff, #ffcc44);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    margin-bottom: 8px;
}
.loader-content p { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.progress-bar {
    width: 240px; height: 4px; border-radius: 4px;
    background: rgba(255,255,255,0.1); overflow: hidden; margin: 0 auto;
}
.progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #6cc4ff, #ffcc44);
    transition: width 0.3s ease;
}

/* ---------- Panels ---------- */
.panel {
    position: fixed; z-index: 20;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 30px rgba(0,0,0,0.45);
    font-size: 12px;
}
.panel h4 {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
    color: var(--accent); margin-bottom: 10px;
}
.panel hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.panel label {
    display: flex; align-items: center; gap: 7px;
    padding: 3px 0; color: var(--text); cursor: pointer; user-select: none;
}
.panel input[type="range"] { flex: 1; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }

/* ---------- Top bar ---------- */
#top-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 30;
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; padding: 12px 18px;
    background: linear-gradient(180deg, rgba(10,13,18,0.92), rgba(10,13,18,0));
}
.logo { font-weight: 700; letter-spacing: 2px; font-size: 15px; white-space: nowrap; }
.logo .subtitle { display: block; font-size: 10px; letter-spacing: 1px; color: var(--muted); font-weight: 400; }
.mode-tabs {
    display: inline-flex; margin-top: 7px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
    background: rgba(20, 24, 31, 0.78); letter-spacing: 0;
}
.mode-tabs a { padding: 5px 11px; font-size: 11.5px; font-weight: 500; color: var(--muted); text-decoration: none; }
.mode-tabs a + a { border-left: 1px solid var(--border); }
.mode-tabs a:hover { color: var(--text); }
.mode-tabs a.on { background: var(--accent); color: #0a0d12; font-weight: 650; }
/* стартовий вибір системи на екрані завантаження */
.chooser-sub { color: var(--muted); font-size: 13px; margin: -2px 0 20px; }
.chooser-btns { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.chooser-btns button {
    display: flex; flex-direction: column; align-items: center; gap: 5px; width: 210px; padding: 18px 16px 16px;
    border-radius: 14px; border: 1px solid var(--border); background: rgba(20, 24, 31, 0.85); color: var(--text);
    font-family: inherit; cursor: pointer; transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.chooser-btns button:hover, .chooser-btns button:focus-visible { transform: translateY(-2px); border-color: var(--accent); background: rgba(30, 40, 56, 0.92); outline: none; }
.chooser-btns .ch-ico { width: 118px; height: 72px; margin: -4px 0 0; }
.mode-tabs .tab-ico { width: 23px; height: 14px; vertical-align: -3px; margin-right: 5px; }
.chooser-btns b { font-size: 20px; letter-spacing: 1px; }
.chooser-btns small { font-size: 11.5px; color: var(--muted); }
.controls-top { display: flex; flex-wrap: wrap; gap: 6px; }
.btn {
    background: rgba(40,48,60,0.7);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 12px; font-size: 12px; cursor: pointer;
    transition: all 0.18s ease; white-space: nowrap;
}
.btn:hover { background: rgba(70,90,120,0.8); border-color: var(--accent); }
.btn.active { background: var(--accent); color: #0a0d12; border-color: var(--accent); font-weight: 600; }

/* ---------- Positions ---------- */
#legend { top: 88px; left: 16px; max-width: 230px; max-height: calc(100vh - 148px); overflow-y: auto; }
#stats-panel { bottom: 16px; right: 16px; min-width: 220px; max-height: calc(100vh - 120px); overflow-y: auto; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 2px 0; color: var(--muted); }
.swatch { width: 13px; height: 13px; border-radius: 3px; flex-shrink: 0; border: 1px solid rgba(255,255,255,0.15); }
.lg-group { font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase; color: #7f8b97; margin: 9px 0 3px; }
.lg-group:first-of-type { margin-top: 2px; }
.lg-ico { width: 22px; height: 14px; flex-shrink: 0; }
.legend-item { line-height: 1.3; font-size: 12px; }
.legend-item small { display: block; color: #7f8b97; font-size: 10.5px; }

/* ---------- 3D-підписи (CSS2D) ---------- */
#labels3d { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 1; }
.tag { display: flex; flex-direction: column; align-items: center; pointer-events: none; }
.tag-box {
    display: flex; align-items: baseline; gap: 6px; white-space: nowrap;
    padding: 4px 9px 5px 8px; border-radius: 8px;
    background: rgba(16, 20, 26, 0.84); border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.tag-box i { width: 8px; height: 8px; border-radius: 50%; align-self: center; flex-shrink: 0; }
.tag-box b { font-size: 12.5px; font-weight: 650; color: #f2f5f8; letter-spacing: 0.1px; }
.tag-box span { font-size: 11px; color: #a9b4bf; }
.tag-pin { position: relative; width: 2px; height: 16px; opacity: 0.9; }
.tag-pin::after {
    content: ''; position: absolute; left: -2px; bottom: -3px; width: 6px; height: 6px;
    border-radius: 50%; background: inherit; box-shadow: 0 0 0 1.5px rgba(16, 20, 26, 0.8);
}
.stat-row { display: flex; justify-content: space-between; gap: 14px; padding: 3px 0; }
.stat-row span:first-child { color: var(--muted); }
.stat-row span:last-child { color: var(--text); font-weight: 500; }

/* ---------- Compass ---------- */
#compass { position: fixed; top: 78px; right: 18px; z-index: 20; }
.compass-ring {
    position: relative; width: 64px; height: 64px; border-radius: 50%;
    background: var(--panel); border: 1px solid var(--border);
    backdrop-filter: blur(10px); box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.compass-ring span { position: absolute; font-size: 10px; color: var(--muted); transform: translate(-50%, -50%); }
.compass-n { top: 11px; left: 50%; color: #ff7a7a !important; font-weight: 700; }
.compass-s { bottom: 3px; left: 50%; top: auto; }
.compass-e { top: 50%; right: 5px; left: auto; }
.compass-w { top: 50%; left: 9px; }
.compass-needle {
    position: absolute; top: 50%; left: 50%; width: 2px; height: 22px;
    background: linear-gradient(180deg, #ff7a7a 50%, #6cc4ff 50%);
    transform-origin: center top; transform: translate(-50%, 0) rotate(0deg);
}

#hint {
    position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
    z-index: 20; font-size: 11px; color: var(--muted);
    background: rgba(10,13,18,0.55); padding: 5px 12px; border-radius: 20px;
    border: 1px solid var(--border); pointer-events: none;
}

/* ---------- Attribution credit ---------- */
#credit {
    position: fixed; bottom: 4px; left: 8px; z-index: 20;
    font-size: 9px; color: rgba(200,210,220,0.62);
    background: rgba(10,13,18,0.4); padding: 2px 7px; border-radius: 6px;
    border: 1px solid rgba(120,150,180,0.14); pointer-events: none;
}

/* ---------- Profile / lift-data window ---------- */
.menu-btn {
    display: block; width: 100%; margin: 0 0 12px; padding: 9px 10px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--accent); color: #0a0d12; font-weight: 600; font-size: 12px; cursor: pointer;
}
.menu-btn:hover { filter: brightness(1.08); }
#profile-modal {
    position: fixed; inset: 0; z-index: 50; display: none;
    align-items: center; justify-content: center;
    background: rgba(6,9,13,0.6); backdrop-filter: blur(4px);
}
#profile-modal.show { display: flex; }
.profile-box {
    position: relative; background: var(--panel); border: 1px solid var(--border);
    border-radius: 14px; padding: 18px 18px 16px; max-width: 94vw; max-height: 92vh; overflow: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.profile-box h3 { font-size: 13px; color: var(--accent); margin-bottom: 10px; letter-spacing: 0.5px; padding-right: 24px; }
.profile-box canvas { display: block; background: rgba(10,14,20,0.5); border-radius: 8px; }
#profile-close {
    position: absolute; top: 8px; right: 12px; background: none; border: none;
    color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1;
}
#profileData { margin-top: 12px; font-size: 12px; }
#profileData .prow {
    display: flex; justify-content: space-between; gap: 20px;
    padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
#profileData .prow span:first-child { color: var(--muted); }
#profileData .prow span:last-child { color: var(--text); font-weight: 500; }
#profileData .prow span:last-child { text-align: right; }
#profileData .pgroup {
    margin: 12px 0 3px; font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--accent);
}
#profileData .pgroup:first-child { margin-top: 0; }

/* ---------- Mobile ---------- */
#legend-toggle {
    display: none; position: fixed; top: 64px; left: 16px; z-index: 31;
    background: var(--accent); color: #0a0d12; border: none; border-radius: 8px;
    padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
@media (max-width: 760px) {
    .logo .subtitle { display: none; }
    .logo .mode-tabs {                                   /* перемикач систем — завжди видимий, знизу по центру */
        position: fixed; left: 50%; transform: translateX(-50%); bottom: 42px; z-index: 30; margin: 0;
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    }
    .logo .mode-tabs a { padding: 9px 15px; font-size: 13px; }
    #legend { max-height: calc(100vh - 200px); }
    .chooser-btns button { width: min(78vw, 280px); }
    #legend-toggle { display: block; }
    #legend { display: none; top: 108px; }
    #legend.show { display: block; }
    #stats-panel { display: none; }
    #hint { display: none; }
    .tag-box span { display: none; }
    .tag-box b { font-size: 11.5px; }
    .controls-top { gap: 4px; }
    .btn { padding: 6px 9px; font-size: 11px; }
    .profile-box { padding: 14px 12px 12px; }
    .profile-box h3 { font-size: 12px; margin-bottom: 8px; }
    #profileData { font-size: 11px; }
    #profileData .prow { gap: 10px; }
}
#credit a { color: var(--accent); pointer-events: auto; text-decoration: underline; }
