.map-experience-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    overflow: hidden;
    pointer-events: none;
}

.map-labels-layer,
.map-bubbles-layer,
.map-dialog-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.map-opening-questions {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.opening-question {
    position: absolute;
    width: 54px;
    height: 54px;
    padding: 0;
    transform: translate(-50%, -100%);
    border: 4px solid #5b321a;
    border-radius: 50%;
    box-shadow: 4px 4px 0 #5b321a;
    color: #fff7df;
    background: #ef7428;
    font: 900 34px/46px "Courier New", monospace;
    cursor: pointer;
    pointer-events: auto;
    perspective: 180px;
    animation: openingQuestionFloat 1.2s steps(4, end) infinite alternate;
}

.opening-question-mark {
    display: inline-block;
    transform-style: preserve-3d;
    animation: openingQuestionYSpin 1s steps(8, end) infinite;
}

.opening-question:hover,
.opening-question:focus-visible {
    outline: 4px solid #fff7df;
    outline-offset: 3px;
    background: #ff9b3d;
}

.map-waiting-dots {
    position: absolute;
    min-width: 70px;
    padding: 6px 12px;
    transform: translate(-50%, -100%);
    font: 900 26px/1 "Courier New", monospace;
    text-align: center;
}

.map-intro-dialog {
    position: absolute;
    left: 50%;
    bottom: 28px;
    width: min(760px, calc(100% - 36px));
    min-height: 92px;
    padding: 18px 48px 18px 22px;
    transform: translateX(-50%);
    font-size: clamp(16px, 2vw, 21px);
    font-weight: 800;
    line-height: 1.65;
    cursor: pointer;
    pointer-events: auto;
}

.map-intro-dialog:focus-visible {
    outline: 4px solid #ef7428;
    outline-offset: 4px;
}

.map-guide-layer {
    position: absolute;
    inset: 0;
    z-index: 18;
    overflow: hidden;
    pointer-events: none;
}

.map-guide-layer[hidden] {
    display: none;
}

.map-guide-card {
    position: absolute;
    width: min(300px, calc(100% - 24px));
    min-height: 92px;
    padding: 14px 15px 10px;
    border-width: 4px;
    font: 900 16px/1.55 "Courier New", "Microsoft YaHei", monospace;
    cursor: pointer;
    pointer-events: auto;
    image-rendering: pixelated;
}

.map-guide-card:focus-visible {
    outline: 4px solid #ef7428;
    outline-offset: 4px;
}

.map-guide-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 8px;
    color: #a25724;
    font-size: 12px;
}

.map-guide-actions button {
    min-width: 52px;
    min-height: 30px;
    padding: 2px 8px;
    border: 3px solid #5b321a;
    box-shadow: 2px 2px 0 #5b321a;
    color: #5b321a;
    background: #ffd28a;
    font: 900 12px/1 "Courier New", "Microsoft YaHei", monospace;
    cursor: pointer;
}

.map-guide-replay-icon {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border: 2px solid currentColor;
    border-radius: 50%;
    font: 900 16px/1 "Courier New", monospace;
}

.map-intro-character {
    display: inline;
}

.map-intro-character.is-entering {
    animation: introCharacterFade 120ms steps(3, end) both;
}

.map-dialog-advance {
    position: absolute;
    right: 17px;
    bottom: 13px;
    color: #ef7428;
    animation: dialogAdvanceSteps 0.8s steps(2, end) infinite alternate;
}

.map-building-bubble {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -100%) scale(var(--bubble-scale, 1));
    transform-origin: 50% 100%;
    min-width: 88px;
    min-height: 72px;
    padding: 8px;
    font-family: inherit;
    font-weight: 900;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
}

.map-building-bubble::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -13px;
    width: 14px;
    height: 14px;
    border-right: 3px solid #5b321a;
    border-bottom: 3px solid #5b321a;
    background: #fff7df;
    transform: translateX(-50%) rotate(45deg);
}

.map-building-bubble:hover,
.map-building-bubble:focus-visible {
    outline: 4px solid #ef7428;
    outline-offset: 3px;
}

.map-department-bubble,
.map-building-bubble.is-mystery {
    width: 158px;
    min-width: 158px;
    max-width: 158px;
    height: 92px;
    min-height: 92px;
    padding: 5px;
}

.map-mystery-mascot {
    width: 54px;
    height: 78px;
    object-fit: contain;
    image-rendering: auto;
}

