:root {
    --wall-width: 3px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    background: #202329;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    position: fixed;
    inset: 0;
}

.table {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 42%, rgba(255,255,255,0.035), transparent 42%),
        #202329;
}

/* The 3px wall around the complete usable screen. */
.table::after {
    content: "";
    position: absolute;
    z-index: 100;
    inset: 0;
    border: var(--wall-width) solid #e7e9ed;
    pointer-events: none;
}

.ball {
    --diameter: clamp(42px, 12vw, 70px);
    position: absolute;
    z-index: 20;
    left: 0;
    top: 0;
    width: var(--diameter);
    height: var(--diameter);
    border-radius: 50%;
    will-change: transform;
    pointer-events: none;
    background:
        radial-gradient(circle at 31% 27%,
            #ffffff 0 5%,
            #d9f3ff 7%,
            #63b9e6 25%,
            #147eb8 52%,
            #07507b 76%,
            #032f4c 100%);
    box-shadow:
        0 9px 12px rgba(0,0,0,0.42),
        inset -7px -9px 12px rgba(0,0,0,0.24),
        inset 5px 5px 8px rgba(255,255,255,0.24);
}

.permission-panel {
    position: absolute;
    z-index: 200;
    inset: 0;
    display: grid;
    place-items: center;
    padding:
        calc(22px + var(--safe-top))
        calc(22px + var(--safe-right))
        calc(22px + var(--safe-bottom))
        calc(22px + var(--safe-left));
    background: rgba(8, 10, 13, 0.72);
    backdrop-filter: blur(10px);
}

.permission-panel.is-hidden {
    display: none;
}

.permission-card {
    width: min(92vw, 420px);
    padding: 26px;
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 18px;
    background: rgba(31, 35, 42, 0.96);
    color: #f6f7f9;
    text-align: center;
    box-shadow: 0 18px 60px rgba(0,0,0,0.38);
}

.permission-card h1 {
    margin: 0 0 10px;
    font-size: 1.65rem;
}

.permission-card p {
    margin: 0 0 18px;
    color: #cbd0d8;
    line-height: 1.45;
}

.permission-card button,
.control-button {
    appearance: none;
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: 999px;
    background: rgba(255,255,255,0.11);
    color: #ffffff;
    font: inherit;
    font-weight: 650;
    cursor: pointer;
}

.permission-card button {
    min-width: 170px;
    padding: 12px 20px;
    background: #f0f2f5;
    color: #17191d;
}

.permission-message {
    min-height: 1.4em;
    margin-top: 14px !important;
    margin-bottom: 0 !important;
    font-size: 0.9rem;
    color: #ffcc80 !important;
}

.controls {
    position: absolute;
    z-index: 120;
    right: calc(12px + var(--safe-right));
    bottom: calc(12px + var(--safe-bottom));
    display: flex;
    gap: 8px;
    opacity: 0.76;
}

.control-button {
    padding: 8px 12px;
    font-size: 0.82rem;
    backdrop-filter: blur(8px);
}

.control-button:active,
.permission-card button:active {
    transform: scale(0.97);
}

.debug {
    position: absolute;
    z-index: 130;
    top: calc(12px + var(--safe-top));
    left: calc(12px + var(--safe-left));
    padding: 6px 9px;
    border-radius: 7px;
    background: rgba(0,0,0,0.55);
    color: white;
    font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
    pointer-events: none;
}

@media (display-mode: standalone) {
    .table {
        height: 100dvh;
    }
}
