*{box-sizing:border-box}html,body{margin:0;height:100%;background:#fff;color:#111;font-family:Arial,Helvetica,sans-serif}body{overscroll-behavior:none}
main{position:relative;height:100dvh;display:flex;flex-direction:column;overflow:hidden}header{display:flex;justify-content:space-between;align-items:center;padding:10px 14px 6px;gap:12px}h1{font-size:30px;line-height:1;margin:0 0 3px;font-weight:800}.tagline{font-size:13px;color:#222;margin-bottom:3px}#level,#status,footer{font-size:12px;color:#666}#status{padding:0 14px 7px}.actions{display:flex;gap:5px}button{background:#fff;border:1px solid #111;border-radius:0;padding:8px 11px;font:inherit}button:disabled{opacity:.35}
#viewport{position:relative;flex:1 1 auto;min-height:240px;margin:0 8px;border:0;overflow:hidden;background:#fff;touch-action:none}canvas{position:absolute;inset:0;width:100%;height:100%;image-rendering:pixelated}
footer{height:30px;padding:0 12px;display:flex;align-items:center;justify-content:space-between}#mobileControls{display:none}
@media(max-width:700px),(pointer:coarse){
header{padding:7px 8px 4px}h1{font-size:15px}#level{font-size:10px}.actions button{padding:7px 8px;font-size:12px}#status{padding:3px 8px;font-size:10px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
 #viewport{margin:0 6px}
 footer{display:none}
 #mobileControls{flex:0 0 150px;display:grid;grid-template-columns:minmax(112px,1fr) 140px 42px;gap:8px;align-items:center;padding:6px 8px max(8px,env(safe-area-inset-bottom));touch-action:none}
 .zoom{display:grid;grid-template-columns:1fr 1fr;gap:6px;align-self:end}.zoom button{min-height:42px;padding:5px}.zoom button.active{background:#111;color:#fff}
 #joystick{width:136px;height:136px;border:1px solid #555;border-radius:50%;position:relative;justify-self:center;touch-action:none;background:#fafafa}
 #joystick:before,#joystick:after{content:"";position:absolute;background:#ccc}#joystick:before{width:1px;height:80%;left:50%;top:10%}#joystick:after{height:1px;width:80%;left:10%;top:50%}
 #stick{position:absolute;width:52px;height:52px;border-radius:50%;background:#111;left:42px;top:42px;pointer-events:none}
 #mobileRestart{align-self:end;margin-bottom:5px}
}
.game-settings{display:flex;align-items:center;gap:22px;padding:4px 14px 8px;border-bottom:1px solid #ddd;font-size:12px}
.speed-control{display:flex;align-items:center;gap:7px}.speed-control input[type="range"]{width:180px}.speed-control input[type="number"]{width:58px;padding:5px;border:1px solid #777}
.pal-control{display:flex;align-items:center;gap:6px;white-space:nowrap}
@media(max-width:700px),(pointer:coarse){

 h1{font-size:25px}.tagline{font-size:10px}.brand #level{font-size:9px}
 .game-settings{padding:4px 8px;gap:10px;overflow:hidden}.speed-control{gap:4px}.speed-control input[type="range"]{width:min(26vw,120px)}.speed-control input[type="number"]{width:48px;padding:4px}.speed-control span{display:none}
}

#specimens{font-size:11px;font-weight:700;margin-top:3px;color:#222}
#specimenSwatches{display:inline-flex;gap:3px;vertical-align:middle;align-items:center}
.specimen-swatch{display:inline-block;width:13px;height:13px;border:1px solid #111}
@media(max-width:700px),(pointer:coarse){
  #specimens{font-size:9px;margin-top:2px}
  .zoom{grid-template-columns:repeat(4,1fr)}
  .zoom button{min-height:34px;font-size:11px}
}

.success-screen{position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:rgba(255,255,255,.94);padding:20px}
.success-screen[hidden]{display:none}
.success-card{width:min(560px,100%);text-align:center;background:#fff;border:2px solid #111;padding:24px;margin-top:78px}
.success-card h2{font-size:28px;margin:0 0 10px}
#successWith{width:72px;height:72px;image-rendering:pixelated;display:block;margin:-88px auto 12px}

#leaderboardForm label{display:block;font-weight:700;margin-bottom:7px}
.leaderboard-entry{display:flex;gap:7px}
.leaderboard-entry input{min-width:0;flex:1;border:1px solid #777;padding:9px;font:inherit}
.leaderboard-entry button,#playAgain{border:1px solid #111;background:#fff;padding:9px 12px;font:inherit;font-weight:700;cursor:pointer}
#playAgain{margin-top:14px}
.leaderboard{margin-top:12px;text-align:left;font-size:12px}
.leaderboard ol{margin:6px 0 0;padding-left:28px}
.leaderboard li{padding:2px 0}

.success-metrics{display:grid;grid-template-columns:repeat(3,1fr);border-top:1px solid #bbb;border-bottom:1px solid #bbb;margin:4px 0 16px}
.success-metrics div{padding:9px 5px}.success-metrics div+div{border-left:1px solid #ddd}
.success-metrics span{display:block;font-size:11px;text-transform:uppercase;letter-spacing:.04em}
.success-metrics strong{display:block;font-size:18px;margin-top:2px}
#leaderboardForm{display:grid;grid-template-columns:1fr auto;gap:7px;text-align:left}
#leaderboardForm label{grid-column:1/-1;margin:0}
#leaderboardForm input,#leaderboardForm textarea{box-sizing:border-box;width:100%;border:1px solid #777;padding:9px;font:inherit}
#leaderboardForm textarea{grid-column:1/-1;min-height:54px;resize:vertical}
#leaderboardForm button{grid-column:2;grid-row:2;border:1px solid #111;background:#fff;padding:9px 12px;font:inherit;font-weight:700}
.leaderboard{max-height:230px;overflow:auto;margin-top:15px}
.leaderboard table{border-collapse:collapse;width:100%;font-size:11px}
.leaderboard th,.leaderboard td{padding:4px 5px;border-bottom:1px solid #ddd;text-align:right;vertical-align:top}
.leaderboard th:nth-child(2),.leaderboard td:nth-child(2),.leaderboard th:nth-child(6),.leaderboard td:nth-child(6){text-align:left}
@media(max-width:600px){
 .success-metrics strong{font-size:14px}.success-metrics span{font-size:9px}
 .leaderboard th:nth-child(3),.leaderboard td:nth-child(3),.leaderboard th:nth-child(6),.leaderboard td:nth-child(6){display:none}
}

.success-card h2{margin:0 0 18px;font-size:30px}
.success-metrics{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));margin:0 0 24px;border:1px solid #bbb}
.success-metrics div{padding:14px 10px}
.success-metrics div+div{border-left:1px solid #ccc}
.success-metrics span{display:block;margin-bottom:7px;font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.06em;color:#555}
.success-metrics strong{display:block;font-size:20px;line-height:1.15;white-space:nowrap}
#leaderboardForm>label{font-size:16px;margin-bottom:7px}
@media(max-width:600px){
 .success-card{padding:18px;margin-top:70px}
 #successWith{width:64px;height:64px;margin:-80px auto 10px}
 .success-metrics{grid-template-columns:1fr}
 .success-metrics div+div{border-left:0;border-top:1px solid #ddd}
}

.success-stack{
  display:flex;
  flex-direction:column;
  align-items:center;
  width:min(560px,100%);
  gap:6px;
}
.success-stack .success-card{
  width:100%;
  box-sizing:border-box;
  margin-top:0;
}
.success-stack #successWith{
  width:72px;
  height:72px;
  margin:0;
  display:block;
  flex:0 0 auto;
  image-rendering:pixelated;
}
@media(max-width:600px){
  .success-stack{gap:5px}
  .success-stack #successWith{width:64px;height:64px;margin:0}
  .success-stack .success-card{margin-top:0}
}

.leaderboard{
  width:100%;
  box-sizing:border-box;
  margin-top:18px;
  padding-top:14px;
  border-top:1px solid #bbb;
}
.leaderboard>strong{display:block;margin-bottom:8px;text-align:left}
.leaderboard-empty{text-align:left;color:#666;font-size:12px;padding:4px 0 2px}

/* v21: definitive success layout */
.success-screen{
  flex-direction:column;
}
.success-stack{
  width:min(560px,100%);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:8px;
}
.success-stack #successWith{
  position:static !important;
  width:88px !important;
  height:88px !important;
  margin:0 !important;
  display:block !important;
  flex:none;
  image-rendering:pixelated;
}
.success-stack .success-card{
  width:100%;
  margin:0 !important;
}
@media(max-width:600px){
  .success-stack #successWith{
    width:78px !important;
    height:78px !important;
  }
}

/* Build identifier: deliberately quiet, beside With's bottom-right coordinates. */
#buildVersion{
  color:inherit;
  font:inherit;
  opacity:.55;
  white-space:nowrap;
}


/* v23 — Rules of life */
#rulesButton{white-space:nowrap}
.rules-screen{
  position:absolute;
  inset:0;
  z-index:60;
  display:flex;
  align-items:flex-start;
  justify-content:flex-end;
  background:rgba(255,255,255,.82);
  padding:64px 18px 18px;
}
.rules-screen[hidden]{display:none}
.rules-card{
  position:relative;
  width:min(440px,calc(100vw - 36px));
  max-height:calc(100dvh - 82px);
  overflow:auto;
  background:#fff;
  border:2px solid #111;
  padding:24px;
  font-size:14px;
  line-height:1.42;
}
.rules-card h2{margin:0 36px 18px 0;font-size:26px}
.rules-card p{margin:0 0 16px}
.rules-card a{color:#111;text-decoration:underline;text-underline-offset:2px}
.rules-close{
  position:absolute;
  top:9px;
  right:10px;
  border:0;
  padding:2px 7px;
  background:transparent;
  font-size:28px;
  line-height:1;
  cursor:pointer;
}
.rules-item{display:flex;align-items:center;gap:14px;margin:0 0 16px}
.rules-item p{margin:0}
#rulesWith{
  position:static;
  width:52px;
  height:52px;
  flex:0 0 52px;
  image-rendering:pixelated;
}
.rules-specimen{
  width:22px;
  height:22px;
  flex:0 0 22px;
  background:#9bea63;
  border:1px solid #111;
}
.rules-controls{
  border-top:1px solid #ccc;
  border-bottom:1px solid #ccc;
  padding:10px 0;
  margin:18px 0 14px;
}
.rules-controls>div{
  display:grid;
  grid-template-columns:120px 1fr;
  gap:10px;
  align-items:center;
  min-height:30px;
}
.rules-controls kbd{
  display:inline-block;
  width:max-content;
  min-width:25px;
  padding:2px 6px;
  border:1px solid #888;
  background:#fafafa;
  font:inherit;
  font-size:12px;
  font-weight:700;
  text-align:center;
}
.rules-note{font-size:12px;color:#555;margin-bottom:0!important}

@media(max-width:700px),(pointer:coarse){
  .actions{align-items:center}
  #rulesButton{font-size:11px;padding:7px 8px}
  .rules-screen{padding:54px 8px 8px;align-items:flex-start}
  .rules-card{
    width:100%;
    max-height:calc(100dvh - 62px);
    padding:20px;
    font-size:13px;
  }
  .rules-card h2{font-size:23px}
  .rules-controls>div{grid-template-columns:105px 1fr}
}


/* v25 — simplified mobile controls */
@media(max-width:700px),(pointer:coarse){
  /* Remove the old bank of individual zoom buttons and old restart button. */
  .zoom-pad,
  .mobile-zoom,
  [data-z],
  #mobileRestart{display:none!important}

  /* The joystick is centred on the viewport, independent of neighbouring controls. */
  #joystick{
    position:fixed!important;
    left:50%!important;
    bottom:max(12px,env(safe-area-inset-bottom))!important;
    transform:translateX(-50%)!important;
    margin:0!important;
    z-index:51!important;
  }

  /* Only 4× toggle and restart, anchored at the left edge beside the joystick. */
  .mobile-v25-actions{
    position:fixed;
    left:max(10px,env(safe-area-inset-left));
    bottom:max(28px,calc(env(safe-area-inset-bottom) + 28px));
    z-index:52;
    display:flex;
    gap:8px;
  }
  .mobile-v25-actions button{
    min-width:58px;
    min-height:44px;
  }
}


/* v27 — compact inline identity */
.brand,
.branding,
.title-wrap,
header > div:first-child{
  display:flex;
  align-items:baseline;
  flex-wrap:wrap;
  column-gap:10px;
}
header h1{
  margin-right:0;
}
header h1 + p,
header h1 + .tagline,
header h1 + .byline{
  margin:0;
}


/* v30 — mobile utility buttons: vertical stack at bottom-left */
@media(max-width:700px),(pointer:coarse){
  .mobile-v25-actions{
    position:fixed!important;
    left:max(10px,env(safe-area-inset-left))!important;
    bottom:max(12px,env(safe-area-inset-bottom))!important;
    display:flex!important;
    flex-direction:column!important;
    align-items:stretch!important;
    gap:8px!important;
    transform:none!important;
  }
  #mobileZoom4{order:1}
  #mobileV25Restart{order:2}
}


/* v31 — live mobile controls: separated and always tappable during play */
@media(max-width:700px),(pointer:coarse){
  .mobile-v25-actions{
    position:fixed!important;
    left:max(10px,env(safe-area-inset-left))!important;
    right:auto!important;
    bottom:max(10px,env(safe-area-inset-bottom))!important;
    width:72px!important;
    height:128px!important;
    display:block!important;
    z-index:1000!important;
    pointer-events:none!important;
  }
  #mobileZoom4,
  #mobileV25Restart{
    position:absolute!important;
    left:0!important;
    width:72px!important;
    min-width:72px!important;
    height:48px!important;
    min-height:48px!important;
    margin:0!important;
    pointer-events:auto!important;
    touch-action:manipulation!important;
    z-index:1001!important;
  }
  /* Zoom is the safe, easy-to-hit bottom-left control. */
  #mobileZoom4{
    bottom:0!important;
  }
  /* Restart is deliberately separated above it, just below the arena. */
  #mobileV25Restart{
    top:0!important;
  }
}


/* v32 — mobile success/leaderboard and control hardening */
#joystick,
#joystick *,
.mobile-v25-actions,
.mobile-v25-actions *{
  -webkit-user-select:none!important;
  user-select:none!important;
  -webkit-touch-callout:none!important;
}

@media(max-width:700px),(pointer:coarse){
  #joystick[hidden],
  .mobile-v25-actions[hidden]{
    display:none!important;
  }

  /* Completion UI must be above every live-play control. */
  .success-screen{
    z-index:3000!important;
    overflow-y:auto!important;
    align-items:flex-start!important;
    justify-content:flex-start!important;
    padding-top:max(18px,env(safe-area-inset-top))!important;
    padding-bottom:max(24px,env(safe-area-inset-bottom))!important;
  }

  .success-stack{
    margin:0 auto!important;
    padding-bottom:24px!important;
  }

  /* Make the submit action unambiguous and impossible to render as a blank box. */
  #leaderboardForm{
    display:grid!important;
    grid-template-columns:1fr!important;
    gap:8px!important;
  }
  #leaderboardForm label,
  #leaderboardForm input,
  #leaderboardForm textarea,
  #leaderboardForm button{
    grid-column:1!important;
    grid-row:auto!important;
  }
  #leaderboardForm button[type="submit"]{
    display:block!important;
    width:100%!important;
    min-height:48px!important;
    color:#111!important;
    background:#fff!important;
    opacity:1;
    -webkit-appearance:none!important;
    appearance:none!important;
    font-weight:700!important;
  }
}


/* v33 — mobile play layout: restart top, vertical speed, zoom bottom */
.mobile-speed-control{display:none}

@media(max-width:700px),(pointer:coarse){
  #mobileSpeedControl[hidden]{display:none!important}

  .mobile-v25-actions{
    left:max(12px,env(safe-area-inset-left))!important;
    bottom:max(18px,env(safe-area-inset-bottom))!important;
    width:72px!important;
    height:220px!important;
    z-index:1100!important;
  }

  /* Deliberate ordering: dangerous Restart high; frequent Zoom low. */
  #mobileV25Restart{
    top:0!important;
    bottom:auto!important;
  }
  #mobileZoom4{
    top:auto!important;
    bottom:0!important;
  }

  .mobile-speed-control{
    position:fixed!important;
    display:flex!important;
    flex-direction:column!important;
    align-items:center!important;
    justify-content:center!important;
    gap:5px!important;
    left:max(91px,calc(env(safe-area-inset-left) + 91px))!important;
    bottom:max(18px,env(safe-area-inset-bottom))!important;
    width:58px!important;
    height:220px!important;
    z-index:1100!important;
    pointer-events:auto!important;
    touch-action:none!important;
    -webkit-user-select:none!important;
    user-select:none!important;
    -webkit-touch-callout:none!important;
    background:rgba(255,255,255,.92)!important;
  }

  #mobileSpeedSlider{
    writing-mode:vertical-lr!important;
    direction:rtl!important;
    appearance:auto!important;
    !important;
    width:42px!important;
    height:154px!important;
    margin:0!important;
    touch-action:none!important;
  }

  #mobileSpeedValue{
    font-variant-numeric:tabular-nums;
    font-size:14px;
    line-height:1;
  }
  .mobile-speed-unit{
    font-size:10px;
    line-height:1;
    white-space:nowrap;
  }

  /* Shift joystick right enough to clear the speed controls, but retain
     generous space to drag in every direction. */
  #joystick{
    left:62%!important;
    right:auto!important;
    transform:translateX(-50%)!important;
  }
}


