/* Human in the Loop: one game frame that fills the box it is given. The slot's size is reserved from viewport units alone, before any
   script runs, so nothing on the page moves when the game starts, changes screen or is refitted. The script measures the slot
   (clientWidth x clientHeight) and draws the frame at a whole number of device pixels per art pixel, centred in it.
   On the embed page (/human-in-the-loop/embed/) the box is the whole viewport. */

/* no sideways overscroll (browser back-swipe) on the game page; the script also sets this at runtime */
html:has(.hl-stage),body:has(.hl-stage){overscroll-behavior-x:none}

/* ---------- the stage: game first on screen, head first in the DOM ---------- */
.hl-stage,.app .hero.tight.hl-stage{padding-top:12px;padding-bottom:28px}
.hl-stage>.in,.hl-stage>.in.wide{display:flex;flex-direction:column;gap:18px;max-width:none;
  padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px))}
.hl-slot{order:1;position:relative;display:grid;place-items:center;box-sizing:border-box;width:100%;overflow:hidden;overflow:clip;overscroll-behavior:auto;
  height:max(420px,calc(100vh - 63px));height:max(420px,calc(100svh - 63px))}
.hl-head{order:2;display:flex;flex-direction:column;gap:14px;align-items:flex-start;width:100%;max-width:1080px;margin:0 auto;box-sizing:border-box}
.hl-stage noscript{order:3}
.app .hero.tight.hl-stage h1,.hl-stage h1{font-size:clamp(26px,3.4vw,40px)}
.hl-keys{margin:0;width:100%;max-width:none;font:500 13px/1.7 var(--mono);color:var(--ink)}
.hl-keys span{display:inline-block;margin-right:18px}
.hl-keys b{display:inline-block;font-weight:500;letter-spacing:.06em;text-transform:uppercase;background:var(--ink);color:var(--paper);padding:1px 8px;border-radius:var(--r-pill);margin-right:4px}

