:root {
    --era-ink: #40584b;
    --era-paper: #e8e1cf;
    --era-accent: #a65f48;
    --era-mist: rgba(120, 152, 138, 0.10);
}

body[data-heritage-era="six-dynasties"] {
    --era-ink: #48685d;
    --era-paper: #d9dfd3;
    --era-accent: #9d6654;
    --era-mist: rgba(91, 137, 121, 0.15);
}

body[data-heritage-era="ming-qing"] {
    --era-ink: #405349;
    --era-paper: #dfd3bc;
    --era-accent: #9b5342;
    --era-mist: rgba(151, 105, 73, 0.13);
}

body[data-heritage-era="republican"] {
    --era-ink: #526673;
    --era-paper: #ded9ca;
    --era-accent: #7b6257;
    --era-mist: rgba(91, 121, 137, 0.13);
}

.heritage-atmosphere {
    position: absolute;
    z-index: 7;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 20% 76%, color-mix(in srgb, var(--era-accent) 12%, transparent), transparent 31%),
        radial-gradient(circle at 76% 24%, var(--era-mist), transparent 36%);
    opacity: 0.72;
    transition: background 1200ms ease, opacity 800ms ease;
}

.heritage-texture-canvas {
    position: absolute;
    z-index: 8;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    mix-blend-mode: multiply;
    transition: opacity 900ms cubic-bezier(0.16, 1, 0.3, 1);
    will-change: opacity;
}

.heritage-texture-canvas.is-visible {
    opacity: 0.58;
}

.heritage-poi-marker {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    transform: translate(-8px, -8px);
    white-space: nowrap;
    pointer-events: auto;
    cursor: pointer;
    color: var(--era-ink);
    border: 0;
    background: transparent;
    font-family: 'Noto Serif SC', serif;
    isolation: isolate;
}

.heritage-poi-signal {
    position: absolute;
    z-index: 0;
    left: 10px;
    top: 10px;
    width: 68px;
    height: 68px;
    pointer-events: none;
    border: 1px solid color-mix(in srgb, var(--era-accent) 62%, transparent);
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--era-accent) 18%, transparent) 0 18%, transparent 62%);
    transform: translate(-50%, -50%) scale(0.35);
    opacity: 0;
}

.heritage-poi-signal::after {
    content: '';
    position: absolute;
    inset: 10px;
    border: 1px dashed color-mix(in srgb, var(--era-ink) 42%, transparent);
    border-radius: 50%;
}

.heritage-poi-seal {
    position: relative;
    z-index: 1;
    width: 21px;
    height: 21px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: #fffaf0;
    border: 1px solid rgba(255, 250, 240, 0.72);
    border-radius: 4px;
    background: var(--era-accent);
    box-shadow: 0 2px 8px rgba(71, 55, 42, 0.22);
    transform: rotate(-5deg);
}

.heritage-poi-seal::after {
    content: '';
    width: 5px;
    height: 5px;
    border: 1px solid currentColor;
    border-radius: 50%;
}

.heritage-poi-label {
    position: relative;
    z-index: 1;
    max-width: 150px;
    overflow: hidden;
    padding: 5px 9px;
    border: 1px solid color-mix(in srgb, var(--era-ink) 22%, transparent);
    border-radius: 4px 10px 10px 4px;
    background: color-mix(in srgb, var(--era-paper) 88%, transparent);
    box-shadow: 0 4px 14px rgba(62, 55, 44, 0.12);
    text-overflow: ellipsis;
    display: grid;
    gap: 1px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
}

.heritage-poi-kicker {
    color: var(--era-accent);
    font-family: system-ui, sans-serif;
    font-size: 0.48rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    line-height: 1.1;
}

.heritage-poi-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.heritage-poi-marker.is-entering .heritage-poi-signal {
    animation: heritage-clue-reveal 1500ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.heritage-poi-marker.is-entering .heritage-poi-seal {
    animation: heritage-seal-arrival 1100ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes heritage-seal-arrival {
    0% { opacity: 0; transform: rotate(-18deg) scale(0.3); box-shadow: 0 0 0 0 color-mix(in srgb, var(--era-accent) 30%, transparent); }
    55% { opacity: 1; transform: rotate(-3deg) scale(1.16); box-shadow: 0 0 0 13px transparent; }
    100% { transform: rotate(-5deg) scale(1); }
}

@keyframes heritage-clue-reveal {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.25) rotate(-10deg); }
    24% { opacity: 0.82; }
    72% { opacity: 0.48; transform: translate(-50%, -50%) scale(1.08) rotate(5deg); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.45) rotate(10deg); }
}

