#stack-dialog {
  --sg-ink: #304535;
  --sg-paper: #fffbee;
  width: min(750px, calc(100% - 30px)); max-width: none; max-height: min(94dvh, 850px);
  padding: 0; overflow: auto; overscroll-behavior: contain;
  border: 2px solid #2f4233; border-radius: 7px; color: var(--sg-ink);
  background: var(--sg-paper); box-shadow: 5px 6px 0 #293a2c;
}
#stack-dialog::backdrop { background: #142c27a8; }
#stack-dialog [hidden] { display: none !important; }
#stack-dialog svg { width: 1.18em; height: 1.18em; display: inline-block; flex: none; }
.sg-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 13px 9px 17px; color: #fffbe4; background: #354c3b; border-bottom: 2px solid #293f32; }
.sg-heading h2 { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 20px; line-height: 1.25; letter-spacing: .045em; }
.sg-heading h2 svg { color: #c5e899; }
.sg-close { display: grid; place-items: center; min-width: 35px; min-height: 33px; border: 1px solid #8d9e80; border-radius: 3px; background: #47614a; color: #fffdea; }
.sg-close:hover { background: #5c7658; }
.sg-stage { display: block; isolation: isolate; container-type: size; position: relative; width: 100%; height: clamp(298px, 53dvh, 425px); overflow: hidden; padding: 0; border: 0; border-bottom: 2px solid var(--sg-ink); border-radius: 0; cursor: pointer; background: #a5b89b; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.sg-stage:focus-visible { outline: 3px dashed #fff2a4; outline-offset: -5px; }
.sg-landscape, .sg-world { position: absolute; inset: 0; pointer-events: none; }
.sg-landscape { overflow: hidden; background: #a5b89b; }
/* Crop the preset image and the assembled layers through the same filter-side window. */
.sg-image { display: block; position: absolute; top: 85%; left: 50%; width: max(var(--sg-image-width), var(--sg-image-min)); aspect-ratio: 16/9; transform: translate(var(--sg-image-x), var(--sg-image-y)); background: center / 100% 100% no-repeat; }
.sg-image > .build-scene { width: 100%; height: 100%; }
.sg-landscape::after { content: ''; position: absolute; inset: 0; background: linear-gradient(115deg,#e2e8ce0e,#e4e8cb27 55%,#eff0d31a); }
.sg-world { display: block; }
.sg-world > *, .sg-turtle { position: absolute; }
.sg-hud { position: absolute; z-index: 4; top: 13px; left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; text-align: left; pointer-events: none; }
.sg-score, .sg-record { display: inline-flex; align-items: center; gap: 6px; min-height: 33px; padding: 5px 9px; color: #344732; font: 750 13px/1 var(--sans, sans-serif); background: #fff9deed; border: 1.5px solid #516947; border-radius: 4px; box-shadow: 2px 2px 0 #516b4cb5; }
.sg-score svg { color: #60734e; } .sg-record svg { color: #997223; }
.sg-hud b { font: 800 20px/1 var(--mono, monospace); }
.sg-hud small { font-size: 12px; color: #617355; }
.sg-rock { z-index: 1; display: block; aspect-ratio: 544/119; transform: translateX(-50%); }
.sg-rock img { display: none; width: 100%; height: 100%; object-fit: contain; }
.sg-rock.sg-textured img { display: block; } .sg-rock.sg-textured .sg-rock-fallback { display: none; }
.sg-rock-fallback { position: absolute; inset: 7% 0 0; display: block; background: linear-gradient(165deg, transparent 0 30%, #526d55 31% 39%, transparent 40%), linear-gradient(to bottom, #c4cd75 0 9%, #8aa44e 10% 25%, #617f49 26% 34%, #9d9e7d 35% 52%, #7a8a70 53% 75%, #526b5a 76%); clip-path: polygon(8% 0,90% 0, 92% 6%,96% 7%,96% 17%,100% 26%,98% 62%,93% 75%,86% 86%,65% 100%,26% 98%,13% 87%,8% 72%,3% 70%,0 40%,3% 16%); }
.sg-residents { inset: 0; z-index: 2; pointer-events: none; }
.sg-turtle, .sg-held { display: block; line-height: 0; transform: translateX(-43%); transform-origin: 43% 85%; pointer-events: none; }
.sg-sprite { width: 100%; max-width: none; height: auto; display: block; user-select: none; -webkit-user-drag: none; }
.sg-held { z-index: 4; }
.sg-target { z-index: 3; height: 7px; border: 2px solid #fcf6bb; border-top: 0; border-radius: 0 0 3px 3px; transform: translate(-50%, 0); box-shadow: 0 1.5px 0 #3b543ab0; opacity: .88; }
.sg-target.sg-aligned { border-color: #fffaa2; box-shadow: 0 2px 0 #507141; }
.sg-guide { z-index: 3; width: 2px; background: repeating-linear-gradient(to bottom, #fff8d6d9 0 4px, transparent 4px 9px); filter: drop-shadow(1px 0 0 #475d427a); }
.sg-guide::after { content: ''; position: absolute; bottom: -1px; left: -3px; border: 4px solid transparent; border-top-color: #fff5b5; border-bottom-width: 0; }
.sg-guide.sg-aligned { background: repeating-linear-gradient(to bottom, #e8ffa7 0 4px, transparent 4px 9px); }
.sg-stamp { z-index: 5; left: 50%; transform: translateX(-50%); color: #fff9df; background: #476c49; border: 1.5px solid #e7eac2; border-radius: 3px; padding: 5px 12px; font-size: 14px; font-weight: 850; white-space: nowrap; box-shadow: 2px 2px 0 #38523dc9; animation: sg-stamp .9s ease-out both; }
.sg-stamp.sg-perfect { color: #644d22; background: #fcdf88; border-color: #825e25; }
@keyframes sg-stamp { 0% { opacity: 0; transform: translate(-50%, 6px) scale(.86); } 22%,78% { opacity: 1; transform: translate(-50%, -2px) scale(1); } 100% { opacity: 0; transform: translate(-50%, -10px); } }
.sg-end { display: block; }
.sg-end-card { display: grid; grid-template-columns: 35px auto; column-gap: 9px; row-gap: 2px; align-items: center; color: #354634; }
.sg-end-card pixel-art { grid-row: span 2; width: 34px; height: 34px; }
.sg-end-card strong { font-size: 17px; line-height: 1.2; }
.sg-end-card > span { font-size: 12px; color: #53634e; }
.sg-controls.sg-finished { background: #fbf2d8; }
.sg-finished .sg-message, .sg-finished .sg-nudge { display: none; }
.sg-finished .sg-levels { margin-left: 44px; }
.sg-controls { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 14px 16px 16px; background: #f9f7e9; }
.sg-instructions { display: grid; gap: 8px; min-width: 0; }
.sg-message { font-size: 14px; line-height: 1.5; color: #42553f; font-weight: 600; }
.sg-levels { display: flex; gap: 4px; align-items: center; }
.sg-levels i { width: 13px; height: 6px; border: 1px solid #9aab86; background: #e5e9d4; }
.sg-levels i.sg-done { background: #81a55e; border-color: #587643; } .sg-levels i.sg-center { background: #e6bc58; border-color: #a88537; }
.sg-buttons { display: flex; align-items: center; gap: 7px; flex: none; }
.sg-nudge, .sg-drop { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 15px; font-weight: 800; border: 2px solid #495a40; border-radius: 4px; box-shadow: 2px 2px 0 #495a40; color: #364830; cursor: pointer; }
.sg-nudge { width: 39px; background: #eaf0d9; } .sg-drop { padding: 0 11px; min-width: 95px; background: #f3ce74; }
.sg-drop kbd { font: 600 10px/1.2 var(--sans,sans-serif); border: 1px solid #af914d; padding: 2px 4px; border-radius: 2px; background: #ffe6a6; }
.sg-nudge:not(:disabled):hover { background: #dae9bb; } .sg-drop:not(:disabled):hover { background: #f9d98a; }
.sg-nudge:not(:disabled):active, .sg-drop:not(:disabled):active { box-shadow: none; transform: translate(2px,2px); }
@media (max-width: 600px) {
  #stack-dialog { width: calc(100% - 22px); }
  .sg-heading { padding: 8px 10px 8px 12px; } .sg-heading h2 { font-size: 18px; }
  .sg-stage { height: clamp(270px, 46dvh, 380px); }
  .sg-hud { top: 9px; left: 10px; right: 10px; } .sg-score,.sg-record { padding: 4px 6px; min-height: 28px; gap: 4px; font-size: 12px; }
  .sg-hud b { font-size: 17px; } .sg-hud small { font-size: 11px; }
  .sg-controls { flex-wrap: wrap; padding: 11px 12px 14px; gap: 10px; }
  .sg-instructions { width: 100%; gap: 5px; } .sg-message { font-size: 13px; }
  .sg-buttons { width: 100%; } .sg-nudge { width: 45px; } .sg-drop { flex: 1; } .sg-drop kbd { display: none; }
}
@media (max-height: 520px) and (min-width: 570px) {
  .sg-stage { min-height: 190px; height: 55dvh; } .sg-controls { padding: 7px 12px 9px; } .sg-heading { padding-top: 4px; padding-bottom: 4px; }
}
@media (prefers-reduced-motion: reduce) { .sg-stamp { animation: none; } }
