:root {
    --bg: #05040a;
    --bg2: #0c0820;
    --surface: #141414;
    --fg: #fafafa;
    --muted: #a3a3a3;
    --border: #262626;
    --accent: #a855f7;
    --accent-fg: #0b0b0b;
    --radius: 10px;
    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
}

body {
    background: radial-gradient(ellipse at 50% 40%, var(--bg2) 0%, var(--bg) 55%, #000000 100%);
    color: var(--fg);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}

#scene-wrap {
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    width: 100dvw;
    height: 100dvh;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}

#torus-canvas {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
    -ms-touch-action: none;
}

#controls {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: calc(100vw - 24px);
    background: rgba(20, 20, 20, 0.55);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 18px;
    backdrop-filter: blur(6px);
    pointer-events: auto;
}

#spin-speed-label {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    user-select: none;
}

#spin-speed-value {
    color: var(--fg);
    font-variant-numeric: tabular-nums;
}

#spin-speed {
    -webkit-appearance: none;
    appearance: none;
    width: 160px;
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), var(--border));
    outline: none;
    cursor: pointer;
    touch-action: pan-x;
}

#spin-speed::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--fg);
    cursor: pointer;
}

#spin-speed::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--fg);
    cursor: pointer;
}

/* Touch / small-screen: bigger tap target for the slider thumb and
   more breathing room around the control bar so it never overlaps
   system UI (notches, home indicator) on phones. */
@media (pointer: coarse), (max-width: 640px) {
    #controls {
        left: 50%;
        right: auto;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        width: calc(100vw - 24px);
        max-width: 420px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 14px 18px calc(14px + env(safe-area-inset-bottom, 0px) * 0);
    }

    #spin-speed-label {
        font-size: 0.95rem;
        text-align: center;
    }

    #spin-speed {
        width: 100%;
        height: 8px;
    }

    #spin-speed::-webkit-slider-thumb {
        width: 26px;
        height: 26px;
    }

    #spin-speed::-moz-range-thumb {
        width: 26px;
        height: 26px;
    }
}

/* Landscape phones: keep the bar compact and inline so it doesn't eat
   too much vertical space, but still respect side safe-area insets. */
@media (max-width: 900px) and (orientation: landscape) {
    #controls {
        flex-direction: row;
        align-items: center;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        padding: 8px 16px;
        max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
    }

    #spin-speed {
        width: 140px;
    }
}