.heritage-scene-capsule {
    position: relative;
    --scene-scale: 1;
    --scene-phase: 0;
    width: 68px;
    height: 92px;
    display: grid;
    place-items: end center;
    padding: 0;
    cursor: pointer;
    color: var(--era-ink);
    border: 0;
    background: transparent;
    font-family: 'Noto Serif SC', serif;
    filter: drop-shadow(0 8px 12px rgba(63, 53, 41, 0.18));
    transform-origin: 50% 100%;
    scale: var(--scene-scale);
    will-change: opacity, transform, filter;
}

.heritage-capsule-halo {
    position: absolute;
    z-index: 0;
    left: 50%;
    bottom: 18px;
    width: 60px;
    height: 60px;
    border: 1px solid color-mix(in srgb, var(--era-accent) 24%, transparent);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(249, 245, 232, 0.88) 0 36%, rgba(249, 245, 232, 0.42) 60%, transparent 73%);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transform: translateX(-50%);
}

.heritage-capsule-halo::after {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1px dashed color-mix(in srgb, var(--era-ink) 25%, transparent);
    border-radius: 50%;
}

.heritage-capsule-image {
    position: absolute;
    z-index: 1;
    left: 50%;
    bottom: 18px;
    width: 62px;
    height: 72px;
    object-fit: contain;
    object-position: center bottom;
    transform: translateX(-50%);
}

.heritage-scene-capsule.is-prop .heritage-capsule-image {
    width: 66px;
    height: 68px;
    bottom: 24px;
}

.heritage-scene-capsule.is-architecture .heritage-capsule-image {
    width: 74px;
    height: 66px;
    bottom: 22px;
}

.heritage-scene-capsule.is-nearby {
    opacity: 0.90;
}

