html {
    --vh: 100vh;

    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    padding: 0;
    margin: 0;
    background: #231F20;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    --canvas-w: min(100vw, var(--vh) * 4 / 5);
    --canvas-h: min(var(--vh), 100vw * 5 / 4);
    --canvas-top-ratio: 0.12;
    --canvas-top: calc(var(--canvas-top-ratio) * (var(--vh) - var(--canvas-h)));
}

@supports (height: 100dvh) {
    html {
        --vh: 100dvh;
    }
}

body {
    position: fixed;
    inset: 0;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

html,
#unity-container,
#hud-root,
#recording-controls,
#recording-controls *,
.btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    outline: none;
}

#unity-container {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: var(--canvas-top);
}

#unity-canvas {
    width: min(100vw, var(--vh) * 4 / 5);
    height: min(var(--vh), 100vw * 5 / 4);
    touch-action: none;
    display: block;
}

#unity-loading-bar {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: none
}

#unity-progress-bar-empty {
    width: 141px;
    height: 18px;
    margin-top: 10px;
    margin-left: 6.5px;
    background: url('progress-bar-empty-dark.png') no-repeat center
}

#unity-progress-bar-full {
    width: 0%;
    height: 18px;
    margin-top: 10px;
    background: url('progress-bar-full-dark.png') no-repeat center
}

#unity-warning {
    position: absolute;
    left: 50%;
    top: 5%;
    transform: translate(-50%);
    background: white;
    padding: 10px;
    display: none
}

#hud-root {
    display: none;
}

.overlays-visible #hud-root {
    display: block;
}

#touch-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    touch-action: none;

    --stick-edge-gap: clamp(50px, 6.8vmin, 75px);
    --stick-bottom-gap: clamp(20px, 3.5vmin, 40px);
    --btn-gap: 0px;

    --letterbox-x: calc((100vw - var(--canvas-w)) / 2);
    --letterbox-y: calc((var(--vh) - var(--canvas-h)) / 2);
    --slack: calc(var(--letterbox-x) + var(--letterbox-y));

    --stick-size: clamp(90px, calc(20vmin + 0.12 * var(--slack)), 190px);
    --btn-cluster-size: clamp(110px, calc(24vmin + 0.12 * var(--slack)), 200px);

}

.is-android #touch-overlay {
    --stick-edge-gap: clamp(70px, 9vmin, 100px);
    --stick-bottom-gap: clamp(50px, 7vmin, 80px);
}

.is-desktop #touch-overlay {
    display: none;
}

.joystick-zone {
    position: absolute;
    width: var(--stick-size);
    height: var(--stick-size);
    bottom: calc(var(--stick-bottom-gap) + env(safe-area-inset-bottom, 0px));
    pointer-events: auto;
}

#zone-move {
    left: var(--stick-edge-gap);
}

#zone-look {
    right: var(--stick-edge-gap);
}

.buttons {
    position: absolute;
    right: calc(var(--stick-edge-gap) + var(--stick-size) + var(--btn-gap));
    bottom: calc(var(--stick-bottom-gap) + var(--stick-size) + var(--btn-gap) + env(safe-area-inset-bottom, 0px));
    width: var(--btn-cluster-size);
    aspect-ratio: 1;
    pointer-events: none;
}

.btn {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 46%;
    aspect-ratio: 1;
    border-radius: 50%;
    border: none;
    font: 800 clamp(18px, 4vmin, 30px) system-ui, sans-serif;
    color: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    opacity: 0.85;
    transition: transform 0.05s ease, opacity 0.05s ease;
    pointer-events: auto;
}

.btn:active,
.btn.pressed {
    transform: scale(0.9);
    opacity: 1;
}

#btn-y {
    background: #d4af00;
}

#btn-x {
    background: #1e7fd4;
}

#btn-b {
    background: #d43b1e;
}

#btn-a {
    background: #F6FF00;
}

.btn-hidden {
    display: none;
}

@property --progress {
    syntax: '<angle>';
    inherits: false;
    initial-value: 0deg;
}

#recording-controls {
    display: none;
    position: fixed;
    bottom: calc(32px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    z-index: 9999;
    pointer-events: none;
    touch-action: none;
    --record-size: clamp(60px, 10vmin, 100px);
    --controls-gap: 2.5vmin;
    height: var(--record-size);
}