.map-department-bubble-content {
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.map-department-bubble-icon,
.map-department-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border: 3px solid #5b321a;
    border-radius: 4px;
    color: #fff;
    text-shadow: 2px 2px 0 rgba(91, 50, 26, 0.45);
}

.map-jump-bubble {
    width: 128px;
    min-width: 128px;
    max-width: 128px;
    height: 78px;
    min-height: 78px;
    background: #fff;
    perspective: 180px;
}

.map-jump-bubble .map-question.map-question {
    display: block;
    color: #ef7428;
    font: 900 35px/1 "Courier New", monospace;
    transform-style: preserve-3d;
    animation: jumpQuestionYSpin 1s steps(8, end) infinite;
}

.map-jump-bubble.is-revealed {
    padding-inline: 14px;
    color: #e56820;
    white-space: nowrap;
}

.map-bubble-edge {
    position: absolute;
    z-index: 7;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    padding: 0;
    transform: translate(-50%, -50%);
    border: 3px solid #5b321a;
    border-radius: 50%;
    box-shadow: 3px 3px 0 #5b321a;
    color: #ef7428;
    background: #fff7df;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
}

.map-building-bubble[hidden],
.map-bubble-edge[hidden] {
    display: none !important;
}

.map-bubble-edge-arrow {
    display: inline-block;
    font: 900 24px/1 "Courier New", monospace;
    transform: rotate(var(--edge-angle, 0deg));
}

.map-building-bubble.is-tour-target::before {
    content: "▼";
    position: absolute;
    left: 50%;
    top: -35px;
    color: #ef7428;
    font: 900 27px/1 "Courier New", monospace;
    text-shadow: 2px 2px 0 #fff7df;
    transform: translateX(-50%);
    animation: dialogAdvanceSteps 0.6s steps(2, end) infinite alternate;
}

.is-overview-tour .map-building-bubble {
    pointer-events: none;
}

.is-overview-tour .map-bubble-edge {
    pointer-events: none;
}

/* 地图与覆盖层由同一补间帧同步定位。 */
.map-world.is-camera-animating {
    transition: none;
}

.map-calibration-entry {
    position: absolute;
    top: calc(72px + env(safe-area-inset-top, 0px));
    right: 18px;
    z-index: 7;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 14px;
    color: #e56820;
    font-size: 14px;
    font-weight: 900;
    text-decoration: none;
}

.map-calibration-entry[hidden] {
    display: none;
}

.map-utility-bar {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: max(14px, env(safe-area-inset-right, 0px));
    z-index: 8;
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.map-utility-button {
    min-height: 44px;
    padding: 6px 10px;
    border: 3px solid #5b321a;
    border-radius: 4px;
    box-shadow: 3px 3px 0 #5b321a;
    background: #fff7df;
    color: #9d3f16;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font: 800 13px/1.05 "Microsoft YaHei", "PingFang SC", sans-serif;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
}

.map-utility-button[hidden] {
    display: none;
}

.map-utility-button:hover,
.map-utility-button:focus-visible,
.map-utility-button:active {
    background: #ffcf75;
    color: #5b321a;
    outline: 3px solid #fff7df;
    outline-offset: 2px;
}

.map-utility-button:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #5b321a;
}

.map-utility-copy {
    display: grid;
    gap: 2px;
    text-align: left;
}

.map-utility-copy small {
    color: #a97c50;
    font-size: 10px;
    font-weight: 800;
}

.map-interactive-control {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.map-interactive-control img,
.map-interactive-control i {
    pointer-events: none;
    -webkit-user-drag: none;
}

.map-department-panel {
    position: absolute;
    left: 50%;
    bottom: 28px;
    width: min(820px, calc(100% - 36px));
    max-height: min(42vh, 330px);
    padding: 16px 52px 16px 20px;
    transform: translateX(-50%);
    overflow: auto;
    pointer-events: auto;
}

.map-department-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    font-size: clamp(19px, 2.4vw, 25px);
}

.map-department-panel p {
    margin: 7px 0 13px;
    font-size: clamp(14px, 1.8vw, 17px);
    font-weight: 700;
    line-height: 1.65;
}

.map-panel-close {
    position: absolute;
    top: 8px;
    right: 9px;
    width: 34px;
    height: 34px;
    border: 3px solid #5b321a;
    border-radius: 3px;
    box-shadow: 2px 2px 0 #5b321a;
    color: #5b321a;
    background: #fff;
    font: 900 25px/25px monospace;
    cursor: pointer;
}

.map-department-details {
    display: inline-block;
    padding: 8px 12px;
    color: #fff;
    background: #e56820;
    font-weight: 900;
    text-decoration: none;
}