/* v34 — mobile: use the REAL working speedRange; keep controls below arena */
@media(max-width:700px),(pointer:coarse){
  #mobileSpeedControl{display:none!important}

  /* This is the existing authoritative slider wired directly to setSpeed(). */
  #speedRange{
    position:fixed!important;
    left:24px!important;
    bottom:max(108px,calc(env(safe-area-inset-bottom) + 108px))!important;
    width:44px!important;
    height:188px!important;
    margin:0!important;
    writing-mode:vertical-lr!important;
    direction:rtl!important;
    !important;
    appearance:auto!important;
    touch-action:none!important;
    z-index:1200!important;
  }

  /* Keep the numeric speed box in the header; only the range itself moves. */
  .speed-control{
    display:inline-flex!important;
    align-items:center!important;
    gap:8px!important;
  }

  /* Restart moves to the old speed-side position and is fully below the arena. */
  .mobile-v25-actions{
    position:fixed!important;
    left:96px!important;
    bottom:max(108px,calc(env(safe-area-inset-bottom) + 108px))!important;
    width:84px!important;
    height:188px!important;
    display:block!important;
    pointer-events:none!important;
    z-index:1150!important;
  }
  #mobileV25Restart{
    position:absolute!important;
    left:0!important;
    top:0!important;
    bottom:auto!important;
    width:84px!important;
    height:54px!important;
    pointer-events:auto!important;
  }

  /* Zoom stays isolated at the bottom-left. */
  #mobileZoom4{
    position:fixed!important;
    left:24px!important;
    bottom:max(18px,env(safe-area-inset-bottom))!important;
    top:auto!important;
    width:84px!important;
    height:58px!important;
    pointer-events:auto!important;
    z-index:1200!important;
  }

  /* Leave room for the left controls while retaining a full joystick radius. */
  #joystick{
    left:66%!important;
    right:auto!important;
    transform:translateX(-50%)!important;
  }
}

.leaderboard-mode{display:inline-block;padding:1px 5px;border:1px solid currentColor;font-size:.72em;font-weight:700;letter-spacing:.03em;white-space:nowrap}

/* v36 — leaderboard categories */
.leaderboard-filters{display:flex;gap:6px;margin:8px 0}
.leaderboard-filters button{min-height:30px;padding:4px 9px;background:#fff;color:#111;border:1px solid #111;cursor:pointer}
.leaderboard-filters button.active{background:#111;color:#fff}


/* v37 — safer mobile play controls */
@media(max-width:700px),(pointer:coarse){
  /* Restart lives only in the header. */
  #mobileV25Restart{display:none!important}

  /* Dedicated thumb field with generous screen-edge clearance. */
  #joystick{
    position:fixed!important;
    left:auto!important;
    right:clamp(72px,14vw,110px)!important;
    bottom:max(118px,calc(env(safe-area-inset-bottom) + 96px))!important;
    transform:none!important;
    z-index:1100!important;
  }

  /* Real authoritative speed slider stays left and clear of the arena. */
  #speedRange{
    left:30px!important;
    bottom:max(132px,calc(env(safe-area-inset-bottom) + 112px))!important;
  }

  /* Zoom stays isolated at bottom-left. */
  #mobileZoom4{
    left:24px!important;
    bottom:max(20px,calc(env(safe-area-inset-bottom) + 8px))!important;
  }

  /* The old floating-actions container must not intercept touches. */
  .mobile-v25-actions{
    display:none!important;
    pointer-events:none!important;
  }
}


/* v38 — mobile Rate + rapid-access Zoom, monochrome controls */
.mobile-rate-label{display:none}

@media(max-width:700px),(pointer:coarse){
  /*
    Left control rail:
      Rate
      vertical speed
      Zoom
    The speed input is still the real #speedRange wired directly to setSpeed().
  */
  .mobile-rate-label{
    display:block!important;
    position:fixed!important;
    left:24px!important;
    bottom:max(326px,calc(env(safe-area-inset-bottom) + 306px))!important;
    width:58px!important;
    text-align:center!important;
    font-size:14px!important;
    line-height:1!important;
    color:#111!important;
    z-index:1201!important;
    pointer-events:none!important;
  }

  #speedRange{
    position:fixed!important;
    left:31px!important;
    bottom:max(126px,calc(env(safe-area-inset-bottom) + 106px))!important;
    width:44px!important;
    height:188px!important;
    writing-mode:vertical-lr!important;
    direction:rtl!important;
    !important;
    appearance:auto!important;
    accent-color:#111!important;
    filter:grayscale(1)!important;
    z-index:1200!important;
  }

  /* Zoom is essential during mobile play: directly below Rate/speed. */
  #mobileZoom4{
    display:block!important;
    position:fixed!important;
    left:18px!important;
    bottom:max(28px,calc(env(safe-area-inset-bottom) + 12px))!important;
    top:auto!important;
    width:72px!important;
    height:54px!important;
    background:#fff!important;
    color:#111!important;
    border:1px solid #111!important;
    z-index:1201!important;
    pointer-events:auto!important;
  }

  /* Keep all mobile play controls monochrome rather than browser-blue. */
  #speedRange::-webkit-slider-runnable-track{
    background:#b8b8b8!important;
  }
  #speedRange::-webkit-slider-thumb{
    background:#111!important;
    border-color:#111!important;
  }

  /* Preserve the generous steering field from v37. */
  #joystick{
    right:clamp(72px,14vw,110px)!important;
    bottom:max(118px,calc(env(safe-area-inset-bottom) + 96px))!important;
  }
}


/* v40 — Zoom must remain a real, visible mobile play control.
   It is now outside the hidden legacy .mobile-v25-actions wrapper. */
@media(max-width:700px),(pointer:coarse){
  #mobileZoom4{
    display:block!important;
    position:fixed!important;
    left:18px!important;
    bottom:max(28px,calc(env(safe-area-inset-bottom) + 12px))!important;
    width:72px!important;
    height:54px!important;
    background:#fff!important;
    color:#111!important;
    border:1px solid #111!important;
    z-index:1300!important;
    pointer-events:auto!important;
    touch-action:manipulation!important;
  }

  .mobile-rate-label{
    color:#111!important;
  }

  #speedRange{
    accent-color:#111!important;
    filter:grayscale(1)!important;
  }
}


/* v41 — compact mobile controls, based on authoritative v40 */
@media(max-width:700px),(pointer:coarse){
  /* Reserve only a compact strip beneath the arena. */
  #mobileControls{
    flex:0 0 116px!important;
    min-height:116px!important;
    padding:4px 8px max(8px,env(safe-area-inset-bottom))!important;
  }

  /* Restart remains header-only. */
  #mobileRestart,
  #mobileV25Restart{display:none!important}

  /* Compact Rate rail: same real #speedRange, still wired to setSpeed(). */
  .mobile-rate-label{
    left:17px!important;
    bottom:max(112px,calc(env(safe-area-inset-bottom) + 100px))!important;
    width:48px!important;
    font-size:11px!important;
  }
  #speedRange{
    left:22px!important;
    bottom:max(48px,calc(env(safe-area-inset-bottom) + 40px))!important;
    width:34px!important;
    height:62px!important;
    margin:0!important;
  }

  /* Small zoom button directly under the Rate control. */
  #mobileZoom4{
    left:15px!important;
    bottom:max(8px,env(safe-area-inset-bottom))!important;
    width:52px!important;
    min-width:52px!important;
    height:34px!important;
    min-height:34px!important;
    padding:0!important;
    font-size:15px!important;
  }

  /* Compact joystick with proportionally smaller thumb. */
  #joystick{
    width:108px!important;
    height:108px!important;
    right:clamp(44px,12vw,72px)!important;
    bottom:max(8px,env(safe-area-inset-bottom))!important;
  }
  #stick{
    width:42px!important;
    height:42px!important;
    left:33px!important;
    top:33px!important;
  }
}


/* v42 — slide-across stepped Rate + multitouch Zoom */
@media(max-width:700px),(pointer:coarse){
  /* Desktop range remains authoritative but is not the mobile UI. */
  #speedRange,
  .mobile-rate-label{display:none!important}

  #mobileRateSteps{
    position:fixed!important;
    left:14px!important;
    bottom:max(58px,calc(env(safe-area-inset-bottom) + 50px))!important;
    display:grid!important;
    grid-template-columns:30px repeat(5,36px)!important;
    align-items:center!important;
    gap:2px!important;
    height:42px!important;
    padding:3px!important;
    background:#fff!important;
    border:1px solid #111!important;
    z-index:1400!important;
    touch-action:none!important;
    user-select:none!important;
    -webkit-user-select:none!important;
    -webkit-touch-callout:none!important;
  }
  .mobile-rate-title{
    font-size:10px!important;
    text-align:center!important;
    pointer-events:none!important;
  }
  #mobileRateSteps button{
    width:36px!important;
    min-width:36px!important;
    height:34px!important;
    min-height:34px!important;
    padding:0!important;
    margin:0!important;
    border:0!important;
    border-left:1px solid #bbb!important;
    background:#fff!important;
    color:#111!important;
    font-size:12px!important;
    font-weight:600!important;
    touch-action:none!important;
  }
  #mobileRateSteps button.active{
    background:#111!important;
    color:#fff!important;
  }

  /* About twice v41's width; activates on pointerdown during joystick capture. */
  #mobileZoom4{
    left:14px!important;
    bottom:max(8px,env(safe-area-inset-bottom))!important;
    width:104px!important;
    min-width:104px!important;
    height:40px!important;
    min-height:40px!important;
    font-size:16px!important;
    touch-action:none!important;
    pointer-events:auto!important;
    z-index:1401!important;
  }

  #mobileControls{
    flex-basis:116px!important;
    min-height:116px!important;
  }

  /* Keep joystick compact and clear of the rate rail. */
  #joystick{
    width:108px!important;
    height:108px!important;
    right:clamp(22px,7vw,46px)!important;
    bottom:max(8px,env(safe-area-inset-bottom))!important;
  }
}


/* v43 — mobile touch polish */
@media(max-width:700px),(pointer:coarse){
  /* Zoom is a control, never selectable/callout text on iOS. */
  #mobileZoom4,
  #mobileZoom4 *{
    -webkit-user-select:none!important;
    user-select:none!important;
    -webkit-touch-callout:none!important;
    -webkit-tap-highlight-color:transparent!important;
  }

  /* Move joystick modestly left from v42. */
  #joystick{
    right:clamp(42px,12vw,66px)!important;
  }
}


/* v44 — maximize separation between left mobile controls */
@media(max-width:700px),(pointer:coarse){
  /* Rate at the top-left of the reserved control area. */
  #mobileRateSteps{
    left:14px!important;
    top:auto!important;
    bottom:max(72px,calc(env(safe-area-inset-bottom) + 64px))!important;
  }

  /* Zoom at the opposite, bottom-left edge with a clear dead gap. */
  #mobileZoom4{
    left:14px!important;
    top:auto!important;
    bottom:max(8px,env(safe-area-inset-bottom))!important;
    width:104px!important;
    min-width:104px!important;
    height:40px!important;
    min-height:40px!important;
  }
}


