
/****************************************/
/* common styles used for v1 through v4 */
/****************************************/
::-webkit-scrollbar { 
    display: none; 
}

body          { font-family: Arial, Helvetica, sans-serif; background-color: #000; margin: 0px; overflow: hidden; }
#stats        { border: 2px solid black; }
#controls     { width: 28em; float: left; padding: 1em; font-size: 0.7em; }
#controls th  { text-align: right; vertical-align: middle; }
#instructions { clear: left; float: left; width: 17em; padding: 1em; border: 1px solid black; box-shadow: 0 0 5px black; }
#game-shell   { position: fixed; inset: 0; overflow: hidden; background: #000; }
#racer        { position: relative; z-index: 0; 
	/* width: 1024px; 
	height: 512px; */ 
	margin: 0px;
	border: 0px solid white; 
	text-align: left;
	font-size: small; font-weight: bold; color: #bbb; }
#canvas       { position: relative; z-index: 0; /* width: 1024px; height: 512px; */ z-index: 0; background-color: #72D7EE; 
	padding: 0; margin: 0; }
#mute         { background-position:   0px 0px; width: 32px; height: 32px; background: url(images/mute.png); display: inline-block; cursor: pointer; position: absolute; margin-left: 20em; }
#mute.on      { background-position: -32px 0px; }

/**************************************************/
/* rudimentary heads up display (only used in v4) */
/**************************************************/

#hud                   { position: absolute; z-index: 1; width: 100%; /* width: 1024px; */ padding: 5px 0; font-family: Verdana, Geneva, sans-serif; font-size: 2em; background-color: rgba(40,40,50,0.5); color: black; border-bottom: 2px solid black; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; }
#hud .hud              { background-color: rgba(255,255,255,0.6); padding: 5px; border-radius: 5px; border: 1px solid black; margin: 0 5px; transition-property: background-color; transition-duration: 2s; -webkit-transition-property: background-color; -webkit-transition-duration: 2s; }
#hud #speed            { float: right; }
#hud #current_lap_time { float: left;  }
#hud #last_lap_time    { float: left; display: none;  }
#hud #fast_lap_time    { display: block; width: 12em;  margin: 0 auto; text-align: center; transition-property: background-color; transition-duration: 2s; -webkit-transition-property: background-color; -webkit-transition-duration: 2s; }
#hud .value            { color: black; font-weight: bold; }
#hud .fastest          { background-color: rgba(255,215,0,0.5); }

#mobile-controls {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  align-items: flex-end;
  justify-content: space-between;
  padding: 1rem;
  box-sizing: border-box;
}

body.startup-active #racer,
body.startup-active #mobile-controls,
body.startup-active #hud {
  filter: blur(14px);
  transition: filter 0.4s ease;
}

#startup-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: linear-gradient(rgba(0, 0, 0, 0.92), rgba(0, 0, 0, 0.5)), url(images/bg.png);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: #ffffff;
  opacity: 1;
  transition: opacity 0.9s ease, background 0.9s ease;
  pointer-events: none;
}

#startup-overlay.startup-hidden {
  opacity: 0;
  pointer-events: none;
}

#startup-overlay .startup-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
  padding: 1.5rem;
  width: min(90%, 28rem);
}

#startup-overlay img#startup-logo {
  max-width: 22rem;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,0.6));
}

#startup-overlay .countdown {
  font-size: clamp(4rem, 12vw, 8rem);
  font-weight: 900;
  letter-spacing: -0.05em;
  text-shadow: 0 0 40px rgba(0, 0, 0, 0.7);
  opacity: 1;
  transform: scale(1);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

#startup-overlay .tap-to-start-button {
  display: none;
  border: 0;
  border-radius: 999px;
  padding: 1rem 2rem;
  font-size: clamp(1rem, 2.8vw, 1.35rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #101010;
  background: linear-gradient(135deg, #ffd54a, #ff9b05);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

#startup-overlay .tap-to-start-button.visible {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#startup-overlay.startup-ready .startup-content {
  gap: 1.5rem;
}

#startup-overlay.startup-ready #startup-logo {
  transform: scale(1.02);
}

@media (orientation: portrait) {
  #game-shell {
    width: 100dvh;
    height: 100vw;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
  }

  #startup-overlay {
    background-image: linear-gradient(rgba(0, 0, 0, 0.96), rgba(0, 0, 0, 0.55)), url("images/bg portrait.png");
  }
}

#startup-overlay.startup-pulse .countdown {
  opacity: 1;
  transform: scale(1.12);
}

