body {
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overscroll-behavior: none; 
    touch-action: none;
}

#game-container {
    display: flex;
    flex-direction: row;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
}

#sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    z-index: 100;
    background: rgba(30, 24, 18, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 18px;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.92rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    min-height: 48px;
    touch-action: manipulation;
    transition: all 0.2s ease;
}

#sidebar-toggle:active {
    background: var(--accent-color);
    color: #120e0a;
    transform: translateY(-1px);
}

@media (hover: hover) {
    #sidebar-toggle:hover {
        background: var(--accent-color);
        color: #120e0a;
        transform: translateY(-1px);
    }
}

#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;
    width: min(340px, 88vw);
    transform: translateX(-100%);
    background-color: rgba(18, 14, 10, 0.92);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-right: 1px solid rgba(245, 166, 35, 0.2);
    display: flex;
    flex-direction: column;
    padding: calc(max(15px, env(safe-area-inset-top)) + 55px) 16px max(24px, env(safe-area-inset-bottom)) 16px;
    gap: 16px;
    z-index: 95;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.7);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#sidebar::-webkit-scrollbar {
    width: 4px;
}
#sidebar::-webkit-scrollbar-track {
    background: transparent;
}
#sidebar::-webkit-scrollbar-thumb {
    background: rgba(245, 166, 35, 0.3);
    border-radius: 4px;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-open #sidebar {
    transform: translateX(0);
}

.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
}

.panel-header {
    padding-bottom: 16px;
    text-align: center;
    position: relative;
}

.panel-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    width: 60%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(245, 166, 35, 0.5), transparent);
}

.panel-header h1 {
    font-size: clamp(1.5rem, 5vw, 1.8rem);
    color: var(--text-main);
    font-weight: 800;
    letter-spacing: 1.5px;
    text-shadow: 0 0 20px rgba(245, 166, 35, 0.2);
    font-family: 'Outfit', sans-serif;
}

.panel-header .subtitle {
    font-size: 0.75rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 4px;
    font-weight: 700;
    opacity: 0.85;
}

.panel-section {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 16px;
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.panel-section h2,
.panel-section h3 {
    font-size: 0.82rem;
    text-transform: uppercase;
    color: var(--accent-color);
    opacity: 0.95;
    margin-bottom: 14px;
    letter-spacing: 1px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-section h2 i,
.panel-section h3 i {
    width: 18px;
    height: 18px;
}

.btn-group {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.btn.tool-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    padding: 10px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: clamp(0.72rem, 2.5vw, 0.78rem);
    transition: all 0.25s ease;
    margin-bottom: 0;
    min-height: 46px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    touch-action: manipulation;
}

.btn.tool-btn:active {
    border-color: rgba(245, 166, 35, 0.5);
    background: rgba(245, 166, 35, 0.12);
    color: var(--text-main);
}

@media (hover: hover) {
    .btn.tool-btn:hover {
        border-color: rgba(245, 166, 35, 0.5);
        background: rgba(245, 166, 35, 0.12);
        color: var(--text-main);
    }
}

.btn.tool-btn.active {
    background: linear-gradient(135deg, var(--accent-color), #ffb84d);
    color: #120e0a;
    border-color: transparent;
    font-weight: 800;
    box-shadow: 0 4px 15px rgba(245, 166, 35, 0.4);
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.speed-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.82rem;
    background: rgba(0, 0, 0, 0.25);
    padding: 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.speed-btn-group {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.speed-btn-group::-webkit-scrollbar {
    display: none;
}

.btn-speed {
    flex: 1 0 auto;
    min-width: 42px;
    min-height: 42px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 8px;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-speed:active {
    background: rgba(245, 166, 35, 0.18);
    color: var(--text-main);
}

@media (hover: hover) {
    .btn-speed:hover {
        background: rgba(245, 166, 35, 0.18);
        color: var(--text-main);
    }
}

.btn-speed.active {
    background: var(--accent-color);
    color: #120e0a;
    box-shadow: 0 2px 8px rgba(245, 166, 35, 0.35);
}

.stats-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.84rem;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.025);
}

.stat-line:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-value {
    font-weight: 800;
    color: var(--text-main);
}

.role-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

#nest-warning {
    background: rgba(229, 83, 83, 0.15);
    border: 1px solid rgba(229, 83, 83, 0.35);
    color: #ff6b6b;
    padding: 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    text-align: center;
    font-weight: bold;
    margin-bottom: 10px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(229, 83, 83, 0.3); }
    70% { box-shadow: 0 0 0 10px rgba(229, 83, 83, 0); }
    100% { box-shadow: 0 0 0 0 rgba(229, 83, 83, 0); }
}

hr {
    border: 0;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    margin: 10px 0;
}

#main-view {
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    position: relative;
    background: var(--world-bg);
    overflow: hidden;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* Mobile-First Floating Bottom Inspect Card */
#inspect-panel {
    position: absolute;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
    width: auto;
    max-width: 440px;
    max-height: 70vh;
    max-height: 70dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 auto;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 16px 18px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
    z-index: 80;
    animation: slideUpSheet 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#inspect-panel h4 {
    color: var(--accent-color);
    margin-bottom: 10px;
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(245, 166, 35, 0.15);
    padding-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#inspect-content {
    font-size: 0.85rem;
    line-height: 1.55;
    margin-bottom: 14px;
    color: var(--text-main);
}

#camera-hint {
    display: none;
}

/* Desktop Expansion */
@media (min-width: 1024px) {
    #sidebar-toggle {
        display: none;
    }
    
    #sidebar {
        position: relative;
        transform: none;
        width: 340px;
        min-width: 340px;
        max-width: 340px;
        height: 100vh;
        height: 100dvh;
        padding-top: 24px;
        padding-bottom: 24px;
        border-right: 1px solid rgba(245, 166, 35, 0.2);
    }
    
    #main-view {
        flex: 1;
        width: auto;
    }

    #inspect-panel {
        width: 320px;
        left: auto;
        right: 24px;
        bottom: 24px;
    }

    #camera-hint {
        display: block;
        position: absolute;
        top: 20px;
        right: 20px;
        background: rgba(30, 24, 18, 0.88);
        border: 1px solid var(--border-color);
        border-radius: 10px;
        padding: 8px 14px;
        font-size: 0.75rem;
        color: var(--text-muted);
        font-weight: 600;
        pointer-events: none;
        backdrop-filter: blur(8px);
        box-shadow: 0 4px 14px rgba(0,0,0,0.4);
    }
}