/* v45 — compact two-row mobile Rate block */
@media(max-width:700px),(pointer:coarse){
  #mobileRateSteps{
    /* Rate occupies the left column; five rates wrap over two rows. */
    display:grid!important;
    grid-template-columns:42px repeat(3,42px)!important;
    grid-template-rows:36px 36px!important;
    gap:2px!important;
    width:auto!important;
    height:auto!important;
    padding:3px!important;
    left:14px!important;
    bottom:max(66px,calc(env(safe-area-inset-bottom) + 58px))!important;
  }

  .mobile-rate-title{
    grid-column:1!important;
    grid-row:1 / span 2!important;
    align-self:stretch!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    width:42px!important;
    font-size:11px!important;
  }

  #mobileRateSteps button{
    width:42px!important;
    min-width:42px!important;
    height:36px!important;
    min-height:36px!important;
  }

  /* Explicit placement: 1/15/30 top, 45/60 bottom. */
  #mobileRateSteps button[data-rate="1"]{grid-column:2;grid-row:1}
  #mobileRateSteps button[data-rate="15"]{grid-column:3;grid-row:1}
  #mobileRateSteps button[data-rate="30"]{grid-column:4;grid-row:1}
  #mobileRateSteps button[data-rate="45"]{grid-column:2;grid-row:2}
  #mobileRateSteps button[data-rate="60"]{grid-column:3;grid-row:2}
}


/* v46 — Rules of life is always the topmost interface layer */
#rulesModal{
  z-index:10000!important;
}
#rulesModal .rules-panel{
  position:relative!important;
  z-index:10001!important;
}

/* Mobile play controls can never paint over the Rules overlay. */
body:has(#rulesModal:not([hidden])) #mobileControls,
body:has(#rulesModal:not([hidden])) #joystick,
body:has(#rulesModal:not([hidden])) #mobileRateSteps,
body:has(#rulesModal:not([hidden])) #mobileZoom4{
  visibility:hidden!important;
  pointer-events:none!important;
}


/* v47 — simple 2×3 Rate pad */
@media(max-width:700px),(pointer:coarse){
  #mobileRateSteps{
    display:block!important;
    left:14px!important;
    bottom:max(64px,calc(env(safe-area-inset-bottom) + 56px))!important;
    width:174px!important;
    height:auto!important;
    padding:0!important;
    border:0!important;
    background:transparent!important;
  }
  .mobile-rate-title{
    display:block!important;
    width:auto!important;
    height:auto!important;
    margin:0 0 5px 0!important;
    font-size:12px!important;
    line-height:1.1!important;
    text-align:left!important;
  }
  .mobile-rate-grid{
    display:grid!important;
    grid-template-columns:repeat(3,58px)!important;
    grid-template-rows:repeat(2,38px)!important;
    gap:0!important;
    width:174px!important;
    border:1px solid #111!important;
    background:#fff!important;
  }
  #mobileRateSteps .mobile-rate-grid button{
    width:58px!important;
    min-width:58px!important;
    height:38px!important;
    min-height:38px!important;
    margin:0!important;
    padding:0!important;
    border:0!important;
    border-right:1px solid #aaa!important;
    border-bottom:1px solid #aaa!important;
    background:#fff!important;
    color:#111!important;
    font-size:13px!important;
    font-weight:600!important;
  }
  #mobileRateSteps .mobile-rate-grid button:nth-child(3n){border-right:0!important}
  #mobileRateSteps .mobile-rate-grid button:nth-child(n+4){border-bottom:0!important}
  #mobileRateSteps .mobile-rate-grid button.active{
    background:#111!important;
    color:#fff!important;
  }
}


/* v48 — reclaim mobile vertical space */
@media(max-width:700px),(pointer:coarse){
  header{
    display:flex!important;align-items:center!important;justify-content:space-between!important;
    gap:5px!important;padding:5px 7px 3px!important;flex:0 0 auto!important;
  }
  .brand{display:flex!important;align-items:baseline!important;gap:5px!important;min-width:0!important;flex:0 0 auto!important}
  header h1{font-size:21px!important;line-height:1!important;margin:0!important;white-space:nowrap!important}
  .brand #level{font-size:8px!important;margin:0!important;white-space:nowrap!important}
  .tagline{display:none!important}

  .actions{display:flex!important;align-items:center!important;gap:3px!important;margin:0!important;min-width:0!important;flex:0 1 auto!important}
  .actions button{padding:5px 5px!important;min-height:29px!important;font-size:10px!important;line-height:1!important;white-space:nowrap!important}

  .game-settings{
    display:flex!important;align-items:center!important;flex-wrap:nowrap!important;
    gap:8px!important;padding:3px 7px!important;min-height:0!important;
    overflow:visible!important;white-space:nowrap!important;flex:0 0 auto!important;
  }
  #specimens{display:flex!important;align-items:center!important;gap:3px!important;margin:0!important;font-size:11px!important;font-weight:600!important;white-space:nowrap!important}
  #specimenSwatches .specimen-swatch{width:13px!important;height:13px!important}

  .speed-control{display:flex!important;align-items:center!important;gap:3px!important;margin:0!important;font-size:11px!important;white-space:nowrap!important}
  .speed-control #speedRange,.speed-control > span{display:none!important}
  .speed-control #speedNumber{display:block!important;width:34px!important;height:24px!important;min-height:0!important;padding:1px 3px!important;font-size:11px!important;margin:0!important}

  .pal-control{display:flex!important;align-items:center!important;gap:3px!important;margin:0!important;font-size:11px!important;white-space:nowrap!important}
  .pal-control input{width:17px!important;height:17px!important;margin:0!important}

  #status{
    padding:2px 7px 3px!important;margin:0!important;font-size:10px!important;
    line-height:1.15!important;min-height:0!important;flex:0 0 auto!important;
    white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important;
  }
}


/* v49 — definitive mobile Rate layout */
@media(max-width:700px),(pointer:coarse){
  /*
    Keep the whole Rate control inside the reserved mobile-controls strip.
    Label is a narrow left column spanning both rows.
  */
  #mobileRateSteps{
    position:absolute!important;
    left:10px!important;
    top:8px!important;
    bottom:auto!important;
    display:grid!important;
    grid-template-columns:34px 48px 48px 48px!important;
    grid-template-rows:36px 36px!important;
    gap:0!important;
    width:178px!important;
    height:72px!important;
    padding:0!important;
    margin:0!important;
    border:1px solid #111!important;
    background:#fff!important;
    box-sizing:border-box!important;
    z-index:1400!important;
  }

  .mobile-rate-title{
    grid-column:1!important;
    grid-row:1 / span 2!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    width:34px!important;
    height:72px!important;
    margin:0!important;
    padding:0!important;
    border-right:1px solid #aaa!important;
    font-size:11px!important;
    line-height:1!important;
    box-sizing:border-box!important;
  }

  .mobile-rate-grid{
    grid-column:2 / span 3!important;
    grid-row:1 / span 2!important;
    display:grid!important;
    grid-template-columns:repeat(3,48px)!important;
    grid-template-rows:repeat(2,36px)!important;
    gap:0!important;
    width:144px!important;
    height:72px!important;
    padding:0!important;
    margin:0!important;
    border:0!important;
    background:#fff!important;
    box-sizing:border-box!important;
  }

  /* Explicit cells: 0 1 15 / 30 45 60. No auto-placement ambiguity. */
  #mobileRateSteps .mobile-rate-grid button{
    width:48px!important;
    min-width:48px!important;
    height:36px!important;
    min-height:36px!important;
    margin:0!important;
    padding:0!important;
    border:0!important;
    border-right:1px solid #aaa!important;
    border-bottom:1px solid #aaa!important;
    box-sizing:border-box!important;
  }
  #mobileRateSteps button[data-rate="0"]{grid-column:1!important;grid-row:1!important}
  #mobileRateSteps button[data-rate="1"]{grid-column:2!important;grid-row:1!important}
  #mobileRateSteps button[data-rate="15"]{grid-column:3!important;grid-row:1!important}
  #mobileRateSteps button[data-rate="30"]{grid-column:1!important;grid-row:2!important}
  #mobileRateSteps button[data-rate="45"]{grid-column:2!important;grid-row:2!important}
  #mobileRateSteps button[data-rate="60"]{grid-column:3!important;grid-row:2!important}
  #mobileRateSteps .mobile-rate-grid button:nth-child(3n){border-right:0!important}
  #mobileRateSteps .mobile-rate-grid button:nth-child(n+4){border-bottom:0!important}

  /* The controls container itself owns the below-arena region. */
  #mobileControls{
    position:relative!important;
    overflow:visible!important;
  }
}

/* v50 */
@media(max-width:700px),(pointer:coarse){
  /* The arena now follows the compact status area without the old reserved gap. */
  #gameWrap,#gameArea,.game-wrap,.game-area,main{
    margin-top:0!important;
    padding-top:0!important;
  }
  .start-button{background:#111!important;color:#fff!important;border-color:#111!important}
  .start-button:disabled{opacity:.45!important}
  #mobileControls{padding-bottom:max(12px,env(safe-area-inset-bottom))!important}
}
.rules-pwa{margin-top:16px;padding-top:12px;border-top:1px solid #bbb;font-size:.9em}
.rules-pwa p{margin:.35em 0 0}
#stop[hidden],#restart[hidden]{display:none!important}


/* v51 — deliberate mobile header + cleanly separated play controls */
@media(max-width:700px),(pointer:coarse){

  /* Header is two rows. Descent + Guide occupy the left; Start occupies
     a large square at right spanning both rows. */
  header{
    display:grid!important;
    grid-template-columns:auto auto 1fr 92px!important;
    grid-template-rows:40px 40px!important;
    column-gap:6px!important;
    row-gap:0!important;
    align-items:center!important;
    padding:4px 8px!important;
  }
  .brand{
    grid-column:1!important;
    grid-row:1 / span 2!important;
    display:flex!important;
    align-items:center!important;
    margin:0!important;
  }
  header h1{
    margin:0!important;
    font-size:22px!important;
    line-height:1!important;
  }
  .actions{
    display:contents!important;
  }
  #rulesButton{
    grid-column:2!important;
    grid-row:1 / span 2!important;
    align-self:center!important;
    width:auto!important;
    min-width:54px!important;
    height:34px!important;
    min-height:34px!important;
    padding:4px 7px!important;
    font-size:11px!important;
  }
  #run{
    grid-column:4!important;
    grid-row:1 / span 2!important;
    width:92px!important;
    min-width:92px!important;
    height:80px!important;
    min-height:80px!important;
    padding:0!important;
    font-size:16px!important;
    font-weight:600!important;
    align-self:stretch!important;
  }

  /* Do not let hidden legacy Stop/Restart consume grid space. */
  #stop[hidden],#restart[hidden]{display:none!important}

  /*
    Mobile play controls:
    Rate gets its own upper-left block.
    Zoom gets its own lower-left block.
    They do not touch or overlap.
  */
  #mobileControls{
    position:relative!important;
    min-height:205px!important;
    padding:0 10px max(16px,env(safe-area-inset-bottom))!important;
    box-sizing:border-box!important;
  }

  #mobileRateSteps{
    position:absolute!important;
    left:14px!important;
    top:12px!important;
    bottom:auto!important;
    margin:0!important;
  }

  #mobileZoom4{
    position:absolute!important;
    left:14px!important;
    top:116px!important;
    bottom:auto!important;
    width:120px!important;
    min-width:120px!important;
    height:48px!important;
    min-height:48px!important;
    margin:0!important;
  }

  #joystick{
    top:18px!important;
    bottom:auto!important;
    right:38px!important;
    left:auto!important;
    transform:none!important;
  }
}


/* v53 — restore joystick placement + finish Rate control */
@media(max-width:700px),(pointer:coarse){

  /* Restore joystick to the stable lower-right control position used before
     the header redesign; keep it wholly below the arena. */
  #joystick{
    position:absolute!important;
    top:12px!important;
    right:14px!important;
    bottom:auto!important;
    left:auto!important;
    transform:none!important;
  }

  /* Rate is a closed rectangular control: all four outer borders explicit. */
  #mobileRateSteps{
    box-sizing:border-box!important;
    border:1px solid #111!important;
    border-right:1px solid #111!important;
    border-bottom:1px solid #111!important;
    overflow:hidden!important;
  }

  /* Narrow label column; text reads vertically to reclaim horizontal space. */
  .mobile-rate-title{
    width:24px!important;
    min-width:24px!important;
    border-right:1px solid #aaa!important;
    writing-mode:vertical-rl!important;
    transform:rotate(180deg)!important;
    white-space:nowrap!important;
    text-align:center!important;
  }

  #mobileRateSteps{
    grid-template-columns:24px 48px 48px 48px!important;
    width:168px!important;
  }

  /* Ensure the rate grid closes cleanly at its right and lower edges. */
  .mobile-rate-grid{
    width:144px!important;
    border-right:0!important;
    border-bottom:0!important;
  }
  #mobileRateSteps .mobile-rate-grid button:nth-child(3n){
    border-right:0!important;
  }
  #mobileRateSteps .mobile-rate-grid button:nth-child(n+4){
    border-bottom:0!important;
  }
}


/* v54 — mobile death/restart + final control positioning */
@media(max-width:700px),(pointer:coarse){

  /* Make the title use the otherwise empty header space. */
  header h1{
    font-size:40px!important;
    line-height:1!important;
    letter-spacing:-1px!important;
  }

  /* Explicit complete outer frame for Rate, including the left edge. */
  #mobileRateSteps{
    border-left:1px solid #111!important;
    border-top:1px solid #111!important;
    border-right:1px solid #111!important;
    border-bottom:1px solid #111!important;
  }

  /*
    Centre joystick in the horizontal space remaining after the Rate block.
    Rate begins at 14px and is 168px wide => its right edge is 182px.
    The remaining region is [182px, viewport right]; 50% of that region is
    calc(50% + 91px). Translate by half the joystick's own width.
  */
  #joystick{
    left:calc(50% + 91px)!important;
    right:auto!important;
    transform:translateX(-50%)!important;
    top:12px!important;
    bottom:auto!important;
  }
}


/* v55 — Clock must remain visible in All, PC and Mobile leaderboard views.
   Older nth-child mobile rules depended on the optional Mode column and
   accidentally hid Clock in filtered views. Semantic classes override that. */
@media(max-width:600px){
  .leaderboard .lb-clock-col{display:table-cell!important}
  .leaderboard .lb-comments-col{display:none!important}
  .leaderboard .lb-mode-col{display:none!important}
}