.map-experience-reset-dialog {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(54, 31, 17, 0.42);
    pointer-events: auto;
}

.map-experience-reset-dialog[hidden] {
    display: none !important;
}

.map-experience-reset-card {
    width: min(480px, calc(100vw - 34px));
    padding: 22px;
    text-align: center;
}

.map-experience-reset-card strong {
    display: block;
    margin-bottom: 12px;
    color: #e56820;
    font-size: clamp(20px, 3vw, 27px);
}

.map-experience-reset-card p {
    margin: 0 0 18px;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.65;
}

.map-experience-reset-card.is-error {
    border-color: #b71c1c;
    box-shadow: 4px 4px 0 #b71c1c;
}

.map-experience-reset-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.map-experience-reset-actions button {
    min-width: 112px;
    min-height: 42px;
    padding: 7px 14px;
    font-family: inherit;
    font-weight: 900;
    cursor: pointer;
}

.map-experience-reset-actions .is-primary {
    color: #fff;
    background: #e56820;
}

.map-experience-reset-actions button:disabled {
    cursor: wait;
    opacity: 0.62;
}

.map-experience-reset-actions button[hidden] {
    display: none !important;
}

/* 地图模式玩法介绍弹窗（纯文字介绍，替代旧的引导重播） */
.map-gameplay-intro-dialog {
    position: absolute;
    inset: 0;
    z-index: 21;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(54, 31, 17, 0.42);
    pointer-events: auto;
}

.map-gameplay-intro-dialog[hidden] {
    display: none !important;
}

.map-gameplay-intro-card {
    position: relative;   /* 供 .map-panel-close 定位 */
    width: min(540px, calc(100vw - 34px));
    max-height: 80vh;
    padding: 24px 22px 20px;
    text-align: left;
    overflow: auto;
}

.map-gameplay-intro-card strong {
    display: block;
    margin: 0 0 12px;
    padding-right: 40px;  /* 避让右上角关闭按钮 */
    color: #e56820;
    font-size: clamp(20px, 3vw, 27px);
}

.map-gameplay-intro-list {
    margin: 0;
    padding-left: 20px;
}

.map-gameplay-intro-list li {
    margin: 0 0 10px;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.7;
}

.map-gameplay-intro-list li.map-gameplay-intro-mobile-hint {
    margin-top: 12px;
    padding-left: 0;
    color: #a97c50;
    font-size: 13px;
    font-weight: 800;
    list-style: none;
    text-align: center;
}

.map-gameplay-intro-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 16px;
}

.map-gameplay-intro-actions button {
    min-width: 120px;
    min-height: 44px;
    padding: 7px 16px;
    font-family: inherit;
    font-weight: 900;
    cursor: pointer;
}

.map-gameplay-intro-actions .is-primary {
    color: #fff;
    background: #e56820;
}

.map-return-button {
    position: fixed;
    left: 18px;
    top: calc(76px + env(safe-area-inset-top, 0px));
    z-index: 1200;
    padding: 10px 14px;
    color: #fff;
    background: #e56820;
    font-family: inherit;
    font-size: 15px;
    font-weight: 900;
    cursor: pointer;
}

.map-return-button[hidden] {
    display: none;
}

.map-loading-overlay {
    --map-load-progress: 0%;
    position: absolute;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 18px;
    background:
        linear-gradient(rgba(255, 247, 223, 0.92), rgba(244, 174, 83, 0.9)),
        repeating-linear-gradient(0deg, transparent 0 12px, rgba(91, 50, 26, 0.05) 12px 14px);
    opacity: 1;
    transition: opacity 220ms steps(4, end), visibility 220ms;
}

.map-loading-overlay[hidden] {
    display: none;
}

.map-loading-overlay.is-hidden {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.map-loading-card {
    width: min(520px, calc(100vw - 36px));
    padding: 22px 24px 20px;
    text-align: center;
}

.map-loading-title {
    display: block;
    font-size: clamp(20px, 4vw, 30px);
    line-height: 1.2;
    letter-spacing: 0.12em;
    text-shadow: 2px 2px 0 #ffd08a;
}

#mapLoadingStatus {
    min-height: 1.5em;
    margin: 9px 0 5px;
    color: #9a5524;
    font-size: 14px;
    font-weight: 800;
}

.map-loading-runner-track {
    position: relative;
    height: 76px;
    margin: 0 32px -5px;
    border-bottom: 4px dotted #bd6a2f;
}