.heritage-capsule-caption {
    position: relative;
    z-index: 2;
    min-width: 66px;
    display: grid;
    gap: 1px;
    padding: 4px 7px 5px;
    border: 1px solid color-mix(in srgb, var(--era-ink) 18%, transparent);
    border-left: 3px solid var(--era-accent);
    border-radius: 3px 9px 9px 3px;
    background: rgba(249, 246, 236, 0.90);
    box-shadow: 0 3px 10px rgba(65, 57, 45, 0.13);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.heritage-capsule-label {
    white-space: nowrap;
    font-size: 0.58rem;
    font-weight: 800;
    line-height: 1.15;
}

.heritage-capsule-direction {
    max-width: 96px;
    overflow: hidden;
    white-space: nowrap;
    color: var(--era-accent);
    font-family: system-ui, sans-serif;
    font-size: 0.43rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-overflow: ellipsis;
}

.heritage-scene-capsule.is-arriving {
    animation: heritage-capsule-arrive 900ms cubic-bezier(0.16, 1, 0.3, 1) both;
    animation-delay: calc(var(--scene-phase) * 45ms);
}

.heritage-scene-capsule.is-departing {
    pointer-events: none;
    animation: heritage-capsule-depart 1000ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

.heritage-scene-capsule:hover,
.heritage-scene-capsule:focus-visible {
    filter: drop-shadow(0 10px 16px rgba(63, 53, 41, 0.25));
    transform: translateY(-3px) scale(1.04);
}

@keyframes heritage-capsule-arrive {
    0% { opacity: 0; transform: translateY(16px) scale(0.72); filter: blur(5px); }
    62% { opacity: 1; transform: translateY(-3px) scale(1.05); filter: blur(0); }
    100% { transform: translateY(0) scale(1); filter: blur(0); }
}

@keyframes heritage-capsule-depart {
    0% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
    65% { opacity: 0.32; transform: translateY(-3px) scale(0.97); filter: blur(1.4px); }
    100% { opacity: 0; transform: translateY(-7px) scale(0.92); filter: blur(4px); }
}

.story-branch-modal {
    position: fixed;
    z-index: 1200;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(49, 54, 48, 0.28);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 260ms ease, visibility 0s linear 260ms;
}

.story-branch-modal.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
}

.story-branch-card {
    width: min(88vw, 420px);
    padding: 20px;
    border: 1px solid rgba(69, 83, 73, 0.18);
    border-left: 4px solid var(--era-accent);
    border-radius: 6px 18px 18px 6px;
    background: rgba(247, 243, 232, 0.96);
    box-shadow: 0 22px 62px rgba(45, 43, 36, 0.24);
    transform: translateY(15px) scale(0.97);
    transition: transform 360ms cubic-bezier(0.16, 1, 0.3, 1);
}

.story-branch-modal.is-open .story-branch-card {
    transform: translateY(0) scale(1);
}

.story-branch-eyebrow {
    color: var(--era-accent);
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.16em;
}

.story-branch-title {
    margin: 8px 0 6px;
    color: #35483e;
    font-family: 'Noto Serif SC', serif;
    font-size: 1.05rem;
}

.story-branch-copy {
    margin: 0 0 14px;
    color: #756c5d;
    font-size: 0.78rem;
    line-height: 1.6;
}

.story-branch-options {
    display: grid;
    gap: 8px;
}

.story-branch-option,
.story-branch-skip {
    width: 100%;
    padding: 11px 13px;
    cursor: pointer;
    text-align: left;
    color: #3e5549;
    border: 1px solid rgba(64, 83, 73, 0.16);
    border-radius: 10px;
    background: rgba(255, 253, 246, 0.84);
    font-family: 'Noto Serif SC', serif;
}

.story-branch-option:hover {
    border-color: color-mix(in srgb, var(--era-accent) 50%, transparent);
    background: #fffdf6;
}

.story-branch-skip {
    margin-top: 6px;
    padding: 8px 13px;
    text-align: center;
    color: #82796a;
    border: 0;
    background: transparent;
    font-family: inherit;
    font-size: 0.72rem;
}

.journey-strip {
    position: absolute;
    z-index: 98;
    left: 14px;
    bottom: calc(max(30px, calc(env(safe-area-inset-bottom) + 24px)) + clamp(108px, 15vh, 150px) + 12px);
    width: min(46vw, 430px);
    min-height: 48px;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 7px 9px;
    overflow-x: auto;
    border: 1px solid rgba(70, 88, 77, 0.16);
    border-radius: 7px 16px 16px 7px;
    background: rgba(246, 242, 231, 0.84);
    box-shadow: 0 8px 24px rgba(69, 61, 47, 0.13);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.journey-strip.has-items {
    display: flex;
}

.journey-strip-title {
    flex: 0 0 auto;
    padding: 0 4px;
    color: var(--era-ink);
    font-family: 'Noto Serif SC', serif;
    font-size: 0.64rem;
    font-weight: 700;
    line-height: 1.3;
}

.journey-thumb {
    position: relative;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    overflow: hidden;
    padding: 0;
    cursor: pointer;
    border: 2px solid rgba(255, 251, 239, 0.94);
    border-radius: 7px;
    background: #d9d2c2;
    box-shadow: 0 2px 8px rgba(64, 55, 43, 0.18);
}

.journey-thumb img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.journey-map-marker {
    width: 34px;
    height: 34px;
    overflow: hidden;
    padding: 0;
    cursor: pointer;
    border: 2px solid #fff8e8;
    border-radius: 7px 7px 7px 2px;
    background: var(--era-paper);
    box-shadow: 0 4px 13px rgba(59, 51, 41, 0.28);
    transform: rotate(-3deg);
}

.journey-map-marker.imagine-anchor {
    display: grid;
    place-items: center;
    color: #fff8e8;
    border-color: rgba(255, 248, 232, 0.95);
    background: color-mix(in srgb, var(--era-accent) 78%, #4a5e53);
}

.imagine-anchor-core {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 0 rgba(255, 248, 232, 0.62);
    animation: imagine-developing 1.4s ease-out infinite;
}

.journey-map-marker.is-memory {
    animation: memory-arrive 680ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.journey-map-marker.is-failed {
    color: #fff;
    background: #8b5549;
}

@keyframes imagine-developing {
    0% { box-shadow: 0 0 0 0 rgba(255, 248, 232, 0.62); opacity: 1; }
    100% { box-shadow: 0 0 0 15px rgba(255, 248, 232, 0); opacity: 0.7; }
}

@keyframes memory-arrive {
    0% { opacity: 0; transform: translateY(8px) scale(0.62) rotate(-9deg); }
    100% { opacity: 1; transform: translateY(0) scale(1) rotate(-3deg); }
}

.journey-map-marker img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.journey-toggle.active {
    color: #fffaf0;
    background: var(--era-accent);
}

.journey-toggle.is-busy i {
    animation: fa-spin 1.2s linear infinite;
}

@media (max-width: 520px) {
    .heritage-poi-label {
        max-width: 116px;
        font-size: 0.61rem;
    }

    .journey-strip {
        right: 86px;
        width: auto;
        bottom: calc(max(30px, calc(env(safe-area-inset-bottom) + 24px)) + clamp(102px, 14vh, 132px) + 10px);
    }

    .journey-strip-title {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .heritage-poi-marker.is-entering .heritage-poi-seal {
        animation: none;
    }
}