/* v56 — Guide is above every game control */
.rules-screen{position:fixed!important;inset:0!important;z-index:100000!important}
.rules-card{position:relative!important;z-index:100001!important}
body.rules-open #joystick,
body.rules-open #mobileControls,
body.rules-open #mobileRateSteps,
body.rules-open #mobileZoom4{visibility:hidden!important;pointer-events:none!important}
.rules-pwa{margin-top:20px!important;padding-top:14px!important;border-top:1px solid #bbb!important}
.rules-pwa-note{font-size:.85em!important;opacity:.7!important}

/* v57 — whole arena is a mobile relative trackpad; joystick remains visual feedback */
@media(max-width:700px),(pointer:coarse){
  #world{touch-action:none!important}
}
.platform-guide{margin-top:20px;padding-top:14px;border-top:1px solid #bbb}
.platform-guide h3{margin:0 0 10px}
.platform-guide-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.platform-guide p{margin:.35em 0 0}
@media(max-width:700px){.platform-guide-grid{grid-template-columns:1fr}}


/* v58 — 3×3 mobile Rate selector */
@media(max-width:700px),(pointer:coarse){
  #mobileRateSteps{
    grid-template-columns:24px 48px 48px 48px!important;
    grid-template-rows:repeat(3,36px)!important;
    width:168px!important;
    height:108px!important;
  }
  .mobile-rate-title{
    grid-column:1!important;
    grid-row:1 / span 3!important;
    width:24px!important;
    min-width:24px!important;
    height:108px!important;
  }
  .mobile-rate-grid{
    grid-column:2 / span 3!important;
    grid-row:1 / span 3!important;
    display:grid!important;
    grid-template-columns:repeat(3,48px)!important;
    grid-template-rows:repeat(3,36px)!important;
    width:144px!important;
    height:108px!important;
  }
  #mobileRateSteps .mobile-rate-grid button{
    width:48px!important;min-width:48px!important;
    height:36px!important;min-height:36px!important;
    border-right:1px solid #aaa!important;
    border-bottom:1px solid #aaa!important;
  }
  #mobileRateSteps button[data-rate="0"]{grid-column:1!important;grid-row:1!important}
  #mobileRateSteps button[data-rate="1"]{grid-column:2!important;grid-row:1!important}
  #mobileRateSteps button[data-rate="5"]{grid-column:3!important;grid-row:1!important}
  #mobileRateSteps button[data-rate="10"]{grid-column:1!important;grid-row:2!important}
  #mobileRateSteps button[data-rate="15"]{grid-column:2!important;grid-row:2!important}
  #mobileRateSteps button[data-rate="20"]{grid-column:3!important;grid-row:2!important}
  #mobileRateSteps button[data-rate="30"]{grid-column:1!important;grid-row:3!important}
  #mobileRateSteps button[data-rate="45"]{grid-column:2!important;grid-row:3!important}
  #mobileRateSteps button[data-rate="60"]{grid-column:3!important;grid-row:3!important}
  #mobileRateSteps .mobile-rate-grid button:nth-child(3n){border-right:0!important}
  #mobileRateSteps .mobile-rate-grid button:nth-child(n+7){border-bottom:0!important}

  /* Preserve clear separation between the taller Rate block and Zoom. */
  #mobileZoom4{top:152px!important}
  #mobileControls{min-height:241px!important}
}


/* v60 — Map sits beside Palimpsest and shows the intact starting world */
.map-control{
  appearance:none;
  border:1px solid #aaa;
  background:#fff;
  color:#111;
  font:inherit;
  padding:3px 8px;
  cursor:pointer;
}
.map-control.active{background:#111;color:#fff;border-color:#111}
@media(max-width:700px),(pointer:coarse){
  .map-control{padding:2px 7px;min-height:28px;touch-action:manipulation}
}


/* v61 — Ancestors is a first-class leaderboard entry beside Guide */
.ancestors-screen{
  position:fixed;
  inset:0;
  z-index:100000;
  background:rgba(255,255,255,.96);
  display:flex;
  align-items:flex-start;
  justify-content:center;
  padding:clamp(18px,5vh,48px) 16px;
  overflow:auto;
}
.ancestors-screen[hidden]{display:none!important}
.ancestors-card{
  position:relative;
  width:min(900px,100%);
  background:#fff;
  border:1px solid #111;
  padding:24px;
}
.ancestors-card h2{margin:0 42px 2px 0;font-size:2rem}
.ancestors-note{margin:0 0 18px;color:#555}
body.ancestors-open #joystick,
body.ancestors-open #mobileControls,
body.ancestors-open #mobileRateSteps,
body.ancestors-open #mobileZoom4{visibility:hidden!important;pointer-events:none!important}

@media(max-width:700px),(pointer:coarse){
  header .actions{gap:5px!important}
  #rulesButton,#ancestorsButton{padding-left:7px!important;padding-right:7px!important}
  .ancestors-screen{padding:12px 8px}
  .ancestors-card{padding:16px 10px}
}


/* v62 — Guide and Ancestors are one matched header pair */
#rulesButton,#ancestorsButton{
  box-sizing:border-box;
  height:44px;
  min-height:44px;
  padding:0 12px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  line-height:1;
  vertical-align:top;
}
@media(max-width:700px),(pointer:coarse){
  header .actions{
    display:grid!important;
    grid-template-columns:auto auto auto;
    align-items:start!important;
    column-gap:6px!important;
  }
  #rulesButton,#ancestorsButton{
    grid-row:1;
    align-self:start;
    height:44px!important;
    min-height:44px!important;
    margin:0!important;
    padding:0 9px!important;
  }
  #rulesButton{grid-column:1}
  #ancestorsButton{grid-column:2}
  #run{grid-column:3;grid-row:1}
}


/* v63 — restore the original mobile Start geometry; secondary nav gets its own row */
@media(max-width:700px),(pointer:coarse){
  header{
    position:relative!important;
  }
  header .actions{
    display:flex!important;
    grid-template-columns:none!important;
    align-items:flex-start!important;
    gap:0!important;
  }

  /* Start goes back to the header's original primary-action position/size. */
  #run{
    grid-column:auto!important;
    grid-row:auto!important;
    margin:0!important;
  }

  /* Guide + Ancestors become a clean matched secondary row below the header,
     above Specimens/Rate/Palimpsest/Map. */
  #rulesButton,#ancestorsButton{
    position:absolute!important;
    top:100%!important;
    height:38px!important;
    min-height:38px!important;
    margin-top:8px!important;
    padding:0 10px!important;
    z-index:20;
    background:#fff;
    box-sizing:border-box;
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
    line-height:1!important;
  }
  #rulesButton{
    left:16px!important;
    right:auto!important;
  }
  #ancestorsButton{
    left:96px!important;
    right:auto!important;
  }

  /* Reserve exactly one secondary-nav row before the settings. */
  .game-settings{
    margin-top:54px!important;
  }
}


/* v64 — compact mobile header: [Guide/Ancestors stack] [Start] */
@media(max-width:700px),(pointer:coarse){
  header{
    position:relative!important;
  }
  header .actions{
    position:static!important;
    display:flex!important;
    flex-direction:row!important;
    align-items:stretch!important;
    justify-content:flex-end!important;
    gap:8px!important;
  }

  /* Restore Start as the top-right primary action; do not resize it. */
  #run{
    position:static!important;
    grid-column:auto!important;
    grid-row:auto!important;
    order:3!important;
    margin:0!important;
    flex:0 0 auto!important;
  }

  /* The two secondary buttons occupy one column immediately left of Start.
     Each is half the Start height (minus the inter-button gap). */
  #rulesButton,#ancestorsButton{
    position:absolute!important;
    left:auto!important;
    width:104px!important;
    min-width:104px!important;
    height:calc((100% - 6px)/2)!important;
    min-height:0!important;
    margin:0!important;
    padding:0 8px!important;
    box-sizing:border-box!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    line-height:1!important;
    background:#fff!important;
    z-index:20!important;
  }
  #rulesButton{
    top:0!important;
    bottom:auto!important;
    right:calc(var(--mobile-start-width, 98px) + 8px)!important;
  }
  #ancestorsButton{
    top:auto!important;
    bottom:0!important;
    right:calc(var(--mobile-start-width, 98px) + 8px)!important;
  }

  /* No artificial row between header and settings. */
  .game-settings{
    margin-top:0!important;
  }
}

@media(max-width:700px),(pointer:coarse){
  header .actions{
    position:static!important;
    display:flex!important;
    align-items:stretch!important;
    gap:8px!important;
  }
  header .secondary-actions{
    position:static!important;
    display:flex!important;
    flex-direction:column!important;
    align-self:stretch!important;
    width:104px!important;
    gap:6px!important;
    order:2!important;
  }
  header .secondary-actions #rulesButton,
  header .secondary-actions #ancestorsButton{
    position:static!important;
    inset:auto!important;
    right:auto!important;
    top:auto!important;
    bottom:auto!important;
    width:104px!important;
    min-width:104px!important;
    height:auto!important;
    min-height:0!important;
    flex:1 1 0!important;
    margin:0!important;
  }
  header .actions #run{
    order:3!important;
    align-self:stretch!important;
  }
}


/* v65 — bounded mobile header controls */
@media(max-width:700px),(pointer:coarse){
  header{
    box-sizing:border-box!important;
    width:100%!important;
    max-width:100vw!important;
    padding-left:16px!important;
    padding-right:16px!important;
    position:relative!important;
    overflow:visible!important;
  }

  header .actions{
    position:absolute!important;
    top:0!important;
    right:16px!important;
    left:auto!important;
    width:auto!important;
    height:112px!important;
    display:flex!important;
    flex-direction:row!important;
    align-items:stretch!important;
    justify-content:flex-end!important;
    gap:6px!important;
    margin:0!important;
    padding:0!important;
    box-sizing:border-box!important;
  }

  header .actions #run{
    position:static!important;
    inset:auto!important;
    order:2!important;
    flex:0 0 112px!important;
    width:112px!important;
    min-width:112px!important;
    max-width:112px!important;
    height:112px!important;
    min-height:112px!important;
    max-height:112px!important;
    aspect-ratio:1/1!important;
    margin:0!important;
    padding:0!important;
    box-sizing:border-box!important;
    align-self:auto!important;
  }

  header .secondary-actions{
    position:static!important;
    inset:auto!important;
    order:1!important;
    flex:0 0 96px!important;
    width:96px!important;
    min-width:96px!important;
    max-width:96px!important;
    height:112px!important;
    display:flex!important;
    flex-direction:column!important;
    align-items:stretch!important;
    justify-content:stretch!important;
    gap:6px!important;
    margin:0!important;
    padding:0!important;
    box-sizing:border-box!important;
  }

  header .secondary-actions #rulesButton,
  header .secondary-actions #ancestorsButton{
    position:static!important;
    inset:auto!important;
    flex:1 1 0!important;
    width:96px!important;
    min-width:96px!important;
    max-width:96px!important;
    height:53px!important;
    min-height:53px!important;
    max-height:53px!important;
    margin:0!important;
    padding:0 5px!important;
    box-sizing:border-box!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    line-height:1!important;
  }

  /* Keep the title from being covered by the fixed top-right controls. */
  header .brand{
    box-sizing:border-box!important;
    max-width:calc(100% - 220px)!important;
    overflow:visible!important;
  }

  .game-settings{
    margin-top:0!important;
  }
}


/* v66 — mobile UI is two non-overlapping structural rows */
@media(max-width:700px),(pointer:coarse){
  /* ROW 1: Descent | Guide/Ancestors | Start */
  header{
    position:static!important;
    display:grid!important;
    grid-template-columns:minmax(0,1fr) 88px 88px!important;
    grid-template-rows:88px!important;
    column-gap:6px!important;
    align-items:stretch!important;
    width:100%!important;
    max-width:100%!important;
    min-height:88px!important;
    height:88px!important;
    padding:0 8px!important;
    margin:0!important;
    box-sizing:border-box!important;
    overflow:hidden!important;
  }
  header .brand{
    position:static!important;
    grid-column:1!important;
    grid-row:1!important;
    min-width:0!important;
    max-width:none!important;
    width:auto!important;
    height:88px!important;
    display:flex!important;
    align-items:center!important;
    overflow:hidden!important;
  }
  header .brand h1{
    margin:0!important;
    padding:0!important;
    max-width:100%!important;
    font-size:clamp(30px,9.5vw,48px)!important;
    line-height:.92!important;
    white-space:nowrap!important;
  }
  header .actions{
    position:static!important;
    inset:auto!important;
    grid-column:2 / 4!important;
    grid-row:1!important;
    width:auto!important;
    height:88px!important;
    display:grid!important;
    grid-template-columns:88px 88px!important;
    grid-template-rows:88px!important;
    gap:6px!important;
    margin:0!important;
    padding:0!important;
    box-sizing:border-box!important;
    align-items:stretch!important;
    justify-content:stretch!important;
  }
  header .secondary-actions{
    position:static!important;
    inset:auto!important;
    grid-column:1!important;
    grid-row:1!important;
    width:88px!important;
    min-width:0!important;
    max-width:none!important;
    height:88px!important;
    display:grid!important;
    grid-template-rows:41px 41px!important;
    gap:6px!important;
    margin:0!important;
    padding:0!important;
    box-sizing:border-box!important;
  }
  header .secondary-actions #rulesButton,
  header .secondary-actions #ancestorsButton{
    position:static!important;
    inset:auto!important;
    width:88px!important;
    min-width:0!important;
    max-width:none!important;
    height:41px!important;
    min-height:0!important;
    max-height:none!important;
    margin:0!important;
    padding:0 3px!important;
    box-sizing:border-box!important;
    font-size:13px!important;
    line-height:1!important;
    overflow:hidden!important;
  }
  header .actions #run{
    position:static!important;
    inset:auto!important;
    grid-column:2!important;
    grid-row:1!important;
    width:88px!important;
    min-width:88px!important;
    max-width:88px!important;
    height:88px!important;
    min-height:88px!important;
    max-height:88px!important;
    aspect-ratio:1/1!important;
    margin:0!important;
    padding:0!important;
    box-sizing:border-box!important;
    font-size:18px!important;
  }

  /* ROW 2: Specimens | Rate | Palimpsest | Map.
     Every item owns a cell; nothing can intrude into a neighbour. */
  .game-settings{
    position:static!important;
    display:grid!important;
    grid-template-columns:minmax(0,1.55fr) minmax(58px,.7fr) minmax(0,1.25fr) 58px!important;
    grid-template-rows:44px!important;
    width:100%!important;
    max-width:100%!important;
    height:44px!important;
    margin:6px 0 0!important;
    padding:0 8px!important;
    gap:4px!important;
    box-sizing:border-box!important;
    align-items:stretch!important;
    overflow:hidden!important;
  }
  .game-settings .setting-cell{
    min-width:0!important;
    height:44px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    overflow:hidden!important;
    box-sizing:border-box!important;
  }
  .game-settings .specimen-cell{justify-content:flex-start!important}
  #specimens{
    min-width:0!important;
    max-width:100%!important;
    white-space:nowrap!important;
    font-size:clamp(12px,3.6vw,16px)!important;
    overflow:hidden!important;
  }
  #specimenSwatches .specimen-swatch{
    width:18px!important;
    height:18px!important;
  }
  .game-settings .speed-control{
    width:100%!important;
    min-width:0!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    gap:3px!important;
    white-space:nowrap!important;
    font-size:clamp(12px,3.5vw,16px)!important;
    overflow:hidden!important;
  }
  .game-settings .speed-control > span:not(.mobile-rate-label),
  .game-settings #speedRange,
  .game-settings .mobile-rate-label{
    display:none!important;
  }
  .game-settings #speedNumber{
    width:42px!important;
    min-width:0!important;
    box-sizing:border-box!important;
  }
  .game-settings .pal-control{
    min-width:0!important;
    max-width:100%!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    gap:3px!important;
    white-space:nowrap!important;
    font-size:clamp(11px,3.3vw,15px)!important;
    overflow:hidden!important;
  }
  .game-settings #palimpsestToggle{
    flex:0 0 auto!important;
    margin:0!important;
  }
  .game-settings .map-control{
    width:100%!important;
    min-width:0!important;
    height:36px!important;
    min-height:36px!important;
    margin:0!important;
    padding:0 4px!important;
    box-sizing:border-box!important;
    font-size:14px!important;
  }

  /* Status begins only after both rows. */
  #status{
    position:static!important;
    clear:both!important;
  }
}