.map-loading-leader {
    position: absolute;
    bottom: 1px;
    left: var(--map-load-progress);
    width: 58px;
    height: 70px;
    object-fit: contain;
    image-rendering: pixelated;
    transform: translateX(-50%);
    transition: left 120ms linear;
    animation: mapLoadingLeaderWalk 420ms steps(2, end) infinite alternate;
}

.map-loading-progress {
    position: relative;
    height: 24px;
    overflow: hidden;
    border: 4px solid #5b321a;
    border-radius: 2px;
    background: #f1d19b;
    box-shadow: 3px 3px 0 #5b321a;
}

.map-loading-fill {
    display: block;
    width: var(--map-load-progress);
    height: 100%;
    background:
        repeating-linear-gradient(90deg, #f58b35 0 14px, #ffb64f 14px 28px);
    transition: width 120ms linear;
}

.map-loading-percent {
    display: block;
    margin-top: 10px;
    color: #5b321a;
    font-size: 19px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.map-loading-retry {
    margin-top: 12px;
    padding: 8px 16px;
    font-family: inherit;
    font-weight: 900;
    cursor: pointer;
}

.map-loading-retry[hidden] {
    display: none;
}

.map-loading-overlay.is-error .map-loading-progress {
    border-color: #8f2f25;
    box-shadow: 3px 3px 0 #8f2f25;
}

.map-loading-overlay.is-error .map-loading-fill {
    background: #c34b3f;
}

@keyframes mapLoadingLeaderWalk {
    from { margin-bottom: 0; }
    to { margin-bottom: 4px; }
}

@keyframes dialogAdvanceSteps {
    to { transform: translateX(5px); }
}

@keyframes openingQuestionYSpin {
    to { transform: rotateY(360deg); }
}

@keyframes openingQuestionFloat {
    from { margin-top: 0; }
    to { margin-top: -8px; }
}

@keyframes introCharacterFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes jumpQuestionYSpin {
    to { transform: rotateY(360deg); }
}

.pixel-panel,
.map-building-bubble,
.map-label,
.pixel-button {
    border: 3px solid #5b321a;
    border-radius: 4px;
    box-shadow: 4px 4px 0 #5b321a;
    background: #fff7df;
    color: #5b321a;
}

.map-label {
    position: absolute;
    transform: translate(-50%, -50%);
    min-width: max-content;
    padding: calc(3px * var(--label-scale, 1))
        calc(7px * var(--label-scale, 1));
    border-width: calc(3px * var(--label-scale, 1));
    border-radius: calc(4px * var(--label-scale, 1));
    box-shadow:
        calc(4px * var(--label-scale, 1))
        calc(4px * var(--label-scale, 1)) 0 #5b321a;
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: calc(16px * var(--label-scale, 1));
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0.04em;
    white-space: nowrap;
    pointer-events: auto;
}

button.map-label {
    appearance: none;
    cursor: pointer;
}

/* 按下时保留地图定位，避免全局按钮缩放覆盖 translate。 */
button.map-label:active {
    transform: translate(-50%, -50%);
}

.map-building-bubble:active {
    transform: translate(-50%, -100%) scale(var(--bubble-scale, 1));
}

.map-bubble-edge:active {
    transform: translate(-50%, -50%);
}

.opening-question:active {
    transform: translate(-50%, -100%);
}

button.map-label:hover,
button.map-label:focus-visible {
    color: #fff;
    background: #e56820;
    outline: 3px solid #fff7df;
    outline-offset: 2px;
}

.map-label.is-road,
.map-label.is-static {
    border-width: calc(2px * var(--label-scale, 1));
    box-shadow:
        calc(2px * var(--label-scale, 1))
        calc(2px * var(--label-scale, 1)) 0 #5b321a;
    background: rgba(255, 247, 223, 0.9);
    font-size: calc(15px * var(--label-scale, 1));
}

.map-label.is-vertical {
    writing-mode: vertical-rl;
    text-orientation: upright;
}

.map-original-fallback .map-labels-layer {
    display: none;
}

.map-building-bubble {
    animation: bubbleFloatSteps 1.2s steps(4, end) infinite alternate;
}

.map-question:not(.opening-question) {
    animation: questionSpinSteps 1s steps(8, end) infinite;
}

@keyframes bubbleFloatSteps {
    from { margin-top: 0; }
    to { margin-top: -8px; }
}

@keyframes questionSpinSteps {
    to { transform: rotate(360deg); }
}

@media (max-width: 768px), (orientation: landscape) and (max-height: 480px) and (max-width: 1024px) {
    .map-label {
        padding: calc(2px * var(--label-scale, 1))
            calc(5px * var(--label-scale, 1));
        font-size: calc(13px * var(--label-scale, 1));
        box-shadow:
            calc(2px * var(--label-scale, 1))
            calc(2px * var(--label-scale, 1)) 0 #5b321a;
    }

    .pixel-panel {
        width: calc(100vw - 24px);
        max-height: 42vh;
    }

    .opening-question {
        width: 46px;
        height: 46px;
        font-size: 29px;
        line-height: 38px;
    }

    .map-intro-dialog {
        bottom: 16px;
        width: calc(100% - 24px);
        min-height: 106px;
        padding: 14px 38px 14px 16px;
    }

    .map-guide-card {
        width: min(270px, calc(100% - 24px));
        min-height: 88px;
        padding: 12px 13px 9px;
        font-size: 14px;
    }

    .map-building-bubble {
        min-width: 70px;
        min-height: 58px;
        padding: 6px;
        font-size: 12px;
        transform: translate(-50%, -100%) scale(0.68);
        transform-origin: 50% 100%;
    }

    .map-building-bubble:active {
        transform: translate(-50%, -100%) scale(0.68);
    }

    .map-department-bubble,
    .map-building-bubble.is-mystery {
        width: 132px;
        min-width: 132px;
        max-width: 132px;
        height: 78px;
        min-height: 78px;
    }

    .map-mystery-mascot {
        width: 46px;
        height: 66px;
    }

    .map-jump-bubble {
        width: 110px;
        min-width: 110px;
        max-width: 110px;
        height: 68px;
        min-height: 68px;
    }

    .map-department-bubble-icon {
        width: 34px;
        height: 34px;
    }

    .map-department-panel {
        bottom: 16px;
        width: calc(100% - 24px);
        max-height: 46vh;
        padding: 13px 44px 13px 14px;
    }

    .map-gameplay-intro-card {
        width: calc(100vw - 24px);
        max-height: 74vh;
        padding: 18px 14px 14px;
    }

}

@media (prefers-reduced-motion: reduce) {
    .map-world.is-camera-animating {
        transition: none;
    }

    .opening-question,
    .opening-question-mark,
    .map-building-bubble,
    .map-building-bubble.is-tour-target::before,
    .map-question,
    .map-intro-character,
    .map-dialog-advance {
        animation: none;
    }

    .map-loading-overlay,
    .map-loading-fill,
    .map-loading-leader {
        transition: none;
    }

    .map-loading-leader {
        animation: none;
    }
}

@media (max-width: 768px), (orientation: landscape) and (max-height: 480px) and (max-width: 1024px) {
    body[data-mobile-page="home"] .map-viewer {
        top: env(safe-area-inset-top, 0px);
        bottom: auto;
        /* 旧浏览器不支持 svh 时逐级回退，避免地图查看器塌陷为 0 高（白屏） */
        height: calc(100vh - 62px);
        height: calc(100vh - 62px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        height: calc(100svh - 62px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        --map-dialog-left-gutter: 12px;
        --map-dialog-right-gutter: 110px;
    }
    body[data-mobile-page="home"] .map-controls {
        right: max(10px, env(safe-area-inset-right, 0px));
        bottom: max(10px, env(safe-area-inset-bottom, 0px));
        display: grid;
        grid-template-columns: repeat(2, 44px);
        gap: 6px;
    }
    body[data-mobile-page="home"] .map-controls button,
    body[data-mobile-page="home"] .map-controls a {
        width: 44px;
        height: 44px;
    }
    body[data-mobile-page="home"] .map-view-toggle {
        display: none;
    }
    body[data-mobile-page="home"] .map-utility-bar {
        top: max(8px, env(safe-area-inset-top, 0px));
        right: max(8px, env(safe-area-inset-right, 0px));
        gap: 6px;
    }
    body[data-mobile-page="home"] .map-utility-button {
        min-height: 44px;
        padding: 5px 8px;
        gap: 6px;
        font-size: 12px;
    }
    body[data-mobile-page="home"] .map-utility-copy small {
        font-size: 9px;
    }
    body[data-mobile-page="home"] .map-intro-dialog,
    body[data-mobile-page="home"] .map-department-panel {
        left: var(--map-dialog-left-gutter);
        right: var(--map-dialog-right-gutter);
        bottom: max(10px, env(safe-area-inset-bottom, 0px));
        width: auto;
        transform: none;
    }
}
