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

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #14181f;
    color: #eef2f7;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#canvas-container {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Верхняя панель управления */
.top-bar {
    position: fixed;
    top: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    pointer-events: none;
    z-index: 20;
}

.brand-card, .controls-card {
    pointer-events: auto;
    background: rgba(18, 23, 31, 0.84);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.brand-card {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-badge {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    padding: 6px 9px;
    border-radius: 8px;
    letter-spacing: 0.5px;
}

.brand-title {
    font-size: 15px;
    font-weight: 600;
    color: #f8fafc;
}

.brand-sub {
    font-size: 12px;
    color: #94a3b8;
}

.controls-card {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(30, 41, 59, 0.9);
    color: #e2e8f0;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn:hover {
    background: rgba(51, 65, 85, 0.95);
    border-color: rgba(148, 163, 184, 0.4);
}

.btn.active {
    background: #2563eb;
    border-color: #3b82f6;
    color: #ffffff;
}

.btn-vr {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    border-color: #38bdf8;
    color: #fff;
    font-weight: 600;
}

.btn-vr:disabled {
    background: rgba(51, 65, 85, 0.6);
    border-color: rgba(148, 163, 184, 0.25);
    color: #94a3b8;
    cursor: default;
}

.btn-danger {
    background: rgba(127, 29, 29, 0.65);
    border-color: rgba(248, 113, 113, 0.35);
}

/* Левая панель сценария и телепортации */
.left-panel {
    position: fixed;
    top: 84px;
    left: 14px;
    width: 310px;
    max-height: calc(100vh - 165px);
    overflow-y: auto;
    background: rgba(18, 23, 31, 0.84);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 14px;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 8px;
}

.panel-heading-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-mini {
    display: none;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(30, 41, 59, 0.9);
    color: #cbd5e1;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
}

.panel-heading h2 {
    font-size: 13.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #93c5fd;
}

.step-counter {
    font-size: 12px;
    font-weight: 600;
    color: #38bdf8;
}

.progress-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #38bdf8, #22c55e);
    transition: width 0.3s ease;
}

.current-task-box {
    background: rgba(37, 99, 235, 0.16);
    border: 1px solid rgba(59, 130, 246, 0.35);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.task-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #f8fafc;
    margin-bottom: 4px;
}

.task-desc {
    font-size: 12.5px;
    line-height: 1.45;
    color: #cbd5e1;
}

.safety-note {
    margin-top: 7px;
    font-size: 11.5px;
    color: #fbbf24;
    line-height: 1.35;
}

.steps-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.steps-list li {
    font-size: 12px;
    padding: 6px 8px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #94a3b8;
    background: rgba(255, 255, 255, 0.03);
}

.steps-list li.done {
    color: #86efac;
    background: rgba(34, 197, 94, 0.12);
}

.steps-list li.current {
    color: #ffffff;
    background: rgba(37, 99, 235, 0.28);
    border: 1px solid rgba(96, 165, 250, 0.45);
    font-weight: 500;
}

.step-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10.5px;
    font-weight: 700;
    flex-shrink: 0;
    background: rgba(148, 163, 184, 0.2);
}

.steps-list li.done .step-dot {
    background: #22c55e;
    color: #052e16;
}

.steps-list li.current .step-dot {
    background: #3b82f6;
    color: #fff;
}

/* Нижняя панель: инструменты и точки телепортации */
.bottom-bar {
    position: fixed;
    bottom: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    pointer-events: none;
    z-index: 20;
}

