/* 3D layer for the hero demo, loaded last and on the home page only: the Loot Valley diorama and the workspace keyboard.
   CSS 3D transforms only (no canvas, no library). demo.js sets --yaw, --tilt and --pan on #game-scene.
   The flat 2D rules for the same elements still sit in styles.css (shared by every page), so some lines here only reset them. */

/* ---------- Camera ---------- */
.hero-visual .game-scene {
  --yaw: -24deg; --tilt: -22deg; --pan: 0px; --gs: 1.1;
  height: 256px; background: #1b1c39; cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.hero-visual .game-scene.is-dragging { cursor: grabbing; }
.game-scene .game-landscape { inset: 0 auto 0 -15%; width: 130%; transform: translateX(var(--pan)); transition: transform .35s ease-out; }
.game-stage {
  position: absolute; inset: 0; pointer-events: none;
  perspective: 760px; perspective-origin: 50% 30%;
  background: linear-gradient(#0000 55%, #15132be6);
}
.game-orbit, .game-world, .game-sway, .g-box, .g-tree, .c3-origin, .c3-hinge, .coin-bob, .coin-disc { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-style: preserve-3d; }
.game-orbit { left: 50%; top: 63%; }
.game-world {
  /* Undoes the camera rotation, so coins and the light beam always face the viewer. */
  --bb: rotateY(calc(var(--yaw) * -1)) rotateX(calc(var(--tilt) * -1));
  transform: scale3d(var(--gs), var(--gs), var(--gs)) rotateX(var(--tilt)) rotateY(var(--yaw));
  transition: transform .35s ease-out;
}
.is-dragging .game-world, .is-dragging .game-landscape { transition: none; }
.game-sway { animation: g-sway 16s ease-in-out infinite alternate; }
.game-scene.is-paused *, .game-scene.is-dragging .game-sway { animation-play-state: paused !important; }
@keyframes g-sway { from { transform: rotateY(-4deg); } to { transform: rotateY(4deg); } }

/* ---------- Island, trees, rocks, fireflies ---------- */
.g-island {
  position: absolute; left: -150px; top: -150px; width: 300px; height: 300px; border-radius: 50%;
  transform: rotateX(90deg);
  background: radial-gradient(circle, #0007 0 15%, #0000 29%), radial-gradient(circle at 30% 35%, #6f9468, #4a6b4e 55%, #3a5542);
  box-shadow: inset 0 0 0 3px #7fa672;
}
.g-island.rim-a { transform: translateY(8px) rotateX(90deg) scale(.97); background: #5b4636; box-shadow: none; }
.g-island.rim-b { transform: translateY(17px) rotateX(90deg) scale(.86); background: #4a3a30; box-shadow: none; }
.g-island.rim-c { transform: translateY(27px) rotateX(90deg) scale(.68); background: #3b2f2a; box-shadow: none; }
.g-island.rim-d { transform: translateY(38px) rotateX(90deg) scale(.42); background: #2e2524; box-shadow: none; }
.g-tree { transform: translate3d(var(--x), 0, var(--z)) scale(var(--k, 1)); }
.g-tree > i {
  position: absolute; left: -22px; top: -74px; width: 44px; height: 74px;
  clip-path: polygon(50% 0, 100% 80%, 58% 80%, 58% 100%, 42% 100%, 42% 80%, 0 80%);
  background: linear-gradient(#7fb58a, #3f6b53 80%, #5a4030 80%);
}
.g-tree > i + i { transform: rotateY(90deg); background: linear-gradient(#5f9670, #33584a 80%, #493326 80%); }
.tree-a { --x: -112px; --z: -52px; --k: 1.05; }
.tree-b { --x: -64px; --z: -104px; --k: .8; }
.tree-c { --x: 96px; --z: -78px; --k: 1.15; }
.tree-d { --x: 124px; --z: -6px; --k: .7; }
.g-box > i { position: absolute; }
.g-box > .f, .g-box > .b { left: calc(var(--w) / -2); top: calc(var(--h) / -2); width: var(--w); height: var(--h); }
.g-box > .l, .g-box > .r { left: calc(var(--d) / -2); top: calc(var(--h) / -2); width: var(--d); height: var(--h); }
.g-box > .t, .g-box > .u { left: calc(var(--w) / -2); top: calc(var(--d) / -2); width: var(--w); height: var(--d); }
.g-box > .f { transform: translateZ(calc(var(--d) / 2)); }
.g-box > .b { transform: rotateY(180deg) translateZ(calc(var(--d) / 2)); }
.g-box > .l { transform: rotateY(-90deg) translateZ(calc(var(--w) / 2)); }
.g-box > .r { transform: rotateY(90deg) translateZ(calc(var(--w) / 2)); }
.g-box > .t { transform: rotateX(90deg) translateZ(calc(var(--h) / 2)); }
.g-box > .u { transform: rotateX(-90deg) translateZ(calc(var(--h) / 2)); }
.g-rock > i { background: #6c6a7c; }
.g-rock > .l, .g-rock > .b { background: #4d4b5c; }
.g-rock > .r { background: #5b596b; }
.g-rock > .t { background: #8a889b; }
.rock-a { --w: 22px; --h: 13px; --d: 17px; transform: translate3d(-58px, -6.5px, 92px) rotateY(24deg); }
.rock-b { --w: 14px; --h: 9px; --d: 12px; transform: translate3d(108px, -4.5px, 70px) rotateY(-18deg); }
.g-fly {
  position: absolute; left: -2px; top: -2px; width: 4px; height: 4px; border-radius: 50%;
  background: #f5e9a0; box-shadow: 0 0 8px 2px #f5e9a080;
  transform: translate3d(var(--x), var(--y), var(--z));
  animation: g-fly 5s ease-in-out infinite alternate;
}
.fly-a { --x: -96px; --y: -58px; --z: 20px; }
.fly-b { --x: 70px; --y: -84px; --z: -40px; animation-duration: 6.5s; animation-delay: -2s; }
.fly-c { --x: 26px; --y: -40px; --z: 104px; animation-duration: 4.2s; animation-delay: -1s; }
.fly-d { --x: -30px; --y: -96px; --z: -90px; animation-duration: 7s; animation-delay: -3s; }
@keyframes g-fly { to { transform: translate3d(calc(var(--x) + 16px), calc(var(--y) - 18px), calc(var(--z) + 12px)); opacity: .25; } }

/* ---------- Chest ---------- */
.game-scene .game-chest,
.game-scene .game-chest:hover:not(:disabled),
.game-scene .game-chest.macro-target { filter: none; }
.game-scene .game-chest {
  position: absolute; left: -46px; top: -68px; width: 92px; height: 68px; padding: 0; border: 0; background: none;
  overflow: visible; outline: 0; transform: none; transform-style: preserve-3d; pointer-events: auto; cursor: pointer;
}
.game-scene .game-interactive:disabled { cursor: default; }
.c3-origin { left: 46px; top: 68px; }
.c3-base > i, .c3-lid > i, .c3-cap > i {
  --wood: #74422e; --au: #c39143;
  background: linear-gradient(90deg, var(--au) 0 8px, #0000 8px calc(100% - 8px), var(--au) calc(100% - 8px)), repeating-linear-gradient(90deg, #0000 0 13px, #0003 13px 14px), var(--wood);
}
.c3-base > .f, .c3-lid > .f, .c3-cap > .f { --wood: #94583a; --au: #e3b55e; }
.c3-base > .b, .c3-lid > .b, .c3-cap > .b { --wood: #5c3526; --au: #a87c3a; }
.c3-lid > .t, .c3-cap > .t { --wood: #b1713e; --au: #f1cd7c; }
.c3-base { --w: 92px; --h: 44px; --d: 58px; transform: translateY(-22.5px); }
.c3-base > .f, .c3-base > .b, .c3-base > .l, .c3-base > .r { box-shadow: inset 0 3px 0 var(--au), inset 0 -4px 0 #0003; }
.c3-base > .f::after {
  content: ""; position: absolute; left: 50%; top: 0; width: 16px; height: 17px; margin-left: -8px; border-radius: 0 0 5px 5px;
  background: radial-gradient(circle at 50% 45%, #5d4530 0 2.5px, #0000 3px), #f7d68a; box-shadow: inset 0 0 0 2px #60482b;
}
.c3-base > .c3-gold {
  left: -42px; top: -25px; width: 84px; height: 50px; transform: rotateX(90deg) translateZ(11px);
  background: radial-gradient(circle at 28% 40%, #fff6c4 0 5%, #0000 6%), radial-gradient(circle at 66% 62%, #fff6c4 0 4%, #0000 5%), radial-gradient(circle at 80% 30%, #fff6c4 0 3%, #0000 4%), linear-gradient(135deg, #f5cf63, #c18a2a);
}
.c3-hinge { transform: translate3d(0, -45px, -29px); transition: transform .45s cubic-bezier(.34, 1.4, .5, 1); }
.game-chest.is-open .c3-hinge { transform: translate3d(0, -45px, -29px) rotateX(108deg); }
.c3-lid { --w: 96px; --h: 14px; --d: 62px; transform: translate3d(0, -7px, 29px); }
.c3-lid > .u { background: #3b2620; }
.c3-lid > .f::after {
  content: ""; position: absolute; left: 50%; bottom: 0; width: 14px; height: 9px; margin-left: -7px; border-radius: 3px 3px 0 0;
  background: #f7d68a; box-shadow: inset 0 0 0 2px #60482b;
}
.c3-cap { --w: 82px; --h: 8px; --d: 48px; transform: translate3d(0, -18px, 29px); }
.c3-ring {
  position: absolute; left: -72px; top: -72px; width: 144px; height: 144px; border-radius: 50%;
  border: 3px solid #c38bf3; box-shadow: 0 0 18px #c38bf3, inset 0 0 18px #c38bf380;
  transform: translateY(-1px) rotateX(90deg); opacity: 0; transition: opacity .15s;
}
.game-chest:hover:not(:disabled) .c3-ring { opacity: .75; border-color: #f1ca72; box-shadow: 0 0 18px #f1ca72, inset 0 0 18px #f1ca7280; }
.game-chest:focus-visible .c3-ring, .game-chest.macro-target .c3-ring { opacity: 1; }
.c3-beam {
  position: absolute; left: -48px; top: -206px; width: 96px; height: 166px; pointer-events: none;
  transform-origin: 50% 100%; transform: var(--bb);
  clip-path: polygon(30% 100%, 70% 100%, 100% 0, 0 0);
  background: linear-gradient(to top, #ffe9a0b8, #ffe9a000 88%);
  opacity: 0; transition: opacity .35s;
}
.game-chest.is-open .c3-beam { opacity: 1; }

/* ---------- Coins ---------- */
.game-scene .game-coin {
  position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: none;
  overflow: visible; transform-style: preserve-3d; pointer-events: auto; cursor: pointer;
  transform: translate3d(var(--x), -27px, var(--z)) var(--bb);
  animation: coin-pop .55s cubic-bezier(.3, 1.3, .6, 1) 0s backwards;
}
.game-scene .coin-one { --x: -84px; --z: 34px; }
.game-scene .coin-two { --x: 6px; --z: 80px; animation-delay: .07s; }
.game-scene .coin-three { --x: 88px; --z: 26px; animation-delay: .14s; }
.game-coin:focus-visible { outline: 2px solid #c38bf3; outline-offset: 2px; }
.coin-bob { left: 22px; top: 22px; animation: coin-bob 1.8s ease-in-out infinite alternate; }
.coin-disc { animation: coin-spin 2.6s linear infinite; }
.coin-two .coin-bob, .coin-two .coin-disc { animation-delay: -.6s; }
.coin-three .coin-bob, .coin-three .coin-disc { animation-delay: -1.2s; }
.coin-disc > i { position: absolute; left: -15px; top: -15px; width: 30px; height: 30px; border-radius: 50%; background: #a8741f; }
.coin-disc > i:nth-child(1) { transform: translateZ(3px); }
.coin-disc > i:nth-child(2) { transform: translateZ(1.5px); }
.coin-disc > i:nth-child(3) { box-shadow: 0 0 18px 2px #f5c25670; }
.coin-disc > i:nth-child(4) { transform: translateZ(-1.5px); }
.coin-disc > i:nth-child(5) { transform: translateZ(-3px) rotateY(180deg); }
.coin-disc > i:nth-child(1), .coin-disc > i:nth-child(5) {
  display: grid; place-items: center; border: 3px solid #ffe69d;
  background: linear-gradient(135deg, #ffdf80, #c38a26); box-shadow: inset 0 0 0 2px #a86f22;
  color: #83591d; font: normal 15px/1 var(--font);
}
.coin-disc > i:nth-child(1)::after, .coin-disc > i:nth-child(5)::after { content: "✦"; }
.game-coin:hover .coin-disc > i, .game-coin.macro-target .coin-disc > i { filter: brightness(1.25); }
.game-coin.macro-target .coin-disc > i:nth-child(3) { box-shadow: 0 0 22px 6px #c38bf3; }
@keyframes coin-pop {
  0% { transform: translate3d(0, -40px, 0) var(--bb) scale(.2); }
  55% { transform: translate3d(calc(var(--x) * .7), -100px, calc(var(--z) * .7)) var(--bb); }
}
@keyframes coin-bob { from { transform: translateY(-3px); } to { transform: translateY(3px); } }
@keyframes coin-spin { to { transform: rotateY(360deg); } }

/* ---------- Screen-space overlays: macro cursor, +10, labels ---------- */
.game-scene .game-cursor {
  width: 22px; height: 22px; margin: -2px 0 0 -3px; font-size: 0; text-shadow: none;
  filter: drop-shadow(0 2px 3px #000a); transition: transform .32s cubic-bezier(.3, .9, .4, 1), opacity .15s;
}
.game-cursor svg { display: block; width: 100%; height: 100%; }
.game-cursor::after { content: ""; position: absolute; left: -9px; top: -9px; width: 24px; height: 24px; border: 2px solid #fff; border-radius: 50%; opacity: 0; }
.game-cursor.is-clicking::after { animation: g-click .4s ease-out; }
.game-pop {
  position: absolute; z-index: 6; margin: -12px 0 0 -14px; pointer-events: none;
  color: #ffe69d; font: 700 13px/1 var(--font); text-shadow: 0 1px 3px #000c;
  animation: g-pop .75s ease-out forwards;
}
.game-gold.is-bumped strong { display: inline-block; animation: g-bump .35s ease-out; }
.hero-visual .game-level-label, .hero-visual .game-scene-label { font-size: 9px; text-shadow: 0 1px 3px #000c; pointer-events: none; }
.hero-visual .game-scene-label { bottom: 9px; }
.hero-visual .game-bottom { font-size: 10px; }
@keyframes g-click { from { opacity: .9; transform: scale(.3); } to { opacity: 0; transform: scale(1.6); } }
@keyframes g-pop { from { opacity: 0; transform: translateY(4px) scale(.7); } 25% { opacity: 1; transform: translateY(-8px) scale(1.1); } to { opacity: 0; transform: translateY(-34px); } }
@keyframes g-bump { 40% { transform: scale(1.35); color: #fff3c4; } }

/* ---------- Editor: step progress and shortcut keycaps ---------- */
#demo:focus { outline: 0; }
.hero-visual .demo-queue { position: relative; }
.demo-queue li { position: relative; overflow: hidden; }
.demo-queue li.executing::after {
  content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 2px; background: var(--accent);
  transform-origin: 0 50%; animation: q-fill var(--step-ms, .5s) linear both;
}
@keyframes q-fill { from { transform: scaleX(0); } }
.demo-controls kbd { margin-left: 6px; padding: 1px 5px; border: 1px solid currentColor; border-radius: 4px; background: none; color: inherit; font: 600 9px/1.4 var(--font); opacity: .75; }
@media (hover: none), (pointer: coarse) { .demo-controls kbd { display: none; } }

/* ---------- Everyday workflow: message window above a keyboard that follows the typing ---------- */
.hero-visual .target-heading { margin-bottom: 12px; }
.work-stage { perspective: 800px; perspective-origin: 50% 20%; }
.work-screen { padding: 12px; border: 1px solid #34363b; border-radius: 10px; background: linear-gradient(160deg, #1d1e22, #131417); box-shadow: 0 14px 30px -14px #000c; }
.work-screen label { display: block; margin-bottom: 8px; color: #adaeb0; font-size: 10px; }
.hero-visual .work-screen textarea { min-height: 84px; resize: none; }
.target-button { transition: transform .12s, border-color .12s, background .12s; }
.target-button.macro-target { transform: translateY(1px) scale(.985); border-color: #c38bf3; background: #c38bf333; color: #fff; }
.work-deck {
  display: grid; gap: 4px; width: 92%; margin: 12px auto -16px; padding: 8px 10px 11px; border-radius: 8px;
  background: linear-gradient(#222328, #17181b); box-shadow: 0 9px 0 -3px #0b0b0d, 0 26px 30px -16px #000;
  transform: rotateX(46deg); transform-origin: 50% 0; transform-style: preserve-3d;
}
.work-row { display: flex; justify-content: center; gap: 4px; transform-style: preserve-3d; }
.work-key {
  flex: 0 1 9%; display: grid; place-items: center; height: 20px; border-radius: 4px;
  background: linear-gradient(#3a3c42, #2a2b30); box-shadow: 0 3px 0 #101114; color: #b9bbc1; font: 600 8px/1 var(--font);
  transform: translateZ(5px); transition: transform .09s, background .09s, color .09s, box-shadow .09s;
}
.work-key.work-space { flex-basis: 46%; }
.work-key.is-down { transform: translateZ(0); background: #c38bf3; box-shadow: 0 0 12px #c38bf3; color: #2b0355; }

/* ---------- Sizes ---------- */
@media (min-width: 1200px) { .hero-visual .game-scene { --gs: 1; height: 264px; } }
@media (max-width: 540px) { .hero-visual .game-scene { --gs: .84; height: 226px; } }
