/* STORY MODE (Phase A): the world is the stage; this is only the frame.
   Loaded sitewide next to widget.css; everything namespaced story-*. */

html[data-story] {
    overflow: hidden; /* the camera owns the scroll */
}
html[data-story] .widget-wrapper {
    display: none; /* the pocket steps out while the story plays */
}

.story-stage {
    position: fixed;
    inset: 0;
    z-index: 90;
    pointer-events: none;
}

.story-bar-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: max(24px, env(safe-area-inset-top, 0px));
    background: #04030d;
    animation: storyBarIn 0.6s ease both;
}
@keyframes storyBarIn {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

.story-exit {
    position: absolute;
    top: max(30px, calc(env(safe-area-inset-top, 0px) + 8px));
    right: 14px;
    width: 38px;
    height: 38px;
    pointer-events: auto;
    background: rgba(4, 3, 13, 0.72);
    border: 2px solid rgba(246, 231, 198, 0.5);
    border-radius: 4px;
    color: #f6e7c6;
    font-size: 15px;
    cursor: pointer;
}

.story-box {
    position: absolute;
    left: 50%;
    bottom: max(14px, env(safe-area-inset-bottom, 0px));
    translate: -50% 0;
    width: min(720px, calc(100vw - 20px));
    display: flex;
    align-items: flex-start;
    gap: 10px;
    pointer-events: auto;
    cursor: pointer;
    animation: storyBoxIn 0.5s cubic-bezier(0.2, 1.2, 0.4, 1) both;
}
@keyframes storyBoxIn {
    from { opacity: 0; transform: translateY(26px); }
    to { opacity: 1; transform: translateY(0); }
}

.story-portrait {
    flex-shrink: 0;
    width: 92px;
    height: 92px;
    border: 3px solid #fbbf24;
    border-radius: 4px;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.6), inset 0 0 0 2px rgba(0, 0, 0, 0.65);
    background: #0b0c14;
    overflow: hidden;
}
.story-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.story-panel {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 92px;
    margin-top: 7px;
    background: rgba(6, 7, 16, 0.93);
    border: 2px solid rgba(226, 232, 240, 0.8);
    border-radius: 6px;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.6), inset 0 0 0 2px rgba(0, 0, 0, 0.6), inset 0 0 26px rgba(0, 0, 0, 0.4);
    padding: 16px 30px 14px 14px;
}
.story-name {
    position: absolute;
    top: -10px;
    left: 10px;
    margin: 0;
    padding: 2px 9px;
    background: #0b0c14;
    border: 2px solid rgba(226, 232, 240, 0.8);
    border-radius: 4px;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    line-height: 1.6;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.story-text {
    font-family: Inter, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: #e8e6ff;
    min-height: 48px;
}
.story-text .rw {
    display: inline-block;
    opacity: 0;
    transform: translateY(5px);
    animation: storyWord 0.22s ease forwards;
}
@keyframes storyWord {
    to { opacity: 1; transform: none; }
}
.story-text.rw-done .rw {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
}

.story-adv {
    position: absolute;
    right: 10px;
    bottom: 8px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid #fbbf24;
    opacity: 0;
    animation: storyAdv 0.55s ease-in-out infinite alternate;
    pointer-events: none;
}
.story-adv.on { opacity: 1; }
@keyframes storyAdv {
    from { translate: 0 0; }
    to { translate: 0 -4px; }
}

.story-hands {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.story-hand {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: #0b0c14;
    background: #f6e7c6;
    border: 0;
    border-bottom: 3px solid rgba(0, 0, 0, 0.45);
    border-radius: 6px;
    padding: 9px 12px;
    cursor: pointer;
    transition: transform 0.1s ease;
}
.story-hand:hover { transform: translateY(-1px); }
.story-hand:active { transform: translateY(1px); border-bottom-width: 1px; }

/* the trailhead: a quiet sign chip in the scene, postcard-style */
.story-trailhead {
    position: absolute;
    left: 1.5%;
    top: 66%;
    z-index: 26;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    letter-spacing: 0.5px;
    color: #4a2f18;
    background: #f6e7c6;
    border: 2px solid #5a3921;
    border-radius: 2px;
    box-shadow: 2px 2px 0 #2b1a10, inset 0 0 0 1px #e2c795;
    padding: 8px 10px;
    cursor: pointer;
    image-rendering: pixelated;
}
.story-trailhead:hover { translate: 0 -1px; }

@media (max-width: 700px) {
    .story-portrait { width: 64px; height: 64px; }
    .story-text { font-size: 13.5px; }
    .story-trailhead { font-size: 8px; padding: 6px 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .story-bar-top, .story-box { animation: none; }
    .story-adv { animation: none; }
    .story-text .rw { animation: none; opacity: 1; transform: none; }
}
