:root {
    --bg-color: #0b0f17;
    --panel-bg: rgba(18, 24, 38, 0.92);
    --border-color: #273144;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-arc: #0284c7;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #16a34a;
    --danger: #dc2626;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    display: flex;
}

#viewport {
    flex: 1;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.top-bar {
    position: absolute;
    top: 14px;
    left: 14px;
    right: 14px;
    height: 52px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    backdrop-filter: blur(12px);
    z-index: 10;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.3px;
}

.brand-badge {
    background: var(--accent-color);
    color: #fff;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-label {
    font-size: 12px;
    color: var(--text-muted);
}

.separator {
    width: 1px;
    height: 22px;
    background: var(--border-color);
    margin: 0 4px;
}

.btn {
    background: #1e293b;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
    background: #334155;
    border-color: #64748b;
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-danger {
    color: #f87171;
}

.select-angle {
    background: #1e293b;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
}

.side-panel {
    position: absolute;
    top: 76px;
    right: 14px;
    width: 300px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    backdrop-filter: blur(12px);
    z-index: 10;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
}

.panel-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.stat-value {
    font-weight: 700;
    color: #38bdf8;
    font-family: monospace;
    font-size: 14px;
}

.stat-input {
    width: 65px;
    background: #0b0f17;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 6px;
    color: #38bdf8;
    font-family: monospace;
    font-weight: 700;
    font-size: 13px;
    text-align: right;
    outline: none;
}

.room-item {
    background: #1e293b;
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.instructions {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    background: #0b0f17;
    padding: 10px;
    border-radius: 8px;
    border: 1px dashed var(--border-color);
}

.instructions ul {
    padding-left: 16px;
    margin-top: 4px;
}

.instructions li {
    margin-bottom: 4px;
}

#edit-modal {
    position: absolute;
    display: none;
    background: #1e293b;
    border: 1px solid var(--accent-color);
    padding: 6px 10px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.6);
    z-index: 100;
    align-items: center;
    gap: 8px;
    transform: translate(-50%, -50%);
}

.edit-dir-group {
    display: flex;
    gap: 2px;
    background: #0b0f17;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 2px;
}

.edit-dir-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 26px;
    height: 26px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.edit-dir-btn:hover {
    color: #fff;
    background: #334155;
}

.edit-dir-active {
    background: var(--accent-color) !important;
    color: #fff !important;
}

#edit-input {
    width: 75px;
    background: #0b0f17;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 5px 8px;
    color: #fff;
    font-size: 14px;
    font-family: monospace;
    outline: none;
    text-align: center;
}

.edit-unit {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.edit-btn {
    background: var(--accent-color);
    border: none;
    color: #fff;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.panel-toggle-btn {
    display: none;
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: var(--accent-color);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 13px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    z-index: 20;
    cursor: pointer;
}

@media (max-width: 768px) {
    .brand { display: none; }
    .top-bar {
        left: 8px;
        right: 8px;
        top: 8px;
        height: 46px;
        padding: 0 8px;
        justify-content: center;
    }
    .toolbar {
        width: 100%;
        justify-content: space-between;
        gap: 4px;
    }
    .btn {
        padding: 6px 8px;
        font-size: 12px;
    }
    .separator { margin: 0 2px; }
    .panel-toggle-btn { display: block; }
    .side-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 60vh;
        border-radius: 16px 16px 0 0;
        transform: translateY(105%);
        transition: transform 0.25s ease;
        z-index: 25;
    }
    .side-panel.open {
        transform: translateY(0);
    }
}