.overlays-visible #recording-controls {
    display: block;
}

.record-btn {
    --size: var(--record-size);
    --thickness: clamp(5px, calc(var(--size) * 0.1), 10px);
    --progress: 0deg;
    --duration: 0s;
    --inner-color-idle: #722f37;
    --inner-color-active: #ff5555;

    position: absolute;
    top: 0;
    left: 0;
    margin-left: calc(var(--size) / -2);
    transform: none;
    width: var(--size);
    height: var(--size);
    border-radius: 50%;
    background: conic-gradient(#ff0000 var(--progress), #F6FF00 var(--progress));
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s ease, scale 0.08s ease, filter 0.08s ease;
    pointer-events: auto;
}

.record-inner {
    width: calc(var(--size) - var(--thickness) * 2);
    height: calc(var(--size) - var(--thickness) * 2);
    background: var(--inner-color-idle);
    border-radius: 50%;
    transition: background 0.3s ease;
}

@keyframes pulse {
    0% {
        background: var(--inner-color-active);
    }

    50% {
        background: var(--inner-color-idle);
    }

    100% {
        background: var(--inner-color-active);
    }
}

@keyframes fill {
    from {
        --progress: 0deg;
    }

    to {
        --progress: 360deg;
    }
}

.pulsing .record-inner {
    animation: pulse 1.5s linear infinite;
}

.recording {
    animation: fill var(--duration) linear forwards;
}

.recording .record-inner {
    animation: pulse 1.5s linear infinite;
}

.export-btn {
    --size: clamp(44px, 7vmin, 72px);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M9 12C9 13.3807 7.88071 14.5 6.5 14.5C5.11929 14.5 4 13.3807 4 12C4 10.6193 5.11929 9.5 6.5 9.5C7.88071 9.5 9 10.6193 9 12Z'/%3E%3Cpath d='M14 6.5L9 10'/%3E%3Cpath d='M14 17.5L9 14'/%3E%3Cpath d='M19 18.5C19 19.8807 17.8807 21 16.5 21C15.1193 21 14 19.8807 14 18.5C14 17.1193 15.1193 16 16.5 16C17.8807 16 19 17.1193 19 18.5Z'/%3E%3Cpath d='M19 5.5C19 6.88071 17.8807 8 16.5 8C15.1193 8 14 6.88071 14 5.5C14 4.11929 15.1193 3 16.5 3C17.8807 3 19 4.11929 19 5.5Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: 80%;
    background-position: 40% 50%;
    position: absolute;
    top: 50%;
    left: calc(var(--controls-gap) + var(--record-size) / 2);
    margin-top: calc(var(--size) / -2);
    transform: none;
    width: var(--size);
    height: var(--size);
    border-radius: 50%;
    background-color: #2fae4e;
    display: none;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.2s ease, scale 0.08s ease, filter 0.08s ease;
}

.export-btn.visible {
    display: flex;
}

.export-btn.bounce-in {
    animation: exportBounceIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.export-btn.pulse-change {
    animation: exportPulse 0.4s ease-in-out 2;
}

#pov-overlay {
    position: absolute;
    --pov-margin: 10px;
    --pov-ref-w: calc(var(--canvas-w) - 2 * var(--pov-margin));
    left: calc(50vw - (var(--pov-ref-w) * 2999 / 1166));
    top: calc(var(--canvas-top) + (var(--canvas-h) / 2) - (var(--pov-ref-w) * 1398.5 / 1166));
    width: calc(var(--pov-ref-w) * 6000 / 1166);
    height: calc(var(--pov-ref-w) * 2800 / 1166);
    max-width: none;
    max-height: none;
    pointer-events: none;
    -webkit-user-drag: none;
    user-select: none;
    z-index: 1;
}

.export-btn.pressed,
.record-btn.pressed,
.export-btn:active,
.record-btn:active {
    scale: 0.88;
    filter: brightness(0.75);
}

@media (hover: hover) {
    .record-btn:hover,
    .export-btn:hover {
        transform: scale(1.05);
    }
}

@keyframes exportBounceIn {
    0%   { opacity: 0; transform: scale(0.3); }
    60%  { opacity: 1; transform: scale(1.15); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes exportPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.15); }
}