#startup-overlay.startup-fade {
  background: rgba(0,0,0,0);
}

#game-over-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.8);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#game-over-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

#game-over-overlay .game-over-content {
  background: rgba(20,20,30,0.95);
  border: 2px solid #fff;
  padding: 2rem 2.5rem;
  text-align: center;
  border-radius: 1rem;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
}

#game-over-overlay .game-over-title {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 900;
  margin-bottom: 0.75rem;
  letter-spacing: 0.05em;
}

#game-over-overlay .game-over-text {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
}

#game-over-overlay button {
  font-size: 1.15rem;
  padding: 0.9rem 1.8rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff5f5f, #ff9900);
  color: #111;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 18px 30px rgba(0,0,0,0.3);
}

body.shake {
  animation: shake 0.45s ease-in-out;
}

@keyframes shake {
  0% { transform: translate(0, 0); }
  10% { transform: translate(-12px, 10px); }
  20% { transform: translate(10px, -10px); }
  30% { transform: translate(-10px, 8px); }
  40% { transform: translate(10px, -8px); }
  50% { transform: translate(-6px, 6px); }
  60% { transform: translate(6px, -6px); }
  70% { transform: translate(-4px, 4px); }
  80% { transform: translate(4px, -4px); }
  90% { transform: translate(-2px, 2px); }
  100% { transform: translate(0, 0); }
}

#mobile-controls .control-group {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  pointer-events: auto;
}

#mobile-controls .control-side {
  display: flex;
  flex-direction: row;
  gap: 1rem;
  pointer-events: auto;
}

#mobile-controls .left-side {
  align-items: center;
}

#mobile-controls .right-side {
  align-items: center;
}

.mobile-button {
  width: 7rem;
  height: 7rem;
  min-width: 7rem;
  min-height: 7rem;
  border: none;
  border-radius: 50%;
  background: none;
  background-color: none;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  box-shadow: 0 14px 22px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(10px);
  touch-action: none;
  pointer-events: auto;
  padding: 0;
}

#btn-horn {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  background-size: cover;
  box-shadow: 0 14px 20px rgba(0, 0, 0, 0.35);
}

.mobile-button:active,
.mobile-button.active {
  transform: translateY(2px);
  background-color: rgba(255, 255, 255, 0.4);
}

#btn-left         { background-image: url(images/leftarrow.png); }
#btn-right        { background-image: url(images/rightarrow.png); }
#btn-accelerate   { background-image: url(images/run.png); background-size: 150% 150%; background-position: center center; background-repeat: no-repeat; }
#btn-brake        { background-image: url(images/break.png); }
#btn-horn         { background-image: url(images/horn.png); }

@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  #mobile-controls {
    display: flex;
  }
  #hud {
    font-size: 1.4em;
  }
}

@media (max-width: 640px) {
  #mobile-controls {
    padding: 0.75rem;
  }
  .mobile-button {
    width: 6.5rem;
    height: 6.5rem;
    min-width: 6.5rem;
    min-height: 6.5rem;
    background-size: cover;
    border-radius: 50%;
  }
  .mobile-button:active {
    transform: translateY(1px);
  }
  #btn-horn {
    width: 6rem;
    height: 6rem;
    background-size: cover;
    border-radius: 50%;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  #mobile-controls {
    align-items: stretch;
    justify-content: space-between;
    padding: 0.45rem 0.45rem 0.7rem;
  }

  #mobile-controls .control-group {
    justify-content: space-between;
    gap: 0.4rem;
  }

  #mobile-controls .control-side {
    gap: 0.4rem;
  }

  #mobile-controls .left-group {
    justify-content: flex-end;
    height: 100%;
  }

  #mobile-controls .left-side {
    flex-direction: row;
    justify-content: flex-end;
  }

  #mobile-controls .right-side {
    flex-direction: column;
    justify-content: flex-end;
  }

  .mobile-button {
    width: 4.15rem;
    height: 4.15rem;
    min-width: 4.15rem;
    min-height: 4.15rem;
    box-shadow: 0 8px 14px rgba(0, 0, 0, 0.22);
    opacity: 0.9;
  }

  #btn-horn {
    width: 3.55rem;
    height: 3.55rem;
    min-width: 3.55rem;
    min-height: 3.55rem;
    box-shadow: 0 8px 14px rgba(0, 0, 0, 0.24);
  }

  #btn-accelerate {
    background-size: cover;
  }

  #hud {
    font-size: 1.05em;
  }
}