/* v67 — visible gutters between the three top-row controls */
@media(max-width:700px),(pointer:coarse){
  header{
    grid-template-columns:minmax(0,1fr) 86px 86px!important;
    column-gap:8px!important;
  }
  header .actions{
    grid-template-columns:86px 86px!important;
    gap:8px!important; /* secondary stack ↔ Start */
    height:86px!important;
  }
  header .secondary-actions{
    width:86px!important;
    height:86px!important;
    grid-template-rows:39px 39px!important;
    gap:8px!important; /* Guide ↔ Ancestors */
  }
  header .secondary-actions #rulesButton,
  header .secondary-actions #ancestorsButton{
    width:86px!important;
    height:39px!important;
    min-height:39px!important;
    max-height:39px!important;
  }
  header .actions #run{
    width:86px!important;
    min-width:86px!important;
    max-width:86px!important;
    height:86px!important;
    min-height:86px!important;
    max-height:86px!important;
  }
}


/* v68 — reset stale v62 grid placement; keep Guide/Ancestors in two clean rows */
@media(max-width:700px),(pointer:coarse){
  header .secondary-actions #rulesButton{
    grid-column:1!important;
    grid-row:1!important;
    align-self:stretch!important;
  }
  header .secondary-actions #ancestorsButton{
    grid-column:1!important;
    grid-row:2!important;
    align-self:stretch!important;
  }
  header .secondary-actions{
    row-gap:8px!important;
  }
}


/* v70 — independent With palimpsest + dismissible Success */
.success-card{position:relative}
.success-close{
  position:absolute;
  top:8px;
  right:8px;
  width:34px;
  height:34px;
  padding:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background:#fff;
  color:#111;
  border:1px solid #111;
  font:inherit;
  font-size:24px;
  line-height:1;
  cursor:pointer;
}
.pal-cell{
  gap:7px!important;
}
.with-pal-control{
  display:flex;
  align-items:center;
  gap:3px;
  white-space:nowrap;
}
@media(max-width:700px),(pointer:coarse){
  .pal-cell{
    flex-direction:column!important;
    gap:1px!important;
    line-height:1!important;
  }
  .pal-cell .pal-control,
  .pal-cell .with-pal-control{
    font-size:11px!important;
    min-height:19px!important;
  }
}


/* v84 — Release + persistent mobile restart during a run */
.release-control{
  appearance:none;border:1px solid #aaa;background:#fff;color:#111;
  font:inherit;padding:3px 8px;cursor:pointer;
}
.release-control.active{background:#111;color:#fff;border-color:#111}

@media(max-width:700px),(pointer:coarse){
  /* Row 2 gains an explicit Release cell; all five controls remain isolated. */
  .game-settings{
    grid-template-columns:minmax(0,1.45fr) minmax(54px,.65fr) minmax(0,1.08fr) 52px 64px!important;
  }
  .game-settings .release-control{
    width:100%!important;min-width:0!important;height:36px!important;min-height:36px!important;
    margin:0!important;padding:0 3px!important;box-sizing:border-box!important;font-size:12px!important;
    touch-action:manipulation!important;
  }

  /* Zoom and Release form a pair. Release exists only when the feature is on. */
  #mobileZoom4{
    left:14px!important;top:152px!important;width:80px!important;min-width:80px!important;
    height:40px!important;min-height:40px!important;
  }
  #mobileRelease:not([hidden]){
    display:block!important;position:absolute!important;left:100px!important;top:152px!important;
    width:82px!important;min-width:82px!important;height:40px!important;min-height:40px!important;
    padding:0 4px!important;background:#111!important;color:#fff!important;border:1px solid #111!important;
    font-size:11px!important;z-index:1401!important;touch-action:manipulation!important;
    user-select:none!important;-webkit-user-select:none!important;
  }
  #mobileRelease:disabled{opacity:.35!important}

  /* Rapid retry stays available while the run exists, at the bottom-left. */
  #mobileRestart:not([hidden]){
    display:block!important;position:absolute!important;left:14px!important;bottom:max(8px,env(safe-area-inset-bottom))!important;
    top:auto!important;width:48px!important;min-width:48px!important;height:40px!important;min-height:40px!important;
    margin:0!important;padding:0!important;background:#fff!important;color:#111!important;border:1px solid #111!important;
    font-size:24px!important;line-height:1!important;z-index:1402!important;touch-action:manipulation!important;
  }
  #mobileControls{min-height:250px!important}
}

body.rules-open #mobileRelease,
body.rules-open #mobileRestart,
body.ancestors-open #mobileRelease,
body.ancestors-open #mobileRestart{
  visibility:hidden!important;pointer-events:none!important;
}

/* v93 — mobile-only header/settings reflow */
@media(max-width:700px),(pointer:coarse){
  .game-settings{
    position:relative!important;display:grid!important;
    grid-template-columns:minmax(0,1.25fr) 54px minmax(76px,1fr) 54px!important;
    grid-template-rows:38px 44px!important;
    width:100%!important;max-width:100%!important;height:82px!important;
    margin:-38px 0 0!important;padding:0 8px!important;gap:4px!important;
    overflow:visible!important;box-sizing:border-box!important;align-items:stretch!important;z-index:20!important;
  }
  .game-settings .setting-cell{min-width:0!important;box-sizing:border-box!important}
  .game-settings .specimen-cell{
    grid-column:1 / 3!important;grid-row:1!important;height:38px!important;
    justify-content:flex-start!important;overflow:visible!important;
  }
  #specimens{max-width:none!important;overflow:visible!important;font-size:clamp(13px,3.7vw,16px)!important}
  .game-settings .release-cell{
    grid-column:1!important;grid-row:2!important;height:44px!important;
    justify-content:flex-start!important;overflow:visible!important;
  }
  .game-settings .release-control{
    width:auto!important;max-width:100%!important;min-width:0!important;height:36px!important;
    padding:0 8px!important;font-size:12px!important;white-space:nowrap!important;
  }
  .game-settings .rate-cell{grid-column:2!important;grid-row:2!important;height:44px!important}
  .game-settings .pal-cell{grid-column:3!important;grid-row:2!important;height:44px!important}
  .game-settings .map-cell{grid-column:4!important;grid-row:2!important;height:44px!important}
  #mobileRestart{display:none!important}
}

/* v94 soundtrack */
.music-toggle{appearance:none;border:1px solid #111;background:#111;color:#fff;font:inherit;padding:7px 10px;margin:6px 0 10px;cursor:pointer}.music-toggle[aria-pressed="false"]{background:#fff;color:#111}.music-credits{margin-top:22px;padding-top:10px;border-top:1px solid #ddd;font-size:11px;line-height:1.35}.music-credits p{margin:3px 0}

/* v98 — desktop Rate geometry stabilization.
   Keep the range/input group out of flex shrink/reflow during live UI updates. */
@media (min-width:701px) and (pointer:fine){
  .game-settings .rate-cell{
    flex:0 0 auto!important;
    min-width:max-content!important;
  }
  .game-settings .rate-cell input[type="range"]{
    flex:0 0 180px!important;
    width:180px!important;
    min-width:180px!important;
    max-width:180px!important;
  }
}

/* v100 — Untold Labs ownership lockup + telemetry disclosure */
footer .untold-lockup{
  margin-left:auto;display:inline-flex;align-items:center;gap:6px;
  white-space:nowrap;font-size:10px;font-weight:500;opacity:.72;
}
footer .untold-lockup img{width:18px;height:12px;object-fit:contain;display:block}
.telemetry-note{margin-top:22px;padding-top:10px;border-top:1px solid #ddd;font-size:11px;line-height:1.35}
.telemetry-note p{margin:3px 0}
@media(max-width:700px),(pointer:coarse){
  footer .untold-lockup{width:100%;justify-content:flex-end;margin-top:5px;font-size:9px}
  footer .untold-lockup img{width:16px;height:11px}
}


/* v102 — quiet maker credit + Wisps prototype */
footer .untold-lockup{margin-left:auto;white-space:nowrap;font-size:10px;font-weight:500;opacity:.62}
footer .untold-lockup img{display:none!important}
.wisps-entry{margin-top:20px;padding-top:14px;border-top:1px solid #bbb}
.wisps-entry{display:flex;align-items:center;gap:12px}
.wisps-entry p{margin:0!important;font-size:12px;color:#555}
.wisps-entry button{font-weight:700}
.guide-maker{margin-top:22px;padding-top:12px;border-top:1px solid #ddd;font-size:10px;color:#666}
.guide-maker a{display:inline-flex;align-items:center;gap:5px;text-decoration:none!important;color:#555!important}
.guide-maker img{width:15px;height:15px;object-fit:contain;display:block}
.guide-maker p{margin:4px 0 0!important;font-size:9px;color:#777}

.wisps-screen{position:fixed;inset:0;z-index:100100;background:rgba(255,255,255,.97);display:flex;align-items:center;justify-content:center;padding:18px}
.wisps-screen[hidden]{display:none}
.wisps-card{position:relative;background:#fff;border:1px solid #111;width:min(1180px,96vw);max-height:94dvh;overflow:auto;padding:22px}
.wisps-card h2{margin:0 40px 8px 0;font-size:26px}
.wisps-note{margin:0 0 16px;max-width:850px;font-size:13px;line-height:1.4}
.wisps-builder{display:grid;grid-template-columns:max-content minmax(260px,1fr);gap:20px;align-items:start}
.wisp-grid-wrap{overflow:auto;max-width:70vw;max-height:68dvh;border:1px solid #111;background:#fff}
.wisp-grid{display:grid;grid-template-columns:repeat(28,18px);grid-template-rows:repeat(28,18px);width:max-content}
.wisp-cell{box-sizing:border-box;width:18px;height:18px;border:0;border-right:1px solid #ddd;border-bottom:1px solid #ddd;border-radius:0;padding:0;text-align:center;font:12px/18px ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;outline:none;background:#fff;color:#111}
.wisp-cell:focus{box-shadow:inset 0 0 0 1px #111;position:relative;z-index:1}
.wisp-actions{display:flex;align-items:center;gap:10px;margin-top:8px;font-size:11px;color:#666}
.wisp-actions button{padding:5px 9px}
.wisp-preview-wrap{min-width:0}
.wisp-preview-title{font-size:11px;font-weight:700;margin-bottom:6px}
#wispPreview{display:block;width:100%;height:auto;max-height:68dvh;object-fit:contain;image-rendering:pixelated;border:1px solid #111;background:#fff}
body.wisps-open #mobileControls,body.wisps-open #joystick,body.wisps-open #mobileRateSteps,body.wisps-open #mobileZoom4,body.wisps-open #mobileRelease{visibility:hidden!important;pointer-events:none!important}
@media(max-width:760px),(pointer:coarse){
 .wisps-screen{padding:8px;align-items:flex-start}
 .wisps-card{padding:16px;max-height:96dvh}
 .wisps-builder{grid-template-columns:1fr}
 .wisp-grid-wrap{max-width:calc(100vw - 50px);max-height:52dvh}
 .wisp-grid{grid-template-columns:repeat(28,16px);grid-template-rows:repeat(28,16px)}
 .wisp-cell{width:16px;height:16px;font-size:11px;line-height:16px}
 #wispPreview{max-height:45dvh}
 .guide-maker img{width:13px;height:13px}
 footer .untold-lockup{font-size:9px}
}

.wisp-meta{display:grid;grid-template-columns:minmax(130px,1fr) minmax(180px,2fr) auto minmax(150px,1fr);gap:7px;align-items:center;margin:0 0 10px}
.wisp-meta input,.wisp-meta select,.wisp-meta button{box-sizing:border-box;min-height:30px;border:1px solid #111;background:#fff;color:#111;padding:5px 7px;font:inherit}
#wispStatus{grid-column:1/-1;min-height:14px;font-size:10px;color:#666}
@media(max-width:760px),(pointer:coarse){
 .wisp-meta{grid-template-columns:1fr 1fr}
 .wisp-meta #wispNote{grid-column:1/-1}
}


/* v105 — Wisps: editor above, expanded world below. */
.wisps-card{width:min(1120px,96vw);overflow-y:auto;overflow-x:hidden}
.wisps-builder{display:flex!important;flex-direction:column!important;gap:22px!important;align-items:stretch!important}
.wisp-editor-region,.wisp-world-region{display:block;width:100%;min-width:0}
.wisp-world-region{padding-top:18px;border-top:1px solid #bbb}
.wisp-region-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:0 0 8px;font-size:12px}
.wisp-region-head>span{font-size:10px;color:#666}
.wisp-colour-control{display:inline-flex;align-items:center;gap:7px;font-size:10px;font-weight:500;color:#555}
#wispColour{width:30px;height:24px;padding:0;border:1px solid #999;background:#fff;cursor:pointer}
.wisp-grid-wrap{
  overflow:visible!important;
  max-width:none!important;
  max-height:none!important;
  width:fit-content;
  border:1px solid #111;
}
.wisp-grid{
  grid-template-columns:repeat(28,minmax(16px,1fr))!important;
  grid-template-rows:repeat(28,minmax(16px,1fr))!important;
  width:min(100%,560px)!important;
  aspect-ratio:1/1;
}
.wisp-cell{
  width:100%!important;height:100%!important;min-width:0;min-height:0;
  font-size:clamp(9px,1.1vw,12px)!important;
  line-height:1!important;
}
.wisp-preview-wrap{
  width:100%!important;
  min-width:0!important;
  overflow:hidden!important;
  border:1px solid #111;
  background:#fff;
}
#wispPreview{
  display:block;
  width:100%!important;
  max-width:100%!important;
  height:auto!important;
  max-height:none!important;
  border:0!important;
  object-fit:contain;
  image-rendering:pixelated;
}
@media(max-width:760px),(pointer:coarse){
 .wisps-card{width:100%;max-height:calc(100dvh - 16px);padding:14px}
 .wisps-note{font-size:12px}
 .wisp-grid-wrap{width:100%!important}
 .wisp-grid{width:100%!important;grid-template-columns:repeat(28,minmax(10px,1fr))!important;grid-template-rows:repeat(28,minmax(10px,1fr))!important}
 .wisp-cell{font-size:9px!important}
 .wisp-world-region{padding-top:14px}
 .wisp-region-head{margin-bottom:6px}
}


/* v106 — hard separation of Wisp editor and generated World.
   These rules intentionally override every earlier Wisps layout rule. */
#wispsScreen .wisps-card{
  display:block!important;
  width:min(1180px,calc(100vw - 36px))!important;
  max-width:1180px!important;
  height:auto!important;
  max-height:94dvh!important;
  overflow-y:auto!important;
  overflow-x:hidden!important;
}
#wispsScreen .wisps-builder{
  display:block!important;
  width:100%!important;
  height:auto!important;
}
#wispsScreen .wisp-editor-region,
#wispsScreen .wisp-world-region{
  position:relative!important;
  display:block!important;
  float:none!important;
  clear:both!important;
  width:100%!important;
  height:auto!important;
  min-width:0!important;
  min-height:0!important;
  max-width:none!important;
  max-height:none!important;
  overflow:visible!important;
  box-sizing:border-box!important;
}
#wispsScreen .wisp-editor-region{
  margin:0!important;
  padding:0 0 24px!important;
  border:0!important;
}
#wispsScreen .wisp-world-region{
  margin:0!important;
  padding:20px 0 0!important;
  border:0!important;
  border-top:1px solid #aaa!important;
}

/* The 28×28 ASCII composition grid is the main interface. */
#wispsScreen .wisp-grid-wrap{
  position:relative!important;
  display:block!important;
  width:min(100%,700px)!important;
  height:auto!important;
  max-width:700px!important;
  max-height:none!important;
  margin:0!important;
  padding:0!important;
  overflow:hidden!important;
  border:1px solid #111!important;
  box-sizing:border-box!important;
}
#wispsScreen .wisp-grid{
  position:relative!important;
  display:grid!important;
  grid-template-columns:repeat(28,1fr)!important;
  grid-template-rows:repeat(28,1fr)!important;
  width:100%!important;
  height:auto!important;
  aspect-ratio:1/1!important;
  margin:0!important;
  padding:0!important;
}
#wispsScreen .wisp-cell{
  position:relative!important;
  box-sizing:border-box!important;
  display:block!important;
  width:100%!important;
  height:100%!important;
  min-width:0!important;
  min-height:0!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  border-right:1px solid #ddd!important;
  border-bottom:1px solid #ddd!important;
  text-align:center!important;
  font:12px/1 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace!important;
  background:#fff!important;
  color:#111!important;
}
#wispsScreen .wisp-cell:focus{
  outline:1px solid #111!important;
  outline-offset:-1px!important;
  z-index:2!important;
}
#wispsScreen .wisp-actions{
  display:flex!important;
  align-items:center!important;
  gap:10px!important;
  width:min(100%,700px)!important;
  margin:8px 0 0!important;
}

/* World cannot occupy the editor's layout box: it is an ordinary block below it. */
#wispsScreen .wisp-preview-wrap{
  position:relative!important;
  display:block!important;
  float:none!important;
  clear:both!important;
  width:min(100%,1064px)!important;
  height:auto!important;
  min-width:0!important;
  min-height:0!important;
  max-width:1064px!important;
  max-height:none!important;
  margin:0!important;
  padding:0!important;
  overflow:hidden!important;
  border:1px solid #111!important;
  box-sizing:border-box!important;
  background:#fff!important;
}
#wispsScreen #wispPreview{
  position:relative!important;
  display:block!important;
  width:100%!important;
  height:auto!important;
  max-width:100%!important;
  max-height:none!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  aspect-ratio:1/1!important;
  object-fit:contain!important;
  image-rendering:pixelated!important;
}
@media(max-width:760px),(pointer:coarse){
 #wispsScreen .wisps-card{
   width:calc(100vw - 16px)!important;
   max-height:calc(100dvh - 16px)!important;
   padding:14px!important;
 }
 #wispsScreen .wisp-grid-wrap,
 #wispsScreen .wisp-actions,
 #wispsScreen .wisp-preview-wrap{width:100%!important;max-width:100%!important}
 #wispsScreen .wisp-cell{font-size:9px!important}
 #wispsScreen .wisp-editor-region{padding-bottom:18px!important}
 #wispsScreen .wisp-world-region{padding-top:16px!important}
}


/* v107 — per-tile colour selection. Option/Alt-drag selects rectangular ranges. */
#wispsScreen .wisp-cell.selected{
  background:#e8eefb!important;
  box-shadow:inset 0 0 0 1px #315efb!important;
  z-index:1!important;
}
#wispsScreen #wispSelectionCount{font-weight:600;color:#333}
#wispsScreen .wisp-colour-control input[type="color"]{touch-action:manipulation}

