body {
    margin: 0;
    overflow: hidden;
    background-color: #0f172a;
    color: white;
}

html,
body {
    width: 100%;
    height: 100%;
}

:root {
    --app-height: 100vh;
}

canvas {
    position: fixed;
    inset: 0;
    display: block;
    width: 100vw;
    width: 100dvw;
    height: var(--app-height);
}

#ui-layer {
    position: fixed;
    inset: 0;
    width: 100vw;
    width: 100dvw;
    height: var(--app-height);
    pointer-events: none;
    overflow: clip;
}

.pointer-events-auto {
    pointer-events: auto;
}

.sim-insight-card {
    position: absolute;
    width: min(18rem, 28vw);
    padding: 0.85rem 0.95rem;
    border: 1px solid rgba(71, 85, 105, 0.85);
    border-radius: 1rem;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.74));
    backdrop-filter: blur(14px);
    box-shadow: 0 24px 48px rgba(2, 6, 23, 0.28);
    color: #cbd5e1;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace;
}

.sim-insight-title {
    margin-bottom: 0.75rem;
    color: #67e8f9;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.sim-insight-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem 0.9rem;
    margin-bottom: 0.8rem;
}

.sim-insight-label {
    color: #64748b;
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sim-insight-value {
    margin-top: 0.15rem;
    font-size: 1rem;
    font-weight: 700;
}

.sim-legend-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(71, 85, 105, 0.35);
    font-size: 0.68rem;
    line-height: 1.35;
}

.sim-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #94a3b8;
}

.sim-swatch {
    display: inline-block;
    width: 0.72rem;
    height: 0.72rem;
    border-radius: 999px;
    flex: 0 0 auto;
}

.sim-swatch-load {
    background: linear-gradient(180deg, rgba(34, 197, 94, 0.95), rgba(234, 179, 8, 0.95));
}

.sim-swatch-lock {
    background: transparent;
    border: 2px solid rgba(245, 158, 11, 0.9);
}

.sim-swatch-queue {
    width: 0.85rem;
    height: 0.6rem;
    border-radius: 0;
    background:
        linear-gradient(180deg, rgba(245, 158, 11, 0.92), rgba(245, 158, 11, 0.92)) left top / 70% 2px no-repeat,
        linear-gradient(180deg, rgba(245, 158, 11, 0.8), rgba(245, 158, 11, 0.8)) right bottom / 100% 2px no-repeat;
}

.sim-insight-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 0.8rem;
    padding-top: 0.7rem;
    border-top: 1px solid rgba(71, 85, 105, 0.35);
    color: #64748b;
    font-size: 0.68rem;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 4px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 10px;
}

/* Mobile safe-area support */
#sim-panel {
    bottom: max(1rem, env(safe-area-inset-bottom));
}

/* Drawer sizing — fits any viewport without overflow */
#sim-drawer {
    width: min(20rem, calc(100vw - 2rem));
    max-height: calc(100vh - 5rem);
}

/* Panel content scroll area */
#panel-content {
    max-height: calc(100vh - 8rem);
}

/* Toast button — hidden while drawer is open */
#panel-toast {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Drawer slide transition */
#sim-panel {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Closed state */
#sim-panel.panel-closed {
    opacity: 0;
    transform: translateY(0.75rem);
    pointer-events: none;
}

/* Open state */
#sim-panel.panel-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Toast hidden while panel is open */
#panel-toast.toast-hidden {
    opacity: 0;
    transform: translateY(0.5rem);
    pointer-events: none;
}

@media (max-width: 767px) {
    .sim-insight-card {
        top: 4.75rem;
        left: 1rem;
        right: 1rem;
        width: auto;
        padding: 0.7rem 0.8rem;
        border-radius: 0.85rem;
        background: linear-gradient(180deg, rgba(15, 23, 42, 0.88), rgba(15, 23, 42, 0.68));
    }

    .sim-insight-title {
        margin-bottom: 0.55rem;
        font-size: 0.62rem;
    }

    .sim-insight-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.4rem;
        margin-bottom: 0;
    }

    .sim-insight-label {
        font-size: 0.53rem;
    }

    .sim-insight-value {
        font-size: 0.82rem;
    }

    .sim-legend-list {
        display: none;
    }

    .sim-insight-footer {
        margin-top: 0.55rem;
        padding-top: 0.5rem;
        font-size: 0.6rem;
    }

    #sim-drawer {
        width: min(18rem, calc(100vw - 2rem));
    }
}
