A little bit of JavaScript is the easiest way to do it, by setting Config.navigation.override to a function which will check your countdown variable, and override the navigation if it's less than or equal to zero. For example, you could put this in your JavaScript section:
Config.navigation.override = function (destinationPassage) {
if (hasOwnProperty.call(State.variables, "time") && (State.variables.time <= 0)) {
return "time up";
} else {
return false; // Proceed as normal
}
};
Now, whenever you navigate to a passage, if the $time variable exists and it's less than or equal to zero, then the game will go to the passage named "time up" instead, otherwise navigation will proceed as normal. (That code uses State.variables to access SugarCube story variables from JavaScript. Also, hasOwnProperty is the JavaScript method for checking to see if a property exists on an object.)
Have fun! :-)
P.S. Despite the similarity in the names, Java and JavaScript are quite different beasts. You'll likely only need JavaScript for anything you do in Twine.