/* v108 — Save / Play / Saved are the authoring loop. */
#wispsScreen .wisp-meta{grid-template-columns:minmax(130px,1fr) minmax(180px,2fr) auto auto minmax(150px,1fr)}
#wispsScreen #wispPlay{font-weight:700;background:#111;color:#fff}
@media(max-width:760px),(pointer:coarse){
 #wispsScreen .wisp-meta{grid-template-columns:1fr 1fr}
 #wispsScreen #wispName,#wispsScreen #wispNote{grid-column:1/-1}
 #wispsScreen #wispSavedList{grid-column:1/-1}
}


/* v109 — direct drag selection, no Option/Alt key required. */
#wispsScreen .wisp-grid{user-select:none;-webkit-user-select:none}
#wispsScreen .wisp-cell{touch-action:none}
#wispsScreen .wisp-cell.selected{
  background:#e8eefb!important;
  box-shadow:inset 0 0 0 1px #315efb!important;
}

/* v110 — Wisps is a separate page. */
.wisps-page-link{display:inline-block;color:#111;text-decoration:none;border:1px solid #aaa;padding:7px 14px;background:#fff}
.wisps-page .wisp-meta{display:grid;grid-template-columns:minmax(130px,1fr) minmax(180px,2fr) auto auto minmax(150px,1fr);gap:7px}
.wisps-page .wisps-builder{display:block;width:100%}
.wisps-page .wisp-editor-region,.wisps-page .wisp-world-region{display:block;clear:both;width:100%;box-sizing:border-box}
.wisps-page .wisp-editor-region{padding:16px 0 24px}
.wisps-page .wisp-world-region{padding:20px 0 0;border-top:1px solid #aaa}
.wisps-page .wisp-region-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;font-size:12px}
.wisps-page .wisp-grid-wrap{width:min(100%,700px);overflow:hidden;border:1px solid #111;box-sizing:border-box}
.wisps-page .wisp-grid{display:grid;grid-template-columns:repeat(28,1fr);grid-template-rows:repeat(28,1fr);width:100%;aspect-ratio:1}
.wisps-page .wisp-cell{box-sizing:border-box;width:100%;height:100%;min-width:0;min-height:0;padding:0;border:0;border-right:1px solid #ddd;border-bottom:1px solid #ddd;text-align:center;font:12px/1 ui-monospace,SFMono-Regular,Menlo,monospace;background:#fff;color:#111;touch-action:none}
.wisps-page .wisp-cell.selected{background:#e8eefb;box-shadow:inset 0 0 0 1px #315efb}
.wisps-page .wisp-actions{display:flex;align-items:center;gap:10px;width:min(100%,700px);margin-top:8px;font-size:11px}
.wisps-page .wisp-preview-wrap{width:min(100%,1064px);overflow:hidden;border:1px solid #111;background:#fff}
.wisps-page #wispPreview{display:block;width:100%;height:auto;aspect-ratio:1;image-rendering:pixelated}
.wisps-page #wispPlay{font-weight:700;background:#111;color:#fff}
@media(max-width:760px){
 .wisps-page .wisp-meta{grid-template-columns:1fr 1fr}
 .wisps-page #wispName,.wisps-page #wispNote,.wisps-page #wispSavedList{grid-column:1/-1}
 .wisps-page .wisp-grid-wrap,.wisps-page .wisp-actions,.wisps-page .wisp-preview-wrap{width:100%}
 .wisps-page .wisp-cell{font-size:9px}
}

/* v162 — variable and irregular Wisp geometry */
.wisps-page .wisp-structure-controls{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.wisps-page .wisp-structure-controls label{display:flex;align-items:center;gap:4px;font-size:11px}
.wisps-page #wispWidth,.wisps-page #wispHeight{width:48px}
.wisps-page .shape-mode{border:1px solid #aaa;padding:4px 7px;cursor:pointer}
.wisps-page .wisp-cell.absent{background:#ddd!important;border-color:#ccc!important;box-shadow:inset 0 0 0 1px #bbb!important;cursor:crosshair}
.wisps-page .wisp-cell:disabled{opacity:1}
.wisps-page:has(#wispShapeMode:checked) .wisp-cell{cursor:crosshair}
@media(max-width:760px){.wisps-page .wisp-region-head{align-items:flex-start;gap:8px}.wisps-page .wisp-structure-controls{justify-content:flex-end}}

/* v162 objective HUD */
.objective-status{display:flex;align-items:center;gap:8px;min-width:0}
.beacon-status{display:flex;align-items:center;gap:4px;font-size:11px;font-weight:700;white-space:nowrap}
.beacon-hud-star{display:inline-flex;align-items:center;justify-content:center;font-family:monospace;font-size:24px;line-height:.65;font-weight:700;text-shadow:0 0 0 #111}

@media(max-width:700px),(pointer:coarse){
  .game-settings .specimen-cell{overflow:visible!important;align-items:center!important}
  .objective-status{width:100%;display:grid!important;grid-template-columns:1fr!important;grid-template-rows:auto auto!important;gap:1px!important;align-content:center!important}
  #specimens{font-size:10px!important;line-height:12px!important;overflow:visible!important}
  #specimenSwatches .specimen-swatch{width:12px!important;height:12px!important}
  .beacon-status{font-size:10px!important;line-height:12px!important;min-height:12px}
  .beacon-hud-star{font-size:20px!important;line-height:10px!important}
}
@media(max-width:420px){
  #specimens,.beacon-status{font-size:9px!important}
}

/* v162 compact objective HUD */
.objective-box{
  display:inline-block;width:13px;height:13px;border:1px solid #111;
  box-sizing:border-box;vertical-align:middle;flex:0 0 13px;
}
.objective-label{font-weight:700}
#specimens,.beacon-status{font-weight:700}
#specimens{display:flex;align-items:center;gap:4px}
.beacon-status{display:flex;align-items:center;gap:4px}

@media(max-width:700px),(pointer:coarse){
  /* Two clean objective rows at top-left. */
  .game-settings{
    grid-template-columns:minmax(118px,1.15fr) minmax(54px,.55fr) minmax(0,1fr) 58px!important;
    grid-template-rows:50px!important;
    height:50px!important;
    padding-left:8px!important;
  }
  .game-settings .setting-cell{height:50px!important}
  .objective-status{
    display:grid!important;grid-template-columns:1fr!important;
    grid-template-rows:20px 20px!important;gap:0!important;
    width:100%!important;align-content:center!important;
  }
  #specimens,.beacon-status{
    display:flex!important;align-items:center!important;gap:4px!important;
    font-size:10px!important;line-height:20px!important;
    white-space:nowrap!important;overflow:visible!important;
  }
  #specimenSwatches{display:inline-flex!important}
  #specimenSwatches .objective-box,.beacon-status .objective-box{
    width:13px!important;height:13px!important;flex-basis:13px!important;
  }

  /* Release belongs beneath the objective block, not on top of it. */
  #release{
    position:absolute!important;
    left:8px!important;
    top:calc(100% + 62px)!important;
    width:auto!important;min-width:72px!important;
    height:34px!important;min-height:34px!important;
    margin:0!important;padding:0 8px!important;
    z-index:21!important;
    font-size:11px!important;
  }
}
@media(max-width:420px){
  #specimens,.beacon-status{font-size:9px!important}
}

/* v162 mobile header: controls stay above the playing area. */
@media(max-width:700px),(pointer:coarse){
  header{margin-bottom:0!important}
  .game-settings{
    position:relative!important;
    display:grid!important;
    grid-template-columns:minmax(128px,1.25fr) minmax(58px,.55fr) minmax(108px,1fr) 62px!important;
    grid-template-rows:48px 44px!important;
    width:100%!important;height:92px!important;
    margin:0!important;padding:0 8px!important;gap:0 5px!important;
    overflow:visible!important;box-sizing:border-box!important;
    background:#fff!important;z-index:30!important;
  }
  .game-settings .setting-cell{height:auto!important;min-height:0!important}
  .game-settings .specimen-cell{
    grid-column:1 / 3!important;grid-row:1!important;
    align-items:flex-start!important;justify-content:flex-start!important;
    padding-top:7px!important;overflow:visible!important;
  }
  .objective-status{
    display:grid!important;grid-template-columns:1fr!important;
    grid-template-rows:18px 18px!important;gap:2px!important;align-content:start!important;
  }
  #specimens,.beacon-status{
    font-size:12px!important;line-height:18px!important;font-weight:700!important;
    display:flex!important;align-items:center!important;gap:5px!important;
  }
  #specimenSwatches .objective-box,.beacon-status .objective-box{
    width:14px!important;height:14px!important;flex:0 0 14px!important;
  }
  .game-settings .release-cell{
    grid-column:1!important;grid-row:2!important;
    align-items:center!important;justify-content:flex-start!important;
  }
  #release,.game-settings .release-control{
    position:static!important;left:auto!important;top:auto!important;
    width:auto!important;min-width:72px!important;height:36px!important;min-height:36px!important;
    margin:0!important;padding:0 8px!important;font-size:11px!important;
  }
  .game-settings .rate-cell{grid-column:2!important;grid-row:2!important;height:44px!important}
  .game-settings .pal-cell{grid-column:3!important;grid-row:2!important;height:44px!important}
  .game-settings .map-cell{grid-column:4!important;grid-row:2!important;height:44px!important}
  #status{
    position:relative!important;z-index:25!important;background:#fff!important;
    margin:0!important;min-height:14px!important;
  }
  #viewport{margin-top:0!important}

  /* Mobile button now toggles With-relative field of view, independent of map size. */
  #mobileZoom4{
    width:auto!important;min-width:118px!important;padding:0 8px!important;
    font-size:12px!important;
  }
}

/* v162 — Wisp colour controls are square patches, not circular wells. */
.wisps-page input[type="color"],
#wispsScreen input[type="color"]{
  -webkit-appearance:none!important;appearance:none!important;
  width:28px!important;height:28px!important;min-width:28px!important;
  padding:0!important;border:1px solid #777!important;border-radius:0!important;
  background:none!important;overflow:hidden!important;box-sizing:border-box!important;
}
.wisps-page input[type="color"]::-webkit-color-swatch-wrapper,
#wispsScreen input[type="color"]::-webkit-color-swatch-wrapper{padding:0!important}
.wisps-page input[type="color"]::-webkit-color-swatch,
#wispsScreen input[type="color"]::-webkit-color-swatch{
  border:0!important;border-radius:0!important;
}
.wisps-page input[type="color"]::-moz-color-swatch,
#wispsScreen input[type="color"]::-moz-color-swatch{
  border:0!important;border-radius:0!important;
}
.focus-zoom{font-weight:700;white-space:nowrap}
.focus-zoom.active{background:#111;color:#fff}
@media(max-width:700px),(pointer:coarse){.focus-zoom{display:none!important}}



#viewAncestry{width:100%;margin:12px 0 2px}
.success-ancestry-screen{position:fixed;inset:0;z-index:10020;background:rgba(255,255,255,.94);display:grid;place-items:center;padding:20px}
.success-ancestry-screen[hidden]{display:none!important}
.success-ancestry-card{position:relative;width:min(900px,94vw);max-height:90vh;overflow:auto;border:1px solid #111;background:#fff;padding:24px}
.success-ancestry-card h2{margin:0 38px 2px 0;font-size:1.35rem}
.success-ancestry-note{margin:0 0 12px;font-size:.82rem;opacity:.7}
#successAncestryPlot{display:block;width:100%;height:auto;aspect-ratio:41/26;background:#fff}
@media(max-width:600px){
 .success-ancestry-screen{padding:8px}
 .success-ancestry-card{width:96vw;padding:14px 10px}
 #successAncestryPlot{aspect-ratio:4/3}
}

.music-choice-note{margin:.2rem 0 .55rem;opacity:.7;font-size:.85em}
.music-track-choice{display:flex;align-items:flex-start;gap:.5rem;margin:.38rem 0;cursor:pointer}
.music-track-choice input{margin:.18rem 0 0;accent-color:#111}
.music-track-choice span{line-height:1.25}

.success-ancestry-preview{margin:12px 0 10px;border-top:1px solid rgba(0,0,0,.12);padding-top:10px}
.success-ancestry-preview h3{margin:0 0 1px;font-size:1rem}
#successAncestryPreviewPlot{display:block;width:100%;height:180px;background:#fff}
.success-ancestry-preview #viewAncestry{width:100%;margin:6px 0 0}
@media(max-width:600px){#successAncestryPreviewPlot{height:150px}}

.ancestry-back{position:absolute;left:16px;top:16px;z-index:3}
@media(max-width:600px){.ancestry-back{left:10px;top:10px}}

#successAncestryPreviewPlot{width:min(100%,620px)!important;height:auto!important;aspect-ratio:1/1;margin:0 auto}

/* v164 expanded ancestry: use the viewport first; scroll only when it becomes too small. */
.success-ancestry-screen{
  position:fixed!important;inset:0!important;z-index:10020!important;
  background:rgba(255,255,255,.96)!important;
  display:block!important;padding:0!important;overflow:auto!important;
}
.success-ancestry-screen[hidden]{display:none!important}
.success-ancestry-card{
  box-sizing:border-box!important;position:relative!important;
  width:100%!important;min-height:100vh!important;max-height:none!important;
  margin:0!important;border:0!important;background:#fff!important;
  padding:64px 28px 28px!important;overflow:visible!important;
}
.success-ancestry-card h2,.success-ancestry-card .success-ancestry-note{
  text-align:center;
}
#successAncestryPlot{
  display:block!important;
  width:min(calc(100vw - 56px),calc(100vh - 150px))!important;
  height:auto!important;aspect-ratio:1/1!important;
  min-width:620px!important;
  margin:0 auto!important;background:#fff;
}
.ancestry-back{
  position:fixed!important;left:18px!important;top:18px!important;z-index:10023!important;
  background:#fff!important;border:1px solid #111!important;padding:8px 12px!important;
}
#closeSuccessAncestry{
  position:fixed!important;right:18px!important;top:18px!important;z-index:10023!important;
  background:#fff!important;
}
@media(max-width:700px),(max-height:760px){
  .success-ancestry-card{min-width:700px!important;padding-top:58px!important}
  #successAncestryPlot{width:620px!important;min-width:620px!important}
  .ancestry-back{left:10px!important;top:10px!important}
  #closeSuccessAncestry{right:10px!important;top:10px!important}
}

/* v165: never allow a tall Success card to hide Success!/time/generation/score above the viewport. */
.success-screen{
  position:fixed!important;
  inset:0!important;
  overflow-y:auto!important;
  overflow-x:hidden!important;
  align-items:flex-start!important;
  justify-content:flex-start!important;
  padding:18px 20px 34px!important;
  box-sizing:border-box!important;
}
.success-stack{
  margin:0 auto!important;
  justify-content:flex-start!important;
  flex:0 0 auto!important;
}
.success-stack #successWith{
  margin-top:0!important;
}
.success-stack .success-card{
  flex:0 0 auto!important;
}
@media(max-width:600px){
  .success-screen{padding:10px 8px 28px!important}
}

/* v166 — rigid Success result frame.
   Primary result information owns its own block; ancestry is a later block and cannot overlap it. */
.success-screen{
  position:fixed!important;
  inset:0!important;
  display:block!important;
  overflow:auto!important;
  padding:18px 20px 36px!important;
  box-sizing:border-box!important;
}
.success-screen[hidden]{display:none!important}
.success-stack{
  display:flex!important;
  flex-direction:column!important;
  align-items:center!important;
  justify-content:flex-start!important;
  width:min(560px,100%)!important;
  margin:0 auto!important;
  gap:8px!important;
  padding:0 0 24px!important;
  box-sizing:border-box!important;
}
.success-stack #successWith{
  position:static!important;
  flex:0 0 auto!important;
  margin:0!important;
}
.success-stack .success-card{
  position:relative!important;
  display:flex!important;
  flex-direction:column!important;
  width:100%!important;
  margin:0!important;
  padding:24px!important;
  box-sizing:border-box!important;
  overflow:visible!important;
}
.success-card #successTitle{
  order:1;
  flex:0 0 auto!important;
  margin:0 34px 16px!important;
}
.success-card .success-metrics{
  order:2;
  position:relative!important;
  flex:0 0 auto!important;
  width:100%!important;
  margin:0 0 18px!important;
  z-index:2;
  background:#fff;
}
.success-card .success-ancestry-preview{
  order:3;
  position:relative!important;
  display:block!important;
  flex:0 0 auto!important;
  width:100%!important;
  clear:both!important;
  margin:0 0 16px!important;
  padding:16px 0 0!important;
  border-top:1px solid #bbb!important;
  overflow:hidden!important;
  z-index:1;
  box-sizing:border-box!important;
}
#successAncestryPreviewPlot{
  position:static!important;
  display:block!important;
  width:min(100%,500px)!important;
  height:auto!important;
  aspect-ratio:1/1!important;
  margin:8px auto 0!important;
  max-width:100%!important;
}
.success-ancestry-preview #viewAncestry{
  position:static!important;
  display:block!important;
  width:100%!important;
  margin:10px 0 0!important;
}
.success-card #leaderboardForm{order:4}
.success-card #leaderboard{order:5}
.success-card #playAgain{order:6;align-self:center}
@media(max-width:600px){
  .success-screen{padding:10px 8px 28px!important}
  .success-stack .success-card{padding:18px 12px!important}
  .success-card #successTitle{margin-bottom:12px!important}
  .success-card .success-metrics{grid-template-columns:1fr!important}
  #successAncestryPreviewPlot{width:min(100%,460px)!important}
}

