/* The fins (js/n64-freeswim.js): an easter egg in the Field Office.
   A button rides the pair kicked off by the loveseat, its prompt over
   them; with them on, the swim's instruments step aside for a HUD of
   its own: FINS OFF in the corner, the controls along the bottom (gone
   once you've swum and looked round), and on a touch screen a stick
   under the left thumb, its gate an N64's octagon. */

.cave-fins {
    position: fixed;
    inset: 0;
    z-index: 30;
    margin: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.cave-fins.fp-near {
    opacity: 1;
}

.fins-grab {
    position: absolute;
    left: 0;
    top: 0;
    width: 72px;
    height: 48px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    pointer-events: none;
    -webkit-tap-highlight-color: transparent;
}

.cave-fins.fp-near .fins-grab {
    pointer-events: auto;
}

.fins-grab:focus-visible {
    outline: 2px solid var(--hud-gold, #ffd36a);
    outline-offset: 4px;
}

.fins-caption {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 0.35rem);
    transform: translateX(calc(-50% + var(--cap-dx, 0px)));
    white-space: nowrap;
    pointer-events: none;
}

/* (while it shows, pressing the prompt puts them on too) */
.cave-fins.fp-near.in-reach .fins-caption,
.cave-fins.fp-near.in-reach .press-prompt {
    pointer-events: auto;
    cursor: pointer;
}

/* ===== With the fins on ===== */
html.free-swim .cave-survey,
html.free-swim .cave-return {
    opacity: 0;
    pointer-events: none;
}

/* the page holds still: drags look round, the wheel kicks */
html.free-swim,
html.free-swim body {
    touch-action: none;
    overscroll-behavior: none;
}

html.free-swim .cave-viewport {
    cursor: grab;
}

html.free-swim.free-looking,
html.free-swim.free-looking .cave-viewport {
    cursor: grabbing;
    user-select: none;
    -webkit-user-select: none;
}

.free-hud {
    display: none;
}

html.cave-world .free-hud {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 60;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

html.free-swim .free-hud {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s ease 0.25s, visibility 0s;
}

.fins-off,
.free-legend {
    font-family: var(--hud-font);
    font-weight: 400;
    line-height: 1;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--hud-ink);
    text-shadow: 2px 2px 0 var(--hud-shadow);
}

.fins-off {
    position: absolute;
    top: 0.9rem;
    right: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.42em;
    padding: 0.3rem 0.2rem;
    font-size: 0.8rem;
    background: none;
    border: none;
    cursor: pointer;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
}

html.free-swim .fins-off {
    pointer-events: auto;
}

.fins-off:hover .press-key,
.fins-off:focus-visible .press-key {
    background: #fff0c2;
}

.fins-off:focus-visible {
    outline: 2px solid var(--hud-gold, #ffd36a);
    outline-offset: 3px;
}

.free-legend {
    position: absolute;
    left: 50%;
    bottom: 1.1rem;
    margin: 0;
    transform: translateX(-50%);
    font-size: 0.72rem;
    transition: opacity 0.6s ease;
}

.free-legend .press-key {
    margin: 0 0.18em 0 0.9em;
}

.free-legend .press-key:first-child {
    margin-left: 0;
}

.free-hud.legend-out .free-legend {
    opacity: 0;
}

/* the stick: only on a touch screen, resting low on the left until a
   thumb lands, then under it */
.free-stick {
    display: none;
}

@media (hover: none) and (pointer: coarse) {
    .free-stick {
        display: block;
        position: absolute;
        left: calc(1.4rem + 56px);
        top: calc(100% - 2rem - 56px);
        width: 112px;
        height: 112px;
        margin: -56px 0 0 -56px;
        opacity: 0.5;
        transition: opacity 0.2s ease;
    }

    /* the gate, gold-rimmed (the knob rides over it, never clipped by it) */
    .free-stick::before,
    .free-stick::after {
        content: '';
        position: absolute;
        inset: 0;
        background: var(--hud-gold, #ffd36a);
        clip-path: polygon(29% 0, 71% 0, 100% 29%, 100% 71%, 71% 100%, 29% 100%, 0 71%, 0 29%);
    }

    .free-stick::after {
        inset: 3px;
        background: rgba(3, 12, 24, 0.82);
    }

    .free-stick.held {
        opacity: 0.9;
    }

    .stick-knob {
        position: absolute;
        z-index: 1;
        left: 50%;
        top: 50%;
        width: 44px;
        height: 44px;
        margin: -22px 0 0 -22px;
        border-radius: 50%;
        background: radial-gradient(circle at 38% 34%, #ece6d6 0, #b9b2a2 55%, #77705f 100%);
        box-shadow: 2px 2px 0 var(--hud-shadow, #061220);
    }

    .free-legend {
        bottom: calc(2rem + 120px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cave-fins,
    .free-hud,
    .free-legend {
        transition: none;
    }
}
