body {
  background: #111
    repeating-linear-gradient(45deg, #111 0, #111 12px, #0f0f0f 12px, #0f0f0f 24px);
  margin: 0;
  padding: 0 0 24px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

:root {
  --game-area-width: 800px;
  --game-area-height: 400px;
  --game-scale: 1;
  --page-padding: 12px;
}

#HeaderWrapper {
  position: relative;
  width: 100%;
  margin: 18px auto 6px;
  padding: 0 var(--page-padding);
  box-sizing: border-box;
}

h1 {
  color: white;
  margin: 0;
  text-align: center;
  font-size: 34px;
  letter-spacing: 0.5px;
}

.Byline {
  position: absolute;
  top: 0;
  left: 0;
  font-weight: 700;
  font-size: 18px;
  text-shadow: 3px 3px 3px #666;
  margin: 0;
  padding: 0;
  color: #ffe83b;
  transform: rotate(90deg);
  transform-origin: left top 0;
}

.Subheading {
  color: #ffe83b;
  font-weight: 700;
  margin: 2px auto 6px;
  font-size: 14px;
  text-align: center;
  max-width: 760px;
}

.LevelTabs {
  margin: 2px auto -2px;
  width: 100%;
  padding: 0 var(--page-padding);
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 6px;
}

.LevelTabs button {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  color: #444;
  background: repeating-linear-gradient(0deg, silver 30px, white 60px);
  border: 2px solid #000;
  padding: 2px 7px 0;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  cursor: pointer;
}

.LevelTabs button.ThisOne {
  color: #d40000;
  background: #d8d8d8;
  border-bottom: 0;
  font-weight: 700;
}

#Hud {
  width: 100%;
  margin: 0 auto 8px;
  display: grid;
  grid-template-columns: 70px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 0 var(--page-padding);
  box-sizing: border-box;
}

#Timer {
  font-variant-numeric: tabular-nums;
  color: #fff;
  font-weight: 700;
  justify-self: end;
}

#HudCenter {
  position: relative;
  display: grid;
  grid-auto-rows: min-content;
  gap: 2px;
}

#Selection {
  color: #fff;
  font-weight: 800;
}

#Status {
  color: #ddd;
}

#Status:empty {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

#Status:not(:empty) {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  overflow: visible;
  clip: auto;
  clip-path: none;
  white-space: normal;
}

#KeyboardHelp {
  color: #bbb;
  font-size: 12px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

#KeyboardHelp kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-bottom-color: rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 11px;
}

#HudButtons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

#HudButtons button {
  margin: 0;
  padding: 6px 10px;
  font-weight: 700;
}

#ContainerWrap {
  width: calc(var(--game-area-width) * var(--game-scale));
  height: calc(var(--game-area-height) * var(--game-scale));
  margin: 0 auto 10px;
}

#Container {
  position: relative;
  width: var(--game-area-width);
  height: var(--game-area-height);
  border: 4px solid black;
  border-top: 1px solid gray;
  background-color: white;
  overflow: hidden;
  transform: scale(var(--game-scale));
  transform-origin: top left;
}

#TrackSvg {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#PiecesLayer {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#EffectsLayer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

#OverlayLayer {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  place-items: center;
  background: rgba(0, 0, 0, 0.25);
}

#OverlayLayer.Show {
  display: grid;
}

.WinPrompt {
  max-width: calc(100% - 24px);
  padding: 14px 16px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.75);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  text-align: center;
}

.WinPromptTitle {
  font-weight: 900;
  font-size: 18px;
  margin-bottom: 6px;
}

.WinPromptBody {
  color: rgba(255, 255, 255, 0.85);
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 10px;
}

.WinPrompt button {
  padding: 8px 12px;
  font-weight: 800;
  border: 2px solid #000;
  background: #ffe83b;
  cursor: pointer;
}

.Tram {
  position: absolute;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  border-radius: 20px;
  border: 3px solid black;
  z-index: 100;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  user-select: none;
}

.Destination {
  position: absolute;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  border-radius: 20px;
  border: 3px dashed black;
  opacity: 0.5;
  z-index: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  user-select: none;
}

.TramLabel,
.DestinationLabel {
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}

.TramName,
.DestinationName {
  display: none;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  opacity: 0.95;
}

body.ShowNames .TramName,
body.ShowNames .DestinationName {
  display: block;
}

.CollisionMarker {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 999px;
  border: 5px solid #d40000;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.7) inset;
  transform: translate(-50%, -50%);
  animation: pop 700ms ease-out forwards;
}

@keyframes pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.6);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.25);
  }
}

#Controls {
  margin: auto;
  width: calc(var(--game-area-width) * var(--game-scale));
  max-width: 100%;
  box-sizing: border-box;
  border: 2px solid gray;
  background-color: #ffff99;
  text-align: center;
  padding: 10px 0 16px;
}

#Controls hr {
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.2);
  margin: 10px 18px;
}

@media (max-width: 520px) {
  :root {
    --page-padding: 0px;
  }

  body {
    overflow-x: hidden;
  }

  .Byline {
    display: none;
  }

  #HeaderWrapper {
    margin-top: 12px;
  }

  #Hud {
    padding-left: 0;
    padding-right: 0;
    grid-template-columns: 56px 1fr auto;
    gap: 6px;
  }

  .LevelTabs {
    padding-left: 0;
    padding-right: 0;
  }

  .LevelTabs button {
    font-size: 13px;
    padding: 2px 6px 0;
  }

  #Controls {
    padding: 8px 0 12px;
  }

  #PointControls button,
  #TramControls button {
    margin: 4px 3px;
    font-size: 14px;
    padding: 5px 8px;
  }
}

#PointControls button,
#TramControls button {
  margin: 6px 4px;
  font-size: 16px;
  font-weight: 800;
  padding: 6px 10px;
}

.KeyFlash {
  animation: keyflash 220ms ease-out;
}

@keyframes keyflash {
  0% {
    transform: translateY(0);
    filter: brightness(1);
  }
  35% {
    transform: translateY(-1px);
    filter: brightness(1.2);
  }
  100% {
    transform: translateY(0);
    filter: brightness(1);
  }
}

.TramFlash {
  animation: tramflash 220ms ease-out;
}

@keyframes tramflash {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }
  35% {
    transform: scale(1.05);
    filter: brightness(1.15);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

.TramGroup {
  display: inline-flex;
  align-items: center;
  margin: 6px 8px;
  gap: 6px;
}

.PreLabel {
  display: inline-block;
  width: 62px;
  text-align: right;
  font-weight: 800;
}

.But1,
#Tram1,
#Destination1 {
  background-color: lime;
}
.But2,
#Tram2,
#Destination2 {
  background-color: red;
  color: white;
}
.But3,
#Tram3,
#Destination3 {
  background-color: blue;
  color: white;
}
.But4,
#Tram4,
#Destination4 {
  background-color: yellow;
}
.But5,
#Tram5,
#Destination5 {
  background-color: green;
  color: white;
}
.But6,
#Tram6,
#Destination6 {
  background-color: purple;
  color: white;
}
.But7,
#Tram7,
#Destination7 {
  background-color: orange;
  color: white;
}
.But8,
#Tram8,
#Destination8 {
  background-color: grey;
  color: white;
}

.SelectedTram {
  box-shadow: 0 0 0 3px rgba(0, 140, 255, 0.95), 0 0 0 6px rgba(255, 255, 255, 0.8);
}

#Footer {
  width: 100%;
  padding: 10px var(--page-padding) 0;
  box-sizing: border-box;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

#Footer a {
  color: #ffe83b;
}