/* v167 — compact ancestry preview; leaderboard remains the primary action. */
.success-ancestry-preview h3{margin:0!important;font-size:1rem!important}
.success-ancestry-preview .success-ancestry-note{margin:1px 0 4px!important;line-height:1.15!important}
.success-card .success-ancestry-preview{margin-bottom:14px!important;padding-top:12px!important}
.success-card #leaderboardForm{order:4!important}
.success-card #leaderboard{order:5!important}
.success-card #playAgain{order:6!important}
.success-card .explore-ancestry-bottom{order:7!important;width:100%!important;margin:18px 0 0!important;padding:9px 12px!important;border:1px solid #111!important;background:#fff!important;font:inherit!important}

/* v168 — tight Success lockup: Success → Results → map → Enter Name → leaderboard. */
.success-results-label{order:2;width:100%;margin:0 0 5px;font-weight:700;font-size:15px}
.success-card .success-metrics{order:3!important;margin:0 0 8px!important}
.success-card .success-ancestry-preview{order:4!important;margin:0 0 10px!important;padding:7px 0 0!important}
.success-ancestry-preview h3{margin:0!important}
.success-ancestry-preview .ancestry-subtitle,
.success-ancestry-preview .success-ancestry-note{margin:1px 0 3px!important}
#viewAncestry{display:none!important}
.success-card #leaderboardForm{order:5!important;margin-top:0!important}
#leaderboardForm textarea{display:none!important}
#leaderboardForm h3,#leaderboardForm .leaderboard-form-title{margin:0 0 6px!important}
#leaderboardForm button[type="submit"]{margin-top:6px!important}
.success-card #leaderboard{order:6!important}
.success-card #playAgain{order:7!important}

/* v169 percentile is a first-class result, not a leaderboard action. */
#finalPercentileNote.percentile-note{
  display:block;
  margin-top:3px;
  font-size:10px;
  line-height:1.2;
  font-weight:400;
  color:#666;
  text-transform:none;
  letter-spacing:0;
}

/* v170 — comments are useful context on leaderboard submissions. */
#leaderboardForm textarea{
  display:block!important;
  width:100%!important;
  box-sizing:border-box!important;
  margin-top:6px!important;
  min-height:56px!important;
}

