
/****************************************/
/* common styles used for v1 through v4 */
/****************************************/

body          { font-family: Arial, Helvetica, sans-serif; background-color: #111; color: #ccc; }
#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 #444; box-shadow: 0 0 5px black; }
#racer        { position: relative; z-index: 0; width: 1000px; height: 750px; margin-left: 0; border: 2px solid black; }
#canvas       { position: absolute; z-index: 0; width: 1000px; height: 750px; z-index: 0; background-color: #000000; }
#mute         { background-position:   0px 0px; width: 32px; height: 32px; background: url(images/mute.png); display: inline-block; cursor: pointer; position: absolute; margin-left: 0; }
#mute.on      { background-position: -32px 0px; }

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

#hud                   { position: absolute; z-index: 1; width: 1000px; padding: 5px 0; font-family: 'VT323', monospace; font-size: 1.5em; text-transform: uppercase; background-color: #2a7d7d; color: #fff; border-bottom: 2px solid #1a5555; box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; display: flex; align-items: center; justify-content: flex-end; }
#hud .hud              { background-color: #000; padding: 2px 4px; border: none; margin: 0 3px; transition-property: background-color; transition-duration: 2s; -webkit-transition-property: background-color; -webkit-transition-duration: 2s; }
#hud #speed            { position: absolute; left: 50%; transform: translateX(-50%); }
#hud #current_lap_time { }
#hud #last_lap_time    { display: none; }
#hud #fast_lap_time    { display: none; position: absolute; left: 50%; transform: translateX(-50%); transition-property: background-color; transition-duration: 2s; -webkit-transition-property: background-color; -webkit-transition-duration: 2s; }
#hud .value            { color: #fff; font-weight: bold; }
#hud .fastest          { background-color: rgba(255,215,0,0.5); }
#hint {
  position: absolute;
  top: 15%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  color: #fff;
  font-family: 'VT323', monospace;
  font-size: 2.5em;
  text-transform: uppercase;
  pointer-events: none;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 1s;
}
#about {
  font-size: 0.8em;
  color: #888;
  margin-top: 40px;
}
#about summary {
  cursor: pointer;
  user-select: none;
  color: #aaa;
}
#about summary:hover {
  color: #fff;
}
#about p {
  margin: 4px 0 0 0;
  color: #888;
}
#about a {
  color: #aaa;
}
#about a:hover {
  color: #fff;
}

/****************************************/
/* touch controls (only used in v4)     */
/****************************************/

#touch-controls {
  display: none;
  width: 100%;
  z-index: 2;
  pointer-events: none;
}.touch-btn {
  pointer-events: auto;
  position: absolute;
  bottom: 0;
  width: 90px;
  height: 90px;
  border: none;
  outline: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}

.touch-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.touch-btn:active, .touch-btn.pressed {
  background: none;
}

.touch-btn-left  { left: 20px; }
.touch-btn-right { right: 20px; }

/****************************************/
/* mobile responsive layout             */
/****************************************/

@media (max-width: 768px) and (pointer: coarse) {
  /* Hide desktop UI */
  #controls, #instructions { display: none !important; }
  #mute { display: none; }

  /* Body becomes flex container to center game */
  body {
    margin: 0;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #000;
  }

  /* Main game container - maintain 4:3 aspect ratio */
  #racer {
    margin: 0;
    width: 100vw;
    max-width: 100vw;
    max-height: 75vh;        /* Leave space for touch controls */
    aspect-ratio: 4 / 3;     /* Modern CSS property */
    border: none;
    position: relative;
    height: auto;
  }

  /* Fallback for browsers without aspect-ratio support (Safari <15) */
  @supports not (aspect-ratio: 4 / 3) {
    #racer {
      height: calc(100vw * 0.75);  /* 4:3 = 75% height */
      max-height: 75vh;
    }
  }

  /* Canvas fills the racer container */
  #canvas {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: #000000;
  }

  /* HUD stays at top */
  #hud {
    width: 100%;
    font-size: 1.2em;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
  }

  /* Touch controls flow directly below game canvas */
  #touch-controls {
    position: relative;
    width: 100vw;
    height: 120px;
    z-index: 2;
    pointer-events: none;
  }

  /* Adjust button bottom margin */
  .touch-btn {
    bottom: 10px;  /* Margin from viewport bottom */
  }

  /* Safe area support for notched devices (iPhone X+) */
  @supports (padding: env(safe-area-inset-bottom)) {
    .touch-btn {
      bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .touch-btn-left  {
      left: calc(20px + env(safe-area-inset-left));
    }

    .touch-btn-right {
      right: calc(20px + env(safe-area-inset-right));
    }
  }
}
