:root {
    color-scheme: dark;
    --bg-0: #10111a;
    --bg-1: #1c1e30;
    --panel-bg: rgba(20, 23, 34, 0.82);
    --panel-border: rgba(255, 255, 255, 0.09);
    --text: rgba(255, 255, 255, 0.92);
    --text-dim: rgba(255, 255, 255, 0.62);
    --accent: #7aa2ff;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at 50% 20%, var(--bg-1), var(--bg-0) 65%);
    color: var(--text);
}

#scene {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: pointer;
    touch-action: manipulation;
}

.back-link {
    position: fixed;
    top: 14px;
    left: 16px;
    z-index: 20;
    padding: 7px 13px;
    border-radius: 10px;
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--text-dim);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: color 140ms ease, border-color 140ms ease;
}

.back-link:hover {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.25);
}

#panel {
    position: fixed;
    top: 14px;
    right: 16px;
    z-index: 20;
    width: 268px;
    max-height: calc(100vh - 28px);
    overflow-y: auto;
    padding: 18px 18px 14px;
    border-radius: 16px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    gap: 13px;
}

.panel-header h1 {
    margin: 0;
    font-size: 1.12rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: linear-gradient(90deg, #ff6b7d, #7aa2ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-dim);
}

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.85rem;
}

.row.col {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.row label {
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
}

.row .value {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

select {
    flex: 1;
    max-width: 150px;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

#randomize {
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid rgba(122, 162, 255, 0.4);
    background: linear-gradient(180deg, rgba(122, 162, 255, 0.28), rgba(122, 162, 255, 0.14));
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease;
}

#randomize:hover {
    background: linear-gradient(180deg, rgba(122, 162, 255, 0.4), rgba(122, 162, 255, 0.2));
}

#randomize:active {
    transform: scale(0.97);
}

.stats {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.8rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    color: var(--text-dim);
}

.stat-value {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.icon-btn {
    display: none;
    position: fixed;
    top: 14px;
    right: 16px;
    z-index: 30;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: var(--panel-bg);
    color: var(--text);
    font-size: 1.15rem;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

@media (max-width: 720px) {
    .icon-btn {
        display: block;
    }

    /* open panel takes the upper half; the lattice squeezes into the lower half */
    #panel {
        display: none;
        top: 64px;
        right: 12px;
        left: 12px;
        width: auto;
        max-height: calc(50vh - 72px);
        overflow-y: auto;
        padding: 13px 14px 11px;
        gap: 9px;
    }

    #panel.open {
        display: flex;
    }

    #panel .subtitle {
        font-size: 0.74rem;
    }
}