/* v171 — percentile belongs in the same compact Results lockup. */
.success-metrics{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  align-items:stretch!important;
  width:100%!important;
}
.success-metrics > div{
  min-width:0!important;
  box-sizing:border-box!important;
  padding:12px 7px!important;
  border-right:1px solid #ccc!important;
}
.success-metrics > div:last-child{border-right:0!important}
#finalPercentileNote.percentile-note{
  font-size:9px!important;
  line-height:1.15!important;
  max-width:110px!important;
  margin:3px auto 0!important;
}
@media(max-width:520px){
  .success-card .success-metrics{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
  .success-metrics > div:nth-child(2){border-right:0!important}
  .success-metrics > div:nth-child(-n+2){border-bottom:1px solid #ccc!important}
}

/* v172 */
#leaderboardForm textarea{display:block!important}

/* v173: percentile is deliberately just "Top N%". */
#finalPercentileNote:empty{display:none!important}

/* v180 — per-Wisp instructions and preserved mobile joystick */
@media(max-width:700px),(pointer:coarse){#joystick{display:block!important;visibility:visible!important}}

/* v181 — level-specific instructions are part of the existing Guide. */
.guide-level-instructions{margin:16px 0;padding:12px 0;border-top:1px solid #bbb;border-bottom:1px solid #bbb}
.guide-level-instructions h3{margin:0 0 9px;font-size:15px}
.guide-level-instructions p{margin:5px 0;line-height:1.35}

/* v183 — compact numbered level rules; only the heading is bold. */
.guide-level-instructions .roman-instructions{list-style-type:lower-roman;margin:6px 0 0 25px;padding:0;font-weight:400}
.guide-level-instructions .roman-instructions li{margin:5px 0;line-height:1.35;font-weight:400}
.guide-level-instructions .key-hint{font-weight:400}

/* Guide audio controls */
.sfx-toggle{
 position:absolute;
 top:14px;
 right:98px;
 border:1px solid #111;
 background:#fff;
 color:#111;
 font:inherit;
 padding:5px 8px;
 cursor:pointer;
}



/* Guide audio controls: equal adjacent controls, in normal document flow. */
.guide-audio-toggles{
 display:flex;
 align-items:stretch;
 gap:6px;
 margin:0 46px 14px 0;
}
.guide-audio-toggles .music-toggle,
.guide-audio-toggles .sfx-toggle{
 position:static !important;
 inset:auto !important;
 display:block;
 flex:0 0 128px;
 width:128px;
 min-width:128px;
 box-sizing:border-box;
 margin:0;
 border:1px solid #111;
 background:#fff;
 color:#111;
 font:inherit;
 padding:7px 9px;
 line-height:1.2;
 text-align:center;
 cursor:pointer;
}
.guide-audio-toggles .music-toggle[aria-pressed="true"],
.guide-audio-toggles .sfx-toggle[aria-pressed="true"]{
 background:#111;
 color:#fff;
}

/* v204 — current level identity */
.guide-level-name{
 margin:0 0 3px;
 font-size:14px;
 line-height:1.2;
 font-weight:700;
}


/* v204 — collective run-history palimpsest */
.ancestors-view-tabs{display:flex;gap:6px;margin:0 0 14px;border-bottom:1px solid #bbb;padding-bottom:8px}
.ancestors-view-tabs button,.run-history-colour button{border:1px solid #111;background:#fff;color:#111;font:inherit;padding:7px 11px;cursor:pointer}
.ancestors-view-tabs button.active,.run-history-colour button.active{background:#111;color:#fff}
.run-history-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin:0 0 8px}
.run-history-colour{display:flex;align-items:center;gap:5px}.run-history-colour>span{font-size:.82rem;color:#555;margin-right:2px}
.run-history-legend{display:flex;align-items:center;justify-content:flex-end;gap:10px;flex-wrap:wrap;font-size:.76rem;color:#555}
.run-history-legend>span{display:inline-flex;align-items:center;gap:4px}.run-swatch{display:inline-block;width:16px;height:4px}.run-swatch.success{background:#087f7b}.run-swatch.fail{background:#b10f68}
.run-time-gradient{display:inline-block;width:88px;height:7px;background:linear-gradient(90deg,hsl(190 72% 38%),hsl(257.5 72% 38%),hsl(325 72% 38%));border:1px solid rgba(0,0,0,.15)}
.run-history-status{font-size:.78rem;color:#666;margin:5px 0 8px;text-align:center}
.run-history-canvas-wrap{width:100%;min-height:160px;display:flex;justify-content:center;align-items:flex-start;overflow:auto;background:#fafafa;border:1px solid #ddd;padding:8px;box-sizing:border-box}
#runHistoryCanvas{display:block;background:#fff;image-rendering:auto}
@media(max-width:700px),(pointer:coarse){.run-history-toolbar{align-items:flex-start}.run-history-legend{justify-content:flex-start}.ancestors-view-tabs button,.run-history-colour button{min-height:40px;padding:7px 9px}.run-history-canvas-wrap{padding:5px}}

/* v205 — Ancestors and Run history are peer visualisations everywhere. */
.ancestors-plot-block{margin:0 0 16px;padding:0 0 14px;border-bottom:1px solid #ddd}
.ancestors-plot-block h3{margin:0 0 1px;font-size:1rem}
#ancestorsPlot{display:block;width:100%;height:auto;max-height:430px}
.success-history-tabs{margin:5px 0 7px!important;padding-bottom:6px!important}
.success-history-tabs button{padding:5px 9px!important;font-size:.82rem!important;min-height:0!important}
#runHistoryCanvas,#successRunHistoryCanvas{display:block;background:#fff;image-rendering:auto}
.success-run-history-wrap{max-height:330px;min-height:150px}
#successRunHistoryPanel[hidden],#successAncestorsPanel[hidden],#ancestorsRunHistoryPanel[hidden],#ancestorsTopTimesPanel[hidden]{display:none!important}
@media(max-width:700px),(pointer:coarse){
 #ancestorsPlot{max-height:360px}
 .success-run-history-wrap{max-height:300px}
}

/* v206 — run maps are normal-flow canvases, not game viewport canvases. */
#runHistoryCanvas,#successRunHistoryCanvas{
 position:static!important;
 inset:auto!important;
 flex:0 0 auto;
 max-width:none!important;
 max-height:none!important;
}
.run-history-canvas-wrap{
 position:relative;
 justify-content:center;
 align-items:flex-start;
}

/* v208 — main Ancestors plot owns normal-flow space like the Success ancestry panel. */
.ancestors-plot-block{
  position:relative!important;
  box-sizing:border-box!important;
  width:100%!important;
  overflow:hidden!important;
}
#ancestorsPlot{
  position:static!important;
  inset:auto!important;
  display:block!important;
  box-sizing:border-box!important;
  width:min(100%,620px)!important;
  height:auto!important;
  aspect-ratio:1/1!important;
  max-width:620px!important;
  max-height:none!important;
  margin:8px auto 0!important;
  background:#fff!important;
}
#ancestorsTopTimesPanel{
  position:relative!important;
  width:100%!important;
  min-width:0!important;
}
#ancestorsLeaderboard{
  position:relative!important;
  clear:both!important;
  width:100%!important;
}
@media(max-width:700px),(pointer:coarse){
  #ancestorsPlot{width:100%!important;max-width:620px!important;aspect-ratio:1/1!important}
}


/* v210 — optional inverted surround/UI. The authored world canvas is never inverted. */
#invertToggle{white-space:nowrap}
body.theme-inverted,
body.theme-inverted main{background:#111;color:#f5f5f5}
body.theme-inverted header,
body.theme-inverted .game-settings,
body.theme-inverted #status,
body.theme-inverted footer,
body.theme-inverted #mobileControls{background:#111;color:#f5f5f5}
body.theme-inverted #status,
body.theme-inverted footer,
body.theme-inverted #level,
body.theme-inverted .tagline{color:#aaa}
body.theme-inverted button{background:#111;color:#f5f5f5;border-color:#f5f5f5}
body.theme-inverted button.active,
body.theme-inverted button[aria-pressed="true"]{background:#f5f5f5;color:#111}
body.theme-inverted .game-settings{border-bottom-color:#444}
body.theme-inverted #specimens,
body.theme-inverted .beacon-status{color:#f5f5f5}
body.theme-inverted .specimen-swatch,
body.theme-inverted .objective-box{border-color:#f5f5f5}
body.theme-inverted input[type="number"]{background:#111;color:#f5f5f5;border-color:#888}
body.theme-inverted #joystick{background:#111;border-color:#aaa}
body.theme-inverted #joystick:before,
body.theme-inverted #joystick:after{background:#555}
body.theme-inverted #stick{background:#f5f5f5}

/* Dialog chrome follows the surround theme; graph/world canvases keep their authored palettes. */
body.theme-inverted .rules-screen,
body.theme-inverted .ancestors-screen,
body.theme-inverted .success-screen{background:rgba(17,17,17,.92)}
body.theme-inverted .rules-card,
body.theme-inverted .ancestors-card,
body.theme-inverted .success-card{background:#111;color:#f5f5f5;border-color:#f5f5f5}
body.theme-inverted .rules-card a,
body.theme-inverted .ancestors-card a,
body.theme-inverted .success-card a{color:#f5f5f5}
body.theme-inverted .rules-close,
body.theme-inverted .success-close{color:#f5f5f5}
body.theme-inverted .success-metrics,
body.theme-inverted .success-metrics div+div,
body.theme-inverted .leaderboard,
body.theme-inverted .ancestors-view-tabs,
body.theme-inverted .success-visual-tabs{border-color:#555}
body.theme-inverted .success-metrics span,
body.theme-inverted .success-ancestry-note,
body.theme-inverted .ancestors-note,
body.theme-inverted .run-history-status,
body.theme-inverted .run-history-legend{color:#aaa}
body.theme-inverted .leaderboard th,
body.theme-inverted .leaderboard td{border-color:#444;color:#f5f5f5}
body.theme-inverted .leaderboard-entry input,
body.theme-inverted textarea{background:#111;color:#f5f5f5;border-color:#888}

/* The playing field itself deliberately stays authored/light unless its Wisp says otherwise. */
body.theme-inverted #viewport{background:#fff}

@media(max-width:700px),(pointer:coarse){
  /* Preserve the established two-column mobile header while fitting the third utility. */
  header .secondary-actions{
    grid-template-rows:24px 24px 24px!important;
    row-gap:7px!important;
  }
  header .secondary-actions #rulesButton,
  header .secondary-actions #ancestorsButton,
  header .secondary-actions #invertToggle{
    width:86px!important;height:24px!important;min-height:24px!important;max-height:24px!important;
    padding:2px 5px!important;font-size:11px!important;line-height:1!important;
  }
  header .secondary-actions #invertToggle{grid-column:1!important;grid-row:3!important;align-self:stretch!important}
  body.theme-inverted .game-settings,
  body.theme-inverted #status{background:#111!important;color:#f5f5f5!important}
}
\n\n/* v212 — Invert is a compact game setting; dark mode makes all space outside the authored level black. */
.invert-control{
  padding:2px 6px!important;
  min-height:0!important;
  height:auto!important;
  line-height:1.25!important;
  font-size:11px!important;
  white-space:nowrap;
}
body.theme-inverted #viewport{background:#111!important}
/* The world canvas is transparent outside the renderer's authored level rectangle,
   so the viewport black becomes the void while the Wisp arena keeps its own colours. */
@media(max-width:700px),(pointer:coarse){
  header .secondary-actions{grid-template-rows:24px 24px!important}
  .game-settings .pal-cell{gap:5px!important;flex-wrap:wrap!important}
  .game-settings .invert-control{padding:2px 5px!important;font-size:10px!important}
}

/* v213: compact, expandable music chooser */
.music-credits{margin-top:22px;padding-top:10px;border-top:1px solid #ddd;font-size:11px;line-height:1.35}
.music-credits>summary{cursor:pointer;list-style-position:outside;padding:6px 0;user-select:none}
.music-credits>summary .music-summary-note{font-weight:400;opacity:.65;margin-left:.45em}
.music-track-panel{padding:2px 0 4px;max-height:260px;overflow:auto}


/* v214 — With's matte black (#111) is the canonical black; frame the Guide With glyph. */
#rulesWith{
  border:1px solid #111;
  background:transparent;
}
body.theme-inverted #rulesWith{
  border-color:#fff;
}

/* v217 — Guide contrast in inverted mode. Keycaps stay paper-white with dark legends;
   the With example sits on a white tile so the matte-black sprite remains visible. */
body.theme-inverted .rules-controls kbd{
  background:#fff!important;
  color:#111!important;
  border-color:#aaa!important;
}
body.theme-inverted #rulesWith{
  background:#fff!important;
  border-color:#fff!important;
}


/* v219 — compact mobile toggles, dedicated now-playing row, non-overlapping bottom actions. */
#nowPlaying{font-size:11px;color:#666;padding:0 14px 4px;min-height:0;line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.invert-control{display:flex!important;align-items:center!important;gap:3px!important;padding:0!important;border:0!important;background:transparent!important;color:inherit!important;font:inherit!important;white-space:nowrap!important}
.invert-control input{margin:0!important}
body.theme-inverted #nowPlaying{background:#111;color:#aaa}
body.theme-inverted .invert-control{background:transparent!important;color:#f5f5f5!important}
@media(max-width:700px),(pointer:coarse){
  .game-settings .pal-cell{display:flex!important;flex-direction:column!important;align-items:flex-start!important;justify-content:center!important;gap:0!important;height:44px!important;overflow:visible!important}
  .game-settings .pal-cell .pal-control,
  .game-settings .pal-cell .with-pal-control,
  .game-settings .pal-cell .invert-control{display:flex!important;align-items:center!important;gap:3px!important;font-size:10px!important;line-height:14px!important;min-height:14px!important;height:14px!important;margin:0!important;padding:0!important;border:0!important;background:transparent!important;white-space:nowrap!important}
  .game-settings .pal-cell input[type="checkbox"]{width:13px!important;height:13px!important;min-width:13px!important;margin:0!important}
  #nowPlaying{padding:2px 8px 4px!important;font-size:10px!important;min-height:12px!important;background:#fff}
  body.theme-inverted #nowPlaying{background:#111!important;color:#aaa!important}
  #mobileZoom4{left:30px!important;top:152px!important;width:88px!important;min-width:88px!important;height:40px!important;min-height:40px!important;padding:0 4px!important;font-size:11px!important}
  #mobileRelease:not([hidden]){left:122px!important;top:152px!important;width:88px!important;min-width:88px!important;height:40px!important;min-height:40px!important;padding:0 3px!important;font-size:10px!important}
}

/* v219 — systematic inverted-mode contrast pass for application chrome.
   Data/world canvases deliberately retain their authored light palettes. */
body.theme-inverted .success-metrics{
  background:#111!important;
  color:#f5f5f5!important;
  border-color:#777!important;
}
body.theme-inverted .success-metrics > div{
  background:#111!important;
  color:#f5f5f5!important;
  border-color:#666!important;
}
body.theme-inverted .success-metrics span,
body.theme-inverted .success-metrics strong,
body.theme-inverted .success-metrics small,
body.theme-inverted .success-results-label,
body.theme-inverted #finalPercentileNote{
  color:#f5f5f5!important;
}
body.theme-inverted #finalPercentileNote{opacity:.72}

/* Form fields are intentionally paper-white: always pair them with matte-black text. */
body.theme-inverted #leaderboardForm input,
body.theme-inverted #leaderboardForm textarea,
body.theme-inverted .leaderboard-entry input,
body.theme-inverted input[type="text"],
body.theme-inverted input[type="search"]{
  background:#fff!important;
  color:#111!important;
  border-color:#aaa!important;
  caret-color:#111!important;
}
body.theme-inverted #leaderboardForm input::placeholder,
body.theme-inverted #leaderboardForm textarea::placeholder,
body.theme-inverted .leaderboard-entry input::placeholder,
body.theme-inverted input[type="text"]::placeholder,
body.theme-inverted input[type="search"]::placeholder{
  color:#666!important;
  opacity:1!important;
}
body.theme-inverted #leaderboardForm button[type="submit"]:not(:disabled),
body.theme-inverted #playAgain:not(:disabled){
  background:#111!important;
  color:#f5f5f5!important;
  border-color:#f5f5f5!important;
}
body.theme-inverted #leaderboardForm button[type="submit"]:disabled{
  background:#333!important;
  color:#888!important;
  border-color:#666!important;
}

/* Tabs and table filters: selected = paper, unselected = matte. */
body.theme-inverted .ancestors-view-tabs button,
body.theme-inverted .success-history-tabs button,
body.theme-inverted .leaderboard button{
  background:#111!important;
  color:#f5f5f5!important;
  border-color:#f5f5f5!important;
}
body.theme-inverted .ancestors-view-tabs button.active,
body.theme-inverted .success-history-tabs button.active,
body.theme-inverted .leaderboard button.active,
body.theme-inverted .ancestors-view-tabs button[aria-pressed="true"],
body.theme-inverted .success-history-tabs button[aria-pressed="true"]{
  background:#fff!important;
  color:#111!important;
}

body.theme-inverted .ancestors-plot-block,
body.theme-inverted .success-ancestry-preview,
body.theme-inverted #leaderboardForm,
body.theme-inverted .leaderboard{
  color:#f5f5f5!important;
  border-color:#555!important;
}
body.theme-inverted .leaderboard th,
body.theme-inverted .leaderboard td{
  background:#111!important;
  color:#f5f5f5!important;
  border-color:#444!important;
}

/* Explicit light visualisation surfaces. Their internal drawing code owns colours. */
body.theme-inverted #successAncestryPreviewPlot,
body.theme-inverted #successAncestryPlot,
body.theme-inverted #ancestorsPlot,
body.theme-inverted .run-history-canvas-wrap,
body.theme-inverted #runHistoryCanvas,
body.theme-inverted #successRunHistoryCanvas{
  background:#fff!important;
}

/* Secondary ancestry dialog was older chrome and must follow the same theme. */
body.theme-inverted .success-ancestry-screen{background:rgba(17,17,17,.92)!important}
body.theme-inverted .success-ancestry-card{
  background:#111!important;
  color:#f5f5f5!important;
  border-color:#f5f5f5!important;
}
body.theme-inverted .success-ancestry-card button{border-color:#f5f5f5!important}