.tool-status, .teleport-bar {
    pointer-events: auto;
    background: rgba(18, 23, 31, 0.86);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 9px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tool-label {
    font-size: 11.5px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tool-value {
    font-size: 13px;
    font-weight: 600;
    color: #38bdf8;
}

.stats-chip {
    font-size: 12px;
    padding: 4px 9px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: #cbd5e1;
}

.stats-chip.err {
    color: #fca5a5;
}

/* Всплывающее уведомление */
.toast {
    position: fixed;
    top: 84px;
    left: 50%;
    transform: translateX(-50%) translateY(-12px);
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    max-width: 520px;
    text-align: center;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.info {
    background: rgba(15, 23, 42, 0.94);
    border: 1px solid #38bdf8;
    color: #e0f2fe;
}

.toast.success {
    background: rgba(20, 83, 45, 0.94);
    border: 1px solid #4ade80;
    color: #dcfce7;
}

.toast.error {
    background: rgba(127, 29, 29, 0.95);
    border: 1px solid #f87171;
    color: #fee2e2;
}

/* Виньетка комфорта при телепортации */
#comfort-vignette {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 30;
    opacity: 0;
    background: radial-gradient(circle, transparent 42%, rgba(0, 0, 0, 0.88) 100%);
    transition: opacity 0.18s ease;
}

#comfort-vignette.active {
    opacity: 1;
}

/* Подсказка при наведении на 3D-объект */
#hover-tooltip {
    position: fixed;
    pointer-events: none;
    z-index: 35;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(56, 189, 248, 0.55);
    color: #f8fafc;
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 6px;
    display: none;
    white-space: nowrap;
}

/* Итоговое окно завершения */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(9, 13, 20, 0.72);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal-backdrop.open {
    display: flex;
}

.modal-card {
    width: 440px;
    max-width: 92vw;
    background: #161d29;
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-card h3 {
    font-size: 18px;
    color: #4ade80;
    margin-bottom: 8px;
}

.modal-card p {
    font-size: 13.5px;
    color: #cbd5e1;
    line-height: 1.5;
    margin-bottom: 14px;
}

.result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.result-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px;
}

.result-item .lbl {
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
}

.result-item .val {
    font-size: 17px;
    font-weight: 700;
    color: #f8fafc;
    margin-top: 2px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Адаптация под мобильные устройства и планшеты */
@media (max-width: 900px) {
    .top-bar {
        top: max(8px, env(safe-area-inset-top));
        left: 8px;
        right: 8px;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .brand-card {
        padding: 7px 10px;
        gap: 8px;
    }

    .brand-title {
        font-size: 13px;
    }

    .brand-sub {
        display: none;
    }

    .controls-card {
        padding: 6px 8px;
        gap: 5px;
        justify-content: space-between;
    }

    .btn {
        padding: 5px 8px;
        font-size: 11.5px;
    }

    .left-panel {
        top: auto;
        bottom: 112px;
        left: 8px;
        right: 8px;
        width: auto;
        max-height: 44dvh;
        padding: 10px 12px;
    }

    .btn-mini {
        display: inline-block;
    }

    .left-panel.collapsed .steps-list {
        display: none;
    }

    .left-panel.collapsed .current-task-box {
        margin-bottom: 0;
        padding: 8px 10px;
    }

    .task-title {
        font-size: 12.5px;
    }

    .task-desc {
        font-size: 11.5px;
        line-height: 1.35;
    }

    .safety-note {
        font-size: 11px;
        margin-top: 4px;
    }

    .bottom-bar {
        bottom: max(8px, env(safe-area-inset-bottom));
        left: 8px;
        right: 8px;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .tool-status {
        padding: 6px 10px;
        justify-content: space-between;
    }

    .teleport-bar {
        padding: 6px 10px;
        gap: 6px;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .teleport-bar .tool-label {
        display: none;
    }

    #teleport-buttons {
        flex-wrap: nowrap !important;
        width: 100%;
    }

    #teleport-buttons .btn {
        white-space: nowrap;
        flex: 1 0 auto;
        text-align: center;
    }

    .toast {
        top: 108px;
        max-width: calc(100vw - 24px);
        font-size: 12px;
        padding: 8px 12px;
    }
}

@media (max-height: 540px) and (orientation: landscape) {
    .left-panel {
        top: 62px;
        bottom: auto;
        right: auto;
        width: 260px;
        max-height: calc(100dvh - 122px);
    }

    .bottom-bar {
        flex-direction: row;
        align-items: flex-end;
    }
}
