html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0b1020;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Microsoft YaHei", sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
    overscroll-behavior: none;
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

body::before {
    background:
        radial-gradient(ellipse at center, rgba(255, 226, 154, 0.08) 0%, rgba(132, 169, 206, 0.05) 55%, rgba(48, 60, 88, 0.16) 100%);
    mix-blend-mode: soft-light;
}

body::after {
    background:
        linear-gradient(105deg, rgba(170, 64, 48, 0.08), transparent 38%, rgba(255, 216, 112, 0.08) 66%, rgba(62, 88, 132, 0.10));
    mix-blend-mode: overlay;
    opacity: 0.28;
}

#walk-canvas {
    position: fixed;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   HUD overlay
   ========================================================================== */
#walk-hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.hud-panel {
    position: absolute;
    background:
        linear-gradient(180deg, rgba(24, 19, 20, 0.82), rgba(6, 8, 14, 0.72));
    border: 1px solid rgba(196, 145, 61, 0.56);
    border-radius: 6px;
    box-shadow:
        inset 0 0 0 1px rgba(255, 225, 150, 0.12),
        0 8px 24px rgba(0, 0, 0, 0.28);
    color: rgba(237, 223, 191, 0.92);
    font-size: 14px;
    line-height: 1.5;
    padding: 8px 13px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.75);
}

#hud-help {
    top: 12px;
    left: 12px;
    max-width: calc(100vw - 24px);
}

#hud-status {
    top: 12px;
    right: 12px;
    text-align: right;
    white-space: nowrap;
    letter-spacing: 0;
}

#hud-status span + span::before {
    content: "";
    display: inline-block;
    width: 5px;
    height: 5px;
    margin: 0 8px 1px;
    transform: rotate(45deg);
    background: rgba(202, 151, 66, 0.72);
    box-shadow: 0 0 8px rgba(202, 151, 66, 0.35);
    opacity: 0.9;
}

/* proximity POI label — fades in when near a landmark */
#hud-nearby {
    position: fixed;
    bottom: 68px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 10;
    font-size: 15px;
    font-style: italic;
    letter-spacing: 0.04em;
    color: rgba(237, 206, 148, 0.0);
    text-shadow:
        0 0 12px rgba(220, 170, 60, 0.0),
        0 1px 2px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
    transition: color 0.6s ease, text-shadow 0.6s ease;
}

#hud-nearby.hud-nearby-visible {
    color: rgba(237, 206, 148, 0.88);
    text-shadow:
        0 0 12px rgba(220, 170, 60, 0.45),
        0 1px 2px rgba(0, 0, 0, 0.8);
}

.hud-help-touch {
    display: none;
}

/* ==========================================================================
   Touch controls
   ========================================================================== */
#touch-zone {
    position: fixed;
    inset: 0;
    z-index: 20;
    pointer-events: none;
    display: none;
}

#touch-joystick {
    position: absolute;
    left: 24px;
    bottom: 28px;
    width: 132px;
    height: 132px;
    pointer-events: auto;
}

#touch-joystick-base {
    position: absolute;
    inset: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.25);
}

#touch-joystick-stick {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.45);
    border: 2px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

#touch-turn {
    position: absolute;
    right: 24px;
    bottom: 32px;
    display: flex;
    gap: 14px;
    pointer-events: auto;
}

#touch-turn button {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    touch-action: none;
}

#touch-turn button:active {
    background: rgba(255, 255, 255, 0.3);
}

#walk-noscript {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: #0b1020;
    z-index: 100;
}

/* ==========================================================================
   Mobile: show touch UI + touch help, hide desktop help
   ========================================================================== */
@media (hover: none) and (pointer: coarse) {
    #touch-zone {
        display: block;
    }

    .hud-help-desktop {
        display: none;
    }

    .hud-help-touch {
        display: inline;
    }
}

@media (max-width: 640px) {
    #walk-hud {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px;
    }

    .hud-panel {
        position: static;
        max-width: 100%;
        font-size: 13px;
        padding: 7px 10px;
    }

    #hud-status {
        text-align: left;
    }
}

