/* ─── OVERWORLD HERO ────────────────────────────────────────
   A parallax pixel scene on the home page. Every layer is drawn at
   2x (one art pixel = 2 CSS px). The sky follows the visitor's
   local time: dawn, day, dusk, night.
   ────────────────────────────────────────────────────────── */

.overworld {
    --shift: 0px;          /* pointer parallax, set by overworld.js */
    --lift: 0px;           /* scroll parallax, set by overworld.js */
    position: relative;
    box-sizing: border-box;
    width: 97%;
    max-width: 1500px;
    height: 300px;
    margin: 0 auto 1.5%;
    overflow: hidden;
    border: 4px solid var(--fp-frame);
    border-radius: 7px;
    box-shadow:
        0 0 0 2px var(--fp-frame-dark),
        5px 5px 0 0 rgba(5, 7, 28, 0.55);
    background: linear-gradient(180deg, #3f6fd6 0%, #7fb4f0 60%, #b9e0ff 100%);
    image-rendering: pixelated;
    isolation: isolate;
}

.overworld[data-time="dawn"]  { background: linear-gradient(180deg, #2f3d8f 0%, #b77aa8 55%, #ffc08a 100%); }
.overworld[data-time="dusk"]  { background: linear-gradient(180deg, #1f2468 0%, #9c4f86 50%, #ff9a6a 100%); }
.overworld[data-time="night"] { background: linear-gradient(180deg, #05071c 0%, #10164a 60%, #1d2a6e 100%); }

.ow-layer {
    position: absolute;
    left: -60px;
    right: -60px;
    background-repeat: repeat-x;
    pointer-events: none;
    will-change: transform;
}

.ow-stars {
    top: 0;
    height: 180px;
    background-image: url('images/scene/layer-stars.png');
    background-size: 400px 180px;
    opacity: 0;
    transition: opacity 1s;
}
.overworld[data-time="night"] .ow-stars { opacity: 1; }
.overworld[data-time="dawn"] .ow-stars  { opacity: 0.35; }

.ow-orb {
    position: absolute;
    width: 48px;
    height: 48px;
    background: url('images/scene/sun.png') center / 48px 48px no-repeat;
    left: var(--orb-x, 70%);
    top: var(--orb-y, 30px);
    filter: drop-shadow(0 0 10px rgba(255, 210, 63, 0.6));
    pointer-events: none;
}
.overworld[data-time="night"] .ow-orb {
    width: 44px;
    height: 44px;
    background-image: url('images/scene/moon.png');
    background-size: 44px 44px;
    filter: drop-shadow(0 0 10px rgba(220, 230, 255, 0.5));
}

.ow-clouds {
    top: 14px;
    height: 96px;
    background-image: url('images/scene/layer-clouds.png');
    background-size: 800px 96px;
    animation: owDrift 140s linear infinite;
    opacity: 0.95;
    transform: translate3d(calc(var(--shift) * 0.1), 0, 0);
}
.overworld[data-time="night"] .ow-clouds { opacity: 0.35; }

@keyframes owDrift {
    from { background-position-x: 0; }
    to   { background-position-x: -800px; }
}

.ow-mountains {
    bottom: 92px;
    height: 160px;
    background-image: url('images/scene/layer-mountains.png');
    background-size: 640px 160px;
    background-position: 0 bottom;
    transform: translate3d(calc(var(--shift) * 0.25), calc(var(--lift) * 0.2), 0);
}

.ow-hills {
    bottom: 64px;
    height: 128px;
    background-image: url('images/scene/layer-hills.png');
    background-size: 640px 128px;
    background-position: 120px bottom;
    transform: translate3d(calc(var(--shift) * 0.5), calc(var(--lift) * 0.4), 0);
}

.ow-castle {
    position: absolute;
    right: 16%;
    bottom: -14px;
    width: 160px;
    height: 128px;
    image-rendering: pixelated;
}

.ow-ground {
    bottom: 0;
    height: 80px;
    background-image: url('images/scene/layer-ground.png');
    background-size: 128px 80px;
    transform: translate3d(var(--shift), 0, 0);
}

/* time-of-day colour grade: per-channel multiply (SVG filters in index.html),
   applied to the landscape and the wizard only, so the sky, stars and moon stay bright */
.overworld[data-time="dawn"] :is(.ow-mountains, .ow-hills, .ow-ground, .ow-sprite)  { filter: url(#ow-grade-dawn); }
.overworld[data-time="dusk"] :is(.ow-mountains, .ow-hills, .ow-ground, .ow-sprite)  { filter: url(#ow-grade-dusk); }
.overworld[data-time="night"] :is(.ow-mountains, .ow-hills, .ow-ground, .ow-sprite) { filter: url(#ow-grade-night); }

/* fireflies, night only */
.ow-fly {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #fff6a0;
    box-shadow: 0 0 6px 2px rgba(255, 240, 120, 0.7);
    z-index: 7;
    opacity: 0;
    display: none;
    pointer-events: none;
    animation: owFly 4s ease-in-out infinite;
}
.overworld[data-time="night"] .ow-fly,
.overworld[data-time="dusk"] .ow-fly { display: block; }
.ow-fly:nth-of-type(1) { left: 12%; bottom: 96px;  animation-delay: 0s; }
.ow-fly:nth-of-type(2) { left: 38%; bottom: 120px; animation-delay: 1.3s; }
.ow-fly:nth-of-type(3) { left: 57%; bottom: 90px;  animation-delay: 2.1s; }
.ow-fly:nth-of-type(4) { left: 71%; bottom: 140px; animation-delay: 0.7s; }
.ow-fly:nth-of-type(5) { left: 88%; bottom: 104px; animation-delay: 2.8s; }

@keyframes owFly {
    0%, 100% { opacity: 0;   transform: translate(0, 0); }
    30%      { opacity: 1; }
    50%      { opacity: 0.8; transform: translate(10px, -12px); }
    70%      { opacity: 1; }
}

/* ─── location plate ─────────────────────────────────────── */
.ow-plate {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 9;
    padding: 10px 14px 8px;
    background-image: linear-gradient(180deg, var(--fp-window) 0%, var(--fp-window-2) 100%);
    border: 3px solid var(--fp-frame);
    border-radius: 5px;
    box-shadow: 0 0 0 2px var(--fp-frame-dark), 3px 3px 0 0 rgba(5, 7, 28, 0.5);
}
.ow-plate-title {
    margin: 0;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--fp-gold);
    text-shadow: 2px 2px 0 var(--fp-shadow);
    letter-spacing: 1px;
}
.ow-plate-sub {
    margin: 4px 0 0;
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--fp-text-muted);
}

/* ─── the wizard ─────────────────────────────────────────── */
.ow-wizard {
    position: absolute;
    left: var(--wiz-x, 18%);
    bottom: 22px;
    width: 184px;
    height: 184px;
    margin-left: -92px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: var(--cursor-hand);
    z-index: 8;
    -webkit-tap-highlight-color: transparent;
}
.ow-wizard:focus-visible { outline: 3px dashed var(--fp-gold); outline-offset: -20px; }

.ow-sprite {
    display: block;
    width: 184px;
    height: 184px;
    background-repeat: no-repeat;
    image-rendering: pixelated;
    filter: drop-shadow(0 4px 0 rgba(5, 7, 28, 0.35));
}

.ow-wizard[data-anim="walk"] .ow-sprite {
    background-image: url('images/scene/wizard-walk.png');
    background-size: 1104px 184px;
    animation: owWalk 0.72s steps(6) infinite;
}
.ow-wizard[data-anim="idle"] .ow-sprite {
    background-image: url('images/scene/wizard-idle.png');
    background-size: 736px 184px;
    animation: owIdle 1.4s steps(4) infinite;
}
.ow-wizard[data-anim="cast"] .ow-sprite {
    background-image: url('images/scene/wizard-cast.png');
    background-size: 1104px 184px;
    animation: owCast 0.66s steps(6) 1 forwards;
}
@keyframes owWalk { to { background-position-x: -1104px; } }
@keyframes owIdle { to { background-position-x: -736px; } }
@keyframes owCast { to { background-position-x: -1104px; } }

.ow-wizard.is-entering { transition: left 2.6s linear; }

/* the spell */
.ow-fireball {
    position: absolute;
    width: 52px;
    height: 28px;
    background: url('images/scene/fireball.png') center / 52px 28px no-repeat;
    image-rendering: pixelated;
    z-index: 8;
    pointer-events: none;
    opacity: 0;
    filter: drop-shadow(0 0 8px rgba(255, 160, 60, 0.9));
}
.ow-fireball.is-flying {
    opacity: 1;
    transition: left 0.9s cubic-bezier(.3, .1, .6, 1), bottom 0.9s ease-out;
}
.ow-burst {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--fp-gold);
    box-shadow:
        -22px 0 0 var(--fp-gold), 22px 0 0 var(--fp-gold),
        0 -22px 0 var(--fp-gold), 0 22px 0 var(--fp-gold),
        -15px -15px 0 #ff8f5a, 15px -15px 0 #ff8f5a,
        -15px 15px 0 #ff8f5a, 15px 15px 0 #ff8f5a;
    z-index: 8;
    pointer-events: none;
    animation: owBurst 0.5s steps(5) forwards;
}
@keyframes owBurst {
    from { transform: scale(0.4); opacity: 1; }
    to   { transform: scale(1.8); opacity: 0; }
}

/* ─── speech bubble (JRPG text box) ─────────────────────── */
.ow-bubble {
    position: absolute;
    left: calc(var(--wiz-x, 18%) + 40px);
    bottom: 186px;
    z-index: 10;
    max-width: min(340px, 62%);
    min-height: 1.2em;
    padding: 10px 30px 10px 14px;
    background-image: linear-gradient(180deg, var(--fp-window) 0%, var(--fp-window-2) 100%);
    border: 3px solid var(--fp-frame);
    border-radius: 5px;
    box-shadow: 0 0 0 2px var(--fp-frame-dark), 3px 3px 0 0 rgba(5, 7, 28, 0.5);
    font-family: 'VT323', monospace;
    font-size: 1.35rem;
    line-height: 1.15;
    color: var(--fp-text);
    text-align: left;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}
.ow-bubble.is-open { opacity: 1; transform: none; }
.ow-bubble::after {
    content: '▼';
    position: absolute;
    right: 10px;
    bottom: 6px;
    font-size: 0.8rem;
    color: var(--fp-gold);
    animation: owNext 0.8s steps(2) infinite;
}
@keyframes owNext { 50% { transform: translateY(3px); } }

.ow-hint {
    position: absolute;
    right: 14px;
    bottom: 10px;
    z-index: 9;
    margin: 0;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5rem;
    color: var(--fp-frame);
    text-shadow: 2px 2px 0 var(--fp-shadow);
    letter-spacing: 1px;
}

/* ─── small screens ──────────────────────────────────────── */
@media screen and (max-width: 768px) {
    .overworld { width: 94%; height: 330px; margin-bottom: 24px; }
    .ow-castle { right: 2%; }
    .ow-plate { top: 10px; left: 10px; padding: 8px 10px 6px; }
    .ow-plate-title { font-size: 0.6rem; }
    .ow-bubble { left: auto; right: 10px; max-width: 58%; bottom: 168px; font-size: 1.25rem; }
    .ow-hint { display: none; }
}
@media screen and (min-width: 768px) and (max-width: 1280px) {
    .overworld { width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
    .ow-clouds, .ow-fly, .ow-bubble::after { animation: none; }
    .ow-wizard[data-anim="idle"] .ow-sprite,
    .ow-wizard[data-anim="walk"] .ow-sprite { animation: none; }
    .ow-wizard.is-entering { transition: none; }
}

.ow-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