/* landscape windows: the slot is as wide as the page and at most 16:9, never taller than what is left under the site bar */
@media (min-aspect-ratio:1/1) and (min-width:600px){
  .hl-slot{height:min(calc(100vh - 79px),calc((100vw - 32px)*.5625));height:min(calc(100svh - 79px),calc((100vw - 32px)*.5625));min-height:300px}
}
/* portrait windows: a phone held upright. The frame runs edge to edge under the site bar. */
@media not all and (min-aspect-ratio:1/1) and (min-width:600px){
  .hl-stage,.app .hero.tight.hl-stage{padding-top:4px}
  .hl-stage>.in,.hl-stage>.in.wide{padding-left:0;padding-right:0;gap:20px}
  .hl-head,.hl-stage noscript{padding:0 16px}
  .hl-slot{background:#141018;border-bottom:3px solid var(--ink)}
  .hl-keys span{display:block;margin-right:0}
}
/* under about 375px wide the site bar's links wrap it to 64px (52px above), so the slot leaves 69px: bar, 4px of padding, 1px spare */
@media (max-width:374px){.hl-slot{height:max(420px,calc(100vh - 69px));height:max(420px,calc(100svh - 69px))}}
/* a phone on its side (or any very short window): the site bar shrinks to a 32px strip so the field gets the height, and the
   bottom edge keeps clear of the home indicator. Only this page's bar; the links stay, just smaller. */
@media (orientation:landscape) and (max-height:500px){
  body:has(.hl-stage):not(.embed) header.top .in{min-height:32px;gap:12px}
  body:has(.hl-stage):not(.embed) header.top .logo{font-size:20px;padding:4px 2px}
  body:has(.hl-stage):not(.embed) header.top .logo::after{inset:-2px -6px}
  body:has(.hl-stage):not(.embed) header.top nav{gap:2px;margin-right:-8px}
  body:has(.hl-stage):not(.embed) header.top nav a{padding:10px 10px}
  .hl-stage,.app .hero.tight.hl-stage{padding-top:4px}
  .hl-slot{min-height:240px;
    height:calc(100vh - 36px - max(6px,env(safe-area-inset-bottom,0px)));height:calc(100svh - 36px - max(6px,env(safe-area-inset-bottom,0px)))}
}

/* ---------- the frame ---------- */
.hl-frame{position:relative;width:100%;height:100%;flex:none;box-sizing:content-box;background:#141018;border:0;outline:3px solid var(--ink);box-shadow:8px 8px 0 var(--cyan);line-height:0;
  touch-action:manipulation;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}
@media not all and (min-aspect-ratio:1/1) and (min-width:600px){
  .hl-frame{outline-width:0;box-shadow:none}
}
/* Until the script has fitted the frame (it writes the size as an inline style) the frame is not shown, so it is never seen at the
   wrong size. The animation is only a safety net: if the size never arrives, show the frame anyway. */
.hl-frame:not([style]){width:240px;height:240px;visibility:hidden;animation:hl-show 0s linear 4s forwards}
@keyframes hl-show{to{visibility:visible}}
/* The script sizes and measures these at once. The site turns every transition into a .01ms one when the device asks for less
   motion, which would make a measurement read the old box. Nothing here ever transitions or animates. */
.hl-stage,.hl-slot,.hl-frame[style],.hl-frame canvas,.hl-hits,.hl-hits button,.hl-big,.hl-sr,.hl-svh{transition:none!important;animation:none!important}
.hl-frame:focus{outline:3px solid var(--ink)}
.hl-frame:focus-visible{outline:3px solid #ffe033}
.hl-frame canvas{display:block;width:100%;height:100%;image-rendering:pixelated;image-rendering:crisp-edges;
  -webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}

/* Touch: the page scrolls normally with a swipe over the title and the menus, and never pans while you draw.
   The shell adds hl-play to the frame while the screen is play or pause, and only on a change of screen. */
.hl-frame,.hl-frame canvas,.hl-hits button{touch-action:manipulation}
.hl-frame.hl-play,.hl-frame.hl-play canvas,.hl-frame.hl-play .hl-hits button{touch-action:none}
/* The in-post player has nothing to scroll, so a pinch on any screen must never zoom it (in a post it would stay zoomed and crop). */
body.embed,body.embed .hl-frame,body.embed .hl-frame canvas,body.embed .hl-hits button,body.embed .hl-big{touch-action:none!important}

/* ---------- the hit layer: real buttons over drawn controls ---------- */
.hl-hits{position:absolute;inset:0;overflow:hidden;pointer-events:none}
.hl-hits button{position:absolute;margin:0;padding:0;border:0;background:transparent;color:transparent;font-size:0;cursor:pointer;pointer-events:auto;
  -webkit-appearance:none;appearance:none;border-radius:0;-webkit-tap-highlight-color:transparent}
.hl-hits button:disabled{cursor:default}
.hl-hits button[hidden]{display:none}
.hl-hits button:focus{outline:none}
.hl-hits button:focus-visible{outline:2px solid #ffe033;outline-offset:-2px}

/* screen-reader only */
.hl-sr,.hl-hits .hl-sronly{position:absolute;left:0;top:0;width:1px;height:1px;margin:0;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;font-size:16px;line-height:1.2}
/* the viewport probe the shell may add to read svh */
.hl-svh{position:fixed;left:0;top:0;width:0;height:100vh;height:100svh;visibility:hidden;pointer-events:none}

/* ---------- the full-screen control: an <a> inside the frame over the HUD cell; its icon is drawn on the canvas ---------- */
.hl-big{position:absolute;z-index:3;display:none;box-sizing:border-box;margin:0;padding:0;background:transparent;color:transparent;border:0;font-size:0;line-height:0;
  text-decoration:none;cursor:pointer;touch-action:manipulation;-webkit-tap-highlight-color:transparent;overflow:hidden}
.hl-big span{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.hl-big:focus{outline:none}
.hl-big:focus-visible{outline:2px solid #ffe033;outline-offset:-2px}
body.embed .hl-big{display:block}
body.embed .hl-big.off{display:none}

/* ---------- the art contact sheet, appended by #sheet ---------- */
.hl-sheet{display:flex;flex-wrap:wrap;gap:14px;align-items:flex-end;padding:16px 0}
.hl-sheet figure{margin:0;display:flex;flex-direction:column;gap:4px;font:500 11px/1.2 var(--mono)}
.hl-sheet canvas{image-rendering:pixelated;image-rendering:crisp-edges;border:2px solid var(--ink);background:#141018}

/* ---------- the embed page: the game alone, filling the player box exactly, no scroll ---------- */
html:has(body.embed){overflow:hidden;overscroll-behavior:none;background:#141018}
body.embed{margin:0;padding:0;background:#141018;overflow:hidden;overscroll-behavior:none;min-height:100vh;min-height:100svh}
body.embed .embed-main{margin:0;padding:0}
body.embed .hl-stage,body.embed.app .hero.tight.hl-stage,body.embed .hero.first.tight.hl-stage{padding:0!important;margin:0;border:0;background:#141018;min-height:0}
body.embed .hl-stage>.in,body.embed .hl-stage>.in.wide{padding:0;gap:0;margin:0;max-width:none}
body.embed .hl-slot{height:100vh;height:100svh;min-height:0;width:100vw;background:#141018;border:0;place-items:center}
body.embed .hl-frame,body.embed .hl-frame:focus{box-shadow:none;outline:0}
body.embed .hl-frame:focus-visible{outline:2px solid #ffe033;outline-offset:-2px}
body.embed .embed-foot{position:absolute;left:0;top:0;width:1px;height:1px;margin:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
/* the link itself is clipped to its 1px box too, so nothing is ever wider than the player; on keyboard focus it becomes a readable bar along the bottom that wraps to fit even a 300px box */
body.embed .embed-foot a{display:block;width:100%;max-width:100vw;overflow:hidden;box-sizing:border-box}
body.embed .embed-foot:focus-within{position:fixed;left:6px;right:6px;top:auto;bottom:6px;width:auto;height:auto;max-width:calc(100vw - 12px);overflow:visible;clip-path:none;white-space:normal;z-index:20}
body.embed .embed-foot:focus-within a{width:auto;padding:8px 10px;background:#141018;color:#ffe033;border:2px solid #ffe033;font:700 14px/1.3 system-ui,sans-serif;text-align:center;overflow-wrap:break-word;outline:0;text-decoration:underline}
/* kit.js appends a visually hidden live region to the body; pinned to the top so it cannot add a pixel of scroll under the frame */
body.embed>.vh{left:0;top:0;margin:0}