/* Tablet / small-laptop tier (641–1024px): keep the desktop layout but
   slightly larger HUD text for readability on mid-size screens. */
@media (min-width: 641px) and (max-width: 1024px) {
    .hud-panel {
        font-size: 15px;
        padding: 9px 15px;
    }
}

/* Desktop / tablet layout (≥641px): the help panel sits top-left while the
   status panel is top-right. Reserve the status panel's footprint (~195px +
   12px right margin + gap) so the now-wrappable help text never slides
   underneath it. box-sizing:border-box makes max-width govern the visible
   (border-box) width, so the panel's own padding/border don't eat into the
   reserved space. Mobile (≤640px) uses a flex column stack, unaffected here. */
@media (min-width: 641px) {
    #hud-help {
        box-sizing: border-box;
        max-width: calc(100vw - 24px - 220px);
    }
}

/* Very narrow portrait phones (<360px): pull the touch controls inward so
   the joystick and turn buttons don't collide horizontally. */
@media (max-width: 360px) {
    #touch-joystick {
        left: 12px;
    }

    #touch-turn {
        right: 12px;
        gap: 10px;
    }

    #touch-turn button {
        width: 56px;
        height: 56px;
        font-size: 20px;
    }
}

/* ==========================================================================
   Loading overlay (P0-2): shown immediately, fades out when models resolve
   ========================================================================== */
#walk-loading {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: #0b1020;
    color: rgba(237, 223, 191, 0.92);
    transition: opacity 0.6s ease;
}

#walk-loading.walk-loading-done {
    opacity: 0;
    pointer-events: none;
}

.walk-loading-spinner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid rgba(196, 145, 61, 0.25);
    border-top-color: rgba(202, 151, 66, 0.9);
    animation: walk-spin 1s linear infinite;
}

@keyframes walk-spin {
    to { transform: rotate(360deg); }
}

.walk-loading-text {
    font-size: 14px;
    letter-spacing: 0.04em;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.75);
}

/* ==========================================================================
   WebGL fallback (P0-1): same look as the noscript fallback, shown by JS
   ========================================================================== */
#walk-webgl-error {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: #0b1020;
    z-index: 100;
    font-size: 15px;
    text-align: center;
    padding: 0 24px;
}

/* ==========================================================================
   Pointer Lock hint (P1-2): shown while the mouse is captured
   ========================================================================== */
#walk-lock-hint {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    z-index: 30;
    display: none;
    padding: 7px 14px;
    border: 1px solid rgba(196, 145, 61, 0.56);
    border-radius: 6px;
    background: linear-gradient(180deg, rgba(24, 19, 20, 0.82), rgba(6, 8, 14, 0.72));
    color: rgba(237, 223, 191, 0.92);
    font-size: 13px;
    pointer-events: none;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.75);
}

body.pointer-locked #walk-lock-hint {
    display: block;
}

/* ==========================================================================
   Hybrid touch devices (P1-3): a `.touch-ui` class added at first touch shows
   the touch controls on fine-pointer devices (touchscreen laptops), which the
   `(hover: none) and (pointer: coarse)` media query alone would miss.
   ========================================================================== */
body.touch-ui #touch-zone {
    display: block;
}

body.touch-ui .hud-help-desktop {
    display: none;
}

body.touch-ui .hud-help-touch {
    display: inline;
}

/* ==========================================================================
   Touch button feedback (P2-9): hover + keyboard focus rings
   ========================================================================== */
#touch-turn button:hover {
    background: rgba(255, 255, 255, 0.2);
}

#touch-turn button:focus-visible {
    outline: 2px solid rgba(202, 151, 66, 0.9);
    outline-offset: 2px;
    background: rgba(255, 255, 255, 0.2);
}

@media (prefers-reduced-motion: reduce) {
    .walk-loading-spinner {
        animation: none;
    }
}